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

#include <Doxymodules_parallel.h>

Inheritance diagram for G4MPIbatch:
G4VMPIsession G4VBasicShell G4UIsession G4coutDestination

Public Member Functions

 G4MPIbatch (const G4String &fname="", G4bool qbatch=false)
 
 ~G4MPIbatch ()
 
virtual G4UIsessionSessionStart ()
 
- Public Member Functions inherited from G4VMPIsession
 G4VMPIsession ()
 
 ~G4VMPIsession ()
 
virtual void PauseSessionStart (const G4String &msg)
 
virtual G4int ReceiveG4cout (const G4String &coutString)
 
virtual G4int ReceiveG4cerr (const G4String &cerrString)
 

Protected Member Functions

G4String ReadCommand ()
 
- Protected Member Functions inherited from G4VMPIsession
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

std::ifstream batch_stream_
 
G4bool is_opened_
 
G4bool is_batch_mode_
 
- Protected Attributes inherited from G4VMPIsession
G4MPImanagerg4mpi_
 
G4bool is_master_
 
G4bool is_slave_
 
G4int rank_
 

Detailed Description

Definition at line 61 of file Doxymodules_parallel.h.

Constructor & Destructor Documentation

◆ G4MPIbatch()

G4MPIbatch::G4MPIbatch ( const G4String fname = "",
G4bool  qbatch = false 
)

Definition at line 64 of file G4MPIbatch.cc.

65 : G4VMPIsession(), is_opened_(false), is_batch_mode_(qbatch)
66{
67 if( is_master_ ) {
68 batch_stream_.open(fname, std::ios::in);
69 if(batch_stream_.fail()) {
70 G4cerr << "cannot open a macro file(" << fname << ")."
71 << G4endl;
72 } else {
73 is_opened_ = true;
74 }
75 }
76}
G4bool is_opened_
Definition G4MPIbatch.hh:43
std::ifstream batch_stream_
Definition G4MPIbatch.hh:42
G4bool is_batch_mode_
Definition G4MPIbatch.hh:44

◆ ~G4MPIbatch()

G4MPIbatch::~G4MPIbatch ( )

Definition at line 79 of file G4MPIbatch.cc.

80{
81 if( is_opened_ ) batch_stream_.close();
82}

Member Function Documentation

◆ SessionStart()

G4UIsession * G4MPIbatch::SessionStart ( )
virtual

Definition at line 154 of file G4MPIbatch.cc.

155{
156 if( is_master_ && !is_opened_ ) { // macro file is not found
157 g4mpi_-> BcastCommand("exit");
158 return NULL;
159 }
160
161 G4String newCommand = "", scommand; // newCommand is always "" in slaves
162
163 while(1) {
164 if( is_master_ ) newCommand = ReadCommand();
165 // broadcast a new G4 command
166 scommand = g4mpi_-> BcastCommand(newCommand);
167 if( scommand == "exit" ) {
168 g4mpi_-> WaitBeamOn();
169 return 0;
170 }
171
172 // just echo something
173 if( scommand[0] == '#' ) {
174 if( G4UImanager::GetUIpointer()-> GetVerboseLevel() == 2 ) {
175 G4cout << scommand << G4endl;
176 }
177 continue;
178 }
179
180 G4int rc = ExecCommand(scommand);
181 if ( rc != fCommandSucceeded ) {
182 G4cerr << G4endl << "***** Batch is interupted!! *****" << G4endl;
183 break;
184 }
185 }
186
187 return NULL;
188}
G4String ReadCommand()
Definition G4MPIbatch.cc:85
G4MPImanager * g4mpi_
G4int ExecCommand(const G4String &acommand)

◆ ReadCommand()

G4String G4MPIbatch::ReadCommand ( )
protected

Definition at line 85 of file G4MPIbatch.cc.

86{
87 enum { BUFSIZE = 4096 };
88 static char linebuf[BUFSIZE];
89
90 G4String cmdtotal = "";
91 G4bool qcontinued = false;
92 while( batch_stream_.good() ) {
93 batch_stream_.getline(linebuf, BUFSIZE);
94
95 G4String cmdline(linebuf);
96
97 // TAB-> ' ' conversion
98 G4String::size_type nb = 0;
99 while ((nb= cmdline.find('\t',nb)) != G4String::npos) {
100 cmdline.replace(nb, 1, " ");
101 }
102
103 // strip
104 G4StrUtil::strip(cmdline);
105
106 // skip null line if single line
107 if( !qcontinued && cmdline.size() == 0 ) continue;
108
109 // '#' is treated as echoing something
110 if( cmdline[0] == '#' ) return cmdline;
111
112 // tokenize...
113 std::vector<G4String> tokens;
114 Tokenize(cmdline, tokens);
115 qcontinued = false;
116 for( G4int i = 0; i < G4int(tokens.size()); i++ ) {
117 // string after '#" is ignored
118 if( tokens[i][0] == '#' ) break;
119 // '\' or '_' is treated as continued line.
120 if( tokens[i] == "\\" || tokens[i] == "_" ) {
121 qcontinued = true;
122 // check nothing after line continuation character
123 if( i != G4int(tokens.size())-1 ) {
124 G4Exception("G4MPIbatch::ReadCommand", "MPI004", JustWarning,
125 "unexpected character after line continuation character");
126 }
127 break; // stop parsing
128 }
129 cmdtotal += tokens[i];
130 cmdtotal += " ";
131 }
132
133 if( qcontinued ) continue; // read the next line
134
135 if( cmdtotal.size() != 0 ) break;
136 if( batch_stream_.eof() ) break;
137 }
138
139 // strip again
140 G4StrUtil::strip(cmdtotal);
141
142 // bypass some commands
143 cmdtotal = BypassCommand(cmdtotal);
144
145 // finally,
146 if( batch_stream_.eof() && cmdtotal.size()==0 ) {
147 return "exit";
148 }
149
150 return cmdtotal;
151}
G4String BypassCommand(const G4String &command) const
void strip(G4String &str, char ch=' ')

Member Data Documentation

◆ batch_stream_

std::ifstream G4MPIbatch::batch_stream_
protected

Definition at line 42 of file G4MPIbatch.hh.

◆ is_opened_

G4bool G4MPIbatch::is_opened_
protected

Definition at line 43 of file G4MPIbatch.hh.

◆ is_batch_mode_

G4bool G4MPIbatch::is_batch_mode_
protected

Definition at line 44 of file G4MPIbatch.hh.


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

Applications | User Support | Publications | Collaboration