Geant4  10.02.p03
G4MPImanager Class Reference

#include <G4MPImanager.hh>

Collaboration diagram for G4MPImanager:

Public Types

enum  { kRANK_MASTER = 0 }
 
enum  {
  kTAG_G4COMMAND = 100, kTAG_G4STATUS = 200, kTAG_G4SEED = 300, kTAG_DATA = 1000,
  kTAG_HISTO = 1001, kTAG_RUN = 1002, kTAG_CMDSCR = 1003
}
 

Public Member Functions

 G4MPImanager ()
 
 G4MPImanager (int argc, char **argv)
 
 ~G4MPImanager ()
 
G4MPIsessionGetMPIsession () const
 
G4int GetVerbose () const
 
void SetVerbose (G4int iverbose)
 
G4int GetSize () const
 
G4int GetRank () const
 
G4bool IsMaster () const
 
G4bool IsSlave () const
 
G4bool IsInitMacro () const
 
const G4StringGetInitFileName () const
 
G4bool IsBatchMode () const
 
const G4StringGetMacroFileName () const
 
void SetMasterWeight (G4double aweight)
 
G4double GetMasterWeight () const
 
G4VMPIseedGeneratorGetSeedGenerator () const
 
G4String BcastCommand (const G4String &command)
 
void ShowStatus ()
 
void ShowSeeds ()
 
void SetSeed (G4int inode, G4long seed)
 
void WaitBeamOn ()
 
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)
 
void ShowHelp () const
 

Static Public Member Functions

static G4MPImanagerGetManager ()
 

Private Member Functions

 DISALLOW_COPY_AND_ASSIGN (G4MPImanager)
 
void Initialize ()
 
void ParseArguments (G4int argc, char **argv)
 
void UpdateStatus ()
 

Private Attributes

G4MPImessengermessenger_
 
G4MPIsessionsession_
 
G4VMPIseedGeneratorseed_generator_
 
G4MPIstatusstatus_
 
G4int verbose_
 
G4bool is_master_
 
G4bool is_slave_
 
G4int rank_
 
G4int size_
 
MPI::Intracomm COMM_G4COMMAND_
 
G4bool qfcout_
 
std::ofstream fscout_
 
G4bool qinitmacro_
 
G4String init_file_name_
 
G4bool qbatchmode_
 
G4String macro_file_name_
 
pthread_t thread_id_
 
G4double master_weight_
 

Static Private Attributes

static G4MPImanagerg4mpi_ = NULL
 

Detailed Description

Definition at line 45 of file G4MPImanager.hh.

Member Enumeration Documentation

◆ anonymous enum

anonymous enum
Enumerator
kRANK_MASTER 

Definition at line 48 of file G4MPImanager.hh.

◆ anonymous enum

anonymous enum
Enumerator
kTAG_G4COMMAND 
kTAG_G4STATUS 
kTAG_G4SEED 
kTAG_DATA 
kTAG_HISTO 
kTAG_RUN 
kTAG_CMDSCR 

Definition at line 50 of file G4MPImanager.hh.

Constructor & Destructor Documentation

◆ G4MPImanager() [1/2]

G4MPImanager::G4MPImanager ( )

Definition at line 68 of file G4MPImanager.cc.

69  : verbose_(0), qfcout_(false), qinitmacro_(false), qbatchmode_(false),
71 {
72  //MPI::Init();
73  MPI::Init_thread(MPI::THREAD_SERIALIZED);
74  Initialize();
75 }
void Initialize()
pthread_t thread_id_
G4bool qbatchmode_
G4double master_weight_
G4bool qinitmacro_
Here is the call graph for this function:

◆ G4MPImanager() [2/2]

G4MPImanager::G4MPImanager ( int  argc,
char **  argv 
)

Definition at line 78 of file G4MPImanager.cc.

