31 #ifndef G4MPIToolsManager_h
32 #define G4MPIToolsManager_h 1
38 #include <tools/impi_world>
39 #include <tools/histo/hmpi>
47 tools::histo::hmpi* hmpi)
55 const std::vector<G4HnInformation*>& hnVector);
60 const std::vector<T*>& htVector,
61 const std::vector<G4HnInformation*>& hnVector);
65 const std::vector<T*>& htVector,
66 const std::vector<G4HnInformation*>& hnVector);
78 const std::vector<T*>& htVector,
79 const std::vector<G4HnInformation*>& hnVector)
85 fHmpi->beg_send(nofActiveT);
88 for (
G4int i=0; i<
G4int(htVector.size()); ++i ) {
90 auto info = hnVector[i];
94 auto ht = htVector[i];
95 auto result =
fHmpi->pack(*ht);
96 finalResult = result && finalResult;
102 description <<
" Rank: " <<
fHmpi->rank() <<
" : can't send histos.";
112 template <
typename T>
114 const std::vector<T*>& htVector,
115 const std::vector<G4HnInformation*>& hnVector)
122 <<
" Failed to get MPI commander size." <<
G4endl
123 <<
" Merging will not be performed.";
130 for (
G4int srank = 0; srank < commSize; ++srank) {
133 if ( srank ==
fHmpi->rank() )
continue;
137 using class_pointer = std::pair<std::string,void*>;
138 std::vector<class_pointer> hs;
139 if ( !
fHmpi->wait_histos(srank, hs) ) {
141 description <<
" wait_histos from " << srank <<
" : failed.";
148 if (
G4int(hs.size()) != nofActiveT ) {
150 description <<
" srank: " << srank <<
" : got " << hs.size() <<
" objects, "
151 <<
"while " << nofActiveT <<
" were exepected." <<
G4endl;
159 for (
G4int i=0; i<
G4int(htVector.size()); ++i ) {
161 auto info = hnVector[i];
164 auto ht = htVector[i];
165 auto newHt =
static_cast<T*
>(hs[counter++].second);
174 template <
typename T>
176 const std::vector<G4HnInformation*>& hnVector)
178 if ( ! htVector.size() )
return true;
181 G4int nofActiveT = 0;
184 for (
G4int i=0; i<
G4int(htVector.size()); ++i ) {
185 auto activation = hnVector[i]->GetActivation();
186 if ( activation ) ++nofActiveT;
189 nofActiveT =
G4int(htVector.size());
192 if ( ! nofActiveT )
return true;
195 if ( !
fHmpi->comm_rank(commRank) ) {
198 <<
" Failed to get MPI commander rank." <<
G4endl
199 <<
" Merging will not be performed.";
205 G4bool finalResult =
true;
207 if ( commRank !=
fHmpi->rank() ) {
212 description <<
"on rank " << commRank
213 <<
" destination rank: " <<
fHmpi->rank();
218 auto result =
Send(nofActiveT, htVector, hnVector);
220 finalResult = result && finalResult;
225 description <<
"on rank " << commRank
226 <<
" destination rank: " <<
fHmpi->rank();
236 description <<
"on rank " << commRank
237 <<
" destination rank: " <<
fHmpi->rank();
242 auto result =
Receive(nofActiveT, htVector, hnVector);
244 finalResult = result && finalResult;
249 description <<
"on rank " << commRank
250 <<
" destination rank: " <<
fHmpi->rank();