Geant4  9.6.p02
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
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 "G4MPImessenger.hh"
29 #include "G4MPImanager.hh"
30 #include "G4VMPIseedGenerator.hh"
31 #include "G4UImanager.hh"
32 #include "G4UIdirectory.hh"
34 #include "G4UIcmdWithAnInteger.hh"
35 #include "G4UIcmdWithAString.hh"
36 #include "G4UIcmdWithADouble.hh"
37 #include "G4UIcommand.hh"
38 #include "G4UIparameter.hh"
39 #include <sstream>
40 
41 // --------------------------------------------------------------------------
43  : G4UImessenger(), g4MPI(manager)
44 {
45  // /mpi
46  dir = new G4UIdirectory("/mpi/");
47  dir-> SetGuidance("MPI control commands");
48 
49  // /mpi/verbose
50  verbose = new G4UIcmdWithAnInteger("/mpi/verbose", this);
51  verbose-> SetGuidance("Set verbose level.");
52  verbose-> SetParameterName("verbose", false, false);
53  verbose->SetRange("verbose>=0 && verbose<=1");
54 
55  // /mpi/status
56  status = new G4UIcmdWithoutParameter("/mpi/status", this);
57  status-> SetGuidance( "Show mpi status.");
58 
59  // /mpi/execute
60  execute = new G4UIcmdWithAString("/mpi/execute", this);
61  execute-> SetGuidance("Execute a macro file. (=/control/execute)");
62  execute-> SetParameterName("fileName", false, false);
63 
64  // /mpi/beamOn
65  beamOn = new G4UIcommand("/mpi/beamOn", this);
66  beamOn-> SetGuidance("Start a parallel run w/ thread.");
67 
68  G4UIparameter* p1= new G4UIparameter("numberOfEvent", 'i', true);
69  p1-> SetDefaultValue(1);
70  p1-> SetParameterRange("numberOfEvent>=0");
71  beamOn-> SetParameter(p1);
72 
73  G4UIparameter* p2= new G4UIparameter("divide", 'b', true);
74  p2-> SetDefaultValue(true);
75  beamOn-> SetParameter(p2);
76 
77  // /mpi/.beamOn
78  dotbeamOn = new G4UIcommand("/mpi/.beamOn", this);
79  dotbeamOn-> SetGuidance("Start a parallel run w/o thread.");
80 
81  p1= new G4UIparameter("numberOfEvent", 'i', true);
82  p1-> SetDefaultValue(1);
83  p1-> SetParameterRange("numberOfEvent>=0");
84  dotbeamOn-> SetParameter(p1);
85 
86  p2= new G4UIparameter("divide", 'b', true);
87  p2-> SetDefaultValue(true);
88  dotbeamOn-> SetParameter(p2);
89 
90  // /mpi/weightForMaster
91  masterWeight = new G4UIcmdWithADouble("/mpi/masterWeight", this);
92  masterWeight-> SetGuidance("Set weight for master node.");
93  masterWeight-> SetParameterName("weight", false, false);
94  masterWeight-> SetRange("weight>=0. && weight<=1.");
95 
96  // /mpi/showSeeds
97  showSeeds = new G4UIcmdWithoutParameter("/mpi/showSeeds", this);
98  showSeeds-> SetGuidance("Show seeds of MPI nodes.");
99 
100  // /mpi/setMasterSeed
101  setMasterSeed = new G4UIcmdWithAnInteger("/mpi/setMasterSeed", this);
102  setMasterSeed-> SetGuidance("Set a master seed for the seed generator.");
103  setMasterSeed-> SetParameterName("seed", false, false);
104 
105  // /mpi/setSeed
106  setSeed = new G4UIcommand("/mpi/setSeed", this);
107  setSeed-> SetGuidance("Set a seed for a specified node.");
108 
109  p1 = new G4UIparameter("node", 'i', false);
110  p1-> SetParameterRange("node>=0");
111  setSeed-> SetParameter(p1);
112 
113  p2 = new G4UIparameter("seed", 'i', false);
114  setSeed-> SetParameter(p2);
115 }
116 
117 // --------------------------------------------------------------------------
119 {
120  delete verbose;
121  delete status;
122  delete execute;
123  delete beamOn;
124  delete dotbeamOn;
125  delete masterWeight;
126  delete showSeeds;
127  delete setMasterSeed;
128  delete setSeed;
129 
130  delete dir;
131 }
132 
133 // --------------------------------------------------------------------------
135 {
136  if (command == verbose) { // /mpi/verbose
137  G4int lv= verbose-> GetNewIntValue(newValue);
138  g4MPI-> SetVerbose(lv);
139 
140  } else if (command == status){ // /mpi/status
141  g4MPI-> ShowStatus();
142 
143  } else if (command == execute){ // /mpi/execute
145  g4MPI-> ExecuteMacroFile(UI-> FindMacroPath(newValue));
146 
147  } else if (command == beamOn){ // /mpi/beamOn
148  std::istringstream is(newValue);
149  G4int nevent;
150  G4bool qdivide;
151  is >> nevent >> qdivide;
152  g4MPI-> BeamOn(nevent, qdivide);
153 
154  } else if (command == dotbeamOn){ // /mpi/.beamOn
155  std::istringstream is(newValue);
156  G4int nevent;
157  G4bool qdivide;
158  is >> nevent >> qdivide;
159  g4MPI-> BeamOn(nevent, qdivide);
160 
161  } else if (command == masterWeight){ // /mpi/masterWeight
162  G4double weight= masterWeight-> GetNewDoubleValue(newValue);
163  g4MPI-> SetMasterWeight(weight);
164 
165  } else if (command == showSeeds){ // /mpi/showSeeds
166  g4MPI-> ShowSeeds();
167 
168  } else if (command == setMasterSeed){ // /mpi/setMasterSeed
169  std::istringstream is(newValue);
170  G4long seed;
171  is >> seed;
172  g4MPI-> GetSeedGenerator()-> SetMasterSeed(seed);
173  g4MPI-> DistributeSeeds();
174 
175  } else if (command == setSeed){ // /mpi/setSeed
176  std::istringstream is(newValue);
177  G4int inode;
178  G4long seed;
179  is >> inode >> seed;
180  g4MPI-> SetSeed(inode, seed);
181  }
182 
183  return;
184 }
185 
186 // --------------------------------------------------------------------------
188 {
189  G4String cv;
190 
191  if (command == verbose) {
192  cv= verbose-> ConvertToString(g4MPI->GetVerbose());
193  } else if (command == masterWeight) {
194  cv= masterWeight-> ConvertToString(g4MPI->GetMasterWeight());
195  }
196 
197  return cv;
198 }
199