79  : verbose_(0), qfcout_(false), qinitmacro_(false), qbatchmode_(false),
81 {
82  //MPI::Init(argc, argv);
83  MPI::Init_thread(argc, argv, MPI::THREAD_SERIALIZED);
84  Initialize();
85  ParseArguments(argc, argv);
86 }
void Initialize()
pthread_t thread_id_
G4bool qbatchmode_
G4double master_weight_
void ParseArguments(G4int argc, char **argv)
G4bool qinitmacro_
Here is the call graph for this function:

◆ ~G4MPImanager()

G4MPImanager::~G4MPImanager ( )

Definition at line 89 of file G4MPImanager.cc.

90 {
91  if( is_slave_ && qfcout_ ) fscout_.close();
92 
93  delete status_;
94  delete messenger_;
95  delete session_;
96 
97  COMM_G4COMMAND_.Free();
98 
99  MPI::Finalize();
100 }
std::ofstream fscout_
G4MPImessenger * messenger_
void Finalize()
Definition: errprop.cc:257
G4MPIstatus * status_
G4bool is_slave_
G4MPIsession * session_
MPI::Intracomm COMM_G4COMMAND_
Here is the call graph for this function:

Member Function Documentation

◆ BcastCommand()

G4String G4MPImanager::BcastCommand ( const G4String command)

Definition at line 416 of file G4MPImanager.cc.

