Import Geant4 11.3.0.beta source tree
This commit is contained in:
@@ -28,23 +28,25 @@
|
||||
#ifndef G4MPI_BATCH_H
|
||||
#define G4MPI_BATCH_H
|
||||
|
||||
#include <fstream>
|
||||
#include "G4VMPIsession.hh"
|
||||
|
||||
class G4MPIbatch : public G4VMPIsession {
|
||||
public:
|
||||
G4MPIbatch(const G4String& fname = "", G4bool qbatch = false);
|
||||
~G4MPIbatch();
|
||||
#include <fstream>
|
||||
|
||||
virtual G4UIsession* SessionStart();
|
||||
class G4MPIbatch : public G4VMPIsession
|
||||
{
|
||||
public:
|
||||
G4MPIbatch(const G4String& fname = "", G4bool qbatch = false);
|
||||
~G4MPIbatch();
|
||||
|
||||
protected:
|
||||
std::ifstream batch_stream_;
|
||||
G4bool is_opened_;
|
||||
G4bool is_batch_mode_;
|
||||
virtual G4UIsession* SessionStart();
|
||||
|
||||
// get a command from a batch script file
|
||||
G4String ReadCommand();
|
||||
protected:
|
||||
std::ifstream batch_stream_;
|
||||
G4bool is_opened_;
|
||||
G4bool is_batch_mode_;
|
||||
|
||||
// get a command from a batch script file
|
||||
G4String ReadCommand();
|
||||
};
|
||||
|
||||
#endif
|
||||
|
||||
@@ -33,20 +33,20 @@
|
||||
|
||||
#ifndef G4MPIEXTRAWORKER_HH
|
||||
|
||||
#include "G4VMPIextraWorker.hh"
|
||||
# include "G4VMPIextraWorker.hh"
|
||||
|
||||
class G4UserRunAction;
|
||||
|
||||
class G4MPIextraWorker : public G4VMPIextraWorker
|
||||
class G4MPIextraWorker : public G4VMPIextraWorker
|
||||
{
|
||||
public:
|
||||
G4MPIextraWorker(G4UserRunAction* runAction) : fRunAction(runAction) {}
|
||||
virtual ~G4MPIextraWorker() {}
|
||||
public:
|
||||
G4MPIextraWorker(G4UserRunAction* runAction) : fRunAction(runAction) {}
|
||||
virtual ~G4MPIextraWorker() {}
|
||||
|
||||
virtual void BeamOn();
|
||||
private:
|
||||
G4UserRunAction* fRunAction;
|
||||
virtual void BeamOn();
|
||||
|
||||
private:
|
||||
G4UserRunAction* fRunAction;
|
||||
};
|
||||
|
||||
#endif //G4MPIEXTRAWORKER_HH
|
||||
|
||||
#endif // G4MPIEXTRAWORKER_HH
|
||||
|
||||
@@ -35,24 +35,24 @@
|
||||
|
||||
class G4VAnalysisManager;
|
||||
|
||||
class G4MPIhistoMerger {
|
||||
public:
|
||||
G4MPIhistoMerger();
|
||||
G4MPIhistoMerger(G4VAnalysisManager* mgr,
|
||||
G4int destination = G4MPImanager::kRANK_MASTER,
|
||||
G4int verbosity = 0);
|
||||
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; }
|
||||
// Get/set methods
|
||||
void SetDestinationRank(G4int i) { destination = i; }
|
||||
void SetScoringManager(G4VAnalysisManager* mgr) { manager = mgr; }
|
||||
void SetVerbosity(G4int ver) { verboseLevel = ver; }
|
||||
|
||||
void Merge();
|
||||
void Merge();
|
||||
|
||||
private:
|
||||
G4VAnalysisManager* manager;
|
||||
G4int destination;
|
||||
G4int verboseLevel;
|
||||
private:
|
||||
G4VAnalysisManager* manager;
|
||||
G4int destination;
|
||||
G4int verboseLevel;
|
||||
};
|
||||
|
||||
#endif //G4MPIHISTOMERGERNEW_HH
|
||||
#endif // G4MPIHISTOMERGERNEW_HH
|
||||
|
||||
@@ -29,9 +29,11 @@
|
||||
#define G4MPI_MANAGER_H
|
||||
|
||||
#include "mpi.h"
|
||||
|
||||
#include "globals.hh"
|
||||
|
||||
#include <fstream>
|
||||
#include <pthread.h>
|
||||
#include "globals.hh"
|
||||
|
||||
#define DISALLOW_COPY_AND_ASSIGN(TypeName) \
|
||||
TypeName(const TypeName&); \
|
||||
@@ -43,143 +45,149 @@ class G4MPIstatus;
|
||||
class G4VMPIseedGenerator;
|
||||
class G4VMPIextraWorker;
|
||||
|
||||
class G4MPImanager {
|
||||
public:
|
||||
// MPI master rank
|
||||
enum { kRANK_MASTER = 0 };
|
||||
class G4MPImanager
|
||||
{
|
||||
public:
|
||||
// MPI master rank
|
||||
enum
|
||||
{
|
||||
kRANK_MASTER = 0
|
||||
};
|
||||
|
||||
enum { // MPI tag
|
||||
kTAG_G4COMMAND = 100,
|
||||
kTAG_G4STATUS = 200,
|
||||
kTAG_G4SEED = 300,
|
||||
kTAG_DATA = 1000,
|
||||
kTAG_HISTO = 1001,
|
||||
kTAG_RUN = 1002,
|
||||
kTAG_CMDSCR = 1003,
|
||||
kTAG_NTUPLE = 1004
|
||||
};
|
||||
enum
|
||||
{ // MPI tag
|
||||
kTAG_G4COMMAND = 100,
|
||||
kTAG_G4STATUS = 200,
|
||||
kTAG_G4SEED = 300,
|
||||
kTAG_DATA = 1000,
|
||||
kTAG_HISTO = 1001,
|
||||
kTAG_RUN = 1002,
|
||||
kTAG_CMDSCR = 1003,
|
||||
kTAG_NTUPLE = 1004
|
||||
};
|
||||
|
||||
G4MPImanager(int nof_extra_workers = 0);
|
||||
G4MPImanager(int argc, char** argv, int nof_extra_workers = 0);
|
||||
~G4MPImanager();
|
||||
G4MPImanager(int nof_extra_workers = 0);
|
||||
G4MPImanager(int argc, char** argv, int nof_extra_workers = 0);
|
||||
~G4MPImanager();
|
||||
|
||||
static G4MPImanager* GetManager();
|
||||
static G4MPImanager* GetManager();
|
||||
|
||||
// set/get methods
|
||||
G4MPIsession* GetMPIsession() const;
|
||||
// set/get methods
|
||||
G4MPIsession* GetMPIsession() const;
|
||||
|
||||
G4int GetVerbose() const;
|
||||
void SetVerbose(G4int iverbose);
|
||||
G4int GetVerbose() const;
|
||||
void SetVerbose(G4int iverbose);
|
||||
|
||||
G4int GetTotalSize() const; // get size of all ranks
|
||||
G4int GetActiveSize() const; // get size of ranks wher RunBeamOn is called
|
||||
G4int GetRank() const;
|
||||
G4int GetTotalSize() const; // get size of all ranks
|
||||
G4int GetActiveSize() const; // get size of ranks wher RunBeamOn is called
|
||||
G4int GetRank() const;
|
||||
|
||||
G4bool IsMaster() const;
|
||||
G4bool IsSlave() const;
|
||||
G4bool IsExtraWorker() const;
|
||||
G4bool IsMaster() const;
|
||||
G4bool IsSlave() const;
|
||||
G4bool IsExtraWorker() const;
|
||||
|
||||
G4bool IsInitMacro() const;
|
||||
const G4String& GetInitFileName() const;
|
||||
G4bool IsInitMacro() const;
|
||||
const G4String& GetInitFileName() const;
|
||||
|
||||
G4bool IsBatchMode() const;
|
||||
const G4String& GetMacroFileName() const;
|
||||
G4bool IsBatchMode() const;
|
||||
const G4String& GetMacroFileName() const;
|
||||
|
||||
void SetMasterWeight(G4double aweight);
|
||||
G4double GetMasterWeight() const;
|
||||
void SetMasterWeight(G4double aweight);
|
||||
G4double GetMasterWeight() const;
|
||||
|
||||
void SetExtraWorker(G4VMPIextraWorker* extraWorker);
|
||||
G4VMPIextraWorker* GetExtraWorker() const;
|
||||
void SetExtraWorker(G4VMPIextraWorker* extraWorker);
|
||||
G4VMPIextraWorker* GetExtraWorker() const;
|
||||
|
||||
G4VMPIseedGenerator* GetSeedGenerator() const;
|
||||
G4VMPIseedGenerator* GetSeedGenerator() const;
|
||||
|
||||
// MPI methods
|
||||
G4String BcastCommand(const G4String& command);
|
||||
void ShowStatus();
|
||||
void ShowSeeds();
|
||||
void SetSeed(G4int inode, G4long seed);
|
||||
void WaitBeamOn();
|
||||
// MPI methods
|
||||
G4String BcastCommand(const G4String& command);
|
||||
void ShowStatus();
|
||||
void ShowSeeds();
|
||||
void SetSeed(G4int inode, G4long seed);
|
||||
void WaitBeamOn();
|
||||
|
||||
// methods for MPI environment
|
||||
void DistributeSeeds();
|
||||
void ExecuteMacroFile(const G4String& fname, G4bool qbatch=false);
|
||||
G4bool CheckThreadStatus();
|
||||
void ExecuteThreadCommand(const G4String& command);
|
||||
void ExecuteBeamOnThread(const G4String& command);
|
||||
void JoinBeamOnThread();
|
||||
// methods for MPI environment
|
||||
void DistributeSeeds();
|
||||
void ExecuteMacroFile(const G4String& fname, G4bool qbatch = false);
|
||||
G4bool CheckThreadStatus();
|
||||
void ExecuteThreadCommand(const G4String& command);
|
||||
void ExecuteBeamOnThread(const G4String& command);
|
||||
void JoinBeamOnThread();
|
||||
|
||||
void BeamOn(G4int nevent, G4bool qdivide=true);
|
||||
void Print(const G4String& message);
|
||||
G4int GetEventsInMaster() const {return fevents_in_master;}
|
||||
G4int GetEventsInSlave() const {return fevents_in_slave;}
|
||||
void BeamOn(G4int nevent, G4bool qdivide = true);
|
||||
void Print(const G4String& message);
|
||||
G4int GetEventsInMaster() const { return fevents_in_master; }
|
||||
G4int GetEventsInSlave() const { return fevents_in_slave; }
|
||||
|
||||
// misc
|
||||
void ShowHelp() const;
|
||||
// misc
|
||||
void ShowHelp() const;
|
||||
|
||||
const MPI::Intracomm* GetComm() const { return &COMM_G4COMMAND_; }
|
||||
const MPI_Comm* GetProcessingComm() const { return &processing_comm_; }
|
||||
const MPI_Comm* GetCollectingComm() const { return &collecting_comm_; }
|
||||
const MPI_Comm* GetAllComm() const { return &all_comm_; }
|
||||
private:
|
||||
DISALLOW_COPY_AND_ASSIGN(G4MPImanager);
|
||||
const MPI::Intracomm* GetComm() const { return &COMM_G4COMMAND_; }
|
||||
const MPI_Comm* GetProcessingComm() const { return &processing_comm_; }
|
||||
const MPI_Comm* GetCollectingComm() const { return &collecting_comm_; }
|
||||
const MPI_Comm* GetAllComm() const { return &all_comm_; }
|
||||
|
||||
// internal use
|
||||
void Initialize();
|
||||
void ParseArguments(G4int argc, char** argv);
|
||||
void UpdateStatus();
|
||||
private:
|
||||
DISALLOW_COPY_AND_ASSIGN(G4MPImanager);
|
||||
|
||||
static G4MPImanager* g4mpi_;
|
||||
G4MPImessenger* messenger_;
|
||||
G4MPIsession* session_;
|
||||
G4VMPIextraWorker* extra_worker_;
|
||||
// internal use
|
||||
void Initialize();
|
||||
void ParseArguments(G4int argc, char** argv);
|
||||
void UpdateStatus();
|
||||
|
||||
// seed generator
|
||||
G4VMPIseedGenerator* seed_generator_;
|
||||
static G4MPImanager* g4mpi_;
|
||||
G4MPImessenger* messenger_;
|
||||
G4MPIsession* session_;
|
||||
G4VMPIextraWorker* extra_worker_;
|
||||
|
||||
G4MPIstatus* status_; // status for each node
|
||||
// seed generator
|
||||
G4VMPIseedGenerator* seed_generator_;
|
||||
|
||||
G4int verbose_;
|
||||
G4MPIstatus* status_; // status for each node
|
||||
|
||||
// MPI rank
|
||||
G4bool is_master_;
|
||||
G4bool is_slave_;
|
||||
G4bool is_extra_worker_;
|
||||
G4int rank_;
|
||||
G4int size_; // processing comm size
|
||||
G4int world_size_; // world comm size
|
||||
G4int verbose_;
|
||||
|
||||
// MPI communicator (when no extra ranks)
|
||||
MPI::Intracomm COMM_G4COMMAND_;
|
||||
// MPI communicator (processing ranks - if ntuple merging)
|
||||
MPI_Comm processing_comm_;
|
||||
// MPI communicator (collecting ranks - if ntuple merging)
|
||||
MPI_Comm collecting_comm_;
|
||||
// MPI communicator (all ranks - if ntuple mergins)
|
||||
MPI_Comm all_comm_;
|
||||
// Interim data - need to be freed
|
||||
MPI_Group world_group_;
|
||||
MPI_Group processing_group_;
|
||||
MPI_Group collecting_group_;
|
||||
MPI_Group all_group_;
|
||||
// MPI rank
|
||||
G4bool is_master_;
|
||||
G4bool is_slave_;
|
||||
G4bool is_extra_worker_;
|
||||
G4int rank_;
|
||||
G4int size_; // processing comm size
|
||||
G4int world_size_; // world comm size
|
||||
|
||||
// cout/cerr control
|
||||
G4bool qfcout_;
|
||||
std::ofstream fscout_;
|
||||
// MPI communicator (when no extra ranks)
|
||||
MPI::Intracomm COMM_G4COMMAND_;
|
||||
// MPI communicator (processing ranks - if ntuple merging)
|
||||
MPI_Comm processing_comm_;
|
||||
// MPI communicator (collecting ranks - if ntuple merging)
|
||||
MPI_Comm collecting_comm_;
|
||||
// MPI communicator (all ranks - if ntuple mergins)
|
||||
MPI_Comm all_comm_;
|
||||
// Interim data - need to be freed
|
||||
MPI_Group world_group_;
|
||||
MPI_Group processing_group_;
|
||||
MPI_Group collecting_group_;
|
||||
MPI_Group all_group_;
|
||||
|
||||
// init/macro file
|
||||
G4bool qinitmacro_;
|
||||
G4String init_file_name_;
|
||||
G4bool qbatchmode_;
|
||||
G4String macro_file_name_;
|
||||
// cout/cerr control
|
||||
G4bool qfcout_;
|
||||
std::ofstream fscout_;
|
||||
|
||||
// for beamOn
|
||||
pthread_t thread_id_;
|
||||
G4int fevents_in_master = 0;
|
||||
G4int fevents_in_slave = 0;
|
||||
// init/macro file
|
||||
G4bool qinitmacro_;
|
||||
G4String init_file_name_;
|
||||
G4bool qbatchmode_;
|
||||
G4String macro_file_name_;
|
||||
|
||||
// parallel parameters
|
||||
G4double master_weight_;
|
||||
G4int nof_extra_workers_;
|
||||
// for beamOn
|
||||
pthread_t thread_id_;
|
||||
G4int fevents_in_master = 0;
|
||||
G4int fevents_in_slave = 0;
|
||||
|
||||
// parallel parameters
|
||||
G4double master_weight_;
|
||||
G4int nof_extra_workers_;
|
||||
};
|
||||
|
||||
// ====================================================================
|
||||
@@ -196,8 +204,8 @@ inline G4int G4MPImanager::GetVerbose() const
|
||||
inline void G4MPImanager::SetVerbose(G4int iverbose)
|
||||
{
|
||||
G4int lv = iverbose;
|
||||
if( iverbose > 1 ) lv = 1;
|
||||
if( iverbose < 0 ) lv = 0;
|
||||
if (iverbose > 1) lv = 1;
|
||||
if (iverbose < 0) lv = 0;
|
||||
|
||||
verbose_ = lv;
|
||||
return;
|
||||
@@ -236,13 +244,11 @@ inline G4bool G4MPImanager::IsExtraWorker() const
|
||||
inline G4bool G4MPImanager::IsInitMacro() const
|
||||
{
|
||||
return qinitmacro_;
|
||||
|
||||
}
|
||||
|
||||
inline const G4String& G4MPImanager::GetInitFileName() const
|
||||
{
|
||||
return init_file_name_;
|
||||
|
||||
}
|
||||
|
||||
inline G4bool G4MPImanager::IsBatchMode() const
|
||||
@@ -259,8 +265,8 @@ inline void G4MPImanager::SetMasterWeight(G4double aweight)
|
||||
{
|
||||
master_weight_ = aweight;
|
||||
|
||||
if( aweight < 0. ) master_weight_ = 0.;
|
||||
if( aweight > 1. ) master_weight_ = 1.;
|
||||
if (aweight < 0.) master_weight_ = 0.;
|
||||
if (aweight > 1.) master_weight_ = 1.;
|
||||
}
|
||||
|
||||
inline G4double G4MPImanager::GetMasterWeight() const
|
||||
|
||||
@@ -42,36 +42,37 @@ class G4UIcmdWithAString;
|
||||
class G4UIcmdWithADouble;
|
||||
class G4UIcommand;
|
||||
|
||||
class G4MPImessenger : public G4UImessenger {
|
||||
public:
|
||||
G4MPImessenger();
|
||||
~G4MPImessenger();
|
||||
class G4MPImessenger : public G4UImessenger
|
||||
{
|
||||
public:
|
||||
G4MPImessenger();
|
||||
~G4MPImessenger();
|
||||
|
||||
virtual void SetNewValue(G4UIcommand* command, G4String newValue);
|
||||
virtual G4String GetCurrentValue(G4UIcommand* command);
|
||||
virtual void SetNewValue(G4UIcommand* command, G4String newValue);
|
||||
virtual G4String GetCurrentValue(G4UIcommand* command);
|
||||
|
||||
void SetTargetObject(G4MPImanager* mpi_manager);
|
||||
void SetTargetObject(G4MPImanager* mpi_manager);
|
||||
|
||||
private:
|
||||
DISALLOW_COPY_AND_ASSIGN(G4MPImessenger);
|
||||
private:
|
||||
DISALLOW_COPY_AND_ASSIGN(G4MPImessenger);
|
||||
|
||||
G4MPImanager* g4mpi_;
|
||||
G4MPImanager* g4mpi_;
|
||||
|
||||
// /mpi
|
||||
G4UIdirectory* dir_;
|
||||
// /mpi
|
||||
G4UIdirectory* dir_;
|
||||
|
||||
G4UIcmdWithAnInteger* verbose_;
|
||||
G4UIcmdWithoutParameter* status_;
|
||||
G4UIcmdWithAnInteger* verbose_;
|
||||
G4UIcmdWithoutParameter* status_;
|
||||
|
||||
G4UIcmdWithAString* execute_;
|
||||
G4UIcmdWithAString* execute_;
|
||||
|
||||
G4UIcommand* beam_on_;
|
||||
G4UIcommand* dot_beam_on_;
|
||||
G4UIcmdWithADouble* master_weight_;
|
||||
G4UIcommand* beam_on_;
|
||||
G4UIcommand* dot_beam_on_;
|
||||
G4UIcmdWithADouble* master_weight_;
|
||||
|
||||
G4UIcmdWithoutParameter* show_seeds_;
|
||||
G4UIcmdWithAnInteger* set_master_seed_;
|
||||
G4UIcommand* set_seed_;
|
||||
G4UIcmdWithoutParameter* show_seeds_;
|
||||
G4UIcmdWithAnInteger* set_master_seed_;
|
||||
G4UIcommand* set_seed_;
|
||||
};
|
||||
|
||||
// ====================================================================
|
||||
|
||||
@@ -33,23 +33,25 @@
|
||||
#include "G4MPImanager.hh"
|
||||
#include "G4VMPIextraWorker.hh"
|
||||
|
||||
namespace toolx {
|
||||
namespace mpi {
|
||||
class wrmpi;
|
||||
}
|
||||
namespace toolx
|
||||
{
|
||||
namespace mpi
|
||||
{
|
||||
class wrmpi;
|
||||
}
|
||||
} // namespace toolx
|
||||
|
||||
class G4RootMpiAnalysisManager;
|
||||
|
||||
class G4MPIntupleMerger
|
||||
{
|
||||
public:
|
||||
G4MPIntupleMerger(G4int nofReducedNtupleFiles = 0,
|
||||
G4bool rowWise = false, G4bool rowMode = true);
|
||||
~G4MPIntupleMerger();
|
||||
public:
|
||||
G4MPIntupleMerger(G4int nofReducedNtupleFiles = 0, G4bool rowWise = false,
|
||||
G4bool rowMode = true);
|
||||
~G4MPIntupleMerger();
|
||||
|
||||
private:
|
||||
toolx::mpi::wrmpi* fWrmpi;
|
||||
private:
|
||||
toolx::mpi::wrmpi* fWrmpi;
|
||||
};
|
||||
|
||||
#endif //G4MPINTUPLEMERGER_HH
|
||||
#endif // G4MPINTUPLEMERGER_HH
|
||||
|
||||
@@ -30,14 +30,15 @@
|
||||
|
||||
#include "G4VMPIseedGenerator.hh"
|
||||
|
||||
class G4MPIrandomSeedGenerator : public G4VMPIseedGenerator {
|
||||
public:
|
||||
G4MPIrandomSeedGenerator();
|
||||
~G4MPIrandomSeedGenerator();
|
||||
class G4MPIrandomSeedGenerator : public G4VMPIseedGenerator
|
||||
{
|
||||
public:
|
||||
G4MPIrandomSeedGenerator();
|
||||
~G4MPIrandomSeedGenerator();
|
||||
|
||||
protected:
|
||||
G4bool CheckDoubleCount();
|
||||
virtual void GenerateSeeds();
|
||||
protected:
|
||||
G4bool CheckDoubleCount();
|
||||
virtual void GenerateSeeds();
|
||||
};
|
||||
|
||||
#endif
|
||||
|
||||
@@ -26,23 +26,23 @@
|
||||
#ifndef G4MPIRUNMERGER_HH_
|
||||
#define G4MPIRUNMERGER_HH_
|
||||
|
||||
#include "G4VUserMPIrunMerger.hh"
|
||||
#include "G4Run.hh"
|
||||
#include "G4VUserMPIrunMerger.hh"
|
||||
|
||||
//MPI Merger for default G4Run class
|
||||
// MPI Merger for default G4Run class
|
||||
|
||||
class G4MPIrunMerger : public G4VUserMPIrunMerger {
|
||||
public:
|
||||
G4MPIrunMerger() : G4VUserMPIrunMerger() {}
|
||||
G4MPIrunMerger(const G4Run* ar,
|
||||
G4int destination = G4MPImanager::kRANK_MASTER,
|
||||
G4int verboose = 0 ) :
|
||||
G4VUserMPIrunMerger(ar,destination,verboose) {}
|
||||
protected:
|
||||
void Pack() {/*nothing do to*/}
|
||||
G4Run* UnPack() { return new G4Run; }
|
||||
class G4MPIrunMerger : public G4VUserMPIrunMerger
|
||||
{
|
||||
public:
|
||||
G4MPIrunMerger() : G4VUserMPIrunMerger() {}
|
||||
G4MPIrunMerger(const G4Run* ar, G4int destination = G4MPImanager::kRANK_MASTER,
|
||||
G4int verboose = 0)
|
||||
: G4VUserMPIrunMerger(ar, destination, verboose)
|
||||
{}
|
||||
|
||||
protected:
|
||||
void Pack() { /*nothing do to*/ }
|
||||
G4Run* UnPack() { return new G4Run; }
|
||||
};
|
||||
|
||||
|
||||
|
||||
#endif /* G4MPIRUNMERGER_HH_ */
|
||||
|
||||
@@ -25,85 +25,86 @@
|
||||
//
|
||||
#ifndef G4MPISCORERMERGER_HH
|
||||
#define G4MPISCORERMERGER_HH
|
||||
#include "G4ScoringManager.hh"
|
||||
#include <vector>
|
||||
#include <memory>
|
||||
#include <utility>
|
||||
#include <mpi.h>
|
||||
#include "G4MPImanager.hh"
|
||||
#include "G4ScoringManager.hh"
|
||||
|
||||
//typedef G4THitsMap<G4double> HitMap;
|
||||
#include <memory>
|
||||
#include <mpi.h>
|
||||
#include <utility>
|
||||
#include <vector>
|
||||
|
||||
// typedef G4THitsMap<G4double> HitMap;
|
||||
typedef G4THitsMap<G4StatDouble> HitStatDoubleMap;
|
||||
|
||||
// This class allows for merging over MPI two command line scorers
|
||||
// via MPI
|
||||
class G4MPIscorerMerger {
|
||||
public:
|
||||
G4MPIscorerMerger();
|
||||
G4MPIscorerMerger( G4ScoringManager* mgr,
|
||||
G4int destination = G4MPImanager::kRANK_MASTER,
|
||||
G4int verbosity = 0 );
|
||||
virtual ~G4MPIscorerMerger();
|
||||
class G4MPIscorerMerger
|
||||
{
|
||||
public:
|
||||
G4MPIscorerMerger();
|
||||
G4MPIscorerMerger(G4ScoringManager* mgr, G4int destination = G4MPImanager::kRANK_MASTER,
|
||||
G4int verbosity = 0);
|
||||
virtual ~G4MPIscorerMerger();
|
||||
|
||||
//Get/set methods
|
||||
void SetDestinationRank( G4int i ) { destinationRank = i; }
|
||||
void SetScoringManager( G4ScoringManager* mgr ) { scoringManager = mgr; }
|
||||
void SetVerbosity( G4int ver ) { verbose = ver; }
|
||||
// Get/set methods
|
||||
void SetDestinationRank(G4int i) { destinationRank = i; }
|
||||
void SetScoringManager(G4ScoringManager* mgr) { scoringManager = mgr; }
|
||||
void SetVerbosity(G4int ver) { verbose = ver; }
|
||||
|
||||
//Main Interface: call this method to merge all results to rank0
|
||||
void Merge();
|
||||
// Main Interface: call this method to merge all results to rank0
|
||||
void Merge();
|
||||
|
||||
protected:
|
||||
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;
|
||||
}
|
||||
protected:
|
||||
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 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 mesh
|
||||
void Pack(const G4VScoringMesh*);
|
||||
void UnPackAndMerge(G4VScoringMesh*);
|
||||
|
||||
//! Pack a single score map
|
||||
//void Pack(const HitMap*);//Used When hits are <double>
|
||||
void Pack(const HitStatDoubleMap*);//Used when hits are statdouble
|
||||
//HitMap* UnPackHitMap(const G4String& detName, const G4String& colName);
|
||||
HitStatDoubleMap* UnPackHitStatDoubleMap(const G4String& detName, const G4String& colName);
|
||||
//! Pack a single score map
|
||||
// void Pack(const HitMap*);//Used When hits are <double>
|
||||
void Pack(const HitStatDoubleMap*); // Used when hits are statdouble
|
||||
// HitMap* UnPackHitMap(const G4String& detName, const G4String& colName);
|
||||
HitStatDoubleMap* UnPackHitStatDoubleMap(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;
|
||||
G4int CalculatePackSize(const HitStatDoubleMap* ) const;
|
||||
// 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;
|
||||
G4int CalculatePackSize(const HitStatDoubleMap*) 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;
|
||||
unsigned int commSize;
|
||||
unsigned int destinationRank;
|
||||
MPI::Intracomm comm;
|
||||
G4int verbose;
|
||||
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;
|
||||
unsigned int commSize;
|
||||
unsigned int destinationRank;
|
||||
MPI::Intracomm comm;
|
||||
G4int verbose;
|
||||
};
|
||||
|
||||
#endif //G4MPISCORERMERGER_HH
|
||||
|
||||
#endif // G4MPISCORERMERGER_HH
|
||||
|
||||
@@ -30,23 +30,24 @@
|
||||
|
||||
#include "G4VMPIsession.hh"
|
||||
|
||||
class G4MPIsession : public G4VMPIsession {
|
||||
public:
|
||||
G4MPIsession(G4VUIshell* ashell = 0);
|
||||
~G4MPIsession();
|
||||
class G4MPIsession : public G4VMPIsession
|
||||
{
|
||||
public:
|
||||
G4MPIsession(G4VUIshell* ashell = 0);
|
||||
~G4MPIsession();
|
||||
|
||||
void SetPrompt(const G4String& prompt);
|
||||
void SetShell(G4VUIshell* ashell);
|
||||
void SetPrompt(const G4String& prompt);
|
||||
void SetShell(G4VUIshell* ashell);
|
||||
|
||||
virtual G4UIsession* SessionStart();
|
||||
virtual G4UIsession* SessionStart();
|
||||
|
||||
private:
|
||||
G4VUIshell* shell_;
|
||||
private:
|
||||
G4VUIshell* shell_;
|
||||
|
||||
// get command from user prompt of the master node
|
||||
G4String GetCommand(const char* msg = 0);
|
||||
// get command from user prompt of the master node
|
||||
G4String GetCommand(const char* msg = 0);
|
||||
|
||||
G4bool TryForcedTerminate();
|
||||
G4bool TryForcedTerminate();
|
||||
};
|
||||
|
||||
#endif
|
||||
|
||||
@@ -28,51 +28,54 @@
|
||||
#ifndef G4MPI_STATUS_H
|
||||
#define G4MPI_STATUS_H
|
||||
|
||||
#include "globals.hh"
|
||||
#include "G4ApplicationState.hh"
|
||||
#include "G4Timer.hh"
|
||||
#include "globals.hh"
|
||||
|
||||
class G4Timer;
|
||||
|
||||
class G4MPIstatus {
|
||||
public:
|
||||
G4MPIstatus();
|
||||
~G4MPIstatus();
|
||||
class G4MPIstatus
|
||||
{
|
||||
public:
|
||||
G4MPIstatus();
|
||||
~G4MPIstatus();
|
||||
|
||||
// set/get functions
|
||||
void SetStatus(G4int arank, G4int runid, G4int noe, G4int evtid,
|
||||
G4ApplicationState state);
|
||||
// set/get functions
|
||||
void SetStatus(G4int arank, G4int runid, G4int noe, G4int evtid, G4ApplicationState state);
|
||||
|
||||
G4int GetRank() const;
|
||||
G4int GetRunID() const;
|
||||
G4int GetNEventToBeProcessed() const;
|
||||
G4int GetEventID() const;
|
||||
G4double GetCPUTime() const;
|
||||
G4ApplicationState GetG4State() const;
|
||||
G4int GetRank() const;
|
||||
G4int GetRunID() const;
|
||||
G4int GetNEventToBeProcessed() const;
|
||||
G4int GetEventID() const;
|
||||
G4double GetCPUTime() const;
|
||||
G4ApplicationState GetG4State() const;
|
||||
|
||||
// for pickling
|
||||
G4int SizeOf() const;
|
||||
void Pack(G4int* data) const;
|
||||
void UnPack(G4int* data);
|
||||
// for pickling
|
||||
G4int SizeOf() const;
|
||||
void Pack(G4int* data) const;
|
||||
void UnPack(G4int* data);
|
||||
|
||||
// for timer
|
||||
void StartTimer();
|
||||
void StopTimer();
|
||||
// for timer
|
||||
void StartTimer();
|
||||
void StopTimer();
|
||||
|
||||
void Print() const;
|
||||
void Print() const;
|
||||
|
||||
enum { kNSIZE = 10 };
|
||||
enum
|
||||
{
|
||||
kNSIZE = 10
|
||||
};
|
||||
|
||||
private:
|
||||
G4int rank_;
|
||||
G4int run_id_;
|
||||
G4int nevent_to_be_processed_;
|
||||
G4int event_id_;
|
||||
G4double cputime_;
|
||||
G4ApplicationState g4state_;
|
||||
G4Timer* timer_;
|
||||
private:
|
||||
G4int rank_;
|
||||
G4int run_id_;
|
||||
G4int nevent_to_be_processed_;
|
||||
G4int event_id_;
|
||||
G4double cputime_;
|
||||
G4ApplicationState g4state_;
|
||||
G4Timer* timer_;
|
||||
|
||||
G4String GetStateString(G4ApplicationState astate) const;
|
||||
G4String GetStateString(G4ApplicationState astate) const;
|
||||
};
|
||||
|
||||
// ====================================================================
|
||||
|
||||
@@ -26,71 +26,68 @@
|
||||
// Utility functions for MPI G4 interface
|
||||
#ifndef G4MPIUTILS_HH
|
||||
#define G4MPIUTILS_HH
|
||||
#include <map>
|
||||
#include <vector>
|
||||
#include <functional>
|
||||
#include <map>
|
||||
#include <numeric>
|
||||
#include <vector>
|
||||
|
||||
//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;
|
||||
// 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 );
|
||||
// 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;
|
||||
}
|
||||
// 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;
|
||||
} // namespace G4mpi
|
||||
|
||||
#endif //G4MPIUTILS_HH
|
||||
#endif // G4MPIUTILS_HH
|
||||
|
||||
@@ -30,12 +30,13 @@
|
||||
|
||||
#include "G4VUIshell.hh"
|
||||
|
||||
class G4UImpish : public G4VUIshell {
|
||||
public:
|
||||
G4UImpish();
|
||||
~G4UImpish();
|
||||
class G4UImpish : public G4VUIshell
|
||||
{
|
||||
public:
|
||||
G4UImpish();
|
||||
~G4UImpish();
|
||||
|
||||
virtual G4String GetCommandLineString(const char* msg = 0);
|
||||
virtual G4String GetCommandLineString(const char* msg = 0);
|
||||
};
|
||||
|
||||
#endif
|
||||
|
||||
@@ -30,13 +30,13 @@
|
||||
|
||||
#ifndef G4MVPIEXTRAWORKER_HH
|
||||
|
||||
class G4VMPIextraWorker {
|
||||
public:
|
||||
G4VMPIextraWorker() {}
|
||||
virtual ~G4VMPIextraWorker() {}
|
||||
class G4VMPIextraWorker
|
||||
{
|
||||
public:
|
||||
G4VMPIextraWorker() {}
|
||||
virtual ~G4VMPIextraWorker() {}
|
||||
|
||||
virtual void BeamOn() = 0;
|
||||
virtual void BeamOn() = 0;
|
||||
};
|
||||
|
||||
#endif //G4MPIVEXTRAWORKER_HH
|
||||
|
||||
#endif // G4MPIVEXTRAWORKER_HH
|
||||
|
||||
@@ -29,25 +29,27 @@
|
||||
#define G4VMPI_SEED_GENERATOR_H
|
||||
|
||||
#include "globals.hh"
|
||||
|
||||
#include <vector>
|
||||
|
||||
class G4VMPIseedGenerator {
|
||||
public:
|
||||
G4VMPIseedGenerator();
|
||||
virtual ~G4VMPIseedGenerator();
|
||||
class G4VMPIseedGenerator
|
||||
{
|
||||
public:
|
||||
G4VMPIseedGenerator();
|
||||
virtual ~G4VMPIseedGenerator();
|
||||
|
||||
// set/get methods
|
||||
void SetMasterSeed(G4long aseed); // trigger GenerateSeeds()
|
||||
G4long GetMasterSeed() const;
|
||||
// set/get methods
|
||||
void SetMasterSeed(G4long aseed); // trigger GenerateSeeds()
|
||||
G4long GetMasterSeed() const;
|
||||
|
||||
const std::vector<G4long>& GetSeedList() const;
|
||||
const std::vector<G4long>& GetSeedList() const;
|
||||
|
||||
protected:
|
||||
G4long master_seed_;
|
||||
std::vector<G4long> seed_list_;
|
||||
protected:
|
||||
G4long master_seed_;
|
||||
std::vector<G4long> seed_list_;
|
||||
|
||||
// generate seeds for MPI nodes
|
||||
virtual void GenerateSeeds() = 0;
|
||||
// generate seeds for MPI nodes
|
||||
virtual void GenerateSeeds() = 0;
|
||||
};
|
||||
|
||||
// ====================================================================
|
||||
|
||||
@@ -30,36 +30,37 @@
|
||||
|
||||
#include "G4VBasicShell.hh"
|
||||
|
||||
typedef void* (*Func_t)(void *); // for thread function
|
||||
typedef void* (*Func_t)(void*); // for thread function
|
||||
|
||||
class G4MPImanager;
|
||||
class G4VUIshell;
|
||||
|
||||
class G4VMPIsession : public G4VBasicShell {
|
||||
public:
|
||||
G4VMPIsession();
|
||||
~G4VMPIsession();
|
||||
class G4VMPIsession : public G4VBasicShell
|
||||
{
|
||||
public:
|
||||
G4VMPIsession();
|
||||
~G4VMPIsession();
|
||||
|
||||
virtual void PauseSessionStart(const G4String& msg);
|
||||
virtual void PauseSessionStart(const G4String& msg);
|
||||
|
||||
virtual G4int ReceiveG4cout(const G4String& coutString);
|
||||
virtual G4int ReceiveG4cerr(const G4String& cerrString);
|
||||
virtual G4int ReceiveG4cout(const G4String& coutString);
|
||||
virtual G4int ReceiveG4cerr(const G4String& cerrString);
|
||||
|
||||
protected:
|
||||
G4MPImanager* g4mpi_;
|
||||
protected:
|
||||
G4MPImanager* g4mpi_;
|
||||
|
||||
// MPI node info (cache)
|
||||
G4bool is_master_;
|
||||
G4bool is_slave_;
|
||||
G4int rank_;
|
||||
// MPI node info (cache)
|
||||
G4bool is_master_;
|
||||
G4bool is_slave_;
|
||||
G4int rank_;
|
||||
|
||||
G4int ExecCommand(const G4String& acommand);
|
||||
G4String TruncateCommand(const G4String& command) const;
|
||||
G4String BypassCommand(const G4String& command) const;
|
||||
G4int ExecCommand(const G4String& acommand);
|
||||
G4String TruncateCommand(const G4String& command) const;
|
||||
G4String BypassCommand(const G4String& command) const;
|
||||
|
||||
// for help operation
|
||||
virtual G4bool GetHelpChoice(G4int& aval);
|
||||
virtual void ExitHelp() const;
|
||||
// for help operation
|
||||
virtual G4bool GetHelpChoice(G4int& aval);
|
||||
virtual void ExitHelp() const;
|
||||
};
|
||||
|
||||
#endif
|
||||
|
||||
@@ -25,91 +25,99 @@
|
||||
//
|
||||
#ifndef G4MPIRUNMERGER_HH
|
||||
#define G4MPIRUNMERGER_HH
|
||||
#include "G4Run.hh"
|
||||
#include <mpi.h>
|
||||
#include "G4MPImanager.hh"
|
||||
#include "G4Run.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; }
|
||||
#include <mpi.h>
|
||||
|
||||
virtual void Merge();
|
||||
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; }
|
||||
|
||||
protected:
|
||||
virtual void Pack() = 0;
|
||||
virtual G4Run* UnPack() = 0;
|
||||
virtual void Merge();
|
||||
|
||||
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} );
|
||||
}
|
||||
protected:
|
||||
virtual void Pack() = 0;
|
||||
virtual G4Run* UnPack() = 0;
|
||||
|
||||
// void GetUserData(void* output_data,const MPI::Datatype& dt, int count);
|
||||
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 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;
|
||||
}
|
||||
// void GetUserData(void* output_data,const MPI::Datatype& dt, int count);
|
||||
|
||||
G4int GetPosition() const { return outputBufferPosition; }
|
||||
char* GetBuffer() const { return outputBuffer; }
|
||||
G4int GetBufferSize() const { return outputBufferSize; }
|
||||
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;
|
||||
}
|
||||
|
||||
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;
|
||||
G4int GetPosition() const { return outputBufferPosition; }
|
||||
char* GetBuffer() const { return outputBuffer; }
|
||||
G4int GetBufferSize() const { return outputBufferSize; }
|
||||
|
||||
//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;
|
||||
void Send(const unsigned int destination);
|
||||
void Receive(const unsigned int source);
|
||||
|
||||
//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;
|
||||
};
|
||||
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
|
||||
|
||||
#endif // G4MPIRUNMERGER_HH
|
||||
|
||||
Reference in New Issue
Block a user