Loading...
Searching...
No Matches
Typedefs | Functions
G4mpi Namespace Reference

Typedefs

typedef unsigned int rank_t
 
typedef std::pair< rank_t, rank_tcouple_t
 
typedef std::map< int, std::vector< couple_t > > commMap_t
 
typedef std::function< void(std::function< void(unsigned int)>, std::function< void(unsigned int)>, std::function< void(void)>, unsigned int, unsigned int)> mergerHandler_t
 

Functions

commMap_t buildCommunicationMap (std::vector< rank_t > &input)
 
void Merge (std::function< void(unsigned int)> senderF, std::function< void(unsigned int)> receiverF, std::function< void(void)> barrierF, unsigned int commSize, unsigned int myrank)
 

Typedef Documentation

◆ rank_t

typedef unsigned int G4mpi::rank_t

Definition at line 45 of file G4MPIutils.hh.

◆ couple_t

typedef std::pair<rank_t,rank_t> G4mpi::couple_t

Definition at line 47 of file G4MPIutils.hh.

◆ commMap_t

typedef std::map<int,std::vector<couple_t> > G4mpi::commMap_t

Definition at line 50 of file G4MPIutils.hh.

◆ mergerHandler_t

typedef std::function<void(std::function<void(unsigned int)>, std::function<void(unsigned int)>, std::function<void(void)>, unsigned int, unsigned int)> G4mpi::mergerHandler_t

Definition at line 93 of file G4MPIutils.hh.

Function Documentation

◆ buildCommunicationMap()

commMap_t G4mpi::buildCommunicationMap ( std::vector< rank_t > &  input)

◆ Merge()

void G4mpi::Merge ( std::function< void(unsigned int)>  senderF,
std::function< void(unsigned int)>  receiverF,
std::function< void(void)>  barrierF,
unsigned int  commSize,
unsigned int  myrank 
)

Definition at line 161 of file G4MPIutils.cc.

165 {
166 //Optimize communications between ranks
167 std::vector<G4mpi::rank_t> ranks(commSize);
168 std::iota(ranks.begin(),ranks.end(),0); //{0,1,2,3,...}
169 auto comms = G4mpi::buildCommunicationMap(ranks);
170 //Loop on cycles of communications
171 for ( const auto& cycle : comms ) {
172 //Each cycle is a set of communications between ranks, it is guarantted that
173 //each rank participate in one and only one communication for each cycle
174 for (const auto& pattern : cycle.second ) {
175 //pattern is a couple: sender,receiver
176 if ( myrank == pattern.first ) {
177 //Send to destination
178 senderF(pattern.second);
179 }
180 else if ( myrank == pattern.second ) {
181 //Receive from source
182 receiverF(pattern.first);
183 }
184 }
185 //Important: Wait for this cycle to end before going to the next, even if this rank
186 //did not do anything
187 //This is needed to be sure that the redcutions are done correctly
188 barrierF();
189 }
190}
commMap_t buildCommunicationMap(std::vector< rank_t > &input)

Applications | User Support | Publications | Collaboration