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