Ticket #131: submit_command_async.c

File submit_command_async.c, 3.2 KB (added by remicress, 9 years ago)

[remote HPC server side DRMAA controler] Submit command app (asynchronous)

Line 
1/*
2 * submit_command_async.c
3 *
4 *  Created on: 2 juil. 2015
5 *      Author: cresson
6 */
7
8#include "drmaa.h"
9#include <stdlib.h>     /* exit, EXIT_FAILURE */
10#include <stdlib.h>
11#include <string.h>
12
13void concat(char *s1, char *s2)
14{
15    char *result = malloc(strlen(s1)+strlen(s2)+1);//+1 for the zero-terminator
16    //in real code you would check for errors in malloc here
17    strcpy(result, s1);
18    strcat(result, s2);
19free(s1);
20    s1 = result;
21}
22
23int main (int argc, char **argv) {
24if (argc<2)
25{
26printf ("The given command is empty!\n");
27return EXIT_FAILURE;
28}
29
30   char error[DRMAA_ERROR_STRING_BUFFER];
31   int errnum = 0;
32   drmaa_job_template_t *jt = NULL;
33
34   errnum = drmaa_init (NULL, error, DRMAA_ERROR_STRING_BUFFER);
35
36   if (errnum != DRMAA_ERRNO_SUCCESS) {
37      fprintf (stderr, "Could not initialize the DRMAA library: %s\n", error);
38      return EXIT_FAILURE;
39   }
40
41   errnum = drmaa_allocate_job_template (&jt, error, DRMAA_ERROR_STRING_BUFFER);
42
43   if (errnum != DRMAA_ERRNO_SUCCESS) {
44      fprintf (stderr, "Could not create job template: %s\n", error);
45      return EXIT_FAILURE;
46   }
47   else {
48
49      int i;
50      int count = 0;
51      for (i=1; i<argc; i++)
52      {
53        count += strlen(argv[i]); // argument lenght
54        count += 1; // space between arguments
55      }
56      char command[count];
57      strcpy(command, argv[1]);
58      for (i=2; i<argc; i++)
59      {
60        strcat(command," ");
61        strcat(command,argv[i]);
62      }
63
64      errnum = drmaa_set_attribute (jt, DRMAA_REMOTE_COMMAND, command /*"/gpfs-dell/data/work/GEOSUD/drmaa/test/drmaa_operator/bin/./sleeper.sh"*/,
65                                    error, DRMAA_ERROR_STRING_BUFFER);
66
67      if (errnum != DRMAA_ERRNO_SUCCESS) {
68         fprintf (stderr, "Could not set attribute \"%s\": %s\n",
69                  DRMAA_REMOTE_COMMAND, error);
70         return EXIT_FAILURE;
71      }
72      else {
73/*
74
75         const char *args[2] = {command, NULL};
76
77         errnum = drmaa_set_vector_attribute (jt, DRMAA_V_ARGV, args, error,
78                                              DRMAA_ERROR_STRING_BUFFER);
79      }
80
81      if (errnum != DRMAA_ERRNO_SUCCESS) {
82         fprintf (stderr, "Could not set attribute \"%s\": %s\n",
83                  DRMAA_REMOTE_COMMAND, error);
84         return EXIT_FAILURE;
85      }
86      else {
87*/
88         char jobid[DRMAA_JOBNAME_BUFFER];
89
90         errnum = drmaa_run_job (jobid, DRMAA_JOBNAME_BUFFER, jt, error,
91                                 DRMAA_ERROR_STRING_BUFFER);
92
93         if (errnum != DRMAA_ERRNO_SUCCESS) {
94            fprintf (stderr, "Could not submit job: %s\n", error);
95            return EXIT_FAILURE;
96         }
97         else {
98            printf ("Your job has been submitted with id %s\n", jobid);
99         }
100      } /* else */
101
102      errnum = drmaa_delete_job_template (jt, error, DRMAA_ERROR_STRING_BUFFER);
103
104      if (errnum != DRMAA_ERRNO_SUCCESS) {
105         fprintf (stderr, "Could not delete job template: %s\n", error);
106         return EXIT_FAILURE;
107      }
108   } /* else */
109
110   errnum = drmaa_exit (error, DRMAA_ERROR_STRING_BUFFER);
111
112   if (errnum != DRMAA_ERRNO_SUCCESS) {
113      fprintf (stderr, "Could not shut down the DRMAA library: %s\n", error);
114      return EXIT_FAILURE;
115   }
116
117   return EXIT_SUCCESS;
118}
119

Search

Context Navigation

ZOO Sponsors

http://www.zoo-project.org/trac/chrome/site/img/geolabs-logo.pnghttp://www.zoo-project.org/trac/chrome/site/img/neogeo-logo.png http://www.zoo-project.org/trac/chrome/site/img/apptech-logo.png http://www.zoo-project.org/trac/chrome/site/img/3liz-logo.png http://www.zoo-project.org/trac/chrome/site/img/gateway-logo.png

Become a sponsor !

Knowledge partners

http://www.zoo-project.org/trac/chrome/site/img/ocu-logo.png http://www.zoo-project.org/trac/chrome/site/img/gucas-logo.png http://www.zoo-project.org/trac/chrome/site/img/polimi-logo.png http://www.zoo-project.org/trac/chrome/site/img/fem-logo.png http://www.zoo-project.org/trac/chrome/site/img/supsi-logo.png http://www.zoo-project.org/trac/chrome/site/img/cumtb-logo.png

Become a knowledge partner

Related links

http://zoo-project.org/img/ogclogo.png http://zoo-project.org/img/osgeologo.png