Import Geant4 10.2.0 source tree
This commit is contained in:
@@ -23,41 +23,26 @@
|
||||
// * acceptance of all terms of the Geant4 Software license. *
|
||||
// ********************************************************************
|
||||
//
|
||||
#ifndef G4MPIRUNMERGER_HH
|
||||
#define G4MPIRUNMERGER_HH
|
||||
#ifndef G4MPIRUNMERGER_HH_
|
||||
#define G4MPIRUNMERGER_HH_
|
||||
|
||||
#include "G4VUserMPIrunMerger.hh"
|
||||
#include "G4Run.hh"
|
||||
#include <mpi.h>
|
||||
#include "G4MPImanager.hh"
|
||||
|
||||
class G4MPIRunMerger {
|
||||
//MPI Merger for default G4Run class
|
||||
|
||||
class G4MPIrunMerger : public G4VUserMPIrunMerger {
|
||||
public:
|
||||
G4MPIRunMerger( const G4Run* aRun ,
|
||||
G4int destination = G4MPImanager::kRANK_MASTER ,
|
||||
G4int verbosity = 0);
|
||||
virtual ~G4MPIRunMerger() {}
|
||||
void SetRun( G4Run* r ) { run = r; }
|
||||
const G4Run* GetRun() const { return run; }
|
||||
void SetDestinationRank( G4int i ) { destinationRank = i; }
|
||||
G4int GetDestinationRank() const { return destinationRank; }
|
||||
G4int GetCommSize() const { return commSize; }
|
||||
virtual void Merge();
|
||||
void SetVerbosity( G4int ver ) { verbose = ver; }
|
||||
G4int GetVerbosity() const { return verbose; }
|
||||
G4MPIrunMerger() : G4VUserMPIrunMerger() {}
|
||||
G4MPIrunMerger(const G4Run* ar,
|
||||
G4int destination = G4MPImanager::kRANK_MASTER,
|
||||
G4int verboose = 0 ) :
|
||||
G4VUserMPIrunMerger(ar,destination,verboose) {}
|
||||
protected:
|
||||
virtual void Send();
|
||||
virtual void Receive(G4int rank);
|
||||
|
||||
void SendDouble( G4double* val , G4int size=1);
|
||||
void SendInt( G4int* val , G4int size=1);
|
||||
void ReceiveDouble( G4int rank , G4double* val , G4int size=1);
|
||||
void ReceiveInt(G4int rank , G4int* val, G4int size=1);
|
||||
G4int destinationRank;
|
||||
G4Run* run;
|
||||
G4int commSize;
|
||||
MPI::Intracomm COMM_G4COMMAND_;
|
||||
G4int verbose;
|
||||
|
||||
void Pack() {/*nothing do to*/}
|
||||
G4Run* UnPack() { return new G4Run; }
|
||||
};
|
||||
|
||||
#endif //G4MPIRUNMERGER_HH
|
||||
|
||||
|
||||
#endif /* G4MPIRUNMERGER_HH_ */
|
||||
|
||||
@@ -27,50 +27,76 @@
|
||||
#define G4MPISCORERMERGER_HH
|
||||
#include "G4ScoringManager.hh"
|
||||
#include <vector>
|
||||
#include <memory>
|
||||
#include <utility>
|
||||
#include <mpi.h>
|
||||
#include "G4MPImanager.hh"
|
||||
|
||||
class G4MPIScorerMerger {
|
||||
typedef G4THitsMap<G4double> HitMap;
|
||||
|
||||
class G4MPIscorerMerger {
|
||||
public:
|
||||
G4MPIScorerMerger( G4ScoringManager* mgr,
|
||||
G4MPIscorerMerger();
|
||||
G4MPIscorerMerger( G4ScoringManager* mgr,
|
||||
G4int destination = G4MPImanager::kRANK_MASTER,
|
||||
G4int verbosity = 0 );
|
||||
virtual ~G4MPIScorerMerger() { clear(); }
|
||||
virtual ~G4MPIscorerMerger();
|
||||
|
||||
//Get/set methods
|
||||
void SetDestinationRank( G4int i ) { destinationRank = i; }
|
||||
G4int GetDestinationRank() const { return destinationRank; }
|
||||
void SetScoringManager( G4ScoringManager* mgr ) { scoringManager = mgr; }
|
||||
G4ScoringManager* GetScoringManager() const { return scoringManager; }
|
||||
G4int GetCommSize() const { return commSize; }
|
||||
virtual void Merge();
|
||||
void SetVerbosity( G4int ver ) { verbose = ver; }
|
||||
G4int GetVerbosity() const { return verbose; }
|
||||
|
||||
//Main Interface: call this method to merge all results to rank0
|
||||
void Merge();
|
||||
|
||||
protected:
|
||||
//Internal MPI-friendly format
|
||||
//for a single MeshScoreMap
|
||||
struct convMap_t {
|
||||
G4String name;
|
||||
G4int numElems;
|
||||
G4int* indexes;
|
||||
G4double* values;
|
||||
};
|
||||
virtual convMap_t* convertMap( const G4String& mapName ,
|
||||
G4THitsMap<double>* map ) const;
|
||||
virtual void convertMesh( const G4VScoringMesh* mesh );
|
||||
void clear();
|
||||
std::vector<convMap_t*> convertedMesh;
|
||||
G4int meshID;
|
||||
void SetupOutputBuffer(char* buff, G4int size, G4int position) {
|
||||
outputBuffer = buff;
|
||||
outputBufferSize=size;
|
||||
outputBufferPosition=position;
|
||||
}
|
||||
void DestroyBuffer() {
|
||||
delete[] outputBuffer;
|
||||
outputBuffer = nullptr;
|
||||
outputBufferSize=0;
|
||||
outputBufferPosition=0;
|
||||
ownsBuffer = false;
|
||||
}
|
||||
|
||||
//! Pack all meshes into buffer
|
||||
void Pack(const G4ScoringManager*);
|
||||
void UnPackAndMerge(const G4ScoringManager*);
|
||||
|
||||
//! Pack a single mesh
|
||||
void Pack(const G4VScoringMesh*);
|
||||
void UnPackAndMerge(G4VScoringMesh* );
|
||||
|
||||
//! Pack a single score map
|
||||
void Pack(const HitMap*);
|
||||
HitMap* UnPackHitMap(const G4String& detName, const G4String& colName);
|
||||
|
||||
//Return size (in bytes) of the message needed to send the mesh
|
||||
G4int CalculatePackSize(const G4ScoringManager*) const;
|
||||
G4int CalculatePackSize(const G4VScoringMesh*) const;
|
||||
G4int CalculatePackSize(const HitMap*) const;
|
||||
|
||||
protected:
|
||||
void Send(const unsigned int destination);
|
||||
void Receive(const unsigned int source);
|
||||
|
||||
private:
|
||||
char* outputBuffer;
|
||||
G4int outputBufferSize;
|
||||
G4int outputBufferPosition;
|
||||
long bytesSent;
|
||||
G4bool ownsBuffer;
|
||||
G4ScoringManager* scoringManager;
|
||||
G4int commSize;
|
||||
G4int destinationRank;
|
||||
MPI::Intracomm COMM_G4COMMAND_;
|
||||
unsigned int commSize;
|
||||
unsigned int destinationRank;
|
||||
MPI::Intracomm comm;
|
||||
G4int verbose;
|
||||
|
||||
virtual void SendOneMesh();
|
||||
virtual void ReceiveOneMesh();
|
||||
virtual void MergeOneMesh();
|
||||
friend std::ostream& operator<<(std::ostream& os , const convMap_t& cnv );
|
||||
};
|
||||
|
||||
#endif //G4MPISCORERMERGER_HH
|
||||
|
||||
@@ -0,0 +1,58 @@
|
||||
//
|
||||
// ********************************************************************
|
||||
// * License and Disclaimer *
|
||||
// * *
|
||||
// * The Geant4 software is copyright of the Copyright Holders of *
|
||||
// * the Geant4 Collaboration. It is provided under the terms and *
|
||||
// * conditions of the Geant4 Software License, included in the file *
|
||||
// * LICENSE and available at http://cern.ch/geant4/license . These *
|
||||
// * include a list of copyright holders. *
|
||||
// * *
|
||||
// * Neither the authors of this software system, nor their employing *
|
||||
// * institutes,nor the agencies providing financial support for this *
|
||||
// * work make any representation or warranty, express or implied, *
|
||||
// * regarding this software system or assume any liability for its *
|
||||
// * use. Please see the license in the file LICENSE and URL above *
|
||||
// * for the full disclaimer and the limitation of liability. *
|
||||
// * *
|
||||
// * This code implementation is the result of the scientific and *
|
||||
// * technical work of the GEANT4 collaboration. *
|
||||
// * By using, copying, modifying or distributing the software (or *
|
||||
// * any work based on the software) you agree to acknowledge its *
|
||||
// * use in resulting scientific publications, and indicate your *
|
||||
// * acceptance of all terms of the Geant4 Software license. *
|
||||
// ********************************************************************
|
||||
//
|
||||
// Merge G4analysis histogram objects via MPI
|
||||
//
|
||||
// History:
|
||||
// Jun 27, 2015 : Ivana Hrivnacova - new implementation using g4analysis
|
||||
|
||||
#ifndef G4MPIHISTOMERGER_HH
|
||||
#define G4MPIHISTOMERGER_HH
|
||||
|
||||
#include "G4MPImanager.hh"
|
||||
|
||||
class G4VAnalysisManager;
|
||||
|
||||
class G4MPIhistoMerger {
|
||||
public:
|
||||
G4MPIhistoMerger();
|
||||
G4MPIhistoMerger(G4VAnalysisManager* mgr,
|
||||
G4int destination = G4MPImanager::kRANK_MASTER,
|
||||
G4int verbosity = 0);
|
||||
|
||||
//Get/set methods
|
||||
void SetDestinationRank( G4int i ) { destination = i; }
|
||||
void SetScoringManager( G4VAnalysisManager* mgr ) { manager = mgr; }
|
||||
void SetVerbosity( G4int ver ) { verboseLevel = ver; }
|
||||
|
||||
void Merge();
|
||||
|
||||
private:
|
||||
G4VAnalysisManager* manager;
|
||||
G4int destination;
|
||||
G4int verboseLevel;
|
||||
};
|
||||
|
||||
#endif //G4MPIHISTOMERGERNEW_HH
|
||||
@@ -51,7 +51,10 @@ public:
|
||||
kTAG_G4COMMAND = 100,
|
||||
kTAG_G4STATUS = 200,
|
||||
kTAG_G4SEED = 300,
|
||||
kTAG_DATA = 1000
|
||||
kTAG_DATA = 1000,
|
||||
kTAG_HISTO = 1001,
|
||||
kTAG_RUN = 1002,
|
||||
kTAG_CMDSCR = 1003
|
||||
};
|
||||
|
||||
G4MPImanager();
|
||||
@@ -104,6 +107,7 @@ public:
|
||||
// misc
|
||||
void ShowHelp() const;
|
||||
|
||||
//MPI::Intracomm* GetComm() const { return &COMM_G4COMMAND_; }
|
||||
private:
|
||||
DISALLOW_COPY_AND_ASSIGN(G4MPImanager);
|
||||
|
||||
|
||||
@@ -0,0 +1,96 @@
|
||||
//
|
||||
// ********************************************************************
|
||||
// * License and Disclaimer *
|
||||
// * *
|
||||
// * The Geant4 software is copyright of the Copyright Holders of *
|
||||
// * the Geant4 Collaboration. It is provided under the terms and *
|
||||
// * conditions of the Geant4 Software License, included in the file *
|
||||
// * LICENSE and available at http://cern.ch/geant4/license . These *
|
||||
// * include a list of copyright holders. *
|
||||
// * *
|
||||
// * Neither the authors of this software system, nor their employing *
|
||||
// * institutes,nor the agencies providing financial support for this *
|
||||
// * work make any representation or warranty, express or implied, *
|
||||
// * regarding this software system or assume any liability for its *
|
||||
// * use. Please see the license in the file LICENSE and URL above *
|
||||
// * for the full disclaimer and the limitation of liability. *
|
||||
// * *
|
||||
// * This code implementation is the result of the scientific and *
|
||||
// * technical work of the GEANT4 collaboration. *
|
||||
// * By using, copying, modifying or distributing the software (or *
|
||||
// * any work based on the software) you agree to acknowledge its *
|
||||
// * use in resulting scientific publications, and indicate your *
|
||||
// * acceptance of all terms of the Geant4 Software license. *
|
||||
// ********************************************************************
|
||||
//
|
||||
// Utility functions for MPI G4 interface
|
||||
#ifndef G4MPIUTILS_HH
|
||||
#define G4MPIUTILS_HH
|
||||
#include <map>
|
||||
#include <vector>
|
||||
#include <functional>
|
||||
#include <numeric>
|
||||
|
||||
//Namespace with some utility functions for G4 MPI integration.
|
||||
//Main utilities:
|
||||
// G4mpi::Merge(...) : Merge results via a semi-optimized communication
|
||||
// patterns between ranks. Note that this implementation
|
||||
// is not topology aware. This means that MPI_Reduce and
|
||||
// MPI_Gather are more performant. However if you cannot
|
||||
// implement an appropriate MPI reducer or you cannot efford
|
||||
// the memory overhead of Gather, this can be used instead of
|
||||
// p2p communications.
|
||||
namespace G4mpi {
|
||||
//Simple data type representing a rank
|
||||
typedef unsigned int rank_t;
|
||||
//A couple of sending/receiving ranks
|
||||
typedef std::pair<rank_t,rank_t> couple_t;
|
||||
//This map represent, for each cycle (key) a set of communications
|
||||
//pairs
|
||||
typedef std::map<int,std::vector<couple_t> > commMap_t;
|
||||
|
||||
//This function takes as input a vector of rank_t objects representing
|
||||
//a communication node identified by an ID (rank:int).
|
||||
//It returns a map of cycle:int -> vector<pairs<rank_t> >
|
||||
//Representing a sequence of communciation cycles. At each communication cycle
|
||||
//one or more p2p communications are established: in the pair the first element
|
||||
//is the sender and the second element of the pair is the receiver
|
||||
//At the end of the cycles all communications have been done to rank 0
|
||||
//For example with 4 nodes: [0,1,2,3] we have:
|
||||
// Cycle 0: (3->2),(1->0)
|
||||
// Cycle 1: (2->0)
|
||||
// With 5 nodes:
|
||||
// Cycle 0: (4->3),(2->1)
|
||||
// Cycle 1: (3->1)
|
||||
// Cycle 2: (1->0)
|
||||
// The algorithm can be used to implement a communication across mpi ranks
|
||||
// optimizing the network trafic. Each rank (the nodes) can send/receive to another node.
|
||||
// Once they have sent out the payload they become empty and non-active anymore.
|
||||
commMap_t buildCommunicationMap( std::vector<rank_t>& input );
|
||||
|
||||
//Performs merging to rank 0 using the provided sender, receiver and barrier functions.
|
||||
//CommSize is the size of the communicator and myrank is the rank of the caller
|
||||
//For example: assume a class UserMerger has two members Send(uint) and
|
||||
// Receive(uint) and we are using a MPI::Intracomm object as
|
||||
// communicator, then to use this function the ranks can:
|
||||
// using std::placeholers::_1;
|
||||
// std::function<void(unsigned int)> sender =
|
||||
// std::bind(&Merger::Send,&mergerInst,_1);
|
||||
// std::function<void(unsigned int)> receiver =
|
||||
// std::bind(&Merger::Receiver,&mergerInst,_1);
|
||||
// std::function<void(void)> barrier =
|
||||
// std::bind(&MPI::Intracomm::Barrier,&commInst);
|
||||
// G4mpi::Merge(sender,receiver,barrier,commSize,myrank);
|
||||
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);
|
||||
//Type representing a merging functions
|
||||
typedef std::function<void(std::function<void(unsigned int)>,
|
||||
std::function<void(unsigned int)>,
|
||||
std::function<void(void)>,
|
||||
unsigned int, unsigned int)>
|
||||
mergerHandler_t;
|
||||
}
|
||||
|
||||
#endif //G4MPIUTILS_HH
|
||||
@@ -0,0 +1,115 @@
|
||||
//
|
||||
// ********************************************************************
|
||||
// * License and Disclaimer *
|
||||
// * *
|
||||
// * The Geant4 software is copyright of the Copyright Holders of *
|
||||
// * the Geant4 Collaboration. It is provided under the terms and *
|
||||
// * conditions of the Geant4 Software License, included in the file *
|
||||
// * LICENSE and available at http://cern.ch/geant4/license . These *
|
||||
// * include a list of copyright holders. *
|
||||
// * *
|
||||
// * Neither the authors of this software system, nor their employing *
|
||||
// * institutes,nor the agencies providing financial support for this *
|
||||
// * work make any representation or warranty, express or implied, *
|
||||
// * regarding this software system or assume any liability for its *
|
||||
// * use. Please see the license in the file LICENSE and URL above *
|
||||
// * for the full disclaimer and the limitation of liability. *
|
||||
// * *
|
||||
// * This code implementation is the result of the scientific and *
|
||||
// * technical work of the GEANT4 collaboration. *
|
||||
// * By using, copying, modifying or distributing the software (or *
|
||||
// * any work based on the software) you agree to acknowledge its *
|
||||
// * use in resulting scientific publications, and indicate your *
|
||||
// * acceptance of all terms of the Geant4 Software license. *
|
||||
// ********************************************************************
|
||||
//
|
||||
#ifndef G4MPIRUNMERGER_HH
|
||||
#define G4MPIRUNMERGER_HH
|
||||
#include "G4Run.hh"
|
||||
#include <mpi.h>
|
||||
#include "G4MPImanager.hh"
|
||||
|
||||
class G4VUserMPIrunMerger {
|
||||
public:
|
||||
G4VUserMPIrunMerger();
|
||||
G4VUserMPIrunMerger( const G4Run* aRun ,
|
||||
G4int destination = G4MPImanager::kRANK_MASTER ,
|
||||
G4int verbosity = 0);
|
||||
virtual ~G4VUserMPIrunMerger() { if ( ownsBuffer) DestroyBuffer(); }
|
||||
void SetRun( G4Run* r ) { run = r; }
|
||||
void SetDestinationRank( G4int i ) { destinationRank = i; }
|
||||
void SetVerbosity( G4int ver ) { verbose = ver; }
|
||||
|
||||
virtual void Merge();
|
||||
|
||||
protected:
|
||||
virtual void Pack() = 0;
|
||||
virtual G4Run* UnPack() = 0;
|
||||
|
||||
void InputUserData( /*const*/ void* input_data ,const MPI::Datatype& dt, int count) {
|
||||
input_userdata.push_back( const_registered_data{input_data,dt,count} );
|
||||
}
|
||||
void OutputUserData( void* input_data ,const MPI::Datatype& dt, int count) {
|
||||
output_userdata.push_back( registered_data{input_data,dt,count} );
|
||||
}
|
||||
|
||||
// void GetUserData(void* output_data,const MPI::Datatype& dt, int count);
|
||||
|
||||
void SetupOutputBuffer(char* buff, G4int size, G4int position) {
|
||||
outputBuffer = buff;
|
||||
outputBufferSize=size;
|
||||
outputBufferPosition=position;
|
||||
}
|
||||
void DestroyBuffer() {
|
||||
delete[] outputBuffer;
|
||||
outputBuffer = nullptr;
|
||||
outputBufferSize=0;
|
||||
outputBufferPosition=0;
|
||||
ownsBuffer = false;
|
||||
}
|
||||
|
||||
G4int GetPosition() const { return outputBufferPosition; }
|
||||
char* GetBuffer() const { return outputBuffer; }
|
||||
G4int GetBufferSize() const { return outputBufferSize; }
|
||||
|
||||
void Send(const unsigned int destination);
|
||||
void Receive(const unsigned int source);
|
||||
private:
|
||||
char* outputBuffer;
|
||||
G4int outputBufferSize;
|
||||
G4int outputBufferPosition;
|
||||
G4bool ownsBuffer;
|
||||
unsigned int destinationRank;
|
||||
G4Run* run;
|
||||
unsigned int commSize;
|
||||
MPI::Intracomm COMM_G4COMMAND_;
|
||||
G4int verbose;
|
||||
long bytesSent;
|
||||
|
||||
//Input data to send (read-only)
|
||||
struct const_registered_data {
|
||||
const_registered_data(const const_registered_data&) = default;
|
||||
const_registered_data& operator=(const const_registered_data&) = default;
|
||||
//const_registered_data(const_registered_data&&) = default;
|
||||
//const_registered_data& operator=(const_registered_data&&) = default;
|
||||
/*const*/ void* p_data;
|
||||
/*const*/ MPI::Datatype dt;
|
||||
/*const*/ int count;
|
||||
};
|
||||
std::vector<const_registered_data> input_userdata;
|
||||
|
||||
//Output data
|
||||
struct registered_data {
|
||||
registered_data(const registered_data&) = default;
|
||||
registered_data& operator=(const registered_data&) = default;
|
||||
void* p_data;
|
||||
/*const*/ MPI::Datatype dt;
|
||||
/*const*/ int count;
|
||||
};
|
||||
std::vector<registered_data> output_userdata;
|
||||
|
||||
};
|
||||
|
||||
|
||||
#endif //G4MPIRUNMERGER_HH
|
||||
|
||||
Reference in New Issue
Block a user