forked from Conedy/Conedy
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathinstruction.cpp
342 lines (247 loc) · 8.69 KB
/
instruction.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
#include "instruction.h"
#include "string_config.h"
stringstream vectorForInstruction::chefDagEnding;
vector<int> vectorForInstruction::iterations;
ofstream vectorForInstruction::condorSkript;
ofstream vectorForInstruction::chefDag;
stringstream vectorForInstruction::jobName;
unsigned int vectorForInstruction::loopCounter;
unsigned int vectorForInstruction::nestedness;
params<baseType> *vectorForInstruction::p;
#if CONDOR
string getCurrentPath()
{
char CurrentPath[500];
if ( !getcwd ( CurrentPath, 500) )
throw "getcwd failed!";
return CurrentPath;
}
#endif
void instructionBlock::execute ()
{
list <instruction *> :: iterator it;
for (it = instructionList.begin(); it != instructionList.end(); it++)
(*it)->execute();
}
edgeBlueprint* setEdgeParameter::evaluate() { (( edgeBlueprint *) (edge->evaluate() )) -> setParameter((parameter->evaluate()) ); return edge->evaluate();}
string vectorForInstruction::currentJobName()
{
stringstream ss;
ss << uniqueNumber::number << "_";
for ( unsigned int i =1 ; i < loopCounter; i++ )
ss << iterations[i] << "_";
ss << iterations[loopCounter];
return ss.str();
}
void vectorForInstruction::writeCondorSkript()
{
#if CONDOR
cout << "ID: " << uniqueNumber::number << endl;
cout << getCurrentPath();
jobName.str ( "" );
jobName << "__" << uniqueNumber::number << ".dag";
jobName.str ( "" );
jobName << "__" << uniqueNumber::number << ".condor";
condorSkript.open ( jobName.str().c_str() );
jobName.str("");
condorSkript << "Universe = " << getGlobal<string>("universe") << endl;
// remove newline from dirInstall dirty
string dirInstall = reinterpret_cast<const char *>(dirInstall_h);
dirInstall = dirInstall.substr(0, dirInstall.length() - 1 );
condorSkript << "Executable = " << dirInstall << "/conedy.$$(OpSys).$$(Arch).EXE\n";
condorSkript << "Log = " << commandLineArguments::arg[1] << ".log" << "\n\n";
// condorSkript << "stream_output = True \n"; I'm putting this out because its seems to worsen performance on the submitting pc ?
condorSkript << "Requirements = " ;
bool first = true;
if (getGlobal<bool>("LINUX_x86_64"))
{
if (!first)
condorSkript << " || \\\n";
condorSkript << "(Arch == \"X86_64\" && OpSys == \"LINUX\")";
first = false;
}
if (getGlobal<bool>("LINUX_x86"))
{
if (!first)
condorSkript << " || \\\n";
condorSkript << " (Arch == \"INTEL\" && OpSys == \"LINUX\")";
first = false;
}
if (getGlobal<bool>("WINNT51_x86"))
{
if (!first)
condorSkript << " || \\\n";
condorSkript << " (Arch == \"INTEL\" && OpSys == \"WINNT51\")";
first = false;
}
if (getGlobal<bool>("WINNT60_x86"))
{
if (!first)
condorSkript << " || \\\n";
condorSkript << " (Arch == \"INTEL\" && OpSys == \"WINNT60\")";
first = false;
}
if (getGlobal<bool>("WINNT61_x86"))
{
if (!first)
condorSkript << " || \\\n";
condorSkript << " (Arch == \"INTEL\" && OpSys == \"WINNT61\")";
first = false;
}
condorSkript << "\n\n";
if (getGlobal<bool>("niceUser"))
{
condorSkript << "niceUser = True\n";
}
condorSkript << "transfer_files = ALWAYS\n";
// out <<"notification = Complete\n";
// out <<"notify_user=alex@goedel\n";
// out << "next_job_start_delay = 100 \n";
condorSkript << "should_transfer_files = YES \n";
// condorSkript << "on_exit_remove = (ExitBySignal == False) && (ExitCode == 0)\n";
condorSkript << "WhenToTransferOutput = ON_EXIT\n\n";
size_t found;
found=commandLineArguments::arg[1].find_last_of("/\\");
string fileName = commandLineArguments::arg[1].substr(found+1);
if (nestedness == 0)
condorSkript << "transfer_input_files =" << fileName << "\n";
else
condorSkript << "transfer_input_files = $(transfer)\n";
condorSkript << "\n";
condorSkript << "Arguments =" << fileName;
for ( unsigned int i =1 ; i <= nestedness; i++ )
condorSkript << " $(arg" << i << ") ";
condorSkript << "\n";
condorSkript << "Error =__" << fileName;
for ( unsigned int i =1 ; i <= nestedness; i++ )
condorSkript << "_$(arg" << i << ")";
condorSkript << ".err\n";
condorSkript << "Output =__" << fileName;
for ( unsigned int i =1 ; i <= nestedness; i++ )
condorSkript << "_$(arg" << i << ")";
condorSkript << ".out\n";
condorSkript << "Queue \n";
condorSkript.close();
#endif
}
void vectorForInstruction::submitToCondor()
{
#if CONDOR
if ( loopCounter == 1 )
{
iterations.push_back ( 0 );
cout <<"ID: " << uniqueNumber::number << endl;
cout << getCurrentPath();
// writeCondorSkript();
jobName.str ( "" );
jobName << "__" << uniqueNumber::number << ".dag";
chefDag.open ( jobName.str().c_str() );
jobName.str ( "" );
jobName << "__" << uniqueNumber::number << ".condor";
jobName.str("");
}
if ( loopCounter < nestedness )
{
iterations.push_back ( 0 );
iterations[loopCounter] = 0;
start->execute();
while ( cond->evaluate() )
{
body->execute();
iterations[loopCounter]++;
inc->execute();
}
}
if ( loopCounter == nestedness )
{
iterations.push_back ( 0 );
iterations[loopCounter] = 0;
start->execute();
while ( cond->evaluate() )
{
body->execute();
inc->execute();
chefDag << "JOB J" << currentJobName() << " __" << uniqueNumber::number << ".condor" << "\n";
chefDag << "PRIORITY J" << currentJobName() << " " << getGlobal<baseType>("priority") << "\n";
chefDag << "VARS J" << currentJobName() << " ";
for ( unsigned int i =1 ; i <= loopCounter; i++ )
chefDag << " arg" << i << "=\"" << iterations[i] << "\" ";
chefDag << "transfer=\""<< commandLineArguments::arg[1];
for ( unsigned int i = 0; i < inputFiles.size(); i++ )
chefDag << "," << inputFiles[i];
chefDag << "\"\n";
if ( cond->evaluate() && isChained )
{
chefDagEnding << "PARENT J" << currentJobName() << " ";
chefDagEnding<< "CHILD J" <<uniqueNumber::number << "_";
for ( unsigned int i =1 ; i < loopCounter; i++ )
chefDagEnding << iterations[i] << "_";
chefDagEnding << iterations[loopCounter] + 1 << "\n";
}
iterations[loopCounter]++;
command::inputFiles.clear();
}
}
if ( loopCounter == 1 )
{
/* stringstream startSkriptFilename;
startSkriptFilename << "__start" << uniqueNumber::number << ".sh";
condorSkript.open(startSkriptFilename.str().c_str());
out << "#!/usr/bin/bash" << endl;
out << "EXE=`which " << commandLineArguments::arg[0] << "`" << endl;
out << "cp " << commandLineArguments::arg[1] << " " << jobName.str() << ".ns" << endl;
out << "ssh redwood2 mkdir ~/" << jobName.str() << "\n";
out << "scp $EXE " << jobName.str() << ".ns" << " " << jobName.str();
for (unsigned int i = 0; i < inputFiles.size(); i++)
out << " " << inputFiles[i];
out << " redwood2:~/" << jobName.str() << "/\n";
out << "ssh redwood2 cd ~/" << jobName.str() << " \\; condor_submit " << jobName.str() <<"\n";
out << "while true; do\n";
out << " sleep 300;\n";
out << " if(condor_q -pool redwood2 -name redwood2|grep " << jobName.str() << "); then\n";
out << " echo \"Still Working!\"\n ";
out << " continue;\n";
out << " fi\n";
out << " break;\n";
out << "done\n";
out << "echo \"Finished!\"\n";
out << "scp -r redwood2:~/" << jobName.str() << " " << getCurrentPath()<<"/output" << "\n";
// out << "ssh redwood2 rm -rf ~/" << jobName.str() << "\n";
// out << "rm conedy " << jobName.str() << " " << jobName.str() << ".ns " << "__start.sh\n";
condorSkript.close();
sleep(2);
*/
// condorSkript.close();
chefDag << chefDagEnding.str();
chefDag.close();
/* jobName.str ( "" );
jobName << "__" << uniqueNumber::number << ".dag";
stringstream com;
com << "/usr/condor/bin/condor_submit _dag" << jobName.str();
FILE *lsofFile_p = popen ( com.str().c_str(), "r" );
char buffer[1024];
char *line_p = fgets ( buffer, sizeof ( buffer ), lsofFile_p );
line_p = fgets ( buffer, sizeof ( buffer ), lsofFile_p );
line_p = fgets ( buffer, sizeof ( buffer ), lsofFile_p );
string thirdLine = line_p;
string clusterNumber = thirdLine.substr ( thirdLine.find ( "cluster" ) + 8 , thirdLine.size() - 2 );
pclose ( lsofFile_p );
ofstream jobList;
stringstream runningCondorJobsFileName;
runningCondorJobsFileName << getenv ( "HOME" ) << "/runningCondorJobs";
jobList.open ( runningCondorJobsFileName.str().c_str(),fstream::out | fstream::app );
jobList << clusterNumber << " " << getCurrentPath() << endl;
jobList.close();
*/
// stringstream command;
// command << "condor_submit " << jobName.str();
// if (system(command.str().c_str()))
// {
// throw "condor_submit failed!";
// }
}
// system ("scp " << commandLineArguments::arg[0] << " " << commandLineArguments::arg[1] <<
#else
throw "condor nicht mitkompiliert!";
#endif
}