1
/*___INFO__MARK_BEGIN__*/
2
/*************************************************************************
4
* The Contents of this file are made available subject to the terms of
5
* the Sun Industry Standards Source License Version 1.2
7
* Sun Microsystems Inc., March, 2001
10
* Sun Industry Standards Source License Version 1.2
11
* =================================================
12
* The contents of this file are subject to the Sun Industry Standards
13
* Source License Version 1.2 (the "License"); You may not use this file
14
* except in compliance with the License. You may obtain a copy of the
15
* License at http://gridengine.sunsource.net/Gridengine_SISSL_license.html
17
* Software provided under this License is provided on an "AS IS" basis,
18
* WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING,
19
* WITHOUT LIMITATION, WARRANTIES THAT THE SOFTWARE IS FREE OF DEFECTS,
20
* MERCHANTABLE, FIT FOR A PARTICULAR PURPOSE, OR NON-INFRINGING.
21
* See the License for the specific provisions governing your rights and
22
* obligations concerning the Software.
24
* The Initial Developer of the Original Code is: Sun Microsystems, Inc.
26
* Copyright: 2001 by Sun Microsystems, Inc.
28
* All Rights Reserved.
30
************************************************************************/
31
/*___INFO__MARK_END__*/
35
int main (int argc, char **argv) {
36
char error[DRMAA_ERROR_STRING_BUFFER];
38
drmaa_job_template_t *jt = NULL;
40
errnum = drmaa_init (NULL, error, DRMAA_ERROR_STRING_BUFFER);
42
if (errnum != DRMAA_ERRNO_SUCCESS) {
43
fprintf (stderr, "Could not initialize the DRMAA library: %s\n", error);
47
errnum = drmaa_allocate_job_template (&jt, error, DRMAA_ERROR_STRING_BUFFER);
49
if (errnum != DRMAA_ERRNO_SUCCESS) {
50
fprintf (stderr, "Could not create job template: %s\n", error);
53
errnum = drmaa_set_attribute (jt, DRMAA_REMOTE_COMMAND, "sleeper.sh",
54
error, DRMAA_ERROR_STRING_BUFFER);
56
if (errnum != DRMAA_ERRNO_SUCCESS) {
57
fprintf (stderr, "Could not set attribute \"%s\": %s\n",
58
DRMAA_REMOTE_COMMAND, error);
61
const char *args[2] = {"5", NULL};
63
errnum = drmaa_set_vector_attribute (jt, DRMAA_V_ARGV, args, error,
64
DRMAA_ERROR_STRING_BUFFER);
67
if (errnum != DRMAA_ERRNO_SUCCESS) {
68
fprintf (stderr, "Could not set attribute \"%s\": %s\n",
69
DRMAA_REMOTE_COMMAND, error);
72
drmaa_job_ids_t *ids = NULL;
77
errnum = drmaa_run_bulk_jobs (&ids, jt, start, end, step, error,
78
DRMAA_ERROR_STRING_BUFFER);
80
if (errnum != DRMAA_ERRNO_SUCCESS) {
81
fprintf (stderr, "Could not submit job: %s\n", error);
84
char jobid[DRMAA_JOBNAME_BUFFER];
85
const char *jobids[2] = {DRMAA_JOB_IDS_SESSION_ALL, NULL};
87
while (drmaa_get_next_job_id (ids, jobid, DRMAA_JOBNAME_BUFFER)
88
== DRMAA_ERRNO_SUCCESS) {
89
printf ("A job task has been submitted with id %s\n", jobid);
92
errnum = drmaa_synchronize (jobids, DRMAA_TIMEOUT_WAIT_FOREVER,
93
0, error, DRMAA_ERROR_STRING_BUFFER);
95
if (errnum != DRMAA_ERRNO_SUCCESS) {
96
fprintf (stderr, "Could not wait for jobs: %s\n", error);
99
char jobid[DRMAA_JOBNAME_BUFFER];
101
drmaa_attr_values_t *rusage = NULL;
104
for (count = start; count < end; count += step) {
105
errnum = drmaa_wait (DRMAA_JOB_IDS_SESSION_ANY, jobid,
106
DRMAA_JOBNAME_BUFFER, &status,
107
DRMAA_TIMEOUT_WAIT_FOREVER, &rusage,
108
error, DRMAA_ERROR_STRING_BUFFER);
110
if (errnum != DRMAA_ERRNO_SUCCESS) {
111
fprintf (stderr, "Could not wait for job: %s\n", error);
114
char usage[DRMAA_ERROR_STRING_BUFFER];
117
drmaa_wifaborted(&aborted, status, NULL, 0);
120
printf("Job %s never ran\n", jobid);
125
drmaa_wifexited(&exited, status, NULL, 0);
130
drmaa_wexitstatus(&exit_status, status, NULL, 0);
131
printf("Job %s finished regularly with exit status %d\n",
137
drmaa_wifsignaled(&signaled, status, NULL, 0);
140
char termsig[DRMAA_SIGNAL_BUFFER+1];
142
drmaa_wtermsig(termsig, DRMAA_SIGNAL_BUFFER, status, NULL, 0);
143
printf("Job %s finished due to signal %s\n", jobid, termsig);
146
printf("Job %s finished with unclear conditions\n", jobid);
151
printf ("Job Usage:\n");
153
while (drmaa_get_next_attr_value (rusage, usage, DRMAA_ERROR_STRING_BUFFER)
154
== DRMAA_ERRNO_SUCCESS) {
155
printf (" %s\n", usage);
158
drmaa_release_attr_values (rusage);
164
drmaa_release_job_ids (ids);
167
errnum = drmaa_delete_job_template (jt, error, DRMAA_ERROR_STRING_BUFFER);
169
if (errnum != DRMAA_ERRNO_SUCCESS) {
170
fprintf (stderr, "Could not delete job template: %s\n", error);
174
errnum = drmaa_exit (error, DRMAA_ERROR_STRING_BUFFER);
176
if (errnum != DRMAA_ERRNO_SUCCESS) {
177
fprintf (stderr, "Could not shut down the DRMAA library: %s\n", error);