417 {
418  enum { kBUFF_SIZE = 512 };
419  static char sbuff[kBUFF_SIZE];
420  command.copy(sbuff, kBUFF_SIZE);
421  G4int len = command.size();
422  sbuff[len] ='\0'; // no boundary check
423 
424  // "command" is not yet fixed in slaves at this time.
425 
426  // waiting message exhausts CPU in LAM!
427  //COMM_G4COMMAND_.Bcast(sbuff, ssize, MPI::CHAR, RANK_MASTER);
428 
429  // another implementation
430  if( is_master_ ) {
431  for ( G4int islave = 1; islave < size_; islave++ ) {
432  COMM_G4COMMAND_.Send(sbuff, kBUFF_SIZE, MPI::CHAR,
433  islave, kTAG_G4COMMAND);
434  }
435  } else {
436  // try non-blocking receive
437  MPI::Request request= COMM_G4COMMAND_.Irecv(sbuff, kBUFF_SIZE, MPI::CHAR,
439  // polling...
440  while(! request.Test()) {
441  ::Wait(1000);
442  }
443  }
444 
445  return G4String(sbuff);
446 }
int G4int
Definition: G4Types.hh:78
G4bool is_master_
MPI::Intracomm COMM_G4COMMAND_

◆ BeamOn()

void G4MPImanager::BeamOn ( G4int  nevent,
G4bool  qdivide = true 
)

Definition at line 460 of file G4MPImanager.cc.

461 {
462 #ifndef G4MULTITHREADED
464 #endif
465 
466  if ( qdivide ) { // events are divided
467  G4double ntot = master_weight_ + size_ - 1.;
468  G4int nproc = G4int(nevent/ntot);
469  G4int nproc0 = nevent - nproc*(size_-1);
470 
471  if ( verbose_ > 0 && is_master_ ) {
472  G4cout << "#events in master=" << nproc0 << " / "
473  << "#events in slave=" << nproc << G4endl;
474  }
475 
476  status_-> StartTimer(); // start timer
477 
478 #ifdef G4MULTITHREADED
479  G4String str_nevt;
480  if ( is_master_ ) str_nevt = G4UIcommand::ConvertToString(nproc0);
481  else str_nevt = G4UIcommand::ConvertToString(nproc);
483  UI-> ApplyCommand("/run/beamOn " + str_nevt);
484 #else
485  if ( is_master_ ) runManager-> BeamOn(nproc0);
486  else runManager-> BeamOn(nproc);
487 #endif
488 
489  status_-> StopTimer(); // stop timer
490 
491  } else { // same events are generated in each node (for test use)
492  if( verbose_ > 0 && is_master_ ) {
493  G4cout << "#events in master=" << nevent << " / "
494  << "#events in slave=" << nevent << G4endl;
495  }
496  status_-> StartTimer(); // start timer
497 
498 #ifdef G4MULTITHREADED
501  UI-> ApplyCommand("/run/beamOn " + str_nevt);
502 #else
503  runManager-> BeamOn(nevent);
504 #endif
505 
506  status_-> StopTimer(); // stop timer
507  }
508 }
static G4String ConvertToString(G4bool boolVal)
Definition: G4UIcommand.cc:371
int G4int
Definition: G4Types.hh:78
static G4UImanager * GetUIpointer()
Definition: G4UImanager.cc:58
G4GLOB_DLL std::ostream G4cout
static G4RunManager * GetRunManager()
Definition: G4RunManager.cc:79
G4double master_weight_
G4bool is_master_
G4MPIstatus * status_
#define G4endl
Definition: G4ios.hh:61
void BeamOn(G4int nevent, G4bool qdivide=true)
double G4double
Definition: G4Types.hh:76
Int_t nevent
Here is the call graph for this function:

◆ CheckThreadStatus()

G4bool G4MPImanager::CheckThreadStatus ( )

Definition at line 325 of file G4MPImanager.cc.

326 {
327  unsigned buff;
328  unsigned qstatus = 0;
329 
330  if( is_master_ ) {
331  qstatus = (thread_id_ != 0);
332  // get slave status
333  for ( G4int islave = 1; islave < size_; islave++ ) {
334  MPI::Request request = COMM_G4COMMAND_.Irecv(&buff, 1, MPI::UNSIGNED,
335  islave, kTAG_G4STATUS);
336  while( ! request.Test() ) {
337  ::Wait(1000);
338  }
339  qstatus |= buff;
340  }
341  } else {
342  buff = (thread_id_ !=0);
343  COMM_G4COMMAND_.Send(&buff, 1, MPI::UNSIGNED, kRANK_MASTER, kTAG_G4STATUS);
344  }
345 
346  // broadcast
347  buff = qstatus; // for master
348  COMM_G4COMMAND_.Bcast(&buff, 1, MPI::UNSIGNED, kRANK_MASTER);
349  qstatus = buff; // for slave
350 
351  if ( qstatus != 0 ) return true;
352  else return false;
353 }
pthread_t thread_id_
int G4int
Definition: G4Types.hh:78
G4bool is_master_
MPI::Intracomm COMM_G4COMMAND_
Here is the caller graph for this function:

◆ DISALLOW_COPY_AND_ASSIGN()

G4MPImanager::DISALLOW_COPY_AND_ASSIGN ( G4MPImanager  )
private

◆ DistributeSeeds()

void G4MPImanager::DistributeSeeds ( )

Definition at line 287 of file G4MPImanager.cc.

288 {
289  std::vector<G4long> seed_list = seed_generator_-> GetSeedList();
290  G4Random::setTheSeed(seed_list[rank_]);
291 }
G4VMPIseedGenerator * seed_generator_
Here is the caller graph for this function:

◆ ExecuteBeamOnThread()

void G4MPImanager::ExecuteBeamOnThread ( const G4String command)

Definition at line 385 of file G4MPImanager.cc.

386 {
387  G4bool threadStatus = CheckThreadStatus();
388 
389  if (threadStatus) {
390  if ( is_master_ ) {
391  G4cout << "G4MPIsession:: beamOn is still running." << G4endl;
392  }
393  } else { // ok
394  static G4String cmdstr;
395  cmdstr = command;
396  G4int rc = pthread_create(&thread_id_, 0,
397  (Func_t)thread_ExecuteThreadCommand,
398  (void*)&cmdstr);
399  if (rc != 0)
400  G4Exception("G4MPImanager::ExecuteBeamOnThread()",
401  "MPI003", FatalException,
402  "Failed to create a beamOn thread.");
403  }
404 }
pthread_t thread_id_
int G4int
Definition: G4Types.hh:78
G4GLOB_DLL std::ostream G4cout
bool G4bool
Definition: G4Types.hh:79
void G4Exception(const char *originOfException, const char *exceptionCode, G4ExceptionSeverity severity, const char *comments)
Definition: G4Exception.cc:41
G4bool is_master_
#define G4endl
Definition: G4ios.hh:61
G4bool CheckThreadStatus()
void *(* Func_t)(void *)
Here is the call graph for this function:

◆ ExecuteMacroFile()

void G4MPImanager::ExecuteMacroFile ( const G4String fname,
G4bool  qbatch = false 
)

Definition at line 449 of file G4MPImanager.cc.

450 {
451  G4bool currentmode = qbatchmode_;
452  qbatchmode_ = true;
453  G4MPIbatch* batchSession = new G4MPIbatch(fname, qbatch);
454  batchSession-> SessionStart();
455  delete batchSession;
456  qbatchmode_ = currentmode;
457 }
G4bool qbatchmode_
bool G4bool
Definition: G4Types.hh:79

◆ ExecuteThreadCommand()

void G4MPImanager::ExecuteThreadCommand ( const G4String command)

Definition at line 356 of file G4MPImanager.cc.

357 {
358  // this method is a thread function.
360  G4int rc = UI-> ApplyCommand(command);
361 
362  G4int commandStatus = rc - (rc%100);
363 
364  switch( commandStatus ) {
365  case fCommandSucceeded:
366  break;
368  G4cerr << "illegal application state -- command refused" << G4endl;
369  break;
370  default:
371  G4cerr << "command refused (" << commandStatus << ")" << G4endl;
372  break;
373  }
374 
375  // thread is joined
376  if ( thread_id_ ) {
377  pthread_join(thread_id_, 0);
378  thread_id_ = 0;
379  }
380 
381  return;
382 }
pthread_t thread_id_
int G4int
Definition: G4Types.hh:78
static G4UImanager * GetUIpointer()
Definition: G4UImanager.cc:58
#define G4endl
Definition: G4ios.hh:61
G4GLOB_DLL std::ostream G4cerr
Here is the call graph for this function:

◆ GetInitFileName()

const G4String & G4MPImanager::GetInitFileName ( ) const
inline

Definition at line 203 of file G4MPImanager.hh.

204 {
205  return init_file_name_;
206 
207 }
G4String init_file_name_
Here is the caller graph for this function:

◆ GetMacroFileName()

const G4String & G4MPImanager::GetMacroFileName ( ) const
inline

Definition at line 214 of file G4MPImanager.hh.

215 {
216  return macro_file_name_;
217 }
G4String macro_file_name_
Here is the caller graph for this function:

◆ GetManager()

G4MPImanager * G4MPImanager::GetManager ( )
static

Definition at line 103 of file G4MPImanager.cc.

104 {
105  if ( g4mpi_ == NULL ) {
106  G4Exception("G4MPImanager::GetManager()", "MPI001",
107  FatalException, "G4MPImanager is not instantiated.");
108  }
109  return g4mpi_;
110 }
static G4MPImanager * g4mpi_
void G4Exception(const char *originOfException, const char *exceptionCode, G4ExceptionSeverity severity, const char *comments)
Definition: G4Exception.cc:41
Here is the call graph for this function:
Here is the caller graph for this function:

◆ GetMasterWeight()

G4double G4MPImanager::GetMasterWeight ( ) const
inline

Definition at line 227 of file G4MPImanager.hh.

228 {
229  return master_weight_;
230 }
G4double master_weight_
Here is the caller graph for this function:

◆ GetMPIsession()

G4MPIsession * G4MPImanager::GetMPIsession ( ) const
inline

Definition at line 157 of file G4MPImanager.hh.

158 {
159  return session_;
160 }
G4MPIsession * session_

◆ GetRank()

G4int G4MPImanager::GetRank ( ) const
inline

Definition at line 177 of file G4MPImanager.hh.

178 {
179  return rank_;
180 }

◆ GetSeedGenerator()

G4VMPIseedGenerator * G4MPImanager::GetSeedGenerator ( ) const
inline

Definition at line 232 of file G4MPImanager.hh.

233 {
234  return seed_generator_;
235 }
G4VMPIseedGenerator * seed_generator_

◆ GetSize()

G4int G4MPImanager::GetSize ( ) const
inline

Definition at line 182 of file G4MPImanager.hh.

183 {
184  return size_;
185 }

◆ GetVerbose()

G4int G4MPImanager::GetVerbose ( ) const
inline

Definition at line 162 of file G4MPImanager.hh.

163 {
164  return verbose_;
165 }
Here is the caller graph for this function:

◆ Initialize()

void G4MPImanager::Initialize ( )
private

Definition at line 113 of file G4MPImanager.cc.

114 {
115  if ( g4mpi_ != NULL ) {
116  G4Exception("G4MPImanager::Initialize()", "MPI002",
117  FatalException, "G4MPImanager is already instantiated.");
118  }
119 
120  g4mpi_ = this;
121 
122  // get rank information
123  size_ = MPI::COMM_WORLD.Get_size();
124  rank_ = MPI::COMM_WORLD.Get_rank();
127 
128  // initialize MPI communicator
129  COMM_G4COMMAND_ = MPI::COMM_WORLD.Dup();
130 
131  // new G4MPI stuffs
132  messenger_ = new G4MPImessenger();
133  messenger_-> SetTargetObject(this);
134  session_ = new G4MPIsession;
135  status_ = new G4MPIstatus;
136 
137  // default seed generator is random generator.
139  DistributeSeeds();
140 }
G4MPImessenger * messenger_
static G4MPImanager * g4mpi_
void G4Exception(const char *originOfException, const char *exceptionCode, G4ExceptionSeverity severity, const char *comments)
Definition: G4Exception.cc:41
G4bool is_master_
void DistributeSeeds()
G4MPIstatus * status_
G4bool is_slave_
G4VMPIseedGenerator * seed_generator_
G4MPIsession * session_
MPI::Intracomm COMM_G4COMMAND_
Here is the call graph for this function:
Here is the caller graph for this function:

◆ IsBatchMode()

G4bool G4MPImanager::IsBatchMode ( ) const
inline

Definition at line 209 of file G4MPImanager.hh.

210 {
211  return qbatchmode_;
212 }
G4bool qbatchmode_

◆ IsInitMacro()

G4bool G4MPImanager::IsInitMacro ( ) const
inline

Definition at line 197 of file G4MPImanager.hh.

198 {
199  return qinitmacro_;
200 
201 }
G4bool qinitmacro_

◆ IsMaster()

G4bool G4MPImanager::IsMaster ( ) const
inline

Definition at line 187 of file G4MPImanager.hh.

188 {
189  return is_master_;
190 }
G4bool is_master_

◆ IsSlave()

G4bool G4MPImanager::IsSlave ( ) const
inline

Definition at line 192 of file G4MPImanager.hh.

193 {
194  return is_slave_;
195 }
G4bool is_slave_

◆ JoinBeamOnThread()

void G4MPImanager::JoinBeamOnThread ( )

Definition at line 407 of file G4MPImanager.cc.

408 {
409  if ( thread_id_ ) {
410  pthread_join(thread_id_, 0);
411  thread_id_ = 0;
412  }
413 }
pthread_t thread_id_

◆ ParseArguments()

void G4MPImanager::ParseArguments ( G4int  argc,
char **  argv 
)
private

Definition at line 143 of file G4MPImanager.cc.

144 {
145  G4int qhelp = 0;
146  G4String ofprefix = "mpi";
147 
148  G4int c;
149  while ( 1 ) {
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'},
156  {NULL, 0, NULL, 0}
157  };
158 
159  opterr = 0; // suppress message
160  c = getopt_long(argc, argv, "hvi:o", long_options, &option_index);
161  opterr = 1;
162 
163  if( c == -1 ) break;
164 
165  switch (c) {
166  case 'h' :
167  qhelp = 1;
168  break;
169  case 'v' :
170  verbose_ = 1;
171  break;
172  case 'i' :
173  qinitmacro_ = true;
175  break;
176  case 'o' :
177  qfcout_ = true;
178  if ( optarg ) ofprefix = optarg;
179  break;
180  default:
181  G4cerr << "*** invalid options specified." << G4endl;
182  std::exit(EXIT_FAILURE);
183  break;
184  }
185  }
186 
187  // show help
188  if ( qhelp ) {
189  if ( is_master_ ) ShowHelp();
190  MPI::Finalize();
191  std::exit(EXIT_SUCCESS);
192  }
193 
194  // file output
195  if( is_slave_ && qfcout_ ) {
196  G4String prefix = ofprefix + ".%03d" + ".cout";
197  char str[1024];
198  sprintf(str, prefix.c_str(), rank_);
199  G4String fname(str);
200  fscout_.open(fname.c_str(), std::ios::out);
201  }
202 
203  // non-option ARGV-elements ...
204  if ( optind < argc ) {
205  qbatchmode_ = true;
206  macro_file_name_ = argv[optind];
207  }
208 }
std::ofstream fscout_
int optind
G4String init_file_name_
int G4int
Definition: G4Types.hh:78
G4bool qbatchmode_
int opterr
void ShowHelp() const
G4bool qinitmacro_
void Finalize()
Definition: errprop.cc:257
G4bool is_master_
#define G4endl
Definition: G4ios.hh:61
char * optarg
G4bool is_slave_
G4String macro_file_name_
G4GLOB_DLL std::ostream G4cerr
Here is the call graph for this function:
Here is the caller graph for this function:

