50 void thread_ExecuteThreadCommand(
const G4String* command)
56 void Wait(
G4int ausec)
58 struct timespec treq, trem;
60 treq.tv_nsec = ausec*1000;
62 nanosleep(&treq, &trem);
69 : verbose_(0), qfcout_(false), qinitmacro_(false), qbatchmode_(false),
70 thread_id_(0), master_weight_(1.)
73 MPI::Init_thread(MPI::THREAD_SERIALIZED);
79 : verbose_(0), qfcout_(false), qinitmacro_(false), qbatchmode_(false),
80 thread_id_(0), master_weight_(1.)
83 MPI::Init_thread(argc, argv, MPI::THREAD_SERIALIZED);
106 G4Exception(
"G4MPImanager::GetManager()",
"MPI001",
116 G4Exception(
"G4MPImanager::Initialize()",
"MPI002",
123 size_ = MPI::COMM_WORLD.Get_size();
124 rank_ = MPI::COMM_WORLD.Get_rank();
150 G4int option_index = 0;
151 static struct option long_options[] = {
152 {
"help", no_argument, NULL,
'h'},
153 {
"verbose", no_argument, NULL,
'v'},
154 {
"init", required_argument, NULL,
'i'},
155 {
"ofile", optional_argument, NULL,
'o'},
160 c = getopt_long(argc, argv,
"hvi:o", long_options, &option_index);
178 if ( optarg ) ofprefix = optarg;
182 std::exit(EXIT_FAILURE);
191 std::exit(EXIT_SUCCESS);
198 sprintf(str, prefix.c_str(),
rank_);
200 fscout_.open(fname.c_str(), std::ios::out);
204 if ( optind < argc ) {
214 const G4Run* run = runManager-> GetCurrentRun();
216 G4int runid, eventid, neventTBP;
222 runid = run-> GetRunID();
223 neventTBP = run -> GetNumberOfEventToBeProcessed();
224 eventid = run-> GetNumberOfEvent();
234 status_-> SetStatus(
rank_, runid, neventTBP, eventid, g4state);
253 for (
G4int islave = 1; islave <
size_; islave++ ) {
261 nevtp +=
status_-> GetNEventToBeProcessed();
262 cputime +=
status_-> GetCPUTime();
272 G4cout <<
"-------------------------------------------------------"
274 <<
"* #ranks= " << size_
275 <<
" event= " << nev <<
"/" << nevtp
276 <<
" state= " << strStatus
277 <<
" time= " << cputime <<
"s"
290 G4Random::setTheSeed(seed_list[
rank_]);
301 <<
" seed= " << G4Random::getTheSeed()
304 for (
G4int islave = 1; islave <
size_; islave++ ) {
306 G4cout <<
"* rank= " << islave
311 buff = G4Random::getTheSeed();
319 if(
rank_ == inode ) {
328 unsigned qstatus = 0;
333 for (
G4int islave = 1; islave <
size_; islave++ ) {
336 while( ! request.Test() ) {
351 if ( qstatus != 0 )
return true;
360 G4int rc = UI-> ApplyCommand(command);
362 G4int commandStatus = rc - (rc%100);
364 switch( commandStatus ) {
368 G4cerr <<
"illegal application state -- command refused" <<
G4endl;
371 G4cerr <<
"command refused (" << commandStatus <<
")" <<
G4endl;
391 G4cout <<
"G4MPIsession:: beamOn is still running." <<
G4endl;
397 (
Func_t)thread_ExecuteThreadCommand,
402 "Failed to create a beamOn thread.");
418 enum { kBUFF_SIZE = 512 };
419 static char sbuff[kBUFF_SIZE];
420 command.copy(sbuff, kBUFF_SIZE);
431 for (
G4int islave = 1; islave <
size_; islave++ ) {
437 MPI::Request request=
COMM_G4COMMAND_.Irecv(sbuff, kBUFF_SIZE, MPI::CHAR,
440 while(! request.Test()) {
454 batchSession-> SessionStart();
462 #ifndef G4MULTITHREADED
472 G4cout <<
"#events in master=" << nproc0 <<
" / "
473 <<
"#events in slave=" << nproc <<
G4endl;
478 #ifdef G4MULTITHREADED
483 UI-> ApplyCommand(
"/run/beamOn " + str_nevt);
486 else runManager->
BeamOn(nproc);
493 G4cout <<
"#events in master=" << nevent <<
" / "
494 <<
"#events in slave=" << nevent <<
G4endl;
498 #ifdef G4MULTITHREADED
501 UI-> ApplyCommand(
"/run/beamOn " + str_nevt);
503 runManager->
BeamOn(nevent);
517 for (
G4int islave = 1; islave <
size_; islave++) {
520 while(! request.Test()) {
535 std::cout << message << std::flush;
538 fscout_ << message << std::flush;
540 std::cout <<
rank_ <<
":" << message << std::flush;
552 G4cout <<
"<app> [options] [macro file]"
554 G4cout <<
" -h, --help show this message."
556 G4cout <<
" -v, --verbose show verbose message"
558 G4cout <<
" -i, --init=FNAME set an init macro file"
560 G4cout <<
" -o, --ofile[=FNAME] set slave output to a flie"
static G4RunManager * GetRunManager()
static void setTheSeed(long seed, int lux=3)
MPI::Intracomm COMM_G4COMMAND_
void message(RunManager *runmanager)
static G4MPImanager * g4mpi_
void SetSeed(G4int inode, G4long seed)
void ExecuteBeamOnThread(const G4String &command)
A terminal session for MPI application.
static G4UImanager * GetUIpointer()
G4String macro_file_name_
status of MPI application
G4MPImessenger * messenger_
G4String BcastCommand(const G4String &command)
static G4MPImanager * GetManager()
void ExecuteThreadCommand(const G4String &command)
G4GLOB_DLL std::ostream G4cerr
void BeamOn(G4int nevent, G4bool qdivide=true)
static G4String ConvertToString(G4bool boolVal)
G4bool CheckThreadStatus()
void G4Exception(const char *originOfException, const char *exceptionCode, G4ExceptionSeverity severity, const char *description)
An implementation of random number seed distribution.
void Print(const G4String &message)
G4GLOB_DLL std::ostream G4cout
G4VMPIseedGenerator * seed_generator_
void ExecuteMacroFile(const G4String &fname, G4bool qbatch=false)
static G4StateManager * GetStateManager()
void ParseArguments(G4int argc, char **argv)