Geant4  10.02.p01
G4MPIscorerMerger.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 G4MPISCORERMERGER_HH
27 #define G4MPISCORERMERGER_HH
28 #include "G4ScoringManager.hh"
29 #include <vector>
30 #include <memory>
31 #include <utility>
32 #include <mpi.h>
33 #include "G4MPImanager.hh"
34 
36 
38 public:
41  G4int destination = G4MPImanager::kRANK_MASTER,
42  G4int verbosity = 0 );
43  virtual ~G4MPIscorerMerger();
44 
45  //Get/set methods
48  void SetVerbosity( G4int ver ) { verbose = ver; }
49 
50  //Main Interface: call this method to merge all results to rank0
51  void Merge();
52 
53 protected:
54  void SetupOutputBuffer(char* buff, G4int size, G4int position) {
55  outputBuffer = buff;
56  outputBufferSize=size;
58  }
59  void DestroyBuffer() {
60  delete[] outputBuffer;
61  outputBuffer = nullptr;
64  ownsBuffer = false;
65  }
66 
68  void Pack(const G4ScoringManager*);
69  void UnPackAndMerge(const G4ScoringManager*);
70 
72  void Pack(const G4VScoringMesh*);
74 
76  void Pack(const HitMap*);
77  HitMap* UnPackHitMap(const G4String& detName, const G4String& colName);
78 
79  //Return size (in bytes) of the message needed to send the mesh
82  G4int CalculatePackSize(const HitMap*) const;
83 
84 protected:
85  void Send(const unsigned int destination);
86  void Receive(const unsigned int source);
87 
88 private:
89  char* outputBuffer;
92  long bytesSent;
95  unsigned int commSize;
96  unsigned int destinationRank;
97  MPI::Intracomm comm;
99 
100 };
101 
102 #endif //G4MPISCORERMERGER_HH
103 
void Pack(const G4ScoringManager *)
Pack all meshes into buffer.
G4ScoringManager * scoringManager
unsigned int destinationRank
void UnPackAndMerge(const G4ScoringManager *)
int G4int
Definition: G4Types.hh:78
MPI::Intracomm comm
void Send(const unsigned int destination)
void Receive(const unsigned int source)
#define position
Definition: xmlparse.cc:622
MPI manager class.
HitMap * UnPackHitMap(const G4String &detName, const G4String &colName)
G4THitsMap< G4double > HitMap
bool G4bool
Definition: G4Types.hh:79
G4int CalculatePackSize(const G4ScoringManager *) const
virtual ~G4MPIscorerMerger()
void SetScoringManager(G4ScoringManager *mgr)
void SetVerbosity(G4int ver)
void SetupOutputBuffer(char *buff, G4int size, G4int position)
void SetDestinationRank(G4int i)