Rank.h 2.31 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

33
34
extern MPI_Comm TMPI_COMM_DUP;

Ben Hazelwood's avatar
Ben Hazelwood committed
35
/* Split ranks into teams */
36
int initialiseTMPI(MPI_Comm comm);
Ben Hazelwood's avatar
Ben Hazelwood committed
37
38
39
40
41

int getWorldRank();

int getWorldSize();

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

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

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

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

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

58
59
MPI_Comm getTeamInterComm();

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

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

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

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

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

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

Ben Hazelwood's avatar
Ben Hazelwood committed
80

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

int mapWorldToTeamRank(int rank);

int mapTeamToWorldRank(int rank, int r);

Philipp Samfaß's avatar
Philipp Samfaß committed
87
88
89
90
int translateRank(int srcRank, MPI_Comm srcComm, MPI_Comm destComm);

int mapToWorldRank(int rank, MPI_Comm comm);

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

Ben Hazelwood's avatar
Ben Hazelwood committed
94
/* Barrier on team communicator */
Ben Hazelwood's avatar
Ben Hazelwood committed
95
int synchroniseRanksInTeam();
Ben Hazelwood's avatar
Ben Hazelwood committed
96
97

/* Barrier on all ranks (not called by application) */
Ben Hazelwood's avatar
Ben Hazelwood committed
98
99
100
int synchroniseRanksGlobally();


Ben Hazelwood's avatar
Ben Hazelwood committed
101

102
#endif /* RANK_H_ */