Import Geant4 9.4.0 source tree
This commit is contained in:
@@ -1,7 +1,7 @@
|
||||
# $Id: G4MPI-openmpi.gmk,v 1.1 2007/11/16 13:32:56 kmura Exp $
|
||||
# $Name: geant4-09-02 $
|
||||
# $Id: G4MPI-openmpi.gmk,v 1.3 2010/05/18 06:02:01 kmura Exp $
|
||||
# $Name: geant4-09-04-beta-01 $
|
||||
# ===========================================================
|
||||
# Makefile for building G4MPI (LAM)
|
||||
# Makefile for building G4MPI (OpenMPI)
|
||||
# ===========================================================
|
||||
|
||||
ifndef G4MPIROOT
|
||||
@@ -12,3 +12,5 @@ endif
|
||||
CXX := mpic++
|
||||
CPPFLAGS += -I$(G4MPIROOT)/include -I$(G4MPIROOT)/include/openmpi
|
||||
|
||||
# to suppress compiler warnings for OpenMPI headers
|
||||
CXXFLAGS := $(subst -Wall, , $(CXXFLAGS))
|
||||
|
||||
@@ -1,14 +1,16 @@
|
||||
# $Id: G4MPI.gmk,v 1.1 2007/11/16 13:32:56 kmura Exp $
|
||||
# $Name: geant4-09-02 $
|
||||
# $Id: G4MPI.gmk,v 1.3 2010/05/18 06:01:09 kmura Exp $
|
||||
# $Name: geant4-09-04-beta-01 $
|
||||
# ===========================================================
|
||||
# Makefile for building G4MPI (LAM)
|
||||
# Makefile for building G4MPI (OpenMPI)
|
||||
# ===========================================================
|
||||
|
||||
ifndef G4MPIROOT
|
||||
G4MPIROOT = /opt/lam
|
||||
G4MPIROOT = /opt/ompi
|
||||
endif
|
||||
|
||||
# additional flags
|
||||
CXX := mpic++
|
||||
CPPFLAGS += -I$(G4MPIROOT)/include
|
||||
CPPFLAGS += -I$(G4MPIROOT)/include -I$(G4MPIROOT)/include/openmpi
|
||||
|
||||
# to suppress compiler warnings for OpenMPI headers
|
||||
CXXFLAGS := $(subst -Wall, , $(CXXFLAGS))
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
$Id: History,v 1.1 2007/11/16 13:32:56 kmura Exp $
|
||||
$Id: History,v 1.2 2010/05/18 06:00:40 kmura Exp $
|
||||
-------------------------------------------------------------------
|
||||
|
||||
=========================================================
|
||||
@@ -8,9 +8,17 @@ $Id: History,v 1.1 2007/11/16 13:32:56 kmura Exp $
|
||||
G4MPI History file
|
||||
------------------
|
||||
|
||||
18 May 2010 K.Murakami
|
||||
== Code reviewed ==
|
||||
- OpenMPI as default MPI library instead of LAM/MPI
|
||||
- improve /mpi/status command. (waste of CPU, time measurement)
|
||||
- /mpi/wait command is introduced for waiting until beamOn ends.
|
||||
- improve macro file parser
|
||||
* same parser as G4UIbatch
|
||||
* fixed unexpected behavior at the end of batch mode
|
||||
- changed "beamOn" behavior for better performance
|
||||
* thread-out for interactive, on-thread for batch
|
||||
|
||||
16 Nov. 2007 K.Murakami
|
||||
- commited to G4 CVS.
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
$Id: README,v 1.1 2007/11/16 13:32:56 kmura Exp $
|
||||
$Id: README,v 1.2 2010/05/18 06:00:18 kmura Exp $
|
||||
==========================================================================
|
||||
Geant4 MPI Interface
|
||||
|
||||
@@ -15,20 +15,21 @@ How to build
|
||||
* Redifine CXX as (wrapped) MPI C++ compiler.
|
||||
* Specify additional include paths and compiler flags to "CPPFLAGS".
|
||||
|
||||
Sample makefiles for (LAM, MPICH2, OpenMPI) are also presented.
|
||||
Sample makefiles for (OpnMPI, LAM, MPICH2) are also presented.
|
||||
An example of "G4MPI.gmk":
|
||||
|
||||
# ===========================================================
|
||||
# Makefile for building G4MPI (LAM)
|
||||
# ===========================================================
|
||||
# ===========================================================
|
||||
# Makefile for building G4MPI (OpenMPI)
|
||||
# ===========================================================
|
||||
|
||||
ifndef G4MPIROOT
|
||||
G4MPIROOT = /opt/lam
|
||||
endif
|
||||
ifndef G4MPIROOT
|
||||
G4MPIROOT = /opt/ompi
|
||||
endif
|
||||
|
||||
# additional flags
|
||||
CXX := mpic++
|
||||
CPPFLAGS += -I$(G4MPIROOT)/include
|
||||
# additional flags
|
||||
CXX := mpic++
|
||||
CXXFLAGS := $(subst -Wall, , $(CXXFLAGS))
|
||||
CPPFLAGS += -I$(G4MPIROOT)/include -I$(G4MPIROOT)/include/openmpi
|
||||
|
||||
|
||||
2. Build the library
|
||||
|
||||
@@ -23,8 +23,8 @@
|
||||
// * acceptance of all terms of the Geant4 Software license. *
|
||||
// ********************************************************************
|
||||
//
|
||||
// $Id: G4MPImanager.hh,v 1.1 2007/11/16 14:05:40 kmura Exp $
|
||||
// $Name: geant4-09-02 $
|
||||
// $Id: G4MPImanager.hh,v 1.2 2010/05/18 06:03:27 kmura Exp $
|
||||
// $Name: geant4-09-04-beta-01 $
|
||||
//
|
||||
// ====================================================================
|
||||
// G4MPImanager.hh
|
||||
@@ -54,7 +54,7 @@ private:
|
||||
static G4MPImanager* theManager;
|
||||
G4MPImessenger* messenger;
|
||||
G4MPIsession* session;
|
||||
|
||||
|
||||
G4int verbose;
|
||||
G4MPIstatus* status; // status for each node
|
||||
|
||||
@@ -139,6 +139,7 @@ public:
|
||||
void ShowStatus();
|
||||
void ShowSeeds();
|
||||
void SetSeed(G4int inode, G4long seed);
|
||||
void WaitBeamOn();
|
||||
|
||||
// methods for MPI environment
|
||||
void DistributeSeeds();
|
||||
@@ -225,7 +226,7 @@ inline const G4String& G4MPImanager::GetMacroFileName() const
|
||||
inline void G4MPImanager::SetMasterWeight(G4double aweight)
|
||||
{
|
||||
masterWeight= aweight;
|
||||
|
||||
|
||||
if(aweight<0.) masterWeight= 0.;
|
||||
if(aweight>1.) masterWeight= 1.;
|
||||
}
|
||||
|
||||
@@ -23,8 +23,8 @@
|
||||
// * acceptance of all terms of the Geant4 Software license. *
|
||||
// ********************************************************************
|
||||
//
|
||||
// $Id: G4MPImessenger.hh,v 1.1 2007/11/16 14:05:40 kmura Exp $
|
||||
// $Name: geant4-09-02 $
|
||||
// $Id: G4MPImessenger.hh,v 1.3 2010/12/03 08:21:29 kmura Exp $
|
||||
// $Name: geant4-09-04 $
|
||||
//
|
||||
// ====================================================================
|
||||
// G4MPImessenger.hh
|
||||
@@ -62,7 +62,7 @@ private:
|
||||
G4UIcmdWithAString* execute;
|
||||
|
||||
G4UIcommand* beamOn;
|
||||
G4UIcmdWithAnInteger* dotbeamOn;
|
||||
G4UIcommand* dotbeamOn;
|
||||
G4UIcmdWithADouble* masterWeight;
|
||||
|
||||
G4UIcmdWithoutParameter* showSeeds;
|
||||
@@ -72,10 +72,10 @@ private:
|
||||
public:
|
||||
G4MPImessenger(G4MPImanager* manager);
|
||||
~G4MPImessenger();
|
||||
|
||||
|
||||
virtual void SetNewValue(G4UIcommand* command, G4String newValue);
|
||||
virtual G4String GetCurrentValue(G4UIcommand* command);
|
||||
|
||||
|
||||
};
|
||||
|
||||
#endif
|
||||
|
||||
@@ -23,8 +23,8 @@
|
||||
// * acceptance of all terms of the Geant4 Software license. *
|
||||
// ********************************************************************
|
||||
//
|
||||
// $Id: G4VMPIsession.hh,v 1.1 2007/11/16 14:05:41 kmura Exp $
|
||||
// $Name: geant4-09-02 $
|
||||
// $Id: G4VMPIsession.hh,v 1.2 2010/05/18 06:05:05 kmura Exp $
|
||||
// $Name: geant4-09-04-beta-01 $
|
||||
//
|
||||
// ====================================================================
|
||||
// G4VMPIsession.hh
|
||||
@@ -57,7 +57,7 @@ protected:
|
||||
G4bool isSlave;
|
||||
G4int rank;
|
||||
|
||||
G4int ExecCommand(G4String aCommand);
|
||||
G4int ExecCommand(G4String acommand);
|
||||
G4String TruncateCommand(const G4String& command) const;
|
||||
G4String BypassCommand(const G4String& command) const;
|
||||
|
||||
|
||||
@@ -23,8 +23,8 @@
|
||||
// * acceptance of all terms of the Geant4 Software license. *
|
||||
// ********************************************************************
|
||||
//
|
||||
// $Id: G4MPIbatch.cc,v 1.1 2007/11/16 14:05:41 kmura Exp $
|
||||
// $Name: geant4-09-02 $
|
||||
// $Id: G4MPIbatch.cc,v 1.3 2010/12/03 08:21:29 kmura Exp $
|
||||
// $Name: geant4-09-04 $
|
||||
//
|
||||
// ====================================================================
|
||||
// G4MPIsession.cc
|
||||
@@ -33,7 +33,34 @@
|
||||
// ====================================================================
|
||||
#include "G4MPIbatch.hh"
|
||||
#include "G4MPImanager.hh"
|
||||
#include "G4UImanager.hh"
|
||||
#include "G4UIcommandStatus.hh"
|
||||
#include <vector>
|
||||
|
||||
////////////////////////////////////////////////////////////////////////
|
||||
static void Tokenize(const G4String& str, std::vector<G4String>& tokens)
|
||||
////////////////////////////////////////////////////////////////////////
|
||||
{
|
||||
const char* delimiter= " ";
|
||||
|
||||
str_size pos0= str.find_first_not_of(delimiter);
|
||||
str_size pos = str.find_first_of(delimiter, pos0);
|
||||
|
||||
while (pos != G4String::npos || pos0 != G4String::npos) {
|
||||
if (str[pos0] == '\"') {
|
||||
pos = str.find_first_of("\"", pos0+1);
|
||||
if(pos != G4String::npos) pos++;
|
||||
}
|
||||
if (str[pos0] == '\'') {
|
||||
pos = str.find_first_of("\'", pos0+1);
|
||||
if(pos != G4String::npos) pos++;
|
||||
}
|
||||
|
||||
tokens.push_back(str.substr(pos0, pos-pos0));
|
||||
pos0 = str.find_first_not_of(delimiter, pos);
|
||||
pos = str.find_first_of(delimiter, pos0);
|
||||
}
|
||||
}
|
||||
|
||||
// ====================================================================
|
||||
//
|
||||
@@ -71,35 +98,70 @@ G4MPIbatch::~G4MPIbatch()
|
||||
G4String G4MPIbatch::ReadCommand()
|
||||
//////////////////////////////////
|
||||
{
|
||||
enum { BUFSIZE= 256 };
|
||||
char linebuf[BUFSIZE];
|
||||
|
||||
enum { BUFSIZE= 4096 };
|
||||
static char linebuf[BUFSIZE];
|
||||
|
||||
G4String cmdtotal= "";
|
||||
G4bool qcontinued= false;
|
||||
while(batchStream.good()) {
|
||||
batchStream.getline(linebuf, BUFSIZE);
|
||||
|
||||
|
||||
G4String cmdline(linebuf);
|
||||
|
||||
// TAB-> ' ' conversion
|
||||
str_size nb=0;
|
||||
while ((nb= cmdline.find('\t',nb)) != G4String::npos) {
|
||||
cmdline.replace(nb, 1, " ");
|
||||
}
|
||||
|
||||
// strip
|
||||
cmdline= cmdline.strip(G4String::both);
|
||||
cmdline= cmdline.strip(G4String::both, '\011'); // remove TAB
|
||||
cmdline= TruncateCommand(cmdline);
|
||||
|
||||
str_size ic= cmdline.find_first_of('#');
|
||||
if(ic != G4String::npos) {
|
||||
cmdline= cmdline(0, ic);
|
||||
}
|
||||
|
||||
if(batchStream.eof()) {
|
||||
if(cmdline.size()==0) {
|
||||
return "exit";
|
||||
} else {
|
||||
return cmdline;
|
||||
|
||||
// skip null line if single line
|
||||
if(!qcontinued && cmdline.size()==0) continue;
|
||||
|
||||
// '#' is treated as echoing something
|
||||
if(cmdline[(size_t)0]=='#') return cmdline;
|
||||
|
||||
// tokenize...
|
||||
std::vector<G4String> tokens;
|
||||
Tokenize(cmdline, tokens);
|
||||
qcontinued= false;
|
||||
for (G4int i=0; i< G4int(tokens.size()); i++) {
|
||||
// string after '#" is ignored
|
||||
if(tokens[i][(size_t)0] == '#' ) break;
|
||||
// '\' or '_' is treated as continued line.
|
||||
if(tokens[i] == '\\' || tokens[i] == '_' ) {
|
||||
qcontinued= true;
|
||||
// check nothing after line continuation character
|
||||
if( i != G4int(tokens.size())-1) {
|
||||
G4Exception("unexpected character after "
|
||||
"line continuation character");
|
||||
}
|
||||
break; // stop parsing
|
||||
}
|
||||
cmdtotal+= tokens[i];
|
||||
cmdtotal+= " ";
|
||||
}
|
||||
|
||||
if(cmdline.size()==0) continue; // skip null line
|
||||
return cmdline;
|
||||
}
|
||||
if(qcontinued) continue; // read the next line
|
||||
|
||||
return "exit"; // dummy
|
||||
if(cmdtotal.size() != 0) break;
|
||||
if(batchStream.eof()) break;
|
||||
}
|
||||
|
||||
// strip again
|
||||
cmdtotal= cmdtotal.strip(G4String::both);
|
||||
|
||||
// bypass some commands
|
||||
cmdtotal= BypassCommand(cmdtotal);
|
||||
|
||||
// finally,
|
||||
if(batchStream.eof() && cmdtotal.size()==0) {
|
||||
return "exit";
|
||||
}
|
||||
|
||||
return cmdtotal;
|
||||
}
|
||||
|
||||
|
||||
@@ -109,29 +171,30 @@ G4UIsession* G4MPIbatch::SessionStart()
|
||||
{
|
||||
G4String newCommand="", scommand; // newCommand is always "" in slaves
|
||||
|
||||
if(isMaster) newCommand= ReadCommand();
|
||||
// broadcast a new G4 command
|
||||
scommand= g4MPI-> BcastCommand(newCommand);
|
||||
if(scommand == "exit" ) return 0;
|
||||
|
||||
while(1){
|
||||
G4int rc= ExecCommand(scommand);
|
||||
if(rc != fCommandSucceeded) break;
|
||||
|
||||
if(isMaster) newCommand= ReadCommand();
|
||||
scommand= g4MPI-> BcastCommand(newCommand);
|
||||
if(scommand == "exit" ) {
|
||||
if(isBatchMode) {
|
||||
if(g4MPI-> CheckThreadStatus()) {
|
||||
g4MPI-> JoinBeamOnThread();
|
||||
break;
|
||||
}
|
||||
} else {
|
||||
break;
|
||||
while(1) {
|
||||
if (isMaster) newCommand = ReadCommand();
|
||||
// broadcast a new G4 command
|
||||
scommand = g4MPI-> BcastCommand(newCommand);
|
||||
if(scommand == "exit") {
|
||||
g4MPI-> WaitBeamOn();
|
||||
return 0;
|
||||
}
|
||||
|
||||
// just echo something
|
||||
if( scommand[(size_t)0] == '#') {
|
||||
if(G4UImanager::GetUIpointer()-> GetVerboseLevel()==2) {
|
||||
G4cout << scommand << G4endl;
|
||||
}
|
||||
continue;
|
||||
}
|
||||
|
||||
G4int rc = ExecCommand(scommand);
|
||||
if (rc != fCommandSucceeded) {
|
||||
G4cerr << G4endl << "***** Batch is interupted!! *****" << G4endl;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
@@ -23,8 +23,8 @@
|
||||
// * acceptance of all terms of the Geant4 Software license. *
|
||||
// ********************************************************************
|
||||
//
|
||||
// $Id: G4MPImanager.cc,v 1.1 2007/11/16 14:05:41 kmura Exp $
|
||||
// $Name: geant4-09-02 $
|
||||
// $Id: G4MPImanager.cc,v 1.2 2010/05/18 06:06:21 kmura Exp $
|
||||
// $Name: geant4-09-04-beta-01 $
|
||||
//
|
||||
// ====================================================================
|
||||
// G4MPImanager.cc
|
||||
@@ -67,14 +67,14 @@ static void thread_ExecuteThreadCommand(const G4String* command)
|
||||
|
||||
////////////////////////////
|
||||
G4MPImanager::G4MPImanager()
|
||||
: verbose(0),
|
||||
: verbose(0),
|
||||
qfcout(false),
|
||||
qinitmacro(false),
|
||||
qbatchmode(false),
|
||||
threadID(0),
|
||||
masterWeight(1.)
|
||||
////////////////////////////
|
||||
{
|
||||
{
|
||||
//MPI::Init();
|
||||
MPI::Init_thread(MPI::THREAD_SERIALIZED);
|
||||
Initialize();
|
||||
@@ -85,7 +85,7 @@ G4MPImanager::G4MPImanager()
|
||||
G4MPImanager::G4MPImanager(int argc, char** argv)
|
||||
: verbose(0), qfcout(false),
|
||||
qinitmacro(false), qbatchmode(false),
|
||||
threadID(0),
|
||||
threadID(0),
|
||||
masterWeight(1.)
|
||||
/////////////////////////////////////////////////
|
||||
{
|
||||
@@ -139,7 +139,7 @@ void G4MPImanager::Initialize()
|
||||
rank= MPI::COMM_WORLD.Get_rank();
|
||||
isMaster= (rank == RANK_MASTER);
|
||||
isSlave= (rank != RANK_MASTER);
|
||||
|
||||
|
||||
// initialize MPI communicator
|
||||
COMM_G4COMMAND= MPI::COMM_WORLD.Dup();
|
||||
|
||||
@@ -230,7 +230,7 @@ void G4MPImanager::ParseArguments(int argc, char** argv)
|
||||
G4String prefix= ofprefix+".%03d"+".cout";
|
||||
char str[1024];
|
||||
sprintf(str, prefix.c_str(), rank);
|
||||
G4String fname(str);
|
||||
G4String fname(str);
|
||||
fscout.open(fname.c_str(), std::ios::out);
|
||||
}
|
||||
|
||||
@@ -264,19 +264,22 @@ void G4MPImanager::UpdateStatus()
|
||||
|
||||
G4int runid, eventid, neventTBP;
|
||||
|
||||
if (run) { // running...
|
||||
G4StateManager* stateManager= G4StateManager::GetStateManager();
|
||||
G4ApplicationState g4state= stateManager-> GetCurrentState();
|
||||
|
||||
if (run) {
|
||||
runid= run-> GetRunID();
|
||||
neventTBP= run -> GetNumberOfEventToBeProcessed();
|
||||
eventid= run-> GetNumberOfEvent();
|
||||
if(g4state == G4State_GeomClosed || g4state == G4State_EventProc) {
|
||||
status-> StopTimer();
|
||||
}
|
||||
} else {
|
||||
runid= 0;
|
||||
eventid= 0;
|
||||
neventTBP= 0;
|
||||
}
|
||||
|
||||
G4StateManager* stateManager= G4StateManager::GetStateManager();
|
||||
G4ApplicationState g4state= stateManager-> GetCurrentState();
|
||||
|
||||
status-> SetStatus(rank, runid, neventTBP, eventid, g4state);
|
||||
}
|
||||
|
||||
@@ -307,7 +310,6 @@ void G4MPImanager::ShowStatus()
|
||||
// aggregation
|
||||
nev+= status-> GetEventID();
|
||||
nevtp+= status-> GetNEventToBeProcessed();
|
||||
//mpistate= status-> GetG4State();
|
||||
cputime+= status-> GetCPUTime();
|
||||
}
|
||||
|
||||
@@ -321,13 +323,13 @@ void G4MPImanager::ShowStatus()
|
||||
G4cout << "-------------------------------------------------------"
|
||||
<< G4endl
|
||||
<< "* #ranks= " << size
|
||||
<< " event= " << nev << "/" << nevtp
|
||||
<< " state= " << strStatus
|
||||
<< " event= " << nev << "/" << nevtp
|
||||
<< " state= " << strStatus
|
||||
<< " time= " << cputime << "s"
|
||||
<< G4endl;
|
||||
} else {
|
||||
status-> Pack(buff);
|
||||
COMM_G4COMMAND.Send(buff, G4MPIstatus::NSIZE, MPI::INT,
|
||||
COMM_G4COMMAND.Send(buff, G4MPIstatus::NSIZE, MPI::INT,
|
||||
RANK_MASTER, TAG_G4STATUS);
|
||||
}
|
||||
}
|
||||
@@ -351,13 +353,13 @@ void G4MPImanager::ShowSeeds()
|
||||
|
||||
if(isMaster) {
|
||||
// print master
|
||||
G4cout << "* rank= " << rank
|
||||
<< " seed= " << CLHEP::HepRandom::getTheSeed()
|
||||
G4cout << "* rank= " << rank
|
||||
<< " seed= " << CLHEP::HepRandom::getTheSeed()
|
||||
<< G4endl;
|
||||
// receive from each slave
|
||||
for (G4int islave=1; islave< size; islave++) {
|
||||
COMM_G4COMMAND.Recv(&buff, 1, MPI::LONG, islave, TAG_G4SEED);
|
||||
G4cout << "* rank= " << islave
|
||||
G4cout << "* rank= " << islave
|
||||
<< " seed= " << buff
|
||||
<< G4endl;
|
||||
}
|
||||
@@ -390,7 +392,12 @@ G4bool G4MPImanager::CheckThreadStatus()
|
||||
qstatus= threadID;
|
||||
// get slave status
|
||||
for (G4int islave=1; islave< size; islave++) {
|
||||
COMM_G4COMMAND.Recv(&buff, 1, MPI::UNSIGNED, islave, TAG_G4STATUS);
|
||||
MPI::Request request= COMM_G4COMMAND.Irecv(&buff, 1, MPI::UNSIGNED,
|
||||
islave, TAG_G4STATUS);
|
||||
MPI::Status status;
|
||||
while(! request.Test(status)) {
|
||||
Wait(100);
|
||||
}
|
||||
qstatus |= buff;
|
||||
}
|
||||
} else {
|
||||
@@ -451,7 +458,7 @@ void G4MPImanager::ExecuteBeamOnThread(const G4String& command)
|
||||
} else { // ok
|
||||
static G4String cmdstr;
|
||||
cmdstr= command;
|
||||
G4int rc= pthread_create(&threadID, 0,
|
||||
G4int rc= pthread_create(&threadID, 0,
|
||||
(Func_t)thread_ExecuteThreadCommand,
|
||||
(void*)&cmdstr);
|
||||
if (rc != 0)
|
||||
@@ -486,7 +493,7 @@ G4String G4MPImanager::BcastCommand(const G4String& command)
|
||||
// "command" is not yet fixed in slaves at this time.
|
||||
|
||||
// waiting message exhausts CPU in LAM!
|
||||
//COMM_G4COMMAND.Bcast(sbuff, BUFF_SIZE, MPI::CHAR, RANK_MASTER);
|
||||
//COMM_G4COMMAND.Bcast(sbuff, ssize, MPI::CHAR, RANK_MASTER);
|
||||
|
||||
// another implementation
|
||||
if( isMaster ) {
|
||||
@@ -513,9 +520,12 @@ G4String G4MPImanager::BcastCommand(const G4String& command)
|
||||
void G4MPImanager::ExecuteMacroFile(const G4String& fname, G4bool qbatch)
|
||||
/////////////////////////////////////////////////////////////////////////
|
||||
{
|
||||
G4bool currentmode= qbatchmode;
|
||||
qbatchmode= true;
|
||||
G4MPIbatch* batchSession= new G4MPIbatch(fname, qbatch);
|
||||
batchSession-> SessionStart();
|
||||
delete batchSession;
|
||||
qbatchmode= currentmode;
|
||||
}
|
||||
|
||||
|
||||
@@ -551,6 +561,28 @@ void G4MPImanager::BeamOn(G4int nevent, G4bool qdivide)
|
||||
}
|
||||
}
|
||||
|
||||
///////////////////////////////
|
||||
void G4MPImanager::WaitBeamOn()
|
||||
///////////////////////////////
|
||||
{
|
||||
G4int buff= 0;
|
||||
if (qbatchmode) { // valid only in batch mode
|
||||
if(isMaster) {
|
||||
// receive from each slave
|
||||
for (G4int islave=1; islave< size; islave++) {
|
||||
MPI::Request request= COMM_G4COMMAND.Irecv(&buff, 1, MPI::INT,
|
||||
islave, TAG_G4STATUS);
|
||||
MPI::Status status;
|
||||
while(! request.Test(status)) {
|
||||
Wait(1000);
|
||||
}
|
||||
}
|
||||
} else {
|
||||
buff= 1;
|
||||
COMM_G4COMMAND.Send(&buff, 1, MPI::INT, RANK_MASTER, TAG_G4STATUS);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/////////////////////////////////////////////////
|
||||
void G4MPImanager::Print(const G4String& message)
|
||||
|
||||
@@ -23,8 +23,8 @@
|
||||
// * acceptance of all terms of the Geant4 Software license. *
|
||||
// ********************************************************************
|
||||
//
|
||||
// $Id: G4MPImessenger.cc,v 1.1 2007/11/16 14:05:41 kmura Exp $
|
||||
// $Name: geant4-09-02 $
|
||||
// $Id: G4MPImessenger.cc,v 1.3 2010/12/03 08:21:29 kmura Exp $
|
||||
// $Name: geant4-09-04 $
|
||||
//
|
||||
// ====================================================================
|
||||
// G4MPImessenger.cc
|
||||
@@ -71,7 +71,7 @@ G4MPImessenger::G4MPImessenger( G4MPImanager* manager)
|
||||
// /mpi/execute
|
||||
execute= new G4UIcmdWithAString("/mpi/execute", this);
|
||||
execute-> SetGuidance("Execute a macro file. (=/control/execute)");
|
||||
execute-> SetParameterName("fileName", false, false);
|
||||
execute-> SetParameterName("fileName", false, false);
|
||||
|
||||
// /mpi/beamOn
|
||||
beamOn= new G4UIcommand("/mpi/beamOn", this);
|
||||
@@ -87,11 +87,17 @@ G4MPImessenger::G4MPImessenger( G4MPImanager* manager)
|
||||
beamOn-> SetParameter(p2);
|
||||
|
||||
// /mpi/.beamOn
|
||||
dotbeamOn= new G4UIcmdWithAnInteger("/mpi/.beamOn", this);
|
||||
dotbeamOn-> SetGuidance("Start a parallel run w/o thread. (=/run/beamOn)");
|
||||
dotbeamOn-> SetParameterName("numberOfEvent", true, false);
|
||||
dotbeamOn-> SetDefaultValue(1);
|
||||
dotbeamOn-> SetRange("numberOfEvent>=0");
|
||||
dotbeamOn= new G4UIcommand("/mpi/.beamOn", this);
|
||||
dotbeamOn-> SetGuidance("Start a parallel run w/o thread.");
|
||||
|
||||
p1= new G4UIparameter("numberOfEvent", 'i', true);
|
||||
p1-> SetDefaultValue(1);
|
||||
p1-> SetParameterRange("numberOfEvent>=0");
|
||||
dotbeamOn-> SetParameter(p1);
|
||||
|
||||
p2= new G4UIparameter("divide", 'b', true);
|
||||
p2-> SetDefaultValue(true);
|
||||
dotbeamOn-> SetParameter(p2);
|
||||
|
||||
// /mpi/weightForMaster
|
||||
masterWeight= new G4UIcmdWithADouble("/mpi/masterWeight", this);
|
||||
@@ -134,7 +140,7 @@ G4MPImessenger::~G4MPImessenger()
|
||||
delete showSeeds;
|
||||
delete setMasterSeed;
|
||||
delete setSeed;
|
||||
|
||||
|
||||
delete dir;
|
||||
}
|
||||
|
||||
@@ -161,23 +167,26 @@ void G4MPImessenger::SetNewValue( G4UIcommand* command, G4String newValue)
|
||||
g4MPI-> BeamOn(nevent, qdivide);
|
||||
|
||||
} else if (command == dotbeamOn){ // /mpi/.beamOn
|
||||
G4int nevent= dotbeamOn-> GetNewIntValue(newValue);
|
||||
g4MPI-> BeamOn(nevent);
|
||||
std::istringstream is(newValue);
|
||||
G4int nevent;
|
||||
G4bool qdivide;
|
||||
is >> nevent >> qdivide;
|
||||
g4MPI-> BeamOn(nevent, qdivide);
|
||||
|
||||
} else if (command == masterWeight){ // /mpi/masterWeight
|
||||
G4double weight= masterWeight-> GetNewDoubleValue(newValue);
|
||||
g4MPI-> SetMasterWeight(weight);
|
||||
|
||||
|
||||
} else if (command == showSeeds){ // /mpi/showSeeds
|
||||
g4MPI-> ShowSeeds();
|
||||
|
||||
|
||||
} else if (command == setMasterSeed){ // /mpi/setMasterSeed
|
||||
std::istringstream is(newValue);
|
||||
G4long seed;
|
||||
is >> seed;
|
||||
g4MPI-> GetSeedGenerator()-> SetMasterSeed(seed);
|
||||
g4MPI-> DistributeSeeds();
|
||||
|
||||
|
||||
} else if (command == setSeed){ // /mpi/setSeed
|
||||
std::istringstream is(newValue);
|
||||
G4int inode;
|
||||
|
||||
@@ -23,8 +23,8 @@
|
||||
// * acceptance of all terms of the Geant4 Software license. *
|
||||
// ********************************************************************
|
||||
//
|
||||
// $Id: G4MPIsession.cc,v 1.1 2007/11/16 14:05:41 kmura Exp $
|
||||
// $Name: geant4-09-02 $
|
||||
// $Id: G4MPIsession.cc,v 1.2 2010/05/18 06:06:21 kmura Exp $
|
||||
// $Name: geant4-09-04-beta-01 $
|
||||
//
|
||||
// ====================================================================
|
||||
// G4MPIsession.cc
|
||||
@@ -124,7 +124,7 @@ G4String G4MPIsession::GetCommand(const char* msg)
|
||||
|
||||
} else if(nC == "pwd") { // show current directory
|
||||
G4cout << "Current Command Directory : "
|
||||
<< GetCurrentWorkingDirectory() << G4endl;
|
||||
<< GetCurrentWorkingDirectory() << G4endl;
|
||||
newCommand= nullString;
|
||||
|
||||
} else if(nC == "cwd") { // ... by shell
|
||||
@@ -194,27 +194,21 @@ G4UIsession* G4MPIsession::SessionStart()
|
||||
if(g4MPI-> IsBatchMode()) {
|
||||
g4MPI-> ExecuteMacroFile(g4MPI->GetMacroFileName(), true);
|
||||
return 0;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
// interactive session
|
||||
G4String newCommand="", scommand; // newCommand is always "" in slaves
|
||||
|
||||
if(isMaster) newCommand= GetCommand();
|
||||
// broadcast a new G4 command
|
||||
scommand= g4MPI-> BcastCommand(newCommand);
|
||||
if(scommand == "exit" ) return 0;
|
||||
|
||||
while(1){
|
||||
ExecCommand(scommand);
|
||||
|
||||
// get next ...
|
||||
if(isMaster) newCommand= GetCommand();
|
||||
scommand= g4MPI-> BcastCommand(newCommand);
|
||||
if(scommand == "exit" ) {
|
||||
G4bool qexit= TryForcedTerminate();
|
||||
while(1) {
|
||||
if(isMaster) newCommand = GetCommand();
|
||||
// broadcast a new G4 command
|
||||
scommand = g4MPI-> BcastCommand(newCommand);
|
||||
if(scommand == "exit") {
|
||||
G4bool qexit = TryForcedTerminate();
|
||||
if(qexit) break;
|
||||
else scommand="";
|
||||
else scommand = "";
|
||||
}
|
||||
ExecCommand(scommand);
|
||||
}
|
||||
|
||||
return 0;
|
||||
@@ -253,7 +247,7 @@ G4bool G4MPIsession::TryForcedTerminate()
|
||||
} else {
|
||||
xmessage= g4MPI->BcastCommand("");
|
||||
}
|
||||
|
||||
|
||||
if(xmessage == "kill me") {
|
||||
G4RunManager* runManager= G4RunManager::GetRunManager();
|
||||
runManager-> AbortRun(true); // soft abort
|
||||
|
||||
@@ -23,8 +23,8 @@
|
||||
// * acceptance of all terms of the Geant4 Software license. *
|
||||
// ********************************************************************
|
||||
//
|
||||
// $Id: G4MPIstatus.cc,v 1.1 2007/11/16 14:05:41 kmura Exp $
|
||||
// $Name: geant4-09-02 $
|
||||
// $Id: G4MPIstatus.cc,v 1.2 2010/05/18 06:06:21 kmura Exp $
|
||||
// $Name: geant4-09-04-beta-01 $
|
||||
//
|
||||
// ====================================================================
|
||||
// G4MPIstatus.cc
|
||||
@@ -42,7 +42,7 @@
|
||||
|
||||
//////////////////////////
|
||||
G4MPIstatus::G4MPIstatus()
|
||||
: rank(0), runID(0),
|
||||
: rank(0), runID(0),
|
||||
nEventToBeProcessed(0),
|
||||
eventID(0),
|
||||
cputime(0.),
|
||||
@@ -50,7 +50,6 @@ G4MPIstatus::G4MPIstatus()
|
||||
//////////////////////////
|
||||
{
|
||||
timer= new G4Timer;
|
||||
timer-> Start();
|
||||
}
|
||||
|
||||
|
||||
@@ -63,7 +62,7 @@ G4MPIstatus::~G4MPIstatus()
|
||||
|
||||
|
||||
/////////////////////////////////////////////////////
|
||||
void G4MPIstatus::SetStatus(G4int arank, G4int runid,
|
||||
void G4MPIstatus::SetStatus(G4int arank, G4int runid,
|
||||
G4int noe, G4int evtid,
|
||||
G4ApplicationState state)
|
||||
/////////////////////////////////////////////////////
|
||||
@@ -73,16 +72,15 @@ void G4MPIstatus::SetStatus(G4int arank, G4int runid,
|
||||
nEventToBeProcessed= noe;
|
||||
eventID= evtid;
|
||||
g4state= state;
|
||||
|
||||
timer-> Stop();
|
||||
cputime= timer-> GetUserElapsed();
|
||||
if (timer-> IsValid()) cputime= timer-> GetUserElapsed();
|
||||
else cputime = 0.;
|
||||
}
|
||||
|
||||
|
||||
/////////////////////////////////////////
|
||||
void G4MPIstatus::Pack(G4int* data) const
|
||||
/////////////////////////////////////////
|
||||
{
|
||||
{
|
||||
data[0]= rank;
|
||||
data[1]= runID;
|
||||
data[2]= nEventToBeProcessed;
|
||||
@@ -114,8 +112,8 @@ void G4MPIstatus::Print() const
|
||||
///////////////////////////////
|
||||
{
|
||||
// * rank= 001 run= 10002 event= 00001 / 100000 state= Idle"
|
||||
G4cout << "* rank= " << rank
|
||||
<< " run= " << runID
|
||||
G4cout << "* rank= " << rank
|
||||
<< " run= " << runID
|
||||
<< " event= " << eventID << " / " << nEventToBeProcessed
|
||||
<< " state= " << GetStateString(g4state)
|
||||
<< " time= " << cputime << "s"
|
||||
|
||||
@@ -23,8 +23,8 @@
|
||||
// * acceptance of all terms of the Geant4 Software license. *
|
||||
// ********************************************************************
|
||||
//
|
||||
// $Id: G4VMPIsession.cc,v 1.1 2007/11/16 14:05:41 kmura Exp $
|
||||
// $Name: geant4-09-02 $
|
||||
// $Id: G4VMPIsession.cc,v 1.2 2010/05/18 06:06:21 kmura Exp $
|
||||
// $Name: geant4-09-04-beta-01 $
|
||||
//
|
||||
// ====================================================================
|
||||
// G4VMPIsession.cc
|
||||
@@ -93,19 +93,19 @@ void G4VMPIsession::PauseSessionStart(G4String)
|
||||
|
||||
|
||||
///////////////////////////////////////////////////
|
||||
G4int G4VMPIsession::ExecCommand(G4String aCommand)
|
||||
G4int G4VMPIsession::ExecCommand(G4String acommand)
|
||||
///////////////////////////////////////////////////
|
||||
{
|
||||
if(aCommand.length()<2) return fCommandSucceeded;
|
||||
if(acommand.length()<2) return fCommandSucceeded;
|
||||
|
||||
G4UImanager* UI= G4UImanager::GetUIpointer();
|
||||
G4int returnVal= 0;
|
||||
|
||||
G4String command= BypassCommand(aCommand);
|
||||
|
||||
G4String command= BypassCommand(acommand);
|
||||
|
||||
// "/mpi/beamOn is threaded out.
|
||||
if(command(0,11) == "/mpi/beamOn") {
|
||||
g4MPI-> ExecuteBeamOnThread(aCommand);
|
||||
g4MPI-> ExecuteBeamOnThread(command);
|
||||
returnVal= fCommandSucceeded;
|
||||
} else if(command(0,12) == "/mpi/.beamOn") { // care for beamOn
|
||||
G4bool threadStatus= g4MPI-> CheckThreadStatus();
|
||||
@@ -182,7 +182,7 @@ G4String G4VMPIsession::TruncateCommand(const G4String& command) const
|
||||
|
||||
str_size idx;
|
||||
while( (idx= acommand.find("//")) != G4String::npos) {
|
||||
G4String command1= acommand(0,idx+1);
|
||||
G4String command1= acommand(0,idx+1);
|
||||
G4String command2= acommand(idx+2, acommand.size()-idx-2);
|
||||
acommand= command1 + command2;
|
||||
}
|
||||
@@ -198,19 +198,29 @@ G4String G4VMPIsession::BypassCommand(const G4String& command) const
|
||||
////////////////////////////////////////////////////////////////////
|
||||
{
|
||||
// bypass some commands
|
||||
// /run/beamon -> /mpi/.beamOn
|
||||
// /control/execute -> /mpi/execute
|
||||
// * /mpi/beamOn
|
||||
// -> /mpi/.beamOn (batch session)
|
||||
//
|
||||
// * /run/beamOn
|
||||
// -> /mpi/.beamOn (batch session)
|
||||
// -> /mpi/beamOn (interactive session)
|
||||
//
|
||||
// * /control/execute -> /mpi/execute
|
||||
|
||||
G4String acommand= command;
|
||||
|
||||
if(acommand(0,11) == "/run/beamOn") {
|
||||
if(g4MPI-> GetVerbose()>0 && isMaster) {
|
||||
G4cout << "/run/beamOn is overridden by /mpi/.beamOn"
|
||||
<< G4endl;
|
||||
// /mpi/beamOn
|
||||
if(acommand(0,11) == "/mpi/beamOn") {
|
||||
if(g4MPI-> IsBatchMode()) {
|
||||
acommand= "/mpi/.beamOn";
|
||||
if(command.length() > 11) {
|
||||
acommand +=command.substr(11);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
acommand= "/mpi/.beamOn ";
|
||||
|
||||
// /run/beamOn
|
||||
if(acommand(0,11) == "/run/beamOn") {
|
||||
G4String strarg= "";
|
||||
G4bool qget= false;
|
||||
G4bool qdone= false;
|
||||
@@ -221,21 +231,30 @@ G4String G4VMPIsession::BypassCommand(const G4String& command) const
|
||||
if(qdone) break;
|
||||
continue;
|
||||
}
|
||||
|
||||
if(qget) {
|
||||
strarg+= command[idx];
|
||||
qdone= true;
|
||||
}
|
||||
}
|
||||
acommand += strarg;
|
||||
}
|
||||
|
||||
if(g4MPI-> IsBatchMode()) { // batch session
|
||||
acommand= "/mpi/.beamOn ";
|
||||
if(command.length() > 11) acommand += strarg;
|
||||
} else { // interactive session
|
||||
if(g4MPI-> GetVerbose()>0 && isMaster) {
|
||||
G4cout << "/run/beamOn is overridden by /mpi/.beamOn" << G4endl;
|
||||
}
|
||||
acommand= "/mpi/beamOn ";
|
||||
if(command.length() > 11) acommand += strarg;
|
||||
}
|
||||
}
|
||||
|
||||
// /control/execute
|
||||
if(acommand(0,16) == "/control/execute") {
|
||||
if(g4MPI-> GetVerbose()>0 && isMaster) {
|
||||
G4cout << "/control/execute is overridden by /mpi/execute"
|
||||
G4cout << "/control/execute is overridden by /mpi/execute"
|
||||
<< G4endl;
|
||||
}
|
||||
|
||||
acommand.replace(0, 16, "/mpi/execute ");
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user