◆ Print()

void G4MPImanager::Print ( const G4String message)

Definition at line 532 of file G4MPImanager.cc.

533 {
534  if ( is_master_ ){
535  std::cout << message << std::flush;
536  } else {
537  if ( qfcout_ ) { // output to a file
538  fscout_ << message << std::flush;
539  } else { // output to stdout
540  std::cout << rank_ << ":" << message << std::flush;
541  }
542  }
543 }
std::ofstream fscout_
G4bool is_master_
Here is the caller graph for this function:

◆ SetMasterWeight()

void G4MPImanager::SetMasterWeight ( G4double  aweight)
inline

Definition at line 219 of file G4MPImanager.hh.

220 {
221  master_weight_ = aweight;
222 
223  if( aweight < 0. ) master_weight_ = 0.;
224  if( aweight > 1. ) master_weight_ = 1.;
225 }
G4double master_weight_

◆ SetSeed()

void G4MPImanager::SetSeed ( G4int  inode,
G4long  seed 
)

Definition at line 317 of file G4MPImanager.cc.

318 {
319  if( rank_ == inode ) {
321  }
322 }
static void setTheSeed(long seed, int lux=3)
Definition: Random.cc:132
Here is the call graph for this function:

◆ SetVerbose()

void G4MPImanager::SetVerbose ( G4int  iverbose)
inline

