Skip to content

Commit

Permalink
BUDA: add cmdline field to submission form.
Browse files Browse the repository at this point in the history
Specifies cmdline args for all jobs in batch;
you can also specify per-job args, which come after.

create_work: add logic to support the above;
also fix bug involving pointers to stack vars (big no-no)
  • Loading branch information
davidpanderson committed Dec 4, 2024
1 parent ff7810b commit e38016d
Show file tree
Hide file tree
Showing 3 changed files with 37 additions and 18 deletions.
29 changes: 19 additions & 10 deletions html/user/buda_submit.php
Original file line number Diff line number Diff line change
Expand Up @@ -41,16 +41,17 @@ function submit_form($user) {
containing command-line arguments.
<a href=https://github.com/BOINC/boinc/wiki/BUDA-job-submission>Details</a></small>.
";
$desc2 = "<br><small>
Write Docker commands and output to stderr (for debugging).
";
page_head("Submit jobs to $app ($variant)");
form_start('buda_submit.php');
form_input_hidden('action', 'submit');
form_input_hidden('app', $app);
form_input_hidden('variant', $variant);
form_select("Batch zip file $desc", 'batch_file', $sbitems_zip);
form_checkbox("Verbose Docker output? $desc2", 'wrapper_verbose');
form_input_text('Command line arguments', 'cmdline');
form_checkbox(
"Enabled debugging output <br><small>Write Docker commands and output to stderr</small>.",
'wrapper_verbose'
);
form_submit('OK');
form_end();
page_tail();
Expand Down Expand Up @@ -114,7 +115,8 @@ function parse_batch_dir($batch_dir, $variant_desc) {
foreach(scandir("$batch_dir/$fname") as $f2) {
if ($f2[0] == '.') continue;
if ($f2 == 'cmdline') {
$cmdline = trim(file_get_contents("$batch_dir/$f2"));
$cmdline = trim(file_get_contents("$batch_dir/$fname/cmdline"));
continue;
}
if (!in_array($f2, $unshared_files)) {
error_page("$fname/$f2 is not an input file name");
Expand Down Expand Up @@ -186,7 +188,8 @@ function stage_input_files($batch_dir, $batch_desc, $batch_id) {
// Use --stdin, where each job is described by a line
//
function create_jobs(
$variant_desc, $batch_desc, $batch_id, $batch_dir_name, $wrapper_verbose
$variant_desc, $batch_desc, $batch_id, $batch_dir_name,
$wrapper_verbose, $cmdline
) {
global $buda_app;

Expand All @@ -211,15 +214,20 @@ function create_jobs(
}
$job_cmds .= "$job_cmd\n";
}
$cmd = sprintf(
'cd ../..; bin/create_work --appname %s --batch %d --stdin --command_line "--dockerfile %s %s" --wu_template %s --result_template %s',
$buda_app->name, $batch_id,
$cw_cmdline = sprintf('"--dockerfile %s %s %s"',
$variant_desc->dockerfile,
$wrapper_verbose?'--verbose':'',
$cmdline
);
$cmd = sprintf(
'cd ../..; bin/create_work --appname %s --batch %d --stdin --command_line %s --wu_template %s --result_template %s',
$buda_app->name, $batch_id,
$cw_cmdline,
"buda_batches/$batch_dir_name/template_in",
"buda_batches/$batch_dir_name/template_out"
);
$cmd .= sprintf(' > %s 2<&1', "buda_batches/errfile");

$h = popen($cmd, "w");
if (!$h) error_page('create_work launch failed');
fwrite($h, $job_cmds);
Expand Down Expand Up @@ -316,6 +324,7 @@ function handle_submit($user) {
$batch_file = get_str('batch_file');
if (!is_valid_filename($batch_file)) die('bad arg');
$wrapper_verbose = get_str('wrapper_verbose', true);
$cmdline = get_str('cmdline');

$variant_dir = "../../buda_apps/$app/$variant";
$variant_desc = json_decode(
Expand All @@ -341,7 +350,7 @@ function handle_submit($user) {

create_jobs(
$variant_desc, $batch_desc, $batch->id, $batch_dir_name,
$wrapper_verbose
$wrapper_verbose, $cmdline
);

// mark batch as in progress
Expand Down
5 changes: 5 additions & 0 deletions lib/str_util.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -235,6 +235,11 @@ void nbytes_to_string(double nbytes, double total_bytes, char* str, int len) {
// return an array of pointers to the null-terminated words.
// Modifies the string arg.
// Returns argc
//
// WARNING: the argv[] pointers are into the original string.
// If that goes away (stack) or is modified,
// the pointers are invalidated.

// TODO: use strtok here

#define NOT_IN_TOKEN 0
Expand Down
21 changes: 13 additions & 8 deletions tools/create_work.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
// - to create multiple jobs, where per-job info is passed via stdin,
// one line per job
// available options here:
// --command_line X
// --wu_name X
// --wu_template F
// --result_template F
Expand Down Expand Up @@ -137,15 +138,15 @@ struct JOB_DESC {
char result_template_file[256];
char result_template_path[MAXPATHLEN];
vector <INFILE_DESC> infiles;
char* command_line;
char command_line[1024];
bool assign_flag;
bool assign_multi;
int assign_id;
int assign_type;

JOB_DESC() {
wu.clear();
command_line = NULL;
strcpy(command_line, "");
assign_flag = false;
assign_multi = false;
strcpy(wu_template_file, "");
Expand All @@ -171,15 +172,19 @@ struct JOB_DESC {

}
void create();
void parse_cmdline(int, char**);
void parse_stdin_line(int, char**);
};

// parse additional job-specific info when using --stdin
//
void JOB_DESC::parse_cmdline(int argc, char** argv) {
void JOB_DESC::parse_stdin_line(int argc, char** argv) {
for (int i=0; i<argc; i++) {
if (arg(argv, i, (char*)"command_line")) {
command_line = argv[++i];
// concatenate per-job args to main args
if (strlen(command_line)) {
strcat(command_line, " ");
}
strcat(command_line, argv[++i]);
} else if (arg(argv, i, (char*)"wu_name")) {
safe_strcpy(wu.name, argv[++i]);
} else if (arg(argv, i, (char*)"wu_template")) {
Expand Down Expand Up @@ -310,7 +315,7 @@ int main(int argc, char** argv) {
} else if (arg(argv, i, "opaque")) {
jd.wu.opaque = atoi(argv[++i]);
} else if (arg(argv, i, "command_line")) {
jd.command_line= argv[++i];
strcpy(jd.command_line, argv[++i]);
} else if (arg(argv, i, "wu_id")) {
jd.wu.id = atoi(argv[++i]);
} else if (arg(argv, i, "broadcast")) {
Expand Down Expand Up @@ -458,7 +463,7 @@ int main(int argc, char** argv) {
// things default to what was passed on cmdline
strcpy(jd2.wu.name, "");
_argc = parse_command_line(buf, _argv);
jd2.parse_cmdline(_argc, _argv);
jd2.parse_stdin_line(_argc, _argv);
// get info from stdin line
if (!strlen(jd2.wu.name)) {
snprintf(jd2.wu.name, sizeof(jd2.wu.name), "%s_%d", jd.wu.name, j);
Expand All @@ -483,7 +488,7 @@ int main(int argc, char** argv) {
JOB_DESC jd2 = jd;
strcpy(jd2.wu.name, "");
_argc = parse_command_line(buf, _argv);
jd2.parse_cmdline(_argc, _argv);
jd2.parse_stdin_line(_argc, _argv);
if (!strlen(jd2.wu.name)) {
snprintf(jd2.wu.name, sizeof(jd2.wu.name), "%s_%d", jd.wu.name, j);
}
Expand Down

0 comments on commit e38016d

Please sign in to comment.