Loading...
Searching...
No Matches
Public Member Functions | Protected Member Functions | Protected Attributes | List of all members
G4VMPIsession Class Reference

#include <Doxymodules_parallel.h>

Inheritance diagram for G4VMPIsession:
G4VBasicShell G4UIsession G4coutDestination G4MPIbatch G4MPIsession

Public Member Functions

 G4VMPIsession ()
 
 ~G4VMPIsession ()
 
virtual void PauseSessionStart (const G4String &msg)
 
virtual G4int ReceiveG4cout (const G4String &coutString)
 
virtual G4int ReceiveG4cerr (const G4String &cerrString)
 

Protected Member Functions

G4int ExecCommand (const G4String &acommand)
 
G4String TruncateCommand (const G4String &command) const
 
G4String BypassCommand (const G4String &command) const
 
virtual G4bool GetHelpChoice (G4int &aval)
 
virtual void ExitHelp () const
 

Protected Attributes

G4MPImanagerg4mpi_
 
G4bool is_master_
 
G4bool is_slave_
 
G4int rank_
 

Detailed Description

Definition at line 73 of file Doxymodules_parallel.h.

Constructor & Destructor Documentation

◆ G4VMPIsession()

G4VMPIsession::G4VMPIsession ( )

Definition at line 35 of file G4VMPIsession.cc.

37{
39
40 is_master_ = g4mpi_-> IsMaster();
41 is_slave_ = g4mpi_-> IsSlave();
42 rank_ = g4mpi_-> GetRank();
43
44}
static G4MPImanager * GetManager()
G4MPImanager * g4mpi_

◆ ~G4VMPIsession()

G4VMPIsession::~G4VMPIsession ( )

Definition at line 47 of file G4VMPIsession.cc.

48{
49}

Member Function Documentation

◆ PauseSessionStart()

void G4VMPIsession::PauseSessionStart ( const G4String msg)
virtual

Definition at line 71 of file G4VMPIsession.cc.

72{
73}

◆ ReceiveG4cout()

G4int G4VMPIsession::ReceiveG4cout ( const G4String coutString)
virtual

Definition at line 257 of file G4VMPIsession.cc.

258{
259 g4mpi_-> Print(coutString);
260 return 0;
261}
void Print(const std::vector< T > &data)
Definition DicomRun.hh:109

◆ ReceiveG4cerr()

G4int G4VMPIsession::ReceiveG4cerr ( const G4String cerrString)
virtual

Definition at line 264 of file G4VMPIsession.cc.

265{
266 g4mpi_-> Print(cerrString);
267 return 0;
268}

◆ ExecCommand()

G4int G4VMPIsession::ExecCommand ( const G4String acommand)
protected

Definition at line 76 of file G4VMPIsession.cc.

77{
78 if( acommand.length() < 2 ) return fCommandSucceeded;
79
80 G4UImanager* UI = G4UImanager::GetUIpointer();
81 G4int returnVal = 0;
82
83 G4String command = BypassCommand(acommand);
84
85 // "/mpi/beamOn is threaded out.
86 if( command.substr(0,11) == "/mpi/beamOn" ) {
87 g4mpi_-> ExecuteBeamOnThread(command);
88 returnVal = fCommandSucceeded;
89 } else if( command.substr(0,12) == "/mpi/.beamOn" ) { // care for beamOn
90 G4bool threadStatus = g4mpi_-> CheckThreadStatus();
91 if ( threadStatus ) { // still /run/beamOn is active
92 if( is_master_ ) {
93 G4cout << "G4MPIsession:: beamOn is still running." << G4endl;
94 }
95 returnVal = fCommandSucceeded;
96 } else {
97 returnVal = UI-> ApplyCommand(command);
98 }
99 } else { // normal command
100 returnVal = UI-> ApplyCommand(command);
101 }
102
103 G4int paramIndex = returnVal % 100;
104 // 0 - 98 : paramIndex-th parameter is invalid
105 // 99 : convination of parameters is invalid
106 G4int commandStatus = returnVal - paramIndex;
107
108 G4UIcommand* cmd = 0;
109 if( commandStatus != fCommandSucceeded ) {
110 cmd = FindCommand(command);
111 }
112
113 switch( commandStatus ) {
114 case fCommandSucceeded:
115 break;
116 case fCommandNotFound:
117 G4cerr << "command <" << UI-> SolveAlias(command)
118 << "> not found" << G4endl;
119 break;
120 case fIllegalApplicationState:
121 G4cerr << "illegal application state -- command refused" << G4endl;
122 break;
123 case fParameterOutOfRange:
124 // ...
125 break;
126 case fParameterOutOfCandidates:
127 G4cerr << "Parameter is out of candidate list (index "
128 << paramIndex << ")" << G4endl;
129 G4cerr << "Candidates : "
130 << cmd->GetParameter(paramIndex)-> GetParameterCandidates()
131 << G4endl;
132 break;
133 case fParameterUnreadable:
134 G4cerr << "Parameter is wrong type and/or is not omittable (index "
135 << paramIndex << ")" << G4endl;
136 break;
137 case fAliasNotFound:
138 // ...
139 break;
140 default:
141 G4cerr << "command refused (" << commandStatus << ")" << G4endl;
142 }
143
144 return returnVal;
145}
G4String BypassCommand(const G4String &command) const

