Geant4  10.02
G4MPImessenger.cc
Go to the documentation of this file.
1 //
2 // ********************************************************************
3 // * License and Disclaimer *
4 // * *
5 // * The Geant4 software is copyright of the Copyright Holders of *
6 // * the Geant4 Collaboration. It is provided under the terms and *
7 // * conditions of the Geant4 Software License, included in the file *
8 // * LICENSE and available at http://cern.ch/geant4/license . These *
9 // * include a list of copyright holders. *
10 // * *
11 // * Neither the authors of this software system, nor their employing *
12 // * institutes,nor the agencies providing financial support for this *
13 // * work make any representation or warranty, express or implied, *
14 // * regarding this software system or assume any liability for its *
15 // * use. Please see the license in the file LICENSE and URL above *
16 // * for the full disclaimer and the limitation of liability. *
17 // * *
18 // * This code implementation is the result of the scientific and *
19 // * technical work of the GEANT4 collaboration. *
20 // * By using, copying, modifying or distributing the software (or *
21 // * any work based on the software) you agree to acknowledge its *
22 // * use in resulting scientific publications, and indicate your *
23 // * acceptance of all terms of the Geant4 Software license. *
24 // ********************************************************************
27 
28 #include "mpi.h"
29 #include <sstream>
30 #include "G4UIcmdWithADouble.hh"
31 #include "G4UIcmdWithAnInteger.hh"
32 #include "G4UIcmdWithAString.hh"
34 #include "G4UIcommand.hh"
35 #include "G4UIdirectory.hh"
36 #include "G4UImanager.hh"
37 #include "G4UIparameter.hh"
38 #include "G4MPImanager.hh"
39 #include "G4MPImessenger.hh"
40 #include "G4VMPIseedGenerator.hh"
41 
42 // --------------------------------------------------------------------------
44  : G4UImessenger()
45 {
46  // /mpi
47  dir_ = new G4UIdirectory("/mpi/");
48  dir_-> SetGuidance("MPI control commands");
49 
50  // /mpi/verbose
51  verbose_ = new G4UIcmdWithAnInteger("/mpi/verbose", this);
52  verbose_-> SetGuidance("Set verbose level.");
53  verbose_-> SetParameterName("verbose", false, false);
54  verbose_->SetRange("verbose>=0 && verbose<=1");
55 
56  // /mpi/status
57  status_ = new G4UIcmdWithoutParameter("/mpi/status", this);
58  status_-> SetGuidance( "Show mpi status.");
59 
60  // /mpi/execute
61  execute_ = new G4UIcmdWithAString("/mpi/execute", this);
62  execute_-> SetGuidance("Execute a macro file. (=/control/execute)");
63  execute_-> SetParameterName("fileName", false, false);
64 
65  // /mpi/beamOn
66  beam_on_ = new G4UIcommand("/mpi/beamOn", this);
67  beam_on_-> SetGuidance("Start a parallel run w/ thread.");
68 
69  G4UIparameter* p1= new G4UIparameter("numberOfEvent", 'i', true);
70  p1-> SetDefaultValue(1);
71  p1-> SetParameterRange("numberOfEvent>=0");
72  beam_on_-> SetParameter(p1);
73 
74  G4UIparameter* p2= new G4UIparameter("divide", 'b', true);
75  p2-> SetDefaultValue(true);
76  beam_on_-> SetParameter(p2);
77 
78  // /mpi/.beamOn
79  dot_beam_on_ = new G4UIcommand("/mpi/.beamOn", this);
80  dot_beam_on_-> SetGuidance("Start a parallel run w/o thread.");
81 
82  p1= new G4UIparameter("numberOfEvent", 'i', true);
83  p1-> SetDefaultValue(1);
84  p1-> SetParameterRange("numberOfEvent>=0");
85  dot_beam_on_-> SetParameter(p1);
86 
87  p2= new G4UIparameter("divide", 'b', true);
88  p2-> SetDefaultValue(true);
89  dot_beam_on_-> SetParameter(p2);
90 
91  // /mpi/weightForMaster
92  master_weight_ = new G4UIcmdWithADouble("/mpi/masterWeight", this);
93  master_weight_-> SetGuidance("Set weight for master node.");
94  master_weight_-> SetParameterName("weight", false, false);
95  master_weight_-> SetRange("weight>=0. && weight<=1.");
96 
97  // /mpi/showSeeds
98  show_seeds_ = new G4UIcmdWithoutParameter("/mpi/showSeeds", this);
99  show_seeds_-> SetGuidance("Show seeds of MPI nodes.");
100 
101  // /mpi/setMasterSeed
102  set_master_seed_ = new G4UIcmdWithAnInteger("/mpi/setMasterSeed", this);
103  set_master_seed_-> SetGuidance("Set a master seed for the seed generator.");
104  set_master_seed_-> SetParameterName("seed", false, false);
105 
106  // /mpi/setSeed
107  set_seed_ = new G4UIcommand("/mpi/setSeed", this);
108  set_seed_-> SetGuidance("Set a seed for a specified node.");
109 
110  p1 = new G4UIparameter("node", 'i', false);
111  p1-> SetParameterRange("node>=0");
112  set_seed_-> SetParameter(p1);
113 
114  p2 = new G4UIparameter("seed", 'i', false);
115  set_seed_-> SetParameter(p2);
116 }
117 
118 // --------------------------------------------------------------------------
120 {
121  delete verbose_;
122  delete status_;
123  delete execute_;
124  delete beam_on_;
125  delete dot_beam_on_;
126  delete master_weight_;
127  delete show_seeds_;
128  delete set_master_seed_;
129  delete set_seed_;
130 
131  delete dir_;
132 }
133 
134 // --------------------------------------------------------------------------
136 {
137  if ( command == verbose_ ) { // /mpi/verbose
138  G4int lv = verbose_-> GetNewIntValue(newValue);
139  g4mpi_-> SetVerbose(lv);
140 
141  } else if ( command == status_ ) { // /mpi/status
142  g4mpi_-> ShowStatus();
143 
144  } else if ( command == execute_ ) { // /mpi/execute
146  g4mpi_-> ExecuteMacroFile(UI-> FindMacroPath(newValue));
147 
148  } else if ( command == beam_on_ ) { // /mpi/beamOn
149  std::istringstream is(newValue);
150  G4int nevent;
151  G4bool qdivide;
152  is >> nevent >> qdivide;
153  g4mpi_-> BeamOn(nevent, qdivide);
154 
155  } else if ( command == dot_beam_on_ ) { // /mpi/.beamOn
156  std::istringstream is(newValue);
157  G4int nevent;
158  G4bool qdivide;
159  is >> nevent >> qdivide;
160  g4mpi_-> BeamOn(nevent, qdivide);
161 
162  } else if ( command == master_weight_ ) { // /mpi/masterWeight
163  G4double weight= master_weight_-> GetNewDoubleValue(newValue);
164  g4mpi_-> SetMasterWeight(weight);
165 
166  } else if ( command == show_seeds_ ) { // /mpi/showSeeds
167  g4mpi_-> ShowSeeds();
168 
169  } else if ( command == set_master_seed_ ) { // /mpi/setMasterSeed
170  std::istringstream is(newValue);
171  G4long seed;
172  is >> seed;
173  g4mpi_-> GetSeedGenerator()-> SetMasterSeed(seed);
174  g4mpi_-> DistributeSeeds();
175 
176  } else if ( command == set_seed_ ) { // /mpi/setSeed
177  std::istringstream is(newValue);
178  G4int inode;
179  G4long seed;
180  is >> inode >> seed;
181  g4mpi_-> SetSeed(inode, seed);
182  }
183 
184  return;
185 }
186 
187 // --------------------------------------------------------------------------
189 {
190  G4String cv;
191 
192  if ( command == verbose_ ) {
193  cv = verbose_-> ConvertToString(g4mpi_->GetVerbose());
194  } else if ( command == master_weight_ ) {
195  cv= master_weight_-> ConvertToString(g4mpi_->GetMasterWeight());
196  }
197 
198  return cv;
199 }
Define MPI commands.
G4UIcommand * dot_beam_on_
G4UIcmdWithAnInteger * set_master_seed_
long G4long
Definition: G4Types.hh:80
G4double GetMasterWeight() const
G4MPImanager * g4mpi_
G4UIcmdWithAString * execute_
G4UIcmdWithoutParameter * status_
int G4int
Definition: G4Types.hh:78
static G4UImanager * GetUIpointer()
Definition: G4UImanager.cc:58
G4int GetVerbose() const
A base class for random number seed distribution.
MPI manager class.
G4UIcommand * set_seed_
bool G4bool
Definition: G4Types.hh:79
void SetRange(const char *rs)
Definition: G4UIcommand.hh:125
G4UIcmdWithAnInteger * verbose_
G4UIcmdWithoutParameter * show_seeds_
virtual void SetNewValue(G4UIcommand *command, G4String newValue)
G4UIdirectory * dir_
virtual G4String GetCurrentValue(G4UIcommand *command)
double G4double
Definition: G4Types.hh:76
G4UIcommand * beam_on_
G4UIcmdWithADouble * master_weight_