Commit a72df4ea authored by Philipp Samfaß's avatar Philipp Samfaß
Browse files

added runtime variable to assign world ranks in a round robin fashion

Example:
world rank 0 ->  team 0, rank 0
world rank 1 ->  team 1, rank 0
world rank 2 ->  team 0, rank 1
world rank 3 ->  team 1, rank 1
parent 5e73318f
......@@ -25,6 +25,8 @@ static int teamRank;
static int teamSize;
static int numTeams;
static bool assignConsecutiveRanksRR = false;
static MPI_Comm TMPI_COMM_TEAM;
MPI_Comm TMPI_COMM_DUP;
static MPI_Comm TMPI_COMM_INTER_TEAM;
......@@ -39,7 +41,13 @@ int initialiseTMPI( MPI_Comm comm) {
PMPI_Comm_rank(comm, &worldRank);
teamSize = worldSize / numTeams;
int color = worldRank / teamSize;
int color;
if(assignConsecutiveRanksRR) {
color = worldRank % numTeams;
}
else {
color = worldRank / teamSize;
}
PMPI_Comm_dup(comm, &TMPI_COMM_DUP);
......@@ -95,7 +103,12 @@ int getTeamSize() {
}
int getTeam() {
return getWorldRank() / getTeamSize();
if(assignConsecutiveRanksRR) {
return getWorldRank() % getTeamSize();
}
else {
return getWorldRank() / getTeamSize();
}
}
int getNumberOfTeams() {
......@@ -173,17 +186,30 @@ void outputEnvironment(){
void setEnvironment() {
std::string env(getEnvString("TEAMS"));
numTeams = env.empty() ? 2 : std::stoi(env);
std::string env_rr(getEnvString("ASSIGN_RR"));
assignConsecutiveRanksRR = env_rr.empty() ? false : true;
}
int mapRankToTeamNumber(int rank) {
return rank / getTeamSize();
if(assignConsecutiveRanksRR) {
return rank % getTeamSize();
}
else {
return rank / getTeamSize();
}
}
int mapWorldToTeamRank(int rank) {
if (rank == MPI_ANY_SOURCE) {
return MPI_ANY_SOURCE;
} else {
return rank % getTeamSize();
if(assignConsecutiveRanksRR) {
return rank / getNumberOfTeams();
}
else {
return rank % getTeamSize();
}
}
}
......@@ -192,7 +218,12 @@ int mapTeamToWorldRank(int rank, int team) {
return MPI_ANY_SOURCE;
}
return rank + team * getTeamSize();
if(assignConsecutiveRanksRR) {
return rank * getNumberOfTeams() + team;
}
else {
return rank + team * getTeamSize();
}
}
int translateRank(MPI_Comm srcComm, int srcRank, MPI_Comm destComm) {
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment