ECCE @ EIC Software
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
G4VUserMPIrunMerger.hh
Go to the documentation of this file. Or view the newest version in sPHENIX GitHub for file G4VUserMPIrunMerger.hh
1 //
2 // ********************************************************************
3 // * License and Disclaimer *
4 // * *
5 // * The Geant4 software is copyright of the Copyright Holders of *
6 // * the Geant4 Collaboration. It is provided under the terms and *
7 // * conditions of the Geant4 Software License, included in the file *
8 // * LICENSE and available at http://cern.ch/geant4/license . These *
9 // * include a list of copyright holders. *
10 // * *
11 // * Neither the authors of this software system, nor their employing *
12 // * institutes,nor the agencies providing financial support for this *
13 // * work make any representation or warranty, express or implied, *
14 // * regarding this software system or assume any liability for its *
15 // * use. Please see the license in the file LICENSE and URL above *
16 // * for the full disclaimer and the limitation of liability. *
17 // * *
18 // * This code implementation is the result of the scientific and *
19 // * technical work of the GEANT4 collaboration. *
20 // * By using, copying, modifying or distributing the software (or *
21 // * any work based on the software) you agree to acknowledge its *
22 // * use in resulting scientific publications, and indicate your *
23 // * acceptance of all terms of the Geant4 Software license. *
24 // ********************************************************************
25 //
26 #ifndef G4MPIRUNMERGER_HH
27 #define G4MPIRUNMERGER_HH
28 #include "G4Run.hh"
29 #include <mpi.h>
30 #include "G4MPImanager.hh"
31 
33 public:
35  G4VUserMPIrunMerger( const G4Run* aRun ,
36  G4int destination = G4MPImanager::kRANK_MASTER ,
37  G4int verbosity = 0);
39  void SetRun( G4Run* r ) { run = r; }
41  void SetVerbosity( G4int ver ) { verbose = ver; }
42 
43  virtual void Merge();
44 
45 protected:
46  virtual void Pack() = 0;
47  virtual G4Run* UnPack() = 0;
48 
49  void InputUserData( /*const*/ void* input_data ,const MPI::Datatype& dt, int count) {
50  input_userdata.push_back( const_registered_data{input_data,dt,count} );
51  }
52  void OutputUserData( void* input_data ,const MPI::Datatype& dt, int count) {
53  output_userdata.push_back( registered_data{input_data,dt,count} );
54  }
55 
56  // void GetUserData(void* output_data,const MPI::Datatype& dt, int count);
57 
58  void SetupOutputBuffer(char* buff, G4int size, G4int position) {
59  outputBuffer = buff;
60  outputBufferSize=size;
62  }
63  void DestroyBuffer() {
64  delete[] outputBuffer;
65  outputBuffer = nullptr;
68  ownsBuffer = false;
69  }
70 
72  char* GetBuffer() const { return outputBuffer; }
73  G4int GetBufferSize() const { return outputBufferSize; }
74 
75  void Send(const unsigned int destination);
76  void Receive(const unsigned int source);
77 private:
78  char* outputBuffer;
82  unsigned int destinationRank;
84  unsigned int commSize;
85  MPI::Intracomm COMM_G4COMMAND_;
87  long bytesSent;
88 
89  //Input data to send (read-only)
93  //const_registered_data(const_registered_data&&) = default;
94  //const_registered_data& operator=(const_registered_data&&) = default;
95  /*const*/ void* p_data;
96  /*const*/ MPI::Datatype dt;
97  /*const*/ int count;
98  };
99  std::vector<const_registered_data> input_userdata;
100 
101  //Output data
103  registered_data(const registered_data&) = default;
104  registered_data& operator=(const registered_data&) = default;
105  void* p_data;
106  /*const*/ MPI::Datatype dt;
107  /*const*/ int count;
108  };
109  std::vector<registered_data> output_userdata;
110 
111 };
112 
113 
114 #endif //G4MPIRUNMERGER_HH
115