◆ TruncateCommand()

G4String G4VMPIsession::TruncateCommand ( const G4String command) const
protected

Definition at line 148 of file G4VMPIsession.cc.

149{
150 // replace "//" with "/" in G4command
151 G4String acommand = command;
152 G4String strarg;
153
154 G4String::size_type iarg = acommand.find(' ');
155 if( iarg != G4String::npos ) {
156 strarg = acommand.substr(iarg, acommand.size()-iarg);
157 acommand = acommand.substr(0,iarg);
158 }
159
160 G4String::size_type idx;
161 while( (idx = acommand.find("//")) != G4String::npos) {
162 G4String command1 = acommand.substr(0,idx+1);
163 G4String command2 = acommand.substr(idx+2, acommand.size()-idx-2);
164 acommand = command1 + command2;
165 }
166
167 acommand += strarg;
168
169 return acommand;
170}

◆ BypassCommand()

G4String G4VMPIsession::BypassCommand ( const G4String command) const
protected

Definition at line 173 of file G4VMPIsession.cc.

174{
175 // bypass some commands
176 // * /mpi/beamOn
177 // -> /mpi/.beamOn (batch session)
178 // -> /mpi/.beamOn (MT mode)
179 //
180 // * /run/beamOn
181 // -> /mpi/.beamOn (batch session)
182 // -> /mpi/beamOn (interactive session)
183 // -> /mpi/.beamOn (MT mode)
184 //
185 // * /control/execute -> /mpi/execute
186
187 G4String acommand = command;
188
189 // /mpi/beamOn
190 if( acommand.substr(0,11) == "/mpi/beamOn" ) {
191#ifdef G4MULTITHREADED
192 acommand = "/mpi/.beamOn";
193 if(command.length() > 11) {
194 acommand += command.substr(11);
195 }
196#else
197 if( g4mpi_-> IsBatchMode()) {
198 acommand = "/mpi/.beamOn";
199 if(command.length() > 11) {
200 acommand += command.substr(11);
201 }
202 }
203#endif
204 }
205
206 // /run/beamOn
207 if( acommand.substr(0,11) == "/run/beamOn" ) {
208 G4String strarg = "";
209 G4bool qget = false;
210 G4bool qdone = false;
211
212 for ( G4String::size_type idx = 10; idx < command.size(); idx++ ) {
213 if( command[idx] == ' ' || command[idx] == '\011' ) {
214 qget = true;
215 if(qdone) break;
216 continue;
217 }
218 if( qget ) {
219 strarg += command[idx];
220 qdone = true;
221 }
222 }
223
224 if( g4mpi_-> IsBatchMode() ) { // batch session
225 acommand = "/mpi/.beamOn ";
226 if( command.length() > 11 ) acommand += strarg;
227 } else { // interactive session
228#ifdef G4MULTITHREADED
229 if( g4mpi_-> GetVerbose()>0 && is_master_ ) {
230 G4cout << "/run/beamOn is overridden by /mpi/.beamOn" << G4endl;
231 }
232 acommand = "/mpi/.beamOn ";
233 if( command.length() > 11 ) acommand += strarg;
234#else
235 if( g4mpi_-> GetVerbose()>0 && is_master_ ) {
236 G4cout << "/run/beamOn is overridden by /mpi/beamOn" << G4endl;
237 }
238 acommand = "/mpi/beamOn ";
239 if( command.length() > 11 ) acommand += strarg;
240#endif
241 }
242 }
243
244 // /control/execute
245 if( acommand.substr(0,16) == "/control/execute" ) {
246 if( g4mpi_-> GetVerbose()>0 && is_master_ ) {
247 G4cout << "/control/execute is overridden by /mpi/execute"
248 << G4endl;
249 }
250 acommand.replace(0, 16, "/mpi/execute ");
251 }
252
253 return acommand;
254}

◆ GetHelpChoice()

G4bool G4VMPIsession::GetHelpChoice ( G4int &  aval)
protectedvirtual

Definition at line 52 of file G4VMPIsession.cc.

53{
54 G4cin >> aval;
55 if( !G4cin.good() ){
56 G4cin.clear();
57 G4cin.ignore(30,'\n');
58 return false;
59 }
60 return true;
61}

◆ ExitHelp()

void G4VMPIsession::ExitHelp ( ) const
protectedvirtual

Definition at line 64 of file G4VMPIsession.cc.

65{
66 char temp[100];
67 G4cin.getline(temp, 100);
68}

Member Data Documentation

◆ g4mpi_

G4MPImanager* G4VMPIsession::g4mpi_
protected

Definition at line 49 of file G4VMPIsession.hh.

◆ is_master_

G4bool G4VMPIsession::is_master_
protected

Definition at line 52 of file G4VMPIsession.hh.

◆ is_slave_

G4bool G4VMPIsession::is_slave_
protected

Definition at line 53 of file G4VMPIsession.hh.

◆ rank_

G4int G4VMPIsession::rank_
protected

Definition at line 54 of file G4VMPIsession.hh.


The documentation for this class was generated from the following files:

Applications | User Support | Publications | Collaboration