Geant4  10.03.p02
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
G4VUserMPIrunMerger.hh
Go to the documentation of this file.
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);
38  virtual ~G4VUserMPIrunMerger() { if ( ownsBuffer) DestroyBuffer(); }
39  void SetRun( G4Run* r ) { run = r; }
40  void SetDestinationRank( G4int i ) { destinationRank = i; }
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;
61  outputBufferPosition=position;
62  }
63  void DestroyBuffer() {
64  delete[] outputBuffer;
65  outputBuffer = nullptr;
66  outputBufferSize=0;
67  outputBufferPosition=0;
68  ownsBuffer = false;
69  }
70 
71  G4int GetPosition() const { return outputBufferPosition; }
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;
79  G4int outputBufferSize;
80  G4int outputBufferPosition;
81  G4bool ownsBuffer;
82  unsigned int destinationRank;
83  G4Run* run;
84  unsigned int commSize;
85  MPI::Intracomm COMM_G4COMMAND_;
86  G4int verbose;
87  long bytesSent;
88 
89  //Input data to send (read-only)
90  struct const_registered_data {
91  const_registered_data(const const_registered_data&) = default;
92  const_registered_data& operator=(const const_registered_data&) = default;
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
102  struct registered_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 
void SetDestinationRank(G4int i)
G4int GetBufferSize() const
int G4int
Definition: G4Types.hh:78
char * GetBuffer() const
#define position
Definition: xmlparse.cc:622
MPI manager class.
bool G4bool
Definition: G4Types.hh:79
virtual void Pack()=0
virtual G4Run * UnPack()=0
Definition: G4Run.hh:46
void Send(const unsigned int destination)
void SetVerbosity(G4int ver)
void Receive(const unsigned int source)
void OutputUserData(void *input_data, const MPI::Datatype &dt, int count)
void SetupOutputBuffer(char *buff, G4int size, G4int position)
void InputUserData(void *input_data, const MPI::Datatype &dt, int count)
G4int GetPosition() const