Import Geant4 9.1.0 source tree

This commit is contained in:
Gabriele Cosmo
2016-06-09 15:37:50 +02:00
parent a8e9364cea
commit 96c8bcd0af
6923 changed files with 198390 additions and 41849 deletions
@@ -0,0 +1,14 @@
# $Id: G4MPI-lam.gmk,v 1.1 2007/11/16 13:32:56 kmura Exp $
# $Name: geant4-09-01 $
# ===========================================================
# Makefile for building G4MPI (LAM)
# ===========================================================
ifndef G4MPIROOT
G4MPIROOT = /opt/lam
endif
# additional flags
CXX := mpic++
CPPFLAGS += -I$(G4MPIROOT)/include
@@ -0,0 +1,14 @@
# $Id: G4MPI-mpich2.gmk,v 1.1 2007/11/16 13:32:56 kmura Exp $
# $Name: geant4-09-01 $
# ===========================================================
# Makefile for building G4MPI (MPICH2)
# ===========================================================
ifndef G4MPIROOT
G4MPIROOT = /opt/mpich2
endif
# additional flags
CXX := mpicxx
CPPFLAGS += -I$(G4MPIROOT)/include -DMPICH_IGNORE_CXX_SEEK
@@ -0,0 +1,14 @@
# $Id: G4MPI-openmpi.gmk,v 1.1 2007/11/16 13:32:56 kmura Exp $
# $Name: geant4-09-01 $
# ===========================================================
# Makefile for building G4MPI (LAM)
# ===========================================================
ifndef G4MPIROOT
G4MPIROOT = /opt/ompi
endif
# additional flags
CXX := mpic++
CPPFLAGS += -I$(G4MPIROOT)/include -I$(G4MPIROOT)/include/openmpi
@@ -0,0 +1,14 @@
# $Id: G4MPI.gmk,v 1.1 2007/11/16 13:32:56 kmura Exp $
# $Name: geant4-09-01 $
# ===========================================================
# Makefile for building G4MPI (LAM)
# ===========================================================
ifndef G4MPIROOT
G4MPIROOT = /opt/lam
endif
# additional flags
CXX := mpic++
CPPFLAGS += -I$(G4MPIROOT)/include
@@ -0,0 +1,44 @@
# $Id: GNUmakefile,v 1.1 2007/11/16 13:32:56 kmura Exp $
# $Name: geant4-09-01 $
# ===========================================================
# Makefile for building MPI interface
# ===========================================================
name := G4UImpi
ifndef G4INSTALL
G4INSTALL = ../../../../..
endif
include $(G4INSTALL)/config/architecture.gmk
include $(G4INSTALL)/config/interactivity.gmk
include G4MPI.gmk
CPPFLAGS += -I$(G4BASE)/global/management/include \
-I$(G4BASE)/global/HEPRandom/include \
-I$(G4BASE)/global/HEPGeometry/include \
-I$(G4BASE)/run/include \
-I$(G4BASE)/event/include \
-I$(G4BASE)/track/include \
-I$(G4BASE)/tracking/include \
-I$(G4BASE)/particles/management/include \
-I$(G4BASE)/processes/management/include \
-I$(G4BASE)/processes/cuts/include \
-I$(G4BASE)/processes/electromagnetic/utils/include \
-I$(G4BASE)/processes/transportation/include \
-I$(G4BASE)/processes/decay/include \
-I$(G4BASE)/materials/include \
-I$(G4BASE)/geometry/management/include \
-I$(G4BASE)/geometry/volumes/include \
-I$(G4BASE)/geometry/navigation/include \
-I$(G4BASE)/geometry/magneticfield/include \
-I$(G4BASE)/geometry/biasing/include \
-I$(G4BASE)/digits_hits/detector/include \
-I$(G4BASE)/digits_hits/hits/include \
-I$(G4BASE)/digits_hits/digits/include \
-I$(G4BASE)/interfaces/common/include \
-I$(G4BASE)/interfaces/basic/include \
-I$(G4BASE)/intercoms/include \
-I$(G4BASE)/graphics_reps/include
include $(G4INSTALL)/config/common.gmk
@@ -0,0 +1,16 @@
$Id: History,v 1.1 2007/11/16 13:32:56 kmura Exp $
-------------------------------------------------------------------
=========================================================
Geant4 - an Object-Oriented Toolkit for Simulation in HEP
=========================================================
G4MPI History file
------------------
16 Nov. 2007 K.Murakami
- commited to G4 CVS.
@@ -0,0 +1,41 @@
$Id: README,v 1.1 2007/11/16 13:32:56 kmura Exp $
==========================================================================
Geant4 MPI Interface
Author:
Koichi Murakami (KEK) / Koichi.Murakami@kek.jp
==========================================================================
How to build
============
1. Check "G4MPI.gmk" for yor MPI configuration:
* Set "G4MPIROOT", which is the root path to your MPI library.
* 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.
An example of "G4MPI.gmk":
# ===========================================================
# Makefile for building G4MPI (LAM)
# ===========================================================
ifndef G4MPIROOT
G4MPIROOT = /opt/lam
endif
# additional flags
CXX := mpic++
CPPFLAGS += -I$(G4MPIROOT)/include
2. Build the library
# make
# make includes
The library (libG4UImpi) will be created in $G4LIB,
and header files will be installed into $G4INCLUDE.
@@ -0,0 +1,63 @@
//
// ********************************************************************
// * License and Disclaimer *
// * *
// * The Geant4 software is copyright of the Copyright Holders of *
// * the Geant4 Collaboration. It is provided under the terms and *
// * conditions of the Geant4 Software License, included in the file *
// * LICENSE and available at http://cern.ch/geant4/license . These *
// * include a list of copyright holders. *
// * *
// * Neither the authors of this software system, nor their employing *
// * institutes,nor the agencies providing financial support for this *
// * work make any representation or warranty, express or implied, *
// * regarding this software system or assume any liability for its *
// * use. Please see the license in the file LICENSE and URL above *
// * for the full disclaimer and the limitation of liability. *
// * *
// * This code implementation is the result of the scientific and *
// * technical work of the GEANT4 collaboration. *
// * By using, copying, modifying or distributing the software (or *
// * any work based on the software) you agree to acknowledge its *
// * use in resulting scientific publications, and indicate your *
// * acceptance of all terms of the Geant4 Software license. *
// ********************************************************************
//
// $Id: G4MPIbatch.hh,v 1.1 2007/11/16 14:05:39 kmura Exp $
// $Name: geant4-09-01 $
//
// ====================================================================
// G4MPIbatch.hh
//
// 2007 Q
// ====================================================================
#ifndef G4MPI_BATCH_H
#define G4MPI_BATCH_H
#include "G4VMPIsession.hh"
#include <fstream>
// ====================================================================
//
// class definition
//
// ====================================================================
class G4MPIbatch : public G4VMPIsession {
protected:
std::ifstream batchStream;
G4bool isOpened;
G4bool isBatchMode;
// get command from a batch script file
G4String ReadCommand();
public:
G4MPIbatch(const G4String& fname="", G4bool qbatch=false);
~G4MPIbatch();
// concrete implementations
virtual G4UIsession* SessionStart();
};
#endif
@@ -0,0 +1,243 @@
//
// ********************************************************************
// * License and Disclaimer *
// * *
// * The Geant4 software is copyright of the Copyright Holders of *
// * the Geant4 Collaboration. It is provided under the terms and *
// * conditions of the Geant4 Software License, included in the file *
// * LICENSE and available at http://cern.ch/geant4/license . These *
// * include a list of copyright holders. *
// * *
// * Neither the authors of this software system, nor their employing *
// * institutes,nor the agencies providing financial support for this *
// * work make any representation or warranty, express or implied, *
// * regarding this software system or assume any liability for its *
// * use. Please see the license in the file LICENSE and URL above *
// * for the full disclaimer and the limitation of liability. *
// * *
// * This code implementation is the result of the scientific and *
// * technical work of the GEANT4 collaboration. *
// * By using, copying, modifying or distributing the software (or *
// * any work based on the software) you agree to acknowledge its *
// * use in resulting scientific publications, and indicate your *
// * 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-01 $
//
// ====================================================================
// G4MPImanager.hh
//
// 2007 Q
// ====================================================================
#ifndef G4MPI_MANAGER_H
#define G4MPI_MANAGER_H
#include "mpi.h"
#include "globals.hh"
#include <pthread.h>
#include <fstream>
// ====================================================================
//
// class definition
//
// ====================================================================
class G4MPImessenger;
class G4MPIsession;
class G4MPIstatus;
class G4VMPIseedGenerator;
class G4MPImanager {
private:
static G4MPImanager* theManager;
G4MPImessenger* messenger;
G4MPIsession* session;
G4int verbose;
G4MPIstatus* status; // status for each node
// MPI rank
G4bool isMaster;
G4bool isSlave;
G4int rank;
G4int size;
// MPI communicator
MPI::Intracomm COMM_G4COMMAND;
// cout/cerr control
G4bool qfcout;
std::ofstream fscout;
// init/macro file
G4bool qinitmacro;
G4String initFileName;
G4bool qbatchmode;
G4String macroFileName;
// internal use
void Initialize();
void ParseArguments(G4int argc, char** argv);
void Wait(G4int ausec) const;
void UpdateStatus();
// for beamOn
pthread_t threadID;
// seed generator
G4VMPIseedGenerator* seedGenerator;
// parallel parameters
G4double masterWeight;
public:
enum { // MPI master rank
RANK_MASTER= 0
};
enum { // MPI tag
TAG_G4COMMAND= 100,
TAG_G4STATUS= 200,
TAG_G4SEED= 300,
TAG_DATA= 1000
};
G4MPImanager();
G4MPImanager(int argc, char** argv);
~G4MPImanager();
static G4MPImanager* GetManager();
// set/get methods
G4MPIsession* GetMPIsession() const;
G4int GetVerbose() const;
void SetVerbose(G4int iverbose);
G4int GetSize() const;
G4int GetRank() const;
G4bool IsMaster() const;
G4bool IsSlave() const;
G4bool IsInitMacro() const;
const G4String& GetInitFileName() const;
G4bool IsBatchMode() const;
const G4String& GetMacroFileName() const;
void SetMasterWeight(G4double aweight);
G4double GetMasterWeight() const;
G4VMPIseedGenerator* GetSeedGenerator() const;
// MPI methods
G4String BcastCommand(const G4String& command);
void ShowStatus();
void ShowSeeds();
void SetSeed(G4int inode, G4long seed);
// 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);
// misc
void ShowHelp() const;
};
// ====================================================================
// inline functions
// ====================================================================
inline G4MPIsession* G4MPImanager::GetMPIsession() const
{
return session;
}
inline G4int G4MPImanager::GetVerbose() const
{
return verbose;
}
inline void G4MPImanager::SetVerbose(G4int iverbose)
{
G4int lv=iverbose;
if(iverbose>1) lv=1;
if(iverbose<0) lv=0;
verbose= lv;
return;
}
inline G4int G4MPImanager::GetRank() const
{
return rank;
}
inline G4int G4MPImanager::GetSize() const
{
return size;
}
inline G4bool G4MPImanager::IsMaster() const
{
return isMaster;
}
inline G4bool G4MPImanager::IsSlave() const
{
return isSlave;
}
inline G4bool G4MPImanager::IsInitMacro() const
{
return qinitmacro;
}
inline const G4String& G4MPImanager::GetInitFileName() const
{
return initFileName;
}
inline G4bool G4MPImanager::IsBatchMode() const
{
return qbatchmode;
}
inline const G4String& G4MPImanager::GetMacroFileName() const
{
return macroFileName;
}
inline void G4MPImanager::SetMasterWeight(G4double aweight)
{
masterWeight= aweight;
if(aweight<0.) masterWeight= 0.;
if(aweight>1.) masterWeight= 1.;
}
inline G4double G4MPImanager::GetMasterWeight() const
{
return masterWeight;
}
inline G4VMPIseedGenerator* G4MPImanager::GetSeedGenerator() const
{
return seedGenerator;
}
#endif
@@ -0,0 +1,81 @@
//
// ********************************************************************
// * License and Disclaimer *
// * *
// * The Geant4 software is copyright of the Copyright Holders of *
// * the Geant4 Collaboration. It is provided under the terms and *
// * conditions of the Geant4 Software License, included in the file *
// * LICENSE and available at http://cern.ch/geant4/license . These *
// * include a list of copyright holders. *
// * *
// * Neither the authors of this software system, nor their employing *
// * institutes,nor the agencies providing financial support for this *
// * work make any representation or warranty, express or implied, *
// * regarding this software system or assume any liability for its *
// * use. Please see the license in the file LICENSE and URL above *
// * for the full disclaimer and the limitation of liability. *
// * *
// * This code implementation is the result of the scientific and *
// * technical work of the GEANT4 collaboration. *
// * By using, copying, modifying or distributing the software (or *
// * any work based on the software) you agree to acknowledge its *
// * use in resulting scientific publications, and indicate your *
// * 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-01 $
//
// ====================================================================
// G4MPImessenger.hh
//
// 2007 Q
// ====================================================================
#ifndef G4MPI_MESSENGER_H
#define G4MPI_MESSENGER_H
#include "G4UImessenger.hh"
// ====================================================================
//
// class definition
//
// ====================================================================
class G4MPImanager;
class G4UIdirectory;
class G4UIcmdWithoutParameter;
class G4UIcmdWithAnInteger;
class G4UIcmdWithAString;
class G4UIcmdWithADouble;
class G4UIcommand;
class G4MPImessenger : public G4UImessenger {
private:
G4MPImanager* g4MPI;
// /mpi
G4UIdirectory* dir;
G4UIcmdWithAnInteger* verbose;
G4UIcmdWithoutParameter* status;
G4UIcmdWithAString* execute;
G4UIcommand* beamOn;
G4UIcmdWithAnInteger* dotbeamOn;
G4UIcmdWithADouble* masterWeight;
G4UIcmdWithoutParameter* showSeeds;
G4UIcmdWithAnInteger* setMasterSeed;
G4UIcommand* setSeed;
public:
G4MPImessenger(G4MPImanager* manager);
~G4MPImessenger();
virtual void SetNewValue(G4UIcommand* command, G4String newValue);
virtual G4String GetCurrentValue(G4UIcommand* command);
};
#endif
@@ -0,0 +1,56 @@
//
// ********************************************************************
// * License and Disclaimer *
// * *
// * The Geant4 software is copyright of the Copyright Holders of *
// * the Geant4 Collaboration. It is provided under the terms and *
// * conditions of the Geant4 Software License, included in the file *
// * LICENSE and available at http://cern.ch/geant4/license . These *
// * include a list of copyright holders. *
// * *
// * Neither the authors of this software system, nor their employing *
// * institutes,nor the agencies providing financial support for this *
// * work make any representation or warranty, express or implied, *
// * regarding this software system or assume any liability for its *
// * use. Please see the license in the file LICENSE and URL above *
// * for the full disclaimer and the limitation of liability. *
// * *
// * This code implementation is the result of the scientific and *
// * technical work of the GEANT4 collaboration. *
// * By using, copying, modifying or distributing the software (or *
// * any work based on the software) you agree to acknowledge its *
// * use in resulting scientific publications, and indicate your *
// * acceptance of all terms of the Geant4 Software license. *
// ********************************************************************
//
// $Id: G4MPIrandomSeedGenerator.hh,v 1.1 2007/11/16 14:05:40 kmura Exp $
// $Name: geant4-09-01 $
//
// ====================================================================
// G4MPIrandomSeedGenerator.hh
//
// 2007 Q
// ====================================================================
#ifndef G4MPI_RANDOM_SEED_GENERATOR_H
#define G4MPI_RANDOM_SEED_GENERATOR_H
#include "G4VMPIseedGenerator.hh"
// ====================================================================
//
// class definition
//
// ====================================================================
class G4MPIrandomSeedGenerator : public G4VMPIseedGenerator {
protected:
G4bool CheckDoubleCount();
virtual void GenerateSeeds();
public:
G4MPIrandomSeedGenerator();
~G4MPIrandomSeedGenerator();
};
#endif
@@ -0,0 +1,67 @@
//
// ********************************************************************
// * License and Disclaimer *
// * *
// * The Geant4 software is copyright of the Copyright Holders of *
// * the Geant4 Collaboration. It is provided under the terms and *
// * conditions of the Geant4 Software License, included in the file *
// * LICENSE and available at http://cern.ch/geant4/license . These *
// * include a list of copyright holders. *
// * *
// * Neither the authors of this software system, nor their employing *
// * institutes,nor the agencies providing financial support for this *
// * work make any representation or warranty, express or implied, *
// * regarding this software system or assume any liability for its *
// * use. Please see the license in the file LICENSE and URL above *
// * for the full disclaimer and the limitation of liability. *
// * *
// * This code implementation is the result of the scientific and *
// * technical work of the GEANT4 collaboration. *
// * By using, copying, modifying or distributing the software (or *
// * any work based on the software) you agree to acknowledge its *
// * use in resulting scientific publications, and indicate your *
// * acceptance of all terms of the Geant4 Software license. *
// ********************************************************************
//
// $Id: G4MPIsession.hh,v 1.1 2007/11/16 14:05:41 kmura Exp $
// $Name: geant4-09-01 $
//
// ====================================================================
// G4MPIsession.hh
//
// 2007 Q
// ====================================================================
#ifndef G4MPI_SESSION_H
#define G4MPI_SESSION_H
#include "G4VMPIsession.hh"
// ====================================================================
//
// class definition
//
// ====================================================================
class G4MPIsession : public G4VMPIsession {
protected:
G4VUIshell* shell;
// get command from user prompt of the master node
G4String GetCommand(const char* msg=0);
// misc
G4bool TryForcedTerminate();
public:
G4MPIsession(G4VUIshell* ashell=0);
~G4MPIsession();
void SetPrompt(const G4String& prompt);
void SetShell(G4VUIshell* ashell);
// concrete implementations
virtual G4UIsession* SessionStart();
};
#endif
@@ -0,0 +1,138 @@
//
// ********************************************************************
// * License and Disclaimer *
// * *
// * The Geant4 software is copyright of the Copyright Holders of *
// * the Geant4 Collaboration. It is provided under the terms and *
// * conditions of the Geant4 Software License, included in the file *
// * LICENSE and available at http://cern.ch/geant4/license . These *
// * include a list of copyright holders. *
// * *
// * Neither the authors of this software system, nor their employing *
// * institutes,nor the agencies providing financial support for this *
// * work make any representation or warranty, express or implied, *
// * regarding this software system or assume any liability for its *
// * use. Please see the license in the file LICENSE and URL above *
// * for the full disclaimer and the limitation of liability. *
// * *
// * This code implementation is the result of the scientific and *
// * technical work of the GEANT4 collaboration. *
// * By using, copying, modifying or distributing the software (or *
// * any work based on the software) you agree to acknowledge its *
// * use in resulting scientific publications, and indicate your *
// * acceptance of all terms of the Geant4 Software license. *
// ********************************************************************
//
// $Id: G4MPIstatus.hh,v 1.1 2007/11/16 14:05:41 kmura Exp $
// $Name: geant4-09-01 $
//
// ====================================================================
// G4MPIstatus.hh
//
// 2007 Q
// ====================================================================
#ifndef G4MPI_STATUS_H
#define G4MPI_STATUS_H
#include "globals.hh"
#include "G4ApplicationState.hh"
#include "G4Timer.hh"
// ====================================================================
//
// class definition
//
// ====================================================================
class G4Timer;
class G4MPIstatus {
private:
G4int rank;
G4int runID;
G4int nEventToBeProcessed;
G4int eventID;
G4double cputime;
G4ApplicationState g4state;
G4Timer* timer;
G4String GetStateString(G4ApplicationState astate) const;
public:
enum { NSIZE=10 };
G4MPIstatus();
~G4MPIstatus();
// 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;
// for pickling
G4int SizeOf() const;
void Pack(G4int* data) const;
void UnPack(G4int* data);
// for timer
void StartTimer();
void StopTimer();
void Print() const;
};
// ====================================================================
// inline functions
// ====================================================================
inline G4int G4MPIstatus::SizeOf() const
{
return NSIZE;
}
inline G4int G4MPIstatus::GetRank() const
{
return rank;
}
inline G4int G4MPIstatus::GetRunID() const
{
return runID;
}
inline G4int G4MPIstatus::GetNEventToBeProcessed() const
{
return nEventToBeProcessed;
}
inline G4int G4MPIstatus::GetEventID() const
{
return eventID;
}
inline G4double G4MPIstatus::GetCPUTime() const
{
return cputime;
}
inline G4ApplicationState G4MPIstatus::GetG4State() const
{
return g4state;
}
inline void G4MPIstatus::StartTimer()
{
timer-> Start();
}
inline void G4MPIstatus::StopTimer()
{
timer-> Stop();
}
#endif
@@ -0,0 +1,56 @@
//
// ********************************************************************
// * License and Disclaimer *
// * *
// * The Geant4 software is copyright of the Copyright Holders of *
// * the Geant4 Collaboration. It is provided under the terms and *
// * conditions of the Geant4 Software License, included in the file *
// * LICENSE and available at http://cern.ch/geant4/license . These *
// * include a list of copyright holders. *
// * *
// * Neither the authors of this software system, nor their employing *
// * institutes,nor the agencies providing financial support for this *
// * work make any representation or warranty, express or implied, *
// * regarding this software system or assume any liability for its *
// * use. Please see the license in the file LICENSE and URL above *
// * for the full disclaimer and the limitation of liability. *
// * *
// * This code implementation is the result of the scientific and *
// * technical work of the GEANT4 collaboration. *
// * By using, copying, modifying or distributing the software (or *
// * any work based on the software) you agree to acknowledge its *
// * use in resulting scientific publications, and indicate your *
// * acceptance of all terms of the Geant4 Software license. *
// ********************************************************************
//
// $Id: G4UImpish.hh,v 1.1 2007/11/16 14:05:41 kmura Exp $
// $Name: geant4-09-01 $
//
// ====================================================================
// G4UImpish.hh
//
// shell for MPI slaves
// 2007 Q
// ====================================================================
#ifndef G4UI_MPI_SH_H
#define G4UI_MPI_SH_H
#include "G4VUIshell.hh"
// ====================================================================
//
// class definition
//
// ====================================================================
class G4UImpish : public G4VUIshell {
public:
G4UImpish();
~G4UImpish();
virtual G4String GetCommandLine(const char* msg=0);
};
#endif
@@ -0,0 +1,79 @@
//
// ********************************************************************
// * License and Disclaimer *
// * *
// * The Geant4 software is copyright of the Copyright Holders of *
// * the Geant4 Collaboration. It is provided under the terms and *
// * conditions of the Geant4 Software License, included in the file *
// * LICENSE and available at http://cern.ch/geant4/license . These *
// * include a list of copyright holders. *
// * *
// * Neither the authors of this software system, nor their employing *
// * institutes,nor the agencies providing financial support for this *
// * work make any representation or warranty, express or implied, *
// * regarding this software system or assume any liability for its *
// * use. Please see the license in the file LICENSE and URL above *
// * for the full disclaimer and the limitation of liability. *
// * *
// * This code implementation is the result of the scientific and *
// * technical work of the GEANT4 collaboration. *
// * By using, copying, modifying or distributing the software (or *
// * any work based on the software) you agree to acknowledge its *
// * use in resulting scientific publications, and indicate your *
// * acceptance of all terms of the Geant4 Software license. *
// ********************************************************************
//
// $Id: G4VMPIseedGenerator.hh,v 1.1 2007/11/16 14:05:41 kmura Exp $
// $Name: geant4-09-01 $
//
// ====================================================================
// G4VMPIseedGenerator.hh
//
// 2007 Q
// ====================================================================
#ifndef G4VMPI_SEED_GENERATOR_H
#define G4VMPI_SEED_GENERATOR_H
#include "globals.hh"
#include <vector>
// ====================================================================
//
// class definition
//
// ====================================================================
class G4VMPIseedGenerator {
protected:
G4long masterSeed;
std::vector<G4long> seedList;
// generate seeds for MPI nodes
virtual void GenerateSeeds()=0;
public:
G4VMPIseedGenerator();
virtual ~G4VMPIseedGenerator();
// set/get methods
void SetMasterSeed(G4long aseed); // trigger GenerateSeeds()
G4long GetMasterSeed() const;
const std::vector<G4long>& GetSeedList() const;
};
// ====================================================================
// inline functions
// ====================================================================
inline G4long G4VMPIseedGenerator::GetMasterSeed() const
{
return masterSeed;
}
inline const std::vector<G4long>& G4VMPIseedGenerator::GetSeedList() const
{
return seedList;
}
#endif
@@ -0,0 +1,80 @@
//
// ********************************************************************
// * License and Disclaimer *
// * *
// * The Geant4 software is copyright of the Copyright Holders of *
// * the Geant4 Collaboration. It is provided under the terms and *
// * conditions of the Geant4 Software License, included in the file *
// * LICENSE and available at http://cern.ch/geant4/license . These *
// * include a list of copyright holders. *
// * *
// * Neither the authors of this software system, nor their employing *
// * institutes,nor the agencies providing financial support for this *
// * work make any representation or warranty, express or implied, *
// * regarding this software system or assume any liability for its *
// * use. Please see the license in the file LICENSE and URL above *
// * for the full disclaimer and the limitation of liability. *
// * *
// * This code implementation is the result of the scientific and *
// * technical work of the GEANT4 collaboration. *
// * By using, copying, modifying or distributing the software (or *
// * any work based on the software) you agree to acknowledge its *
// * use in resulting scientific publications, and indicate your *
// * 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-01 $
//
// ====================================================================
// G4VMPIsession.hh
//
// 2007 Q
// ====================================================================
#ifndef G4VMPI_SESSION_H
#define G4VMPI_SESSION_H
#include "G4VBasicShell.hh"
// ====================================================================
//
// class definition
//
// ====================================================================
typedef void* (*Func_t)(void *); // for thead function
class G4MPImanager;
class G4VUIshell;
class G4VMPIsession : public G4VBasicShell {
protected:
// MPI handling
G4MPImanager* g4MPI;
// MPI node info (cache)
G4bool isMaster;
G4bool isSlave;
G4int rank;
G4int ExecCommand(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();
public:
G4VMPIsession();
~G4VMPIsession();
// concrete implementations
virtual void PauseSessionStart(G4String msg);
virtual G4int ReceiveG4cout(G4String coutString);
virtual G4int ReceiveG4cerr(G4String cerrString);
};
#endif
@@ -0,0 +1,137 @@
//
// ********************************************************************
// * License and Disclaimer *
// * *
// * The Geant4 software is copyright of the Copyright Holders of *
// * the Geant4 Collaboration. It is provided under the terms and *
// * conditions of the Geant4 Software License, included in the file *
// * LICENSE and available at http://cern.ch/geant4/license . These *
// * include a list of copyright holders. *
// * *
// * Neither the authors of this software system, nor their employing *
// * institutes,nor the agencies providing financial support for this *
// * work make any representation or warranty, express or implied, *
// * regarding this software system or assume any liability for its *
// * use. Please see the license in the file LICENSE and URL above *
// * for the full disclaimer and the limitation of liability. *
// * *
// * This code implementation is the result of the scientific and *
// * technical work of the GEANT4 collaboration. *
// * By using, copying, modifying or distributing the software (or *
// * any work based on the software) you agree to acknowledge its *
// * use in resulting scientific publications, and indicate your *
// * 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-01 $
//
// ====================================================================
// G4MPIsession.cc
//
// 2007 Q
// ====================================================================
#include "G4MPIbatch.hh"
#include "G4MPImanager.hh"
#include "G4UIcommandStatus.hh"
// ====================================================================
//
// class description
//
// ====================================================================
////////////////////////////////////////////////////////////
G4MPIbatch::G4MPIbatch(const G4String& fname, G4bool qbatch)
: G4VMPIsession(),
isOpened(false), isBatchMode(qbatch)
////////////////////////////////////////////////////////////
{
if(isMaster) {
batchStream.open(fname, std::ios::in);
if(batchStream.fail()) {
G4cerr << "cannot open a macro file(" << fname << ")."
<< G4endl;
} else {
isOpened= true;
}
}
}
/////////////////////////////
G4MPIbatch::~G4MPIbatch()
/////////////////////////////
{
if(isOpened) batchStream.close();
}
//////////////////////////////////
G4String G4MPIbatch::ReadCommand()
//////////////////////////////////
{
enum { BUFSIZE= 256 };
char linebuf[BUFSIZE];
while(batchStream.good()) {
batchStream.getline(linebuf, BUFSIZE);
G4String cmdline(linebuf);
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;
}
}
if(cmdline.size()==0) continue; // skip null line
return cmdline;
}
return "exit"; // dummy
}
///////////////////////////////////////
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;
}
}
}
return 0;
}
@@ -0,0 +1,592 @@
//
// ********************************************************************
// * License and Disclaimer *
// * *
// * The Geant4 software is copyright of the Copyright Holders of *
// * the Geant4 Collaboration. It is provided under the terms and *
// * conditions of the Geant4 Software License, included in the file *
// * LICENSE and available at http://cern.ch/geant4/license . These *
// * include a list of copyright holders. *
// * *
// * Neither the authors of this software system, nor their employing *
// * institutes,nor the agencies providing financial support for this *
// * work make any representation or warranty, express or implied, *
// * regarding this software system or assume any liability for its *
// * use. Please see the license in the file LICENSE and URL above *
// * for the full disclaimer and the limitation of liability. *
// * *
// * This code implementation is the result of the scientific and *
// * technical work of the GEANT4 collaboration. *
// * By using, copying, modifying or distributing the software (or *
// * any work based on the software) you agree to acknowledge its *
// * use in resulting scientific publications, and indicate your *
// * 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-01 $
//
// ====================================================================
// G4MPImanager.cc
//
// 2007 Q
// ====================================================================
#include "G4MPImanager.hh"
#include "G4MPImessenger.hh"
#include "G4MPIsession.hh"
#include "G4MPIbatch.hh"
#include "G4MPIstatus.hh"
#include "G4MPIrandomSeedGenerator.hh"
#include "G4UImanager.hh"
#include "G4RunManager.hh"
#include "G4StateManager.hh"
#include "G4Run.hh"
#include <time.h>
#include <stdio.h>
#include <getopt.h>
G4MPImanager* G4MPImanager::theManager= 0;
// ====================================================================
// wrappers for thread functions
// ====================================================================
////////////////////////////////////////////////////////////////
static void thread_ExecuteThreadCommand(const G4String* command)
////////////////////////////////////////////////////////////////
{
G4MPImanager::GetManager()-> ExecuteThreadCommand(*command);
}
// ====================================================================
//
// class description
//
// ====================================================================
////////////////////////////
G4MPImanager::G4MPImanager()
: verbose(0),
qfcout(false),
qinitmacro(false),
qbatchmode(false),
threadID(0),
masterWeight(1.)
////////////////////////////
{
//MPI::Init();
MPI::Init_thread(MPI::THREAD_SERIALIZED);
Initialize();
}
/////////////////////////////////////////////////
G4MPImanager::G4MPImanager(int argc, char** argv)
: verbose(0), qfcout(false),
qinitmacro(false), qbatchmode(false),
threadID(0),
masterWeight(1.)
/////////////////////////////////////////////////
{
//MPI::Init(argc, argv);
MPI::Init_thread(argc, argv, MPI::THREAD_SERIALIZED);
Initialize();
ParseArguments(argc, argv);
}
/////////////////////////////
G4MPImanager::~G4MPImanager()
/////////////////////////////
{
if(isSlave && qfcout) fscout.close();
delete status;
delete messenger;
delete session;
COMM_G4COMMAND.Free();
MPI::Finalize();
theManager= 0;
}
////////////////////////////////////////
G4MPImanager* G4MPImanager::GetManager()
////////////////////////////////////////
{
if(theManager==0) {
G4Exception("G4MPImanager is not created.");
}
return theManager;
}
///////////////////////////////
void G4MPImanager::Initialize()
///////////////////////////////
{
if(theManager != 0) {
G4Exception("G4MPImanager is constructed twice.");
}
theManager= this;
// get rank information
size= MPI::COMM_WORLD.Get_size();
rank= MPI::COMM_WORLD.Get_rank();
isMaster= (rank == RANK_MASTER);
isSlave= (rank != RANK_MASTER);
// initialize MPI communicator
COMM_G4COMMAND= MPI::COMM_WORLD.Dup();
// new G4MPI stuffs
messenger= new G4MPImessenger(this);
session= new G4MPIsession;
status= new G4MPIstatus;
// default seed generator is random generator.
seedGenerator= new G4MPIrandomSeedGenerator;
DistributeSeeds();
}
////////////////////////////////////////////////////////
void G4MPImanager::ParseArguments(int argc, char** argv)
////////////////////////////////////////////////////////
{
G4int qhelp= 0;
G4String ofprefix="mpi";
G4int c;
while (1) {
G4int option_index= 0;
static struct option long_options[] = {
{"help", 0, 0, 0},
{"verbose", 0, 0, 0},
{"init", 1, 0, 0},
{"ofile", 2, 0, 0},
{0, 0, 0, 0}
};
opterr= 0; // suppress message
c= getopt_long(argc, argv, "hvi:o", long_options, &option_index);
opterr= 1;
if(c == -1) break;
switch (c) {
case 0:
switch(option_index) {
case 0 : // --help
qhelp= 1;
break;
case 1 : // --verbose
verbose= 1;
break;
case 2 : // --init
qinitmacro= true;
initFileName= optarg;
break;
case 3 : // --ofile
qfcout= true;
if(optarg) ofprefix= optarg;
break;
}
break;
case 'h' :
qhelp=1;
break;
case 'v' :
verbose= 1;
break;
case 'i' :
qinitmacro= true;
initFileName= optarg;
break;
case 'o' :
qfcout= true;
break;
default:
break;
}
}
// show help
if(qhelp) {
if(isMaster) ShowHelp();
MPI::Finalize();
exit(0);
}
// file output
if(isSlave && qfcout) {
G4String prefix= ofprefix+".%03d"+".cout";
char str[1024];
sprintf(str, prefix.c_str(), rank);
G4String fname(str);
fscout.open(fname.c_str(), std::ios::out);
}
// non-option ARGV-elements ...
if (optind < argc ) {
qbatchmode= true;
macroFileName= argv[optind];
}
}
//////////////////////////////////////////
void G4MPImanager::Wait(G4int ausec) const
//////////////////////////////////////////
{
struct timespec treq, trem;
treq.tv_sec = 0;
treq.tv_nsec = ausec*1000;
nanosleep(&treq, &trem);
}
// ====================================================================
/////////////////////////////////
void G4MPImanager::UpdateStatus()
/////////////////////////////////
{
G4RunManager* runManager= G4RunManager::GetRunManager();
const G4Run* run= runManager-> GetCurrentRun();
G4int runid, eventid, neventTBP;
if (run) { // running...
runid= run-> GetRunID();
neventTBP= run -> GetNumberOfEventToBeProcessed();
eventid= run-> GetNumberOfEvent();
} else {
runid= 0;
eventid= 0;
neventTBP= 0;
}
G4StateManager* stateManager= G4StateManager::GetStateManager();
G4ApplicationState g4state= stateManager-> GetCurrentState();
status-> SetStatus(rank, runid, neventTBP, eventid, g4state);
}
///////////////////////////////
void G4MPImanager::ShowStatus()
///////////////////////////////
{
G4int buff[G4MPIstatus::NSIZE];
UpdateStatus();
G4bool gstatus= CheckThreadStatus();
if(isMaster) {
status-> Print(); // for maser itself
G4int nev= status-> GetEventID();
G4int nevtp= status-> GetNEventToBeProcessed();
G4double cputime= status-> GetCPUTime();
// receive from each slave
for (G4int islave=1; islave< size; islave++) {
COMM_G4COMMAND.Recv(buff, G4MPIstatus::NSIZE, MPI::INT,
islave, TAG_G4STATUS);
status-> UnPack(buff);
status-> Print();
// aggregation
nev+= status-> GetEventID();
nevtp+= status-> GetNEventToBeProcessed();
//mpistate= status-> GetG4State();
cputime+= status-> GetCPUTime();
}
G4String strStatus;
if(gstatus) {
strStatus= "Run";
} else {
strStatus= "Idle";
}
G4cout << "-------------------------------------------------------"
<< G4endl
<< "* #ranks= " << size
<< " event= " << nev << "/" << nevtp
<< " state= " << strStatus
<< " time= " << cputime << "s"
<< G4endl;
} else {
status-> Pack(buff);
COMM_G4COMMAND.Send(buff, G4MPIstatus::NSIZE, MPI::INT,
RANK_MASTER, TAG_G4STATUS);
}
}
// ====================================================================
////////////////////////////////////
void G4MPImanager::DistributeSeeds()
////////////////////////////////////
{
std::vector<G4long> seedList= seedGenerator-> GetSeedList();
CLHEP::HepRandom::setTheSeed(seedList[rank]);
}
//////////////////////////////
void G4MPImanager::ShowSeeds()
//////////////////////////////
{
G4long buff;
if(isMaster) {
// print master
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
<< " seed= " << buff
<< G4endl;
}
} else { // slaves
buff= CLHEP::HepRandom::getTheSeed();
COMM_G4COMMAND.Send(&buff, 1, MPI::LONG, RANK_MASTER, TAG_G4SEED);
}
}
////////////////////////////////////////////////////
void G4MPImanager::SetSeed(G4int inode, G4long seed)
////////////////////////////////////////////////////
{
if(rank==inode) {
CLHEP::HepRandom::setTheSeed(seed);
}
}
// ====================================================================
////////////////////////////////////////
G4bool G4MPImanager::CheckThreadStatus()
////////////////////////////////////////
{
unsigned buff;
G4bool qstatus= false;
if(isMaster) {
qstatus= threadID;
// get slave status
for (G4int islave=1; islave< size; islave++) {
COMM_G4COMMAND.Recv(&buff, 1, MPI::UNSIGNED, islave, TAG_G4STATUS);
qstatus |= buff;
}
} else {
buff= unsigned(threadID);
COMM_G4COMMAND.Send(&buff, 1, MPI::UNSIGNED, RANK_MASTER, TAG_G4STATUS);
}
// broadcast
buff= qstatus; // for master
COMM_G4COMMAND.Bcast(&buff, 1, MPI::UNSIGNED, RANK_MASTER);
qstatus= buff; // for slave
return qstatus;
}
////////////////////////////////////////////////////////////////
void G4MPImanager::ExecuteThreadCommand(const G4String& command)
////////////////////////////////////////////////////////////////
{
// this method is a thread function.
G4UImanager* UI= G4UImanager::GetUIpointer();
G4int rc= UI-> ApplyCommand(command);
G4int commandStatus = rc - (rc%100);
switch(commandStatus) {
case fCommandSucceeded:
break;
case fIllegalApplicationState:
G4cerr << "illegal application state -- command refused" << G4endl;
break;
default:
G4cerr << "command refused (" << commandStatus << ")" << G4endl;
break;
}
// thread is joined
if(threadID) {
pthread_join(threadID, 0);
threadID= 0;
}
return;
}
///////////////////////////////////////////////////////////////
void G4MPImanager::ExecuteBeamOnThread(const G4String& command)
///////////////////////////////////////////////////////////////
{
G4bool threadStatus= CheckThreadStatus();
if (threadStatus) {
if(isMaster) {
G4cout << "G4MPIsession:: beamOn is still running." << G4endl;
}
} else { // ok
static G4String cmdstr;
cmdstr= command;
G4int rc= pthread_create(&threadID, 0,
(Func_t)thread_ExecuteThreadCommand,
(void*)&cmdstr);
if (rc != 0)
G4Exception("G4MPIsession:: failed to create a beamOn thread.");
}
}
/////////////////////////////////////
void G4MPImanager::JoinBeamOnThread()
/////////////////////////////////////
{
if(threadID) {
pthread_join(threadID, 0);
threadID= 0;
}
}
// ====================================================================
////////////////////////////////////////////////////////////
G4String G4MPImanager::BcastCommand(const G4String& command)
////////////////////////////////////////////////////////////
{
enum { BUFF_SIZE= 512 };
static char sbuff[BUFF_SIZE];
command.copy(sbuff,BUFF_SIZE);
G4int len= command.size();
sbuff[len]='\0'; // no boundary check
// "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);
// another implementation
if( isMaster ) {
for (G4int islave=1; islave< size; islave++) {
COMM_G4COMMAND.Send(sbuff, BUFF_SIZE, MPI::CHAR, islave, TAG_G4COMMAND);
}
} else {
// try non-blocking receive
MPI::Request request= COMM_G4COMMAND.Irecv(sbuff, BUFF_SIZE, MPI::CHAR,
RANK_MASTER, TAG_G4COMMAND);
// polling...
MPI::Status status;
while(! request.Test(status)) {
Wait(100);
}
}
return G4String(sbuff);
}
// ====================================================================
/////////////////////////////////////////////////////////////////////////
void G4MPImanager::ExecuteMacroFile(const G4String& fname, G4bool qbatch)
/////////////////////////////////////////////////////////////////////////
{
G4MPIbatch* batchSession= new G4MPIbatch(fname, qbatch);
batchSession-> SessionStart();
delete batchSession;
}
///////////////////////////////////////////////////////
void G4MPImanager::BeamOn(G4int nevent, G4bool qdivide)
///////////////////////////////////////////////////////
{
G4RunManager* runManager= G4RunManager::GetRunManager();
if(qdivide) { // events are divided
G4double ntot= masterWeight+size-1.;
G4int nproc= G4int(nevent/ntot);
G4int nproc0= nevent-nproc*(size-1);
if(verbose>0 && isMaster) {
G4cout << "#events in master=" << nproc0 << " / "
<< "#events in slave=" << nproc << G4endl;
}
status-> StartTimer(); // start timer
if(isMaster) runManager-> BeamOn(nproc0);
else runManager-> BeamOn(nproc);
status-> StopTimer(); // stop timer
} else { // same events are generated in each node (for test use)
if(verbose>0 && isMaster) {
G4cout << "#events in master=" << nevent << " / "
<< "#events in slave=" << nevent << G4endl;
}
status-> StartTimer(); // start timer
runManager-> BeamOn(nevent);
status-> StopTimer(); // stop timer
}
}
/////////////////////////////////////////////////
void G4MPImanager::Print(const G4String& message)
/////////////////////////////////////////////////
{
if(isMaster){
std::cout << message << std::flush;
} else {
if(qfcout) { // output to a file
fscout << message << std::flush;
} else { // output to stdout
std::cout << rank << ":" << message << std::flush;
}
}
}
///////////////////////////////////
void G4MPImanager::ShowHelp() const
///////////////////////////////////
{
if(isSlave) return;
G4cout << "Geant4 MPI interface" << G4endl;
G4cout << "usage:" << G4endl;
G4cout << "<app> [options] [macro file]"
<< G4endl << G4endl;
G4cout << " -h, --help show this message."
<< G4endl;
G4cout << " -v, --verbose show verbose message"
<< G4endl;
G4cout << " -i, --init=FNAME set an init macro file"
<< G4endl;
G4cout << " -o, --ofile[=FNAME] set slave output to a flie"
<< G4endl;
G4cout << G4endl;
}
@@ -0,0 +1,207 @@
//
// ********************************************************************
// * License and Disclaimer *
// * *
// * The Geant4 software is copyright of the Copyright Holders of *
// * the Geant4 Collaboration. It is provided under the terms and *
// * conditions of the Geant4 Software License, included in the file *
// * LICENSE and available at http://cern.ch/geant4/license . These *
// * include a list of copyright holders. *
// * *
// * Neither the authors of this software system, nor their employing *
// * institutes,nor the agencies providing financial support for this *
// * work make any representation or warranty, express or implied, *
// * regarding this software system or assume any liability for its *
// * use. Please see the license in the file LICENSE and URL above *
// * for the full disclaimer and the limitation of liability. *
// * *
// * This code implementation is the result of the scientific and *
// * technical work of the GEANT4 collaboration. *
// * By using, copying, modifying or distributing the software (or *
// * any work based on the software) you agree to acknowledge its *
// * use in resulting scientific publications, and indicate your *
// * 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-01 $
//
// ====================================================================
// G4MPImessenger.cc
//
// 2007 Q
// ====================================================================
#include "G4MPImessenger.hh"
#include "G4MPImanager.hh"
#include "G4VMPIseedGenerator.hh"
#include "G4UIdirectory.hh"
#include "G4UIcmdWithoutParameter.hh"
#include "G4UIcmdWithAnInteger.hh"
#include "G4UIcmdWithAString.hh"
#include "G4UIcmdWithADouble.hh"
#include "G4UIcommand.hh"
#include "G4UIparameter.hh"
#include <sstream>
// ====================================================================
//
// class description
//
// ====================================================================
//////////////////////////////////////////////////////
G4MPImessenger::G4MPImessenger( G4MPImanager* manager)
: G4UImessenger(), g4MPI(manager)
//////////////////////////////////////////////////////
{
// /mpi
dir= new G4UIdirectory("/mpi/");
dir-> SetGuidance("MPI control commands");
// /mpi/verbose
verbose= new G4UIcmdWithAnInteger("/mpi/verbose", this);
verbose-> SetGuidance("Set verbose level.");
verbose-> SetParameterName("verbose", false, false);
verbose->SetRange("verbose>=0 && verbose<=1");
// /mpi/status
status= new G4UIcmdWithoutParameter("/mpi/status", this);
status-> SetGuidance( "Show mpi status.");
// /mpi/execute
execute= new G4UIcmdWithAString("/mpi/execute", this);
execute-> SetGuidance("Execute a macro file. (=/control/execute)");
execute-> SetParameterName("fileName", false, false);
// /mpi/beamOn
beamOn= new G4UIcommand("/mpi/beamOn", this);
beamOn-> SetGuidance("Start a parallel run w/ thread.");
G4UIparameter* p1= new G4UIparameter("numberOfEvent", 'i', true);
p1-> SetDefaultValue(1);
p1-> SetParameterRange("numberOfEvent>=0");
beamOn-> SetParameter(p1);
G4UIparameter* p2= new G4UIparameter("divide", 'b', true);
p2-> SetDefaultValue(true);
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");
// /mpi/weightForMaster
masterWeight= new G4UIcmdWithADouble("/mpi/masterWeight", this);
masterWeight-> SetGuidance("Set weight for master node.");
masterWeight-> SetParameterName("weight", false, false);
masterWeight-> SetRange("weight>=0. && weight<=1.");
// /mpi/showSeeds
showSeeds= new G4UIcmdWithoutParameter("/mpi/showSeeds", this);
showSeeds-> SetGuidance("Show seeds of MPI nodes.");
// /mpi/setMasterSeed
setMasterSeed= new G4UIcmdWithAnInteger("/mpi/setMasterSeed", this);
setMasterSeed-> SetGuidance("Set a master seed for the seed generator.");
setMasterSeed-> SetParameterName("seed", false, false);
// /mpi/setSeed
setSeed= new G4UIcommand("/mpi/setSeed", this);
setSeed-> SetGuidance("Set a seed for a specified node.");
p1= new G4UIparameter("node", 'i', false);
p1-> SetParameterRange("node>=0");
setSeed-> SetParameter(p1);
p2= new G4UIparameter("seed", 'i', false);
setSeed-> SetParameter(p2);
}
/////////////////////////////////
G4MPImessenger::~G4MPImessenger()
/////////////////////////////////
{
delete verbose;
delete status;
delete execute;
delete beamOn;
delete dotbeamOn;
delete masterWeight;
delete showSeeds;
delete setMasterSeed;
delete setSeed;
delete dir;
}
//////////////////////////////////////////////////////////////////////////
void G4MPImessenger::SetNewValue( G4UIcommand* command, G4String newValue)
//////////////////////////////////////////////////////////////////////////
{
if (command == verbose) { // /mpi/verbose
G4int lv= verbose-> GetNewIntValue(newValue);
g4MPI-> SetVerbose(lv);
} else if (command == status){ // /mpi/status
g4MPI-> ShowStatus();
} else if (command == execute){ // /mpi/execute
g4MPI-> ExecuteMacroFile(newValue);
} else if (command == beamOn){ // /mpi/beamOn
std::istringstream is(newValue);
G4int nevent;
G4bool qdivide;
is >> nevent >> qdivide;
g4MPI-> BeamOn(nevent, qdivide);
} else if (command == dotbeamOn){ // /mpi/.beamOn
G4int nevent= dotbeamOn-> GetNewIntValue(newValue);
g4MPI-> BeamOn(nevent);
} 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;
G4long seed;
is >> inode >> seed;
g4MPI-> SetSeed(inode, seed);
}
return;
}
/////////////////////////////////////////////////////////////
G4String G4MPImessenger::GetCurrentValue(G4UIcommand* command)
/////////////////////////////////////////////////////////////
{
G4String cv;
if (command == verbose) {
cv= verbose-> ConvertToString(g4MPI->GetVerbose());
} else if (command == masterWeight) {
cv= masterWeight-> ConvertToString(g4MPI->GetMasterWeight());
}
return cv;
}
@@ -0,0 +1,99 @@
//
// ********************************************************************
// * License and Disclaimer *
// * *
// * The Geant4 software is copyright of the Copyright Holders of *
// * the Geant4 Collaboration. It is provided under the terms and *
// * conditions of the Geant4 Software License, included in the file *
// * LICENSE and available at http://cern.ch/geant4/license . These *
// * include a list of copyright holders. *
// * *
// * Neither the authors of this software system, nor their employing *
// * institutes,nor the agencies providing financial support for this *
// * work make any representation or warranty, express or implied, *
// * regarding this software system or assume any liability for its *
// * use. Please see the license in the file LICENSE and URL above *
// * for the full disclaimer and the limitation of liability. *
// * *
// * This code implementation is the result of the scientific and *
// * technical work of the GEANT4 collaboration. *
// * By using, copying, modifying or distributing the software (or *
// * any work based on the software) you agree to acknowledge its *
// * use in resulting scientific publications, and indicate your *
// * acceptance of all terms of the Geant4 Software license. *
// ********************************************************************
//
// $Id: G4MPIrandomSeedGenerator.cc,v 1.1 2007/11/16 14:05:41 kmura Exp $
// $Name: geant4-09-01 $
//
// ====================================================================
// G4MPIrandomSeedGenerator.cc
//
// 2007 Q
// ====================================================================
#include "G4MPIrandomSeedGenerator.hh"
#include "G4MPImanager.hh"
#include "Randomize.hh"
// ====================================================================
//
// class description
//
// ====================================================================
////////////////////////////////////////////////////
G4MPIrandomSeedGenerator::G4MPIrandomSeedGenerator()
: G4VMPIseedGenerator()
////////////////////////////////////////////////////
{
GenerateSeeds();
}
/////////////////////////////////////////////////////
G4MPIrandomSeedGenerator::~G4MPIrandomSeedGenerator()
/////////////////////////////////////////////////////
{
}
///////////////////////////////////////////////////
G4bool G4MPIrandomSeedGenerator::CheckDoubleCount()
///////////////////////////////////////////////////
{
G4MPImanager* g4MPI= G4MPImanager::GetManager();
G4int nsize= g4MPI-> GetSize();
for (G4int i=0; i< nsize; i++) {
for (G4int j=0; j< nsize; j++) {
if((i != j) && (seedList[i] == seedList[j])) {
G4double x= G4UniformRand();
seedList[j]= G4long(x*LONG_MAX);
return false;
}
}
}
return true;
}
//////////////////////////////////////////////
void G4MPIrandomSeedGenerator::GenerateSeeds()
//////////////////////////////////////////////
{
G4MPImanager* g4MPI= G4MPImanager::GetManager();
G4int nsize= g4MPI-> GetSize();
seedList.clear();
for (G4int i=0; i< nsize; i++) {
G4double x= G4UniformRand();
G4int seed= G4long(x*LONG_MAX);
seedList.push_back(seed);
}
while(! CheckDoubleCount()) {
continue;
}
}
@@ -0,0 +1,264 @@
//
// ********************************************************************
// * License and Disclaimer *
// * *
// * The Geant4 software is copyright of the Copyright Holders of *
// * the Geant4 Collaboration. It is provided under the terms and *
// * conditions of the Geant4 Software License, included in the file *
// * LICENSE and available at http://cern.ch/geant4/license . These *
// * include a list of copyright holders. *
// * *
// * Neither the authors of this software system, nor their employing *
// * institutes,nor the agencies providing financial support for this *
// * work make any representation or warranty, express or implied, *
// * regarding this software system or assume any liability for its *
// * use. Please see the license in the file LICENSE and URL above *
// * for the full disclaimer and the limitation of liability. *
// * *
// * This code implementation is the result of the scientific and *
// * technical work of the GEANT4 collaboration. *
// * By using, copying, modifying or distributing the software (or *
// * any work based on the software) you agree to acknowledge its *
// * use in resulting scientific publications, and indicate your *
// * 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-01 $
//
// ====================================================================
// G4MPIsession.cc
//
// 2007 Q
// ====================================================================
#include "G4MPIsession.hh"
#include "G4MPImanager.hh"
#include "G4RunManager.hh"
#include "G4UImanager.hh"
#include "G4UIcommand.hh"
#include "G4UIcsh.hh"
#include "G4UImpish.hh"
// ====================================================================
//
// class description
//
// ====================================================================
//////////////////////////////////////////////
G4MPIsession::G4MPIsession(G4VUIshell* ashell)
: G4VMPIsession()
//////////////////////////////////////////////
{
G4UImanager* UI= G4UImanager::GetUIpointer();
UI-> SetSession(this);
UI-> SetCoutDestination(this);
// shell
if(isMaster) {
if(ashell) {
shell= ashell;
} else {
shell= new G4UIcsh;
}
} else {
shell= new G4UImpish;
}
}
/////////////////////////////
G4MPIsession::~G4MPIsession()
/////////////////////////////
{
delete shell;
G4UImanager* UI= G4UImanager::GetUIpointer();
UI-> SetSession(0);
UI-> SetCoutDestination(0);
}
////////////////////////////////////////////////////
void G4MPIsession::SetPrompt(const G4String& prompt)
////////////////////////////////////////////////////
{
shell-> SetPrompt(prompt);
}
///////////////////////////////////////////////
void G4MPIsession::SetShell(G4VUIshell* ashell)
///////////////////////////////////////////////
{
delete shell;
shell= ashell;
}
//////////////////////////////////////////////////
G4String G4MPIsession::GetCommand(const char* msg)
//////////////////////////////////////////////////
{
G4UImanager* UI= G4UImanager::GetUIpointer();
G4String newCommand;
const G4String nullString="";
// get command from shell...
newCommand= shell-> GetCommandLine(msg);
G4String nC= newCommand.strip(G4String::leading);
if( nC.length() == 0 ) {
newCommand= nullString;
} else if( nC(0) == '#' ) {
G4cout << nC << G4endl;
newCommand= nullString;
} else if(nC=="ls" || nC(0,3)=="ls " ) { // list commands
ListDirectory(nC);
newCommand= nullString;
} else if(nC=="lc" || nC(0,3)=="lc " ) { // ... by shell
shell-> ListCommand(nC.remove(0,2));
newCommand= nullString;
} else if(nC == "pwd") { // show current directory
G4cout << "Current Command Directory : "
<< GetCurrentWorkingDirectory() << G4endl;
newCommand= nullString;
} else if(nC == "cwd") { // ... by shell
shell-> ShowCurrentDirectory();
newCommand= nullString;
} else if(nC == "cd" || nC(0,3) == "cd ") { // "cd"
ChangeDirectoryCommand(nC);
shell-> SetCurrentDirectory(GetCurrentWorkingDirectory());
newCommand= nullString;
} else if(nC == "help" || nC(0,5) == "help ") { // "help"
TerminalHelp(nC);
newCommand= nullString;
} else if(nC(0) == '?') { // "show current value of a parameter"
ShowCurrent(nC);
newCommand= nullString;
} else if(nC == "hist" || nC == "history") { // "hist/history"
G4int nh= UI-> GetNumberOfHistory();
for (G4int i=0; i<nh; i++) {
G4cout << i << ": " << UI->GetPreviousCommand(i) << G4endl;
}
newCommand= nullString;
} else if(nC(0) == '!') { // "!"
G4String ss= nC(1, nC.length()-1);
G4int vl;
const char* tt= ss;
std::istringstream is(tt);
is >> vl;
G4int nh= UI-> GetNumberOfHistory();
if(vl>=0 && vl<nh) {
newCommand= UI-> GetPreviousCommand(vl);
G4cout << newCommand << G4endl;
} else {
G4cerr << "history " << vl << " is not found." << G4endl;
newCommand= nullString;
}
} else if( nC.empty() ){ // NULL command
newCommand= nullString;
} else if( nC == "exit" ){ // "exit"
return "exit";
} else { // ...
}
newCommand= TruncateCommand(newCommand);
return ModifyToFullPathCommand(newCommand);
}
/////////////////////////////////////////
G4UIsession* G4MPIsession::SessionStart()
/////////////////////////////////////////
{
// execute init macro
if(g4MPI-> IsInitMacro()) {
g4MPI-> ExecuteMacroFile(g4MPI->GetInitFileName());
}
// batch mode
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();
if(qexit) break;
else scommand="";
}
}
return 0;
}
/////////////////////////////////////////
G4bool G4MPIsession::TryForcedTerminate()
/////////////////////////////////////////
{
if(! g4MPI-> CheckThreadStatus()) {
return true;
}
G4String xmessage;
// beamOn is still running
if(isMaster) {
char c[1024];
while(1) {
G4cout << "Run is still running. Do you abort a run? [y/N]:"
<< std::flush;
G4cin.getline(c,1024);
G4String yesno= c;
if(yesno=="y" || yesno=="Y" ||
yesno=="n" || yesno=="N" || yesno == "") {
break;
}
}
if(c[0]=='y' || c[0]=='Y') {
G4cout << "Aborting a run..." << G4endl;
xmessage= g4MPI-> BcastCommand("kill me");
} else {
xmessage= g4MPI-> BcastCommand("alive");
}
} else {
xmessage= g4MPI->BcastCommand("");
}
if(xmessage == "kill me") {
G4RunManager* runManager= G4RunManager::GetRunManager();
runManager-> AbortRun(true); // soft abort
}
return false;
}
@@ -0,0 +1,161 @@
//
// ********************************************************************
// * License and Disclaimer *
// * *
// * The Geant4 software is copyright of the Copyright Holders of *
// * the Geant4 Collaboration. It is provided under the terms and *
// * conditions of the Geant4 Software License, included in the file *
// * LICENSE and available at http://cern.ch/geant4/license . These *
// * include a list of copyright holders. *
// * *
// * Neither the authors of this software system, nor their employing *
// * institutes,nor the agencies providing financial support for this *
// * work make any representation or warranty, express or implied, *
// * regarding this software system or assume any liability for its *
// * use. Please see the license in the file LICENSE and URL above *
// * for the full disclaimer and the limitation of liability. *
// * *
// * This code implementation is the result of the scientific and *
// * technical work of the GEANT4 collaboration. *
// * By using, copying, modifying or distributing the software (or *
// * any work based on the software) you agree to acknowledge its *
// * use in resulting scientific publications, and indicate your *
// * 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-01 $
//
// ====================================================================
// G4MPIstatus.cc
//
// 2007 Q
// ====================================================================
#include "G4MPIstatus.hh"
#include "G4ApplicationState.hh"
// ====================================================================
//
// class description
//
// ====================================================================
//////////////////////////
G4MPIstatus::G4MPIstatus()
: rank(0), runID(0),
nEventToBeProcessed(0),
eventID(0),
cputime(0.),
g4state(G4State_Quit)
//////////////////////////
{
timer= new G4Timer;
timer-> Start();
}
//////////////////////////
G4MPIstatus::~G4MPIstatus()
//////////////////////////
{
delete timer;
}
/////////////////////////////////////////////////////
void G4MPIstatus::SetStatus(G4int arank, G4int runid,
G4int noe, G4int evtid,
G4ApplicationState state)
/////////////////////////////////////////////////////
{
rank= arank;
runID= runid;
nEventToBeProcessed= noe;
eventID= evtid;
g4state= state;
timer-> Stop();
cputime= timer-> GetUserElapsed();
}
/////////////////////////////////////////
void G4MPIstatus::Pack(G4int* data) const
/////////////////////////////////////////
{
data[0]= rank;
data[1]= runID;
data[2]= nEventToBeProcessed;
data[3]= eventID;
data[4]= g4state;
G4double* ddata= (G4double*)(data+5);
ddata[0]= cputime;
}
/////////////////////////////////////
void G4MPIstatus::UnPack(G4int* data)
/////////////////////////////////////
{
rank= data[0];
runID= data[1];
nEventToBeProcessed= data[2];
eventID= data[3];
g4state= (G4ApplicationState)data[4];
G4double* ddata= (G4double*)(data+5);
cputime= ddata[0];
}
///////////////////////////////
void G4MPIstatus::Print() const
///////////////////////////////
{
// * rank= 001 run= 10002 event= 00001 / 100000 state= Idle"
G4cout << "* rank= " << rank
<< " run= " << runID
<< " event= " << eventID << " / " << nEventToBeProcessed
<< " state= " << GetStateString(g4state)
<< " time= " << cputime << "s"
<< G4endl;
}
/////////////////////////////////////////////////////////////////////
G4String G4MPIstatus::GetStateString(G4ApplicationState astate) const
/////////////////////////////////////////////////////////////////////
{
G4String sname;
switch(astate) {
case G4State_PreInit:
sname = "PreInit";
break;
case G4State_Init:
sname = "Init";
break;
case G4State_Idle:
sname = "Idle";
break;
case G4State_GeomClosed:
sname = "GeomClosed";
break;
case G4State_EventProc:
sname = "EventProc";
break;
case G4State_Quit:
sname = "Quit";
break;
case G4State_Abort:
sname = "Abort";
break;
default:
sname = "Unknown";
break;
}
return sname;
}
@@ -0,0 +1,66 @@
//
// ********************************************************************
// * License and Disclaimer *
// * *
// * The Geant4 software is copyright of the Copyright Holders of *
// * the Geant4 Collaboration. It is provided under the terms and *
// * conditions of the Geant4 Software License, included in the file *
// * LICENSE and available at http://cern.ch/geant4/license . These *
// * include a list of copyright holders. *
// * *
// * Neither the authors of this software system, nor their employing *
// * institutes,nor the agencies providing financial support for this *
// * work make any representation or warranty, express or implied, *
// * regarding this software system or assume any liability for its *
// * use. Please see the license in the file LICENSE and URL above *
// * for the full disclaimer and the limitation of liability. *
// * *
// * This code implementation is the result of the scientific and *
// * technical work of the GEANT4 collaboration. *
// * By using, copying, modifying or distributing the software (or *
// * any work based on the software) you agree to acknowledge its *
// * use in resulting scientific publications, and indicate your *
// * acceptance of all terms of the Geant4 Software license. *
// ********************************************************************
//
// $Id: G4UImpish.cc,v 1.1 2007/11/16 14:05:41 kmura Exp $
// $Name: geant4-09-01 $
//
// ====================================================================
// G4UImpish.cc
//
// 2007 Q
// ====================================================================
#include "G4UImpish.hh"
// ====================================================================
//
// class description
//
// ====================================================================
//////////////////////
G4UImpish::G4UImpish()
: G4VUIshell("")
//////////////////////
{
}
///////////////////////
G4UImpish::~G4UImpish()
///////////////////////
{
}
///////////////////////////////////////////////
G4String G4UImpish::GetCommandLine(const char*)
///////////////////////////////////////////////
{
G4String newCommand;
// recieve command string from master
G4cout << "hoge hoge" << G4endl;
return newCommand;
}
@@ -0,0 +1,63 @@
//
// ********************************************************************
// * License and Disclaimer *
// * *
// * The Geant4 software is copyright of the Copyright Holders of *
// * the Geant4 Collaboration. It is provided under the terms and *
// * conditions of the Geant4 Software License, included in the file *
// * LICENSE and available at http://cern.ch/geant4/license . These *
// * include a list of copyright holders. *
// * *
// * Neither the authors of this software system, nor their employing *
// * institutes,nor the agencies providing financial support for this *
// * work make any representation or warranty, express or implied, *
// * regarding this software system or assume any liability for its *
// * use. Please see the license in the file LICENSE and URL above *
// * for the full disclaimer and the limitation of liability. *
// * *
// * This code implementation is the result of the scientific and *
// * technical work of the GEANT4 collaboration. *
// * By using, copying, modifying or distributing the software (or *
// * any work based on the software) you agree to acknowledge its *
// * use in resulting scientific publications, and indicate your *
// * acceptance of all terms of the Geant4 Software license. *
// ********************************************************************
//
// $Id: G4VMPIseedGenerator.cc,v 1.1 2007/11/16 14:05:41 kmura Exp $
// $Name: geant4-09-01 $
// ====================================================================
// G4VMPIseedGenerator.cc
//
// 2007 Q
// ====================================================================
#include "G4VMPIseedGenerator.hh"
// ====================================================================
//
// class description
//
// ====================================================================
//////////////////////////////////////////
G4VMPIseedGenerator::G4VMPIseedGenerator()
: masterSeed(123456789)
//////////////////////////////////////////
{
}
///////////////////////////////////////////
G4VMPIseedGenerator::~G4VMPIseedGenerator()
///////////////////////////////////////////
{
}
/////////////////////////////////////////////////////
void G4VMPIseedGenerator::SetMasterSeed(G4long aseed)
/////////////////////////////////////////////////////
{
masterSeed= aseed;
GenerateSeeds();
}
@@ -0,0 +1,263 @@
//
// ********************************************************************
// * License and Disclaimer *
// * *
// * The Geant4 software is copyright of the Copyright Holders of *
// * the Geant4 Collaboration. It is provided under the terms and *
// * conditions of the Geant4 Software License, included in the file *
// * LICENSE and available at http://cern.ch/geant4/license . These *
// * include a list of copyright holders. *
// * *
// * Neither the authors of this software system, nor their employing *
// * institutes,nor the agencies providing financial support for this *
// * work make any representation or warranty, express or implied, *
// * regarding this software system or assume any liability for its *
// * use. Please see the license in the file LICENSE and URL above *
// * for the full disclaimer and the limitation of liability. *
// * *
// * This code implementation is the result of the scientific and *
// * technical work of the GEANT4 collaboration. *
// * By using, copying, modifying or distributing the software (or *
// * any work based on the software) you agree to acknowledge its *
// * use in resulting scientific publications, and indicate your *
// * 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-01 $
//
// ====================================================================
// G4VMPIsession.cc
//
// 2007 Q
// ====================================================================
#include "G4VMPIsession.hh"
#include "G4MPImanager.hh"
#include "G4UImanager.hh"
#include "G4UIcommand.hh"
// ====================================================================
//
// class description
//
// ====================================================================
//////////////////////////////
G4VMPIsession::G4VMPIsession()
: G4VBasicShell()
//////////////////////////////
{
// MPI
g4MPI= G4MPImanager::GetManager();
isMaster= g4MPI-> IsMaster();
isSlave= g4MPI-> IsSlave();
rank= g4MPI-> GetRank();
}
///////////////////////////////
G4VMPIsession::~G4VMPIsession()
///////////////////////////////
{
}
////////////////////////////////////////////////
G4bool G4VMPIsession::GetHelpChoice(G4int& aval)
////////////////////////////////////////////////
{
G4cin >> aval;
if(!G4cin.good()){
G4cin.clear();
G4cin.ignore(30,'\n');
return false;
}
return true;
}
//////////////////////////////
void G4VMPIsession::ExitHelp()
//////////////////////////////
{
char temp[100];
G4cin.getline(temp, 100);
}
///////////////////////////////////////////////
void G4VMPIsession::PauseSessionStart(G4String)
///////////////////////////////////////////////
{
}
///////////////////////////////////////////////////
G4int G4VMPIsession::ExecCommand(G4String aCommand)
///////////////////////////////////////////////////
{
if(aCommand.length()<2) return fCommandSucceeded;
G4UImanager* UI= G4UImanager::GetUIpointer();
G4int returnVal= 0;
G4String command= BypassCommand(aCommand);
// "/mpi/beamOn is threaded out.
if(command(0,11) == "/mpi/beamOn") {
g4MPI-> ExecuteBeamOnThread(aCommand);
returnVal= fCommandSucceeded;
} else if(command(0,12) == "/mpi/.beamOn") { // care for beamOn
G4bool threadStatus= g4MPI-> CheckThreadStatus();
if (threadStatus) { // still /run/beamOn is active
if(isMaster) {
G4cout << "G4MPIsession:: beamOn is still running." << G4endl;
}
returnVal= fCommandSucceeded;
} else {
returnVal = UI-> ApplyCommand(command);
}
} else { // normal command
returnVal = UI-> ApplyCommand(command);
}
G4int paramIndex = returnVal % 100;
// 0 - 98 : paramIndex-th parameter is invalid
// 99 : convination of parameters is invalid
G4int commandStatus = returnVal - paramIndex;
G4UIcommand* cmd = 0;
if(commandStatus!=fCommandSucceeded) {
cmd = FindCommand(command);
}
switch(commandStatus) {
case fCommandSucceeded:
break;
case fCommandNotFound:
G4cerr << "command <" << UI->SolveAlias(command)
<< "> not found" << G4endl;
break;
case fIllegalApplicationState:
G4cerr << "illegal application state -- command refused" << G4endl;
break;
case fParameterOutOfRange:
// ...
break;
case fParameterOutOfCandidates:
G4cerr << "Parameter is out of candidate list (index "
<< paramIndex << ")" << G4endl;
G4cerr << "Candidates : "
<< cmd->GetParameter(paramIndex)-> GetParameterCandidates()
<< G4endl;
break;
case fParameterUnreadable:
G4cerr << "Parameter is wrong type and/or is not omittable (index "
<< paramIndex << ")" << G4endl;
break;
case fAliasNotFound:
// ...
break;
default:
G4cerr << "command refused (" << commandStatus << ")" << G4endl;
}
return returnVal;
}
//////////////////////////////////////////////////////////////////////
G4String G4VMPIsession::TruncateCommand(const G4String& command) const
//////////////////////////////////////////////////////////////////////
{
// replace "//" with "/" in G4command
G4String acommand= command;
G4String strarg;
str_size iarg= acommand.find(' ');
if(iarg != G4String::npos) {
strarg= acommand(iarg, acommand.size()-iarg);
acommand= acommand(0,iarg);
}
str_size idx;
while( (idx= acommand.find("//")) != G4String::npos) {
G4String command1= acommand(0,idx+1);
G4String command2= acommand(idx+2, acommand.size()-idx-2);
acommand= command1 + command2;
}
acommand += strarg;
return acommand;
}
////////////////////////////////////////////////////////////////////
G4String G4VMPIsession::BypassCommand(const G4String& command) const
////////////////////////////////////////////////////////////////////
{
// bypass some commands
// /run/beamon -> /mpi/.beamOn
// /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;
}
acommand= "/mpi/.beamOn ";
G4String strarg= "";
G4bool qget= false;
G4bool qdone= false;
for (str_size idx=10; idx< command.size(); idx++) {
if(command[idx] == ' ' || command[idx] == '\011') {
qget= true;
if(qdone) break;
continue;
}
if(qget) {
strarg+= command[idx];
qdone= true;
}
}
acommand += strarg;
}
if(acommand(0,16) == "/control/execute") {
if(g4MPI-> GetVerbose()>0 && isMaster) {
G4cout << "/control/execute is overridden by /mpi/execute"
<< G4endl;
}
acommand.replace(0, 16, "/mpi/execute ");
}
return acommand;
}
// ====================================================================
//////////////////////////////////////////////////////
G4int G4VMPIsession::ReceiveG4cout(G4String coutString)
//////////////////////////////////////////////////////
{
g4MPI-> Print(coutString);
return 0;
}
//////////////////////////////////////////////////////
G4int G4VMPIsession::ReceiveG4cerr(G4String cerrString)
//////////////////////////////////////////////////////
{
g4MPI-> Print(cerrString);
return 0;
}