Skip to content

Commit

Permalink
change things so that input files for BUDA jobs don't have to be in t…
Browse files Browse the repository at this point in the history
…he BUDA dir
  • Loading branch information
davidpanderson committed Nov 13, 2024
1 parent b45907b commit 2d35fd5
Show file tree
Hide file tree
Showing 2 changed files with 48 additions and 32 deletions.
31 changes: 19 additions & 12 deletions tools/submit_buda
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,9 @@

// submit a job for the Docker universal app (which must be named 'buda')
//
// submit_buda [--buda_dir dir] infile ...
// submit_buda [--buda_dir dir] [--verbose] infile ...
//
// the buda dir (default buda/) must contain
// the buda dir (default buda_dir/) must contain
// - buda_in, buda_out: input, output templates
// - other files; typically
// a Dockerfile
Expand All @@ -16,45 +16,52 @@
// a list of the other filenames (one per line)
// in the order of the input template

$buda_dir = 'buda';
$buda_dir = 'buda_dir';
$infiles = [];
$verbose = false;

for ($i=1; $i<$argc; $i++) {
if ($argv[$i] == '--buda_dir') {
$buda_dir = $argv[++$i];
} else if ($argv[$i] == '--verbose') {
$verbose = true;
} else {
$infiles[] = $argv[$i];
}
}

if (!file_exists("$buda_dir/buda_in")) {
if (!file_exists("$buda_dir/template_in")) {
die("no input template\n");
}
if (!file_exists("$buda_dir/buda_out")) {
if (!file_exists("$buda_dir/template_out")) {
die("no output template\n");
}
$file_list = file("$buda_dir/file_list");
if (!$file_list) {
die("no file list\n");
}

$cmd = "bin/submit_job --dir $buda_dir --template buda buda";
$cmd = "bin/submit_job --templates $buda_dir/template_in $buda_dir/template_out buda";

foreach ($file_list as $fname) {
$fname = trim($fname);
if (!file_exists("$buda_dir/$fname")) {
die("missing app file '$buda_dir/$fname'\n");
}
$cmd .= " $fname";
$cmd .= " $buda_dir/$fname";
}

foreach ($infiles as $fname) {
if (!file_exists("$fname")) {
die("missing input file $fname\n");
foreach ($infiles as $path) {
if (!file_exists("$path")) {
die("missing input file $path\n");
}
$cmd .= " $fname";
$cmd .= " $path";
}

echo "cmd: $cmd\n";
if ($verbose) {
echo "cmd: $cmd\n";
$cmd .= " --verbose";
}

if (system($cmd, $ret) === false) {
die("system($cmd) failed\n");
Expand Down
49 changes: 29 additions & 20 deletions tools/submit_job
Original file line number Diff line number Diff line change
Expand Up @@ -5,22 +5,24 @@
//
// usage: submit_job [options] appname [infile ...]
// options:
// --template fname: use template files fname_in and fname_out
// --dir X: files are in dir X
// --templates in out: specify in/out template files
// --verbose
//
// If the app uses a sample assimilator,
// you can use query_job to query the job status and see output files.

$appname = null;
$template = null;
$dir = '.';
$input_template = null;
$output_template = null;
$infiles = [];
$verbose = false;

for ($i=1; $i<$argc; $i++) {
if ($argv[$i] == '--template') {
$template = $argv[++$i];
} else if ($argv[$i] == '--dir') {
$dir = $argv[++$i];
if ($argv[$i] == '--templates') {
$input_template = $argv[++$i];
$output_template = $argv[++$i];
} else if ($argv[$i] == '--verbose') {
$verbose = true;
} else if (!$appname) {
$appname = $argv[$i];
} else {
Expand All @@ -45,8 +47,8 @@ if (!$app) {
// load the input template for this app,
// and make sure the right number of input files were specified
//
if ($template) {
$path = sprintf('%s/%s_in', $dir, $template);
if ($input_template) {
$path = $input_template;
} else {
$path = sprintf('templates/%s_in', $appname);
}
Expand All @@ -64,28 +66,35 @@ if (count($infiles) != $nrefs) {

// stage the input files
//
foreach ($infiles as $fname) {
if (!is_file("$dir/$fname")) {
die("no such file: $fname\n");
$fnames = [];
foreach ($infiles as $path) {
if (!is_file("$path")) {
die("no such file: $path\n");
}
system("cp $dir/$fname `bin/dir_hier_path $fname`", $ret);
$fname = basename($path);
$fnames[] = $fname;
system("cp $path `bin/dir_hier_path $fname`", $ret);
if ($ret) {
die("Couldn't stage file $dir/$fname\n");
die("Couldn't stage file $path\n");
}
}

// create the job
//
$wu_name = sprintf('%s_%d', $appname, time());
$x = '';
if ($template) {
$x = sprintf('--wu_template %s/%s_in --result_template %s/%s_out',
$dir, $template, $dir, $template
);
if ($input_template) {
$x .= " --wu_template $input_template";
}
if ($output_template) {
$x .= " --result_template $output_template";
}
$cmd = sprintf('bin/create_work --appname %s --wu_name %s %s %s',
$appname, $wu_name, $x, implode(' ', $infiles)
$appname, $wu_name, $x, implode(' ', $fnames)
);
if ($verbose) {
echo "submit_job: cmd: $cmd\n";
}
if (system($cmd, $ret) === false) {
die("system($cmd) failed\n");
}
Expand Down

0 comments on commit 2d35fd5

Please sign in to comment.