Definition at line 167 of file G4MPImanager.hh.

168 {
169  G4int lv = iverbose;
170  if( iverbose > 1 ) lv = 1;
171  if( iverbose < 0 ) lv = 0;
172 
173  verbose_ = lv;
174  return;
175 }
int G4int
Definition: G4Types.hh:78

◆ ShowHelp()

void G4MPImanager::ShowHelp ( ) const

Definition at line 546 of file G4MPImanager.cc.

547 {
548  if (is_slave_ ) return;
549 
550  G4cout << "Geant4 MPI interface" << G4endl;
551  G4cout << "usage:" << G4endl;
552  G4cout << "<app> [options] [macro file]"
553  << G4endl << G4endl;
554  G4cout << " -h, --help show this message."
555  << G4endl;
556  G4cout << " -v, --verbose show verbose message"
557  << G4endl;
558  G4cout << " -i, --init=FNAME set an init macro file"
559  << G4endl;
560  G4cout << " -o, --ofile[=FNAME] set slave output to a flie"
561  << G4endl;
562  G4cout << G4endl;
563 }
G4GLOB_DLL std::ostream G4cout
#define G4endl
Definition: G4ios.hh:61
G4bool is_slave_
Here is the caller graph for this function:

◆ ShowSeeds()

void G4MPImanager::ShowSeeds ( )

