51 void thread_ExecuteThreadCommand(
const G4String* command)
57 void Wait(
G4int ausec)
59 struct timespec treq, trem;
61 treq.tv_nsec = ausec*1000;
63 nanosleep(&treq, &trem);
71 COMM_G4COMMAND_(MPI_COMM_NULL), processing_comm_(MPI_COMM_NULL),
72 collecting_comm_(MPI_COMM_NULL), all_comm_(MPI_COMM_NULL),
74 thread_id_(0), master_weight_(1.), nof_extra_workers_(nof_extra_workers)
77 MPI::Init_thread(MPI::THREAD_SERIALIZED);
84 COMM_G4COMMAND_(MPI_COMM_NULL), processing_comm_(MPI_COMM_NULL),
85 collecting_comm_(MPI_COMM_NULL), all_comm_(MPI_COMM_NULL),
87 thread_id_(0), master_weight_(1.), nof_extra_workers_(nof_extra_workers)
90 MPI::Init_thread(argc, argv, MPI::THREAD_SERIALIZED);
130 G4Exception(
"G4MPImanager::GetManager()",
"MPI001",
140 G4Exception(
"G4MPImanager::SetExtraWorker()",
"MPI001",
153 G4Exception(
"G4MPImanager::Initialize()",
"MPI002",
162 G4Exception(
"G4MPImanager::SetExtraWorker()",
"MPI001",
163 JustWarning,
"Cannot reserve extra ranks: the MPI size is not sufficient.");
167 rank_ = MPI::COMM_WORLD.Get_rank();
172 if ( nof_extra_workers_ ) {
182 int* ranks1 =
new int[
size_];
183 for (
int i=0; i<
size_; i++) ranks1[i] = i;
246 G4int option_index = 0;
247 static struct option long_options[] = {
248 {
"help", no_argument, NULL,
'h'},
249 {
"verbose", no_argument, NULL,
'v'},
250 {
"init", required_argument, NULL,
'i'},
251 {
"ofile", optional_argument, NULL,
'o'},
256 c = getopt_long(argc, argv,
"hvi:o", long_options, &option_index);
294 sprintf(str, prefix.c_str(),
rank_);
296 fscout_.open(fname.c_str(), std::ios::out);
310 const G4Run* run = runManager-> GetCurrentRun();
312 G4int runid, eventid, neventTBP;
318 runid = run-> GetRunID();
319 neventTBP = run -> GetNumberOfEventToBeProcessed();
320 eventid = run-> GetNumberOfEvent();
330 status_-> SetStatus(
rank_, runid, neventTBP, eventid, g4state);
349 for (
G4int islave = 1; islave <
size_; islave++ ) {
357 nevtp +=
status_-> GetNEventToBeProcessed();
358 cputime +=
status_-> GetCPUTime();
368 G4cout <<
"-------------------------------------------------------"
370 <<
"* #ranks= " << size_
371 <<
" event= " << nev <<
"/" << nevtp
372 <<
" state= " << strStatus
373 <<
" time= " << cputime <<
"s"
389 G4Random::setTheSeed(seed_list[
rank_]);
400 <<
" seed= " << G4Random::getTheSeed()
403 for (
G4int islave = 1; islave <
size_; islave++ ) {
405 G4cout <<
"* rank= " << islave
410 buff = G4Random::getTheSeed();
418 if(
rank_ == inode ) {
427 unsigned qstatus = 0;
432 for (
G4int islave = 1; islave <
size_; islave++ ) {
435 while( ! request.Test() ) {
450 if ( qstatus != 0 )
return true;
459 G4int rc = UI-> ApplyCommand(command);
461 G4int commandStatus = rc - (rc%100);
463 switch( commandStatus ) {
467 G4cerr <<
"illegal application state -- command refused" <<
G4endl;
470 G4cerr <<
"command refused (" << commandStatus <<
")" <<
G4endl;
490 G4cout <<
"G4MPIsession:: beamOn is still running." <<
G4endl;
496 (
Func_t)thread_ExecuteThreadCommand,
501 "Failed to create a beamOn thread.");
520 enum { kBUFF_SIZE = 512 };
521 static char sbuff[kBUFF_SIZE];
522 command.copy(sbuff, kBUFF_SIZE);
533 for (
G4int islave = 1; islave <
size_; islave++ ) {
539 MPI::Request request=
COMM_G4COMMAND_.Irecv(sbuff, kBUFF_SIZE, MPI::CHAR,
542 while(! request.Test()) {
556 batchSession-> SessionStart();
566 #ifndef G4MULTITHREADED
576 G4cout <<
"#events in master=" << nproc0 <<
" / "
577 <<
"#events in slave=" << nproc <<
G4endl;
582 #ifdef G4MULTITHREADED
587 UI-> ApplyCommand(
"/run/beamOn " + str_nevt);
590 else runManager->
BeamOn(nproc);
597 G4cout <<
"#events in master=" << nevent <<
" / "
598 <<
"#events in slave=" << nevent <<
G4endl;
602 #ifdef G4MULTITHREADED
605 UI-> ApplyCommand(
"/run/beamOn " + str_nevt);
607 runManager->
BeamOn(nevent);
625 G4cout <<
" !!!! extra_worker_ is not defined " <<
G4endl;
634 for (
G4int islave = 1; islave <
size_; islave++) {
638 while(! request.Test()) {
654 std::cout << message << std::flush;
657 fscout_ << message << std::flush;
659 std::cout <<
rank_ <<
":" << message << std::flush;
671 G4cout <<
"<app> [options] [macro file]"
673 G4cout <<
" -h, --help show this message."
675 G4cout <<
" -v, --verbose show verbose message"
677 G4cout <<
" -i, --init=FNAME set an init macro file"
679 G4cout <<
" -o, --ofile[=FNAME] set slave output to a flie"