source: experiments/DRMAA_tests/DRMAA_suspend/suspend.c @ 16

Revision 16, 5.4 KB checked in by mmatloka, 14 years ago (diff)

add experiments

RevLine 
[16]1#include <stdio.h>
2#include <unistd.h>
3#include <string.h>
4#include <drmaa.h>
5
6#define JOB_CHUNK 1
7#define NBULKS 1
8
9static drmaa_job_template_t *create_job_template(const char *job_path, int seconds,
10int as_bulk_job);
11
12int main(int argc, char *argv[])
13{
14        char diagnosis[DRMAA_ERROR_STRING_BUFFER];
15        const char *all_jobids[NBULKS*JOB_CHUNK + JOB_CHUNK+1];
16        char jobid[100];
17        int drmaa_errno, i, pos = 0;
18        const char *job_path = NULL;
19        drmaa_job_template_t *jt = NULL;
20       
21        if (argc<2)
22        {
23                fprintf(stderr, "usage: example <path-to-job>\n");
24                return 1;
25        }
26       
27        job_path = argv[1];
28        if (drmaa_init(NULL, diagnosis, sizeof(diagnosis)-1) != DRMAA_ERRNO_SUCCESS)
29        {
30                fprintf(stderr, "drmaa_init() failed: %s\n", diagnosis);
31                return 1;
32        }
33
34        /*
35        * submit some bulk jobs
36        */
37/*      if (!(jt = create_job_template(job_path, 5, 1)))
38        {
39                fprintf(stderr, "create_job_template() failed\n");
40                return 1;
41        }
42        for (i=0; i<NBULKS; i++)
43        {
44                drmaa_job_ids_t *jobids = NULL;
45                int j;
46                while ((drmaa_errno=drmaa_run_bulk_jobs(&jobids, jt, 1, JOB_CHUNK, 1, diagnosis,
47                sizeof(diagnosis)-1)) == DRMAA_ERRNO_DRM_COMMUNICATION_FAILURE)
48                {
49                        fprintf(stderr, "drmaa_run_bulk_jobs() failed - retry: %s %s\n", diagnosis,
50                        drmaa_strerror(drmaa_errno));
51                        sleep(1);
52                }
53               
54                if (drmaa_errno != DRMAA_ERRNO_SUCCESS)
55                {
56                        fprintf(stderr, "drmaa_run_bulk_jobs() failed: %s %s\n", diagnosis,
57                        drmaa_strerror(drmaa_errno));
58                        return 1;
59                }
60                printf("submitted bulk job with jobids:\n");
61                for (j=0; j<JOB_CHUNK; j++)
62                {
63                        drmaa_get_next_job_id(jobids, jobid, sizeof(jobid)-1);
64                        all_jobids[pos++] = strdup(jobid);
65                        printf("\t \"%s\"\n", jobid);
66                }
67                drmaa_release_job_ids(jobids);
68        }
69        drmaa_delete_job_template(jt, NULL, 0); */
70        /*
71        * submit some sequential jobs
72        */
73        if (!(jt = create_job_template(job_path, 1, 0)))
74        {
75                fprintf(stderr, "create_sleeper_job_template() failed\n");
76                return 1;
77        }
78       
79        for (i=0; i<1; i++)
80        {
81                while ((drmaa_errno=drmaa_run_job(jobid, sizeof(jobid)-1, jt, diagnosis,
82                sizeof(diagnosis)-1)) ==
83                DRMAA_ERRNO_DRM_COMMUNICATION_FAILURE)
84                {
85                        fprintf(stderr, "drmaa_run_job() failed - retry: %s\n", diagnosis);
86                        sleep(1);
87                }
88               
89                if (drmaa_errno != DRMAA_ERRNO_SUCCESS)
90                {
91                        fprintf(stderr, "drmaa_run_job() failed: %s\n", diagnosis);
92                        return 1;
93                }
94               
95                printf("\t \"%s\"\n", jobid);
96                all_jobids[pos++] = strdup(jobid);
97        }
98        /* set string array end mark */
99        all_jobids[pos] = NULL;
100        drmaa_delete_job_template(jt, NULL, 0);
101        sleep(2);
102        drmaa_control(jobid, DRMAA_CONTROL_SUSPEND,diagnosis, sizeof(diagnosis)-1);
103        /*
104        * synchronize with all jobs
105        */
106        /*drmaa_errno = drmaa_synchronize(all_jobids, DRMAA_TIMEOUT_WAIT_FOREVER, 0, diagnosis,
107        sizeof(diagnosis)-1);
108        if (drmaa_errno != DRMAA_ERRNO_SUCCESS)
109        {
110                fprintf(stderr,         "drmaa_synchronize(DRMAA_JOB_IDS_SESSION_ALL, dispose) failed: %s\n",   diagnosis);
111                return 1;
112        }
113        printf("synchronized with all jobs\n");
114*/
115        /*
116        * wait all those jobs
117        */
118        for (pos=0; pos< 1; pos++)
119        {
120                int stat;
121                int aborted, exited, exit_status, signaled;
122                printf("\nDrmaa_wait\n");
123                drmaa_errno = drmaa_wait(all_jobids[pos], jobid, sizeof(jobid)-1, &stat,DRMAA_TIMEOUT_WAIT_FOREVER, NULL, diagnosis, sizeof(diagnosis)-1);
124                printf("\nAfter drmaa_wait\n");
125                if (drmaa_errno != DRMAA_ERRNO_SUCCESS)
126                {
127                        fprintf(stderr, "drmaa_wait(%s) failed: %s\n", all_jobids[pos], diagnosis);
128                        return 1;
129                }
130                /*
131                * report how job finished
132                */
133                drmaa_wifaborted(&aborted, stat, NULL, 0);
134                if (aborted)
135                {
136                        printf("job \"%s\" never ran\n", all_jobids[pos]);
137                }
138                else
139                {
140                        drmaa_wifexited(&exited, stat, NULL, 0);
141                        if (exited)
142                        {
143                                drmaa_wexitstatus(&exit_status, stat, NULL, 0);
144                                printf("job \"%s\" finished regularly with exit status %d\n",
145                                all_jobids[pos], exit_status);
146                        }
147                        else
148                        {
149                                drmaa_wifsignaled(&signaled, stat, NULL, 0);
150                                if (signaled)
151                                {
152                                        char termsig[DRMAA_SIGNAL_BUFFER+1];
153                                        drmaa_wtermsig(termsig, DRMAA_SIGNAL_BUFFER, stat, NULL, 0);
154                                        printf("job \"%s\" finished due to signal %s\n",
155                                        all_jobids[pos], termsig);
156                                }
157                                else
158                                {
159                                        printf("job \"%s\" finished with unclear conditions\n",
160                                        all_jobids[pos]);
161                                }
162                        }
163                }
164        }
165       
166        if (drmaa_exit(diagnosis, sizeof(diagnosis)-1) != DRMAA_ERRNO_SUCCESS)
167        {
168                fprintf(stderr, "drmaa_exit() failed: %s\n", diagnosis);
169                return 1;
170        }
171        return 0;
172}
173
174        static drmaa_job_template_t *create_job_template(const char *job_path, int seconds,     int as_bulk_job)
175        {
176                const char *job_argv[2];
177                drmaa_job_template_t *jt = NULL;
178                char buffer[100];
179                if (drmaa_allocate_job_template(&jt, NULL, 0)!=DRMAA_ERRNO_SUCCESS)
180                {
181                        return NULL;
182                }
183                /* run in users home directory */
184                drmaa_set_attribute(jt, DRMAA_WD, DRMAA_PLACEHOLDER_HD"/michal/experiments/DRMAA_tests/DRMAA_suspend", NULL, 0);
185
186                /**/
187
188               
189                drmaa_set_attribute(jt, DRMAA_NATIVE_SPECIFICATION, "@restart = yes", NULL, 0);
190
191                drmaa_set_attribute(jt, DRMAA_WCT_SLIMIT, "5:00", NULL, 0);
192
193                /**/
194               
195               
196                /* the job to be run */
197                drmaa_set_attribute(jt, DRMAA_REMOTE_COMMAND, job_path, NULL, 0);
198
199                /* the job's arguments */
200                sprintf(buffer, "%d", seconds);
201                job_argv[0] = buffer;
202                job_argv[1] = NULL;
203                drmaa_set_vector_attribute(jt, DRMAA_V_ARGV, job_argv, NULL, 0);
204                /* join output/error file */
205                drmaa_set_attribute(jt, DRMAA_JOIN_FILES, "y", NULL, 0);
206                /* path for output */
207                if (!as_bulk_job)
208                {
209                        drmaa_set_attribute(jt, DRMAA_OUTPUT_PATH, ":"DRMAA_PLACEHOLDER_HD"/DRMAA_JOB", NULL, 0);
210                }
211                else
212                {
213                        drmaa_set_attribute(jt, DRMAA_OUTPUT_PATH,":"DRMAA_PLACEHOLDER_HD"/DRMAA_JOB."DRMAA_PLACEHOLDER_INCR, NULL, 0);
214                }
215                return jt;
216        }
Note: See TracBrowser for help on using the repository browser.