Definition at line 294 of file G4MPImanager.cc.

295 {
296  G4long buff;
297 
298  if ( is_master_ ) {
299  // print master
300  G4cout << "* rank= " << rank_
301  << " seed= " << G4Random::getTheSeed()
302  << G4endl;
303  // receive from each slave
304  for ( G4int islave = 1; islave < size_; islave++ ) {
305  COMM_G4COMMAND_.Recv(&buff, 1, MPI::LONG, islave, kTAG_G4SEED);
306  G4cout << "* rank= " << islave
307  << " seed= " << buff
308  << G4endl;
309  }
310  } else { // slaves
311  buff = G4Random::getTheSeed();
312  COMM_G4COMMAND_.Send(&buff, 1, MPI::LONG, kRANK_MASTER, kTAG_G4SEED);
313  }
314 }
long G4long
Definition: G4Types.hh:80
int G4int
Definition: G4Types.hh:78
G4GLOB_DLL std::ostream G4cout
G4bool is_master_
#define G4endl
Definition: G4ios.hh:61
MPI::Intracomm COMM_G4COMMAND_

◆ ShowStatus()

void G4MPImanager::ShowStatus ( )

Definition at line 238 of file G4MPImanager.cc.

239 {
241 
242  UpdateStatus();
243  G4bool gstatus = CheckThreadStatus();
244 
245  if ( is_master_ ) {
246  status_-> Print(); // for maser itself
247 
248  G4int nev = status_-> GetEventID();
249  G4int nevtp = status_-> GetNEventToBeProcessed();
250  G4double cputime = status_-> GetCPUTime();
251 
252  // receive from each slave
253  for ( G4int islave = 1; islave < size_; islave++ ) {
255  islave, kTAG_G4STATUS);
256  status_-> UnPack(buff);
257  status_-> Print();
258 
259  // aggregation
260  nev += status_-> GetEventID();
261  nevtp += status_-> GetNEventToBeProcessed();
262  cputime += status_-> GetCPUTime();
263  }
264 
265  G4String strStatus;
266  if ( gstatus ) {
267  strStatus = "Run";
268  } else {
269  strStatus = "Idle";
270  }
271 
272  G4cout << "-------------------------------------------------------"
273  << G4endl
274  << "* #ranks= " << size_
275  << " event= " << nev << "/" << nevtp
276  << " state= " << strStatus
277  << " time= " << cputime << "s"
278  << G4endl;
279  } else {
280  status_-> Pack(buff);
283  }
284 }
int G4int
Definition: G4Types.hh:78
G4GLOB_DLL std::ostream G4cout
bool G4bool
Definition: G4Types.hh:79
G4bool is_master_
void Print(const G4String &message)
G4MPIstatus * status_
#define G4endl
Definition: G4ios.hh:61
void UpdateStatus()
G4bool CheckThreadStatus()
double G4double
Definition: G4Types.hh:76
MPI::Intracomm COMM_G4COMMAND_
Here is the call graph for this function:

