-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathPDCTask.php
More file actions
348 lines (300 loc) · 10.7 KB
/
PDCTask.php
File metadata and controls
348 lines (300 loc) · 10.7 KB
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
342
343
344
345
346
347
<?php
namespace Jobe;
/* ==============================================================
*
* PDC
*
* ==============================================================
*
* @copyright 2014 Richard Lobb, University of Canterbury
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
* adapted from cpp_task.php by rab@stolaf.edu, March-May 2023
*/
/* In this "pseudo language", parallel and distributed computations are
performed on another server, a Runestone Backend (RSBE), instead of
being performed on the Jobe server itself. When Jobe receives a PDC
request from Runestone, Jobe invokes an application $this->execpdc that
transmits the requested to RSBE and delivers the results of the desired
PD computation, which Jobe relays to Runestone.
The runspec for a PDC request must include a "compiler" value that
signals a type of PD computation to perform, listed in
$this->supported_compilers, plus standard runspec values and parameters
intended for desired PD computation on RSBE (vs. $this->execpdc on Jobe)
*/
class PDCTask extends LanguageTask {
public $supported_compilers = array(
'g++',
'gcc',
'mpicc',
'mpic++',
'mpi4py',
'nvcc',
'nvcc++',
'pgcc',
'pgc++',
'chpl',
);
public $pdc_default_params = array(
'g++' => array(
'pdc_backend' => 'omp',
'pdc_ncores' => '4',
'pdc_sourcefilename' => 'prog.cpp',
'pdc_autocompileargs' => array(
'-Wall',
'-Werror',
),
),
'gcc' => array(
'pdc_backend' => 'omp',
'pdc_ncores' => '4',
'pdc_sourcefilename' => 'prog.c',
'pdc_autocompileargs' => array(
'-Wall',
'-Werror',
),
),
'mpicc' => array(
'pdc_backend' => 'mpi',
# 'pdc_envmodule' => 'openmpi-4.1.6',
'pdc_nhosts' => '4',
'pdc_ncores' => '2',
'pdc_sourcefilename' => 'prog.c',
'pdc_interpreter' => 'mpirun',
'interpreter_choices' => array('mpirun', 'mpiexec'),
),
'mpic++' => array(
'pdc_backend' => 'mpi',
# 'pdc_envmodule' => 'openmpi-4.1.6',
'pdc_nhosts' => '4',
'pdc_ncores' => '2',
'pdc_sourcefilename' => 'prog.cpp',
'pdc_interpreter' => 'mpirun',
'interpreter_choices' => array('mpirun', 'mpiexec'),
),
'mpi4py' => array(
'pdc_backend' => 'mpi',
# 'pdc_envmodule' => 'openmpi-4.1.6',
'pdc_nhosts' => '4',
'pdc_ncores' => '2',
'pdc_sourcefilename' => 'prog.py',
'pdc_interpreter' => 'mpirun',
'interpreter_choices' => array('mpirun', 'mpiexec'),
'pdc_interpreterexec' => 'python3',
),
'nvcc' => array(
'pdc_backend' => 'gpu',
# 'pdc_envmodule' => 'nvhpc/24.7',
'pdc_sourcefilename' => 'prog.cu',
'pdc_autocompileargs' => array(
'-arch=native',
// '-arch=compute_61',
),
),
'nvcc++' => array(
'pdc_backend' => 'gpu',
# 'pdc_envmodule' => 'nvhpc/24.7',
'pdc_sourcefilename' => 'prog.cu',
'pdc_autocompileargs' => array(
'-arch=native',
// '-arch=compute_61',
),
),
'pgcc' => array(
'pdc_backend' => 'gpu',
# 'pdc_envmodule' => 'nvhpc/24.7',
'pdc_sourcefilename' => 'prog.c',
'pdc_autocompileargs' => array(
// '-acc=gpu',
// '-Minfo=accel',
// '-arch=compute_61',
),
),
'pgc++' => array(
'pdc_backend' => 'gpu',
# 'pdc_envmodule' => 'nvhpc/24.7',
'pdc_sourcefilename' => 'prog.cpp',
'pdc_autocompileargs' => array(
'-acc=gpu',
'-Minfo=accel',
// '-arch=compute_61',
),
),
'chpl' => array(
'pdc_backend' => 'omp',
'pdc_ncores' => '4',
'pdc_sourcefilename' => 'prog.chpl',
'pdc_autocompileargs' => array(
// '-Wall',
// '-Werror',
),
),
);
public $cpl; /* compiler */
public $interpreter_choices;
public $execpdc= "/shared/execpdc/execpdc_client";
function rab_log($msg) {
$log = fopen("/shared/rab_log", "a");
fwrite($log, date("*** md_his: ") . $msg . "\n");
fclose($log);
}
public function __construct($filename, $input, $params) {
$this->rab_log("******************************");
parent::__construct($filename, $input, $params);
$this->rab_log(print_r($this->params, true)); //DEBUG
/* most received runspec values and parameters are intended for the
PD computation to perform on RSBE. We will prepend "pdc_"
to the keys of such parameters, and use them in compile() to
specify the desired PD computation. */
if ($this->sourceFileName != "")
$this->params['sourcefilename'] = $this->sourceFileName;
$this->sourceFileName = $this->defaultFileName('');
foreach ($this->params as $key => $val)
if ($key != "compiler") {
$this->params["pdc_" . $key] = $val ;
unset($this->params[$key]); }
$this->default_params['compiler'] = 'g++';
/* TEST VALIDITY HERE - THROW EXCEPTION IF NOT IN $supported_compilers*/
/* set defaults for params pdc_* in order:
1. generic defaults
2. compiler-specific pdc_envmodule values from .config file
3. compiler-specific values from $pdc_default_params */
foreach(array('nhosts', 'ncores',
'compileargs', 'autocompileargs', 'linkargs',
'interpreter', 'interpreterargs', 'interpreterexec',
'runargs') as $name)
$this->default_params["pdc_$name"] = '';
$this->default_params['pdc_envmodule'] = 'NONE';
if (!($config_lines = file("/shared/execpdc/execpdc.config",
FILE_IGNORE_NEW_LINES)))
$this->rab_log("could not read execpdc/execpdc.config");
else
foreach ($config_lines as $line)
if (!strncmp($line, "ENVMOD=", 7)) {
$envmod_lists = explode(";", substr($line,7));
// $this->rab_log(print_r($envmod_lists, true));
foreach ($envmod_lists as $elist) {
$elist_arr = explode(" ", trim($elist));
$envmod_name = array_shift($elist_arr);
foreach($elist_arr as $cpl_name)
$this->pdc_default_params[$cpl_name]
['pdc_envmodule'] = $envmod_name;
}
}
$cpl_default_params =
$this->pdc_default_params[$this->getParam('compiler')];
foreach ($cpl_default_params as $key => $val)
$this->default_params[$key] = $val;
// $this->rab_log(print_r($this->default_params['pdc_compileargs'], true));
$this->rab_log(print_r($this->default_params, true));
if (isset($cpl_default_params['interpreter_choices']) &&
is_array($cpl_default_params['interpreter_choices']))
$this->interpreter_choices =
$cpl_default_params['interpreter_choices'];
else
$this->interpreter_choices = false;
}
public static function getVersionCommand() {
return array('echo 1.0', '/([0-9.]*)/');
}
/* helper method pdc_flatten(), a generalization of array_merge() for
assembling command lines, etc.
The argument $value may be a single value or a (possibly nested) array
of values. The function returns a combined single string consisting of
all values in depth-first order, separated by spaces. */
function pdc_flatten($value) {
if (is_array($value))
return implode(' ', array_map(array($this, 'pdc_flatten'), $value));
else
return strval($value);
}
public function compile() {
// $code = file_get_contents($this->defaultFileName(''));
// $this->rab_log($code);
// $this->rab_log($this->sourceFileName);
$this->executableFileName = $this->execpdc;
$this->cpl = $this->getParam('compiler');
if ("$this->cpl" == "mpi4py")
$this->cpl = '';
/* prepare first arguments for the $this->execpdc command line, which
will be assembled in getRunCommand() (defined in LanguageTask.php) */
$this->default_params['interpreterargs'] = array(
$this->id,
);
/* prepare final arguments for the $this->execpdc command line */
$this->default_params['runargs'] = array(
$this->id . "." . $this->getParam('compiler'),
);
/* prepare specification of the desired a PD computation (to be
performed by RSBE), and store that specification in target file
(i.e., next command-line argument) for $this->execpdc */
$this->rab_log('cpl = ' . $this->cpl);
// add error checking for the following
$code = file_get_contents($this->sourceFileName);
$pdc = array(
'codelen' => strval(strlen($code)),
);
foreach (array_keys($this->default_params) as $key)
if (substr($key, 0, 4) == "pdc_")
$pdc[substr($key,4)] = $this->getParam($key);
if ($this->cpl == '')
$pdc['executable'] = $pdc['sourcefilename'];
else
$pdc['executable'] = pathinfo($pdc['sourcefilename'],
PATHINFO_FILENAME);
// $this->rab_log(print_r($pdc, true)); //DEBUG
if (!$this->interpreter_choices ||
!in_array($pdc['interpreter'], $this->interpreter_choices)) {
if ($this->interpreter_choices) {
// assert: $this->interpreter_choices is non-empty array
// AND $pdc['interpreter'] is not in that array
$this->rab_log("invalid interpreter: " . $pdc['interpreter']);
// THROW EXCEPTION?? convey to user via do_run script?
}
$pdc['interpreter'] = '';
$pdc['interpreterargs'] = '';
}
/* compose execpdc input file from params and provided code */
$tgt = fopen($this->getTargetFile(), "w");
fwrite($tgt, $this->pdc_flatten(array(
$pdc['backend'])) . "\n");
fwrite($tgt, $this->pdc_flatten(array(
$this->id,
# isset($pdc['nhosts']) ? $pdc['nhosts']: '',
# isset($pdc['ncores']) ? $pdc['ncores']: '',
$pdc['nhosts'],
$pdc['ncores'],
$pdc['envmodule'],
$pdc['codelen'],
$pdc['sourcefilename'] )) );
if ("$this->cpl" != '')
fwrite($tgt, $this->pdc_flatten(array(" $this->cpl",
"-o",
$pdc['executable'],
$pdc['autocompileargs'],
$pdc['sourcefilename'],
$pdc['compileargs'],
$pdc['linkargs'] )) );
fwrite($tgt, "\n");
fwrite($tgt, trim($this->pdc_flatten(array(
$pdc['interpreter'],
$pdc['interpreterargs'],
$pdc['interpreterexec'],
"./" . $pdc['executable'],
$pdc['runargs']))) . "\n");
fwrite($tgt, $code);
fclose($tgt);
$this->rab_log(
implode("", array_slice(file($this->getTargetFile()), 0, 6)) . "...");
}
// A default name for sourcecode files
public function defaultFileName($sourcecode) {
return 'SOURCE_CODE';
}
// The executable is the output from the compilation
public function getExecutablePath() {
return $this->execpdc;
}
public function getTargetFile() {
return 'EXECPDC_INPUT';
}
}