10
#define CMD "/tmp/sleeper.sh"
11
#define CATEGORY "test"
13
int handle_code(int code, char *msg, int r, int t);
16
int main(int argc, char **argv) {
17
int ret = DRMAA_ERRNO_SUCCESS;
18
char error[DRMAA_ERROR_STRING_BUFFER + 1];
24
pthread_t *ids = NULL;
26
ids = (pthread_t *)malloc(sizeof (pthread_t) * threads);
28
ret = drmaa_init(CELL, error, DRMAA_ERROR_STRING_BUFFER);
29
if (handle_code(ret, error, -1, 0) == 1) {
33
for (run_count = 0; run_count < runs; run_count++) {
34
printf("-1 0 STARTING RUN %d %ld\n", run_count, time(NULL));
36
for (thread_count = 0; thread_count < threads; thread_count++) {
37
int *arg = (int *)malloc(sizeof (int) * 2);
40
arg[1] = thread_count;
42
if (pthread_create(&ids[thread_count], NULL, run, arg) != 0) {
43
printf("%d %d EXCEPTION: Couldn't create thread %ld\n", run_count,
44
thread_count, time(NULL));
48
for (thread_count = 0; thread_count < threads; thread_count++) {
49
pthread_join(ids[thread_count], NULL);
52
printf("-1 0 ENDING RUN %d %ld\n", run_count, time(NULL));
55
ret = drmaa_exit(error, DRMAA_ERROR_STRING_BUFFER);
56
handle_code(ret, error, -1, 0);
61
int handle_code(int code, char *msg, int r, int t) {
62
if (code != DRMAA_ERRNO_SUCCESS) {
63
printf("%d %d EXCEPTION: %s %ld\n", r, t, msg, time(NULL));
71
void *run(void *arg) {
72
int ret = DRMAA_ERRNO_SUCCESS;
73
char error[DRMAA_ERROR_STRING_BUFFER + 1];
75
drmaa_job_template_t *jt = NULL;
76
int run = ((int *)arg)[0];
77
int thread = ((int *)arg)[1];
78
char jobid[DRMAA_JOBNAME_BUFFER + 1];
85
ret = drmaa_allocate_job_template(&jt, error, DRMAA_ERROR_STRING_BUFFER);
86
if (handle_code(ret, error, run, thread) == 1) {
90
ret = drmaa_set_attribute(jt, DRMAA_REMOTE_COMMAND, CMD, error,
91
DRMAA_ERROR_STRING_BUFFER);
92
if (handle_code(ret, error, run, thread) == 1) {
96
ret = drmaa_set_attribute(jt, DRMAA_WD, WD, error,
97
DRMAA_ERROR_STRING_BUFFER);
98
if (handle_code(ret, error, run, thread) == 1) {
102
ret = drmaa_set_attribute(jt, DRMAA_JOB_CATEGORY, CATEGORY, error,
103
DRMAA_ERROR_STRING_BUFFER);
104
if (handle_code(ret, error, run, thread) == 1) {
108
printf("%d %d SETUP complete %ld\n", run, thread, time(NULL));
110
ret = drmaa_run_job(jobid, DRMAA_JOBNAME_BUFFER, jt, error,
111
DRMAA_ERROR_STRING_BUFFER);
112
if (handle_code(ret, error, run, thread) == 1) {
116
printf("%d %d SUBMITTED jobid: %s %ld\n", run, thread, jobid, time(NULL));
118
ret = drmaa_delete_job_template(jt, error, DRMAA_ERROR_STRING_BUFFER);
119
handle_code(ret, error, run, thread);
122
ret = drmaa_wait(jobid, NULL, 0, NULL, 2, NULL, error,
123
DRMAA_ERROR_STRING_BUFFER);
125
if (ret != DRMAA_ERRNO_EXIT_TIMEOUT) {
126
if (handle_code(ret, error, run, thread) == 1) {
131
printf ("%d %d TIMEOUT jobid: %s %ld\n", run, thread, jobid, time (NULL));
134
ret = drmaa_job_ps(jobid, &status, error, DRMAA_ERROR_STRING_BUFFER);
135
if (handle_code(ret, error, run, thread) == 1) {
139
queued = (status == DRMAA_PS_QUEUED_ACTIVE) ||
140
(status == DRMAA_PS_SYSTEM_ON_HOLD) ||
141
(status == DRMAA_PS_SYSTEM_ON_HOLD) ||
142
(status == DRMAA_PS_USER_ON_HOLD) ||
143
(status == DRMAA_PS_USER_SYSTEM_ON_HOLD);
146
printf("%d %d RUNNING jobid: %s %ld\n", run, thread, jobid, time(NULL));
150
while (running == 1) {
151
ret = drmaa_wait(jobid, NULL, 0, NULL, 60, NULL, error,
152
DRMAA_ERROR_STRING_BUFFER);
154
if (ret != DRMAA_ERRNO_EXIT_TIMEOUT) {
155
if (handle_code(ret, error, run, thread) == 1) {
161
printf("%d %d FINISHED jobid: %s %ld\n", run, thread, jobid,
165
printf ("%d %d TIMEOUT jobid: %s %ld\n", run, thread, jobid, time (NULL));
167
ret = drmaa_job_ps(jobid, &status, error, DRMAA_ERROR_STRING_BUFFER);
169
if (handle_code(ret, error, run, thread) == 1) {
173
if (status != DRMAA_PS_RUNNING) {
176
printf("%d %d HUNG jobid: %s %ld\n", run, thread, jobid, time(NULL));