◆ UpdateStatus()

void G4MPImanager::UpdateStatus ( )
private

Definition at line 211 of file G4MPImanager.cc.

212 {
214  const G4Run* run = runManager-> GetCurrentRun();
215 
216  G4int runid, eventid, neventTBP;
217 
219  G4ApplicationState g4state = stateManager-> GetCurrentState();
220 
221  if ( run ) {
222  runid = run-> GetRunID();
223  neventTBP = run -> GetNumberOfEventToBeProcessed();
224  eventid = run-> GetNumberOfEvent();
225  if( g4state == G4State_GeomClosed || g4state == G4State_EventProc ) {
226  status_-> StopTimer();
227  }
228  } else {
229  runid = 0;
230  eventid = 0;
231  neventTBP = 0;
232  }
233 
234  status_-> SetStatus(rank_, runid, neventTBP, eventid, g4state);
235 }
int G4int
Definition: G4Types.hh:78
static G4StateManager * GetStateManager()
Definition: G4Run.hh:46
static G4RunManager * GetRunManager()
Definition: G4RunManager.cc:79
G4MPIstatus * status_
G4ApplicationState
Here is the call graph for this function:
Here is the caller graph for this function:

◆ WaitBeamOn()

void G4MPImanager::WaitBeamOn ( )

