-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsubmit.c
75 lines (69 loc) · 2.24 KB
/
submit.c
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
#include <stdio.h>
#include <errno.h>
#include <string.h>
#include <flux/core.h>
extern char **environ;
int main (int argc, char *argv[])
{
flux_jobspec1_t *jobspec;
flux_future_t *f;
flux_t *h;
flux_jobid_t id;
char *spec;
int ntasks = 1;
int cores_per_task = 1;
int gpus_per_task = 0;
int nnodes = 0; /* unset nnodes, let scheduler pick */
double duration = 0.0; /* unlimited duration */
bool success;
const char *errstr;
if (!(jobspec = flux_jobspec1_from_command (argc-1,
argv+1,
environ,
ntasks,
cores_per_task,
gpus_per_task,
nnodes,
duration))) {
fprintf (stderr, "flux_jobspec1_from_command failed\n");
exit (1);
}
if (!(spec = flux_jobspec1_encode (jobspec, 0))) {
fprintf (stderr, "flux_jobspec1_encode failed\n");
exit (1);
}
flux_jobspec1_destroy (jobspec);
if (!(h = flux_open (NULL, 0))) {
fprintf (stderr, "flux_open: %s\n", strerror (errno));
exit (1);
}
if (!(f = flux_job_submit (h, spec, 16, FLUX_JOB_WAITABLE))) {
fprintf (stderr, "flux_job_submit: %s\n", strerror (errno));
exit (1);
}
free (spec);
if (flux_job_submit_get_id (f, &id) < 0) {
fprintf (stderr, "job submission failed: %s\n",
future_strerror (f, errno));
exit (1);
}
flux_future_destroy (f);
if (!(f = flux_job_wait (h, id))) {
fprintf (stderr, "flux_job_wait: %s\n", strerror (errno));
exit (1);
}
if (flux_job_wait_get_status (f, &success, &errstr) < 0) {
fprintf (stderr, "flux_job_wait_get_status: %s\n",
future_strerror (f, errno));
exit (1);
}
if (success)
fprintf (stdout, "%ju: OK\n", (uintmax_t) id);
else {
fprintf (stderr, "%ju: %s\n", (uintmax_t) id, errstr);
exit (1);
}
flux_future_destroy (f);
flux_close (h);
return 0;
}