Rank.h 2.16 KB
Newer Older
Ben Hazelwood's avatar
Ben Hazelwood committed
1
2
3
4
/*
 * RankOperations.h
 *
 *  Created on: 2 Mar 2018
5
 *      Author: Ben Hazelwood, Philipp Samfass
Ben Hazelwood's avatar
Ben Hazelwood committed
6
7
8
9
10
11
12
 */

#ifndef RANK_H_
#define RANK_H_

#include <mpi.h>
#include <string>
13
14
#include <stdint.h>
#include <limits.h>
Ben Hazelwood's avatar
Ben Hazelwood committed
15
16
17

#define MASTER 0

18
19
20
21
22
23
24
25
26
27
28
29
// From https://stackoverflow.com/questions/40807833/sending-size-t-type-data-with-mpi
#if SIZE_MAX == UCHAR_MAX
   #define TMPI_SIZE_T MPI_UNSIGNED_CHAR
#elif SIZE_MAX == USHRT_MAX
   #define TMPI_SIZE_T MPI_UNSIGNED_SHORT
#elif SIZE_MAX == UINT_MAX
   #define TMPI_SIZE_T MPI_UNSIGNED
#elif SIZE_MAX == ULONG_MAX
   #define TMPI_SIZE_T MPI_UNSIGNED_LONG
#elif SIZE_MAX == ULLONG_MAX
   #define TMPI_SIZE_T MPI_UNSIGNED_LONG_LONG
#else
Ben Hazelwood's avatar
Ben Hazelwood committed
30
   #error "Cannot decipher SIZE_MAX"
31
32
#endif

Ben Hazelwood's avatar
Ben Hazelwood committed
33
/* Split ranks into teams */
Ben Hazelwood's avatar
Ben Hazelwood committed
34
35
36
37
38
39
int initialiseTMPI();

int getWorldRank();

int getWorldSize();

Ben Hazelwood's avatar
Ben Hazelwood committed
40
/* Get the rank as seen by the application */
Ben Hazelwood's avatar
Ben Hazelwood committed
41
42
int getTeamRank();

Ben Hazelwood's avatar
Ben Hazelwood committed
43
/* Get the number of ranks as seen by the application */
Ben Hazelwood's avatar
Ben Hazelwood committed
44
45
int getTeamSize();

Ben Hazelwood's avatar
Ben Hazelwood committed
46
/* Also the number of replicas */
Ben Hazelwood's avatar
Ben Hazelwood committed
47
48
int getNumberOfTeams();

Ben Hazelwood's avatar
Ben Hazelwood committed
49
/* Return which team this rank belongs to */
Ben Hazelwood's avatar
Ben Hazelwood committed
50
51
int getTeam();

Ben Hazelwood's avatar
Ben Hazelwood committed
52
/* The communicator used by this team */
53
MPI_Comm getTeamComm(MPI_Comm comm);
Ben Hazelwood's avatar
Ben Hazelwood committed
54
55
int freeTeamComm();

56
57
MPI_Comm getTeamInterComm();

Ben Hazelwood's avatar
Ben Hazelwood committed
58
/* The duplicate MPI_COMM_WORLD used by the library*/
Ben Hazelwood's avatar
Ben Hazelwood committed
59
60
61
MPI_Comm getLibComm();
int freeLibComm();

Ben Hazelwood's avatar
Ben Hazelwood committed
62
/* Get the value of an environment variable (empty string if undefined) */
Ben Hazelwood's avatar
Ben Hazelwood committed
63
64
std::string getEnvString(std::string const& key);

Ben Hazelwood's avatar
Ben Hazelwood committed
65
/* Get the number of teams from environment  */
Ben Hazelwood's avatar
Ben Hazelwood committed
66
67
void setEnvironment();

Ben Hazelwood's avatar
Ben Hazelwood committed
68
/* Output team sizes and any timing inaccuracies between ranks */
Ben Hazelwood's avatar
Ben Hazelwood committed
69
70
void outputEnvironment();

Ben Hazelwood's avatar
Ben Hazelwood committed
71
/* Output the timing differences between replicas */
Ben Hazelwood's avatar
Ben Hazelwood committed
72
73
void outputTiming();

Ben Hazelwood's avatar
Ben Hazelwood committed
74
/* Decide whether data should be manually corrupted upon next heartbeat */
75
76
77
bool getShouldCorruptData();
void setShouldCorruptData(bool toggle);

Ben Hazelwood's avatar
Ben Hazelwood committed
78

Ben Hazelwood's avatar
Ben Hazelwood committed
79
80
81
82
83
84
int mapRankToTeamNumber(int rank);

int mapWorldToTeamRank(int rank);

int mapTeamToWorldRank(int rank, int r);

Ben Hazelwood's avatar
Ben Hazelwood committed
85
/* Alters the MPI_SOURCE member of MPI_Status to 0 <= r < team size */
Ben Hazelwood's avatar
Ben Hazelwood committed
86
87
void remapStatus(MPI_Status *status);

Ben Hazelwood's avatar
Ben Hazelwood committed
88
/* Barrier on team communicator */
Ben Hazelwood's avatar
Ben Hazelwood committed
89
int synchroniseRanksInTeam();
Ben Hazelwood's avatar
Ben Hazelwood committed
90
91

/* Barrier on all ranks (not called by application) */
Ben Hazelwood's avatar
Ben Hazelwood committed
92
93
94
int synchroniseRanksGlobally();


Ben Hazelwood's avatar
Ben Hazelwood committed
95

96
#endif /* RANK_H_ */