31#ifndef G4MPIToolsManager_h
32#define G4MPIToolsManager_h 1
38#include <tools/impi_world>
39#include <tools/histo/hmpi>
47 tools::histo::hmpi* hmpi)
48 : fState(state), fHmpi(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);
70 tools::histo::hmpi* fHmpi;
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];
91 if ( ( fState.
GetIsActivation() && ( ! info->GetActivation() ) ) )
continue;
94 auto ht = htVector[i];
95 auto result = fHmpi->pack(*ht);
96 finalResult = result && finalResult;
100 if ( ! fHmpi->send(fHmpi->rank()) ) {
102 description <<
" Rank: " << fHmpi->rank() <<
" : can't send histos.";
114 const std::vector<T*>& htVector,
115 const std::vector<G4HnInformation*>& hnVector)
118 G4bool result = fHmpi->comm_size(commSize);
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 expected." <<
G4endl;
159 for (
G4int i=0; i<
G4int(htVector.size()); ++i ) {
161 auto info = hnVector[i];
162 if ( ( fState.
GetIsActivation() && ( ! info->GetActivation() ) ) )
continue;
164 auto ht = htVector[i];
165 auto newHt =
static_cast<T*
>(hs[counter++].second);
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();
void G4Exception(const char *originOfException, const char *exceptionCode, G4ExceptionSeverity severity, const char *description)
std::ostringstream G4ExceptionDescription
const G4AnalysisVerbose * GetVerboseL3() const
const G4AnalysisVerbose * GetVerboseL1() const
G4bool GetIsActivation() const
const G4AnalysisVerbose * GetVerboseL4() const
void Message(const G4String &action, const G4String &object, const G4String &objectName, G4bool success=true) const