source: trunk/examples/extended/parallel/MPI/mpi_interface/src/G4VMPIsession.cc@ 1339

Last change on this file since 1339 was 1337, checked in by garnier, 15 years ago

tag geant4.9.4 beta 1 + modifs locales

File size: 8.1 KB
Line 
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: G4VMPIsession.cc,v 1.2 2010/05/18 06:06:21 kmura Exp $
27// $Name: geant4-09-04-beta-01 $
28//
29// ====================================================================
30// G4VMPIsession.cc
31//
32// 2007 Q
33// ====================================================================
34#include "G4VMPIsession.hh"
35#include "G4MPImanager.hh"
36#include "G4UImanager.hh"
37#include "G4UIcommand.hh"
38
39// ====================================================================
40//
41// class description
42//
43// ====================================================================
44
45//////////////////////////////
46G4VMPIsession::G4VMPIsession()
47 : G4VBasicShell()
48//////////////////////////////
49{
50 // MPI
51 g4MPI= G4MPImanager::GetManager();
52
53 isMaster= g4MPI-> IsMaster();
54 isSlave= g4MPI-> IsSlave();
55 rank= g4MPI-> GetRank();
56}
57
58///////////////////////////////
59G4VMPIsession::~G4VMPIsession()
60///////////////////////////////
61{
62}
63
64
65////////////////////////////////////////////////
66G4bool G4VMPIsession::GetHelpChoice(G4int& aval)
67////////////////////////////////////////////////
68{
69 G4cin >> aval;
70 if(!G4cin.good()){
71 G4cin.clear();
72 G4cin.ignore(30,'\n');
73 return false;
74 }
75 return true;
76}
77
78
79//////////////////////////////
80void G4VMPIsession::ExitHelp()
81//////////////////////////////
82{
83 char temp[100];
84 G4cin.getline(temp, 100);
85}
86
87
88///////////////////////////////////////////////
89void G4VMPIsession::PauseSessionStart(G4String)
90///////////////////////////////////////////////
91{
92}
93
94
95///////////////////////////////////////////////////
96G4int G4VMPIsession::ExecCommand(G4String acommand)
97///////////////////////////////////////////////////
98{
99 if(acommand.length()<2) return fCommandSucceeded;
100
101 G4UImanager* UI= G4UImanager::GetUIpointer();
102 G4int returnVal= 0;
103
104 G4String command= BypassCommand(acommand);
105
106 // "/mpi/beamOn is threaded out.
107 if(command(0,11) == "/mpi/beamOn") {
108 g4MPI-> ExecuteBeamOnThread(command);
109 returnVal= fCommandSucceeded;
110 } else if(command(0,12) == "/mpi/.beamOn") { // care for beamOn
111 G4bool threadStatus= g4MPI-> CheckThreadStatus();
112 if (threadStatus) { // still /run/beamOn is active
113 if(isMaster) {
114 G4cout << "G4MPIsession:: beamOn is still running." << G4endl;
115 }
116 returnVal= fCommandSucceeded;
117 } else {
118 returnVal = UI-> ApplyCommand(command);
119 }
120 } else { // normal command
121 returnVal = UI-> ApplyCommand(command);
122 }
123
124 G4int paramIndex = returnVal % 100;
125 // 0 - 98 : paramIndex-th parameter is invalid
126 // 99 : convination of parameters is invalid
127 G4int commandStatus = returnVal - paramIndex;
128
129 G4UIcommand* cmd = 0;
130 if(commandStatus!=fCommandSucceeded) {
131 cmd = FindCommand(command);
132 }
133
134 switch(commandStatus) {
135 case fCommandSucceeded:
136 break;
137 case fCommandNotFound:
138 G4cerr << "command <" << UI->SolveAlias(command)
139 << "> not found" << G4endl;
140 break;
141 case fIllegalApplicationState:
142 G4cerr << "illegal application state -- command refused" << G4endl;
143 break;
144 case fParameterOutOfRange:
145 // ...
146 break;
147 case fParameterOutOfCandidates:
148 G4cerr << "Parameter is out of candidate list (index "
149 << paramIndex << ")" << G4endl;
150 G4cerr << "Candidates : "
151 << cmd->GetParameter(paramIndex)-> GetParameterCandidates()
152 << G4endl;
153 break;
154 case fParameterUnreadable:
155 G4cerr << "Parameter is wrong type and/or is not omittable (index "
156 << paramIndex << ")" << G4endl;
157 break;
158 case fAliasNotFound:
159 // ...
160 break;
161 default:
162 G4cerr << "command refused (" << commandStatus << ")" << G4endl;
163 }
164
165 return returnVal;
166}
167
168
169//////////////////////////////////////////////////////////////////////
170G4String G4VMPIsession::TruncateCommand(const G4String& command) const
171//////////////////////////////////////////////////////////////////////
172{
173 // replace "//" with "/" in G4command
174 G4String acommand= command;
175 G4String strarg;
176
177 str_size iarg= acommand.find(' ');
178 if(iarg != G4String::npos) {
179 strarg= acommand(iarg, acommand.size()-iarg);
180 acommand= acommand(0,iarg);
181 }
182
183 str_size idx;
184 while( (idx= acommand.find("//")) != G4String::npos) {
185 G4String command1= acommand(0,idx+1);
186 G4String command2= acommand(idx+2, acommand.size()-idx-2);
187 acommand= command1 + command2;
188 }
189
190 acommand += strarg;
191
192 return acommand;
193}
194
195
196////////////////////////////////////////////////////////////////////
197G4String G4VMPIsession::BypassCommand(const G4String& command) const
198////////////////////////////////////////////////////////////////////
199{
200 // bypass some commands
201 // * /mpi/beamOn
202 // -> /mpi/.beamOn (batch session)
203 //
204 // * /run/beamOn
205 // -> /mpi/.beamOn (batch session)
206 // -> /mpi/beamOn (interactive session)
207 //
208 // * /control/execute -> /mpi/execute
209
210 G4String acommand= command;
211
212 // /mpi/beamOn
213 if(acommand(0,11) == "/mpi/beamOn") {
214 if(g4MPI-> IsBatchMode()) {
215 acommand= "/mpi/.beamOn";
216 if(command.length() > 11) {
217 acommand +=command.substr(11);
218 }
219 }
220 }
221
222 // /run/beamOn
223 if(acommand(0,11) == "/run/beamOn") {
224 G4String strarg= "";
225 G4bool qget= false;
226 G4bool qdone= false;
227
228 for (str_size idx=10; idx< command.size(); idx++) {
229 if(command[idx] == ' ' || command[idx] == '\011') {
230 qget= true;
231 if(qdone) break;
232 continue;
233 }
234 if(qget) {
235 strarg+= command[idx];
236 qdone= true;
237 }
238 }
239
240 if(g4MPI-> IsBatchMode()) { // batch session
241 acommand= "/mpi/.beamOn ";
242 if(command.length() > 11) acommand += strarg;
243 } else { // interactive session
244 if(g4MPI-> GetVerbose()>0 && isMaster) {
245 G4cout << "/run/beamOn is overridden by /mpi/.beamOn" << G4endl;
246 }
247 acommand= "/mpi/beamOn ";
248 if(command.length() > 11) acommand += strarg;
249 }
250 }
251
252 // /control/execute
253 if(acommand(0,16) == "/control/execute") {
254 if(g4MPI-> GetVerbose()>0 && isMaster) {
255 G4cout << "/control/execute is overridden by /mpi/execute"
256 << G4endl;
257 }
258 acommand.replace(0, 16, "/mpi/execute ");
259 }
260
261 return acommand;
262}
263
264// ====================================================================
265
266//////////////////////////////////////////////////////
267G4int G4VMPIsession::ReceiveG4cout(G4String coutString)
268//////////////////////////////////////////////////////
269{
270 g4MPI-> Print(coutString);
271 return 0;
272}
273
274
275//////////////////////////////////////////////////////
276G4int G4VMPIsession::ReceiveG4cerr(G4String cerrString)
277//////////////////////////////////////////////////////
278{
279 g4MPI-> Print(cerrString);
280 return 0;
281}
282
Note: See TracBrowser for help on using the repository browser.