36 outputBuffer(nullptr),outputBufferSize(0),outputBufferPosition(0),
38 destinationRank(destination),
39 run(const_cast<
G4Run*>(aRun)),
44 #define DMSG( LVL , MSG ) { if ( verbose > LVL ) { G4cout << MSG << G4endl; } } 50 DMSG( 1 ,
"G4VUserMPIrunMerger::Send() : Sending a G4run (" 51 <<
run<<
") with "<<nevts<<
" events to: "<<destination);
57 G4int newbuffsize = 0;
59 newbuffsize += (el.dt.Get_size()*el.count);
61 char*
buffer =
new char[newbuffsize];
64 std::fill(buffer,buffer+newbuffsize,0);
71 #ifdef G4MPI_USE_MPI_PACK_NOT_CONST 72 MPI_Pack(const_cast<void*>(el.p_data),el.count,el.dt,
83 DMSG(2 ,
"G4VUserMPIrunMerger::Send() : Done ");
89 DMSG( 1 ,
"G4VUserMPIrunMerger::Receive(...) , this rank : " 90 <<MPI::COMM_WORLD.Get_rank()<<
" and receiving from : "<<source);
98 const G4int newbuffsize = status.Get_count(MPI::PACKED);
99 DMSG(2,
"Preparing to receive buffer of size: "<<newbuffsize);
102 DMSG(3,
"New larger buffer expected, resize");
105 buffer =
new char[newbuffsize];
108 std::fill(buffer,buffer+newbuffsize,0);
118 if ( aNewRun ==
nullptr ) aNewRun =
new G4Run;
139 DMSG(0,
"G4VUserMPIrunMerger::Merge called");
140 const unsigned int myrank = MPI::COMM_WORLD.Get_rank();
141 commSize = MPI::COMM_WORLD.Get_size();
143 DMSG(1,
"Comm world size is 1, nothing to do");
148 const G4double sttime = MPI::Wtime();
151 typedef std::function<void(unsigned int)> handler_t;
152 using std::placeholders::_1;
155 std::function<void(void)> barrier =
174 const G4double elapsed = MPI::Wtime() - sttime;
180 G4cout<<
"G4VUserMPIrunMerger::Merge() - data transfer performances: " 181 <<double(total)/1000./elapsed<<
" kB/s" 182 <<
" (Total Data Transfer= "<<double(total)/1000<<
" kB in " 183 <<elapsed<<
" s)."<<
G4endl;
189 DMSG(0,
"G4VUserMPIrunMerger::Merge done");
int MPI_Unpack(const void *, int, int *, void *, int, MPI_Datatype, MPI_Comm)
virtual void Merge(const G4Run *)
G4int outputBufferPosition
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)
G4GLOB_DLL std::ostream G4cout
MPI::Intracomm COMM_G4COMMAND_
int MPI_Pack(const void *, int, MPI_Datatype, void *, int, int *, MPI_Comm)
virtual G4Run * UnPack()=0
void Send(const unsigned int destination)
G4double total(Particle const *const p1, Particle const *const p2)
std::vector< const_registered_data > input_userdata
void Receive(const unsigned int source)
std::vector< registered_data > output_userdata
void OutputUserData(void *input_data, const MPI::Datatype &dt, int count)
virtual void RecordEvent(const G4Event *)
static G4String Status(G4StepStatus stps)
unsigned int destinationRank
G4int GetNumberOfEvent() const
void SetupOutputBuffer(char *buff, G4int size, G4int position)
void InputUserData(void *input_data, const MPI::Datatype &dt, int count)