Definition at line 511 of file G4MPImanager.cc.

512 {
513  G4int buff = 0;
514  if ( qbatchmode_ ) { // valid only in batch mode
515  if ( is_master_ ) {
516  // receive from each slave
517  for (G4int islave = 1; islave < size_; islave++) {
518  MPI::Request request = COMM_G4COMMAND_.Irecv(&buff, 1, MPI::INT,
519  islave, kTAG_G4STATUS);
520  while(! request.Test()) {
521  ::Wait(1000);
522  }
523  }
524  } else {
525  buff = 1;
527  }
528  }
529 }
int G4int
Definition: G4Types.hh:78
G4bool qbatchmode_
G4bool is_master_
MPI::Intracomm COMM_G4COMMAND_

Member Data Documentation

◆ COMM_G4COMMAND_

MPI::Intracomm G4MPImanager::COMM_G4COMMAND_
private

Definition at line 137 of file G4MPImanager.hh.

◆ fscout_

std::ofstream G4MPImanager::fscout_
private

Definition at line 141 of file G4MPImanager.hh.

◆ g4mpi_

G4MPImanager * G4MPImanager::g4mpi_ = NULL
staticprivate

Definition at line 119 of file G4MPImanager.hh.

◆ init_file_name_

G4String G4MPImanager::init_file_name_
private

Definition at line 145 of file G4MPImanager.hh.

◆ is_master_

G4bool G4MPImanager::is_master_
private

Definition at line 131 of file G4MPImanager.hh.

◆ is_slave_

G4bool G4MPImanager::is_slave_
private

Definition at line 132 of file G4MPImanager.hh.

◆ macro_file_name_

G4String G4MPImanager::macro_file_name_
private

Definition at line 147 of file G4MPImanager.hh.

◆ master_weight_

G4double G4MPImanager::master_weight_
private

Definition at line 153 of file G4MPImanager.hh.

◆ messenger_

G4MPImessenger* G4MPImanager::messenger_
private

Definition at line 120 of file G4MPImanager.hh.

◆ qbatchmode_

G4bool G4MPImanager::qbatchmode_
private

Definition at line 146 of file G4MPImanager.hh.

◆ qfcout_

G4bool G4MPImanager::qfcout_
private

Definition at line 140 of file G4MPImanager.hh.

◆ qinitmacro_

G4bool G4MPImanager::qinitmacro_
private

Definition at line 144 of file G4MPImanager.hh.

◆ rank_

G4int G4MPImanager::rank_
private

Definition at line 133 of file G4MPImanager.hh.

◆ seed_generator_

G4VMPIseedGenerator* G4MPImanager::seed_generator_
private

Definition at line 124 of file G4MPImanager.hh.

◆ session_

G4MPIsession* G4MPImanager::session_
private

Definition at line 121 of file G4MPImanager.hh.

◆ size_

G4int G4MPImanager::size_
private

Definition at line 134 of file G4MPImanager.hh.

◆ status_

G4MPIstatus* G4MPImanager::status_
private

Definition at line 126 of file G4MPImanager.hh.

◆ thread_id_

pthread_t G4MPImanager::thread_id_
private

Definition at line 150 of file G4MPImanager.hh.

◆ verbose_

G4int G4MPImanager::verbose_
private

Definition at line 128 of file G4MPImanager.hh.


The documentation for this class was generated from the following files: