diff --git a/examples/drmaa/example.c b/examples/drmaa/example.c new file mode 100755 index 0000000..cb5a918 --- /dev/null +++ b/examples/drmaa/example.c @@ -0,0 +1,211 @@ +/*___INFO__MARK_BEGIN__*/ +/************************************************************************* + * + * The Contents of this file are made available subject to the terms of + * the Sun Industry Standards Source License Version 1.2 + * + * Sun Microsystems Inc., March, 2001 + * + * + * Sun Industry Standards Source License Version 1.2 + * ================================================= + * The contents of this file are subject to the Sun Industry Standards + * Source License Version 1.2 (the "License"); You may not use this file + * except in compliance with the License. You may obtain a copy of the + * License at http://gridengine.sunsource.net/Gridengine_SISSL_license.html + * + * Software provided under this License is provided on an "AS IS" basis, + * WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, + * WITHOUT LIMITATION, WARRANTIES THAT THE SOFTWARE IS FREE OF DEFECTS, + * MERCHANTABLE, FIT FOR A PARTICULAR PURPOSE, OR NON-INFRINGING. + * See the License for the specific provisions governing your rights and + * obligations concerning the Software. + * + * The Initial Developer of the Original Code is: Sun Microsystems, Inc. + * + * Copyright: 2001 by Sun Microsystems, Inc. + * + * All Rights Reserved. + * + ************************************************************************/ +/*___INFO__MARK_END__*/ +#include +#include +#include + +#include "drmaa.h" + +#define JOB_CHUNK 8 +#define NBULKS 3 + +static drmaa_job_template_t *create_job_template(const char *job_path, int seconds, int as_bulk_job); + +int main(int argc, char *argv[]) +{ + char diagnosis[DRMAA_ERROR_STRING_BUFFER]; + const char *all_jobids[NBULKS*JOB_CHUNK + JOB_CHUNK+1]; + char jobid[100]; + int drmaa_errno, i, pos = 0; + const char *job_path; + drmaa_job_template_t *jt; + + if (argc<2) { + fprintf(stderr, "usage: example \n"); + return 1; + } + job_path = argv[1]; + + if (drmaa_init(NULL, diagnosis, sizeof(diagnosis)-1) != DRMAA_ERRNO_SUCCESS) { + fprintf(stderr, "drmaa_init() failed: %s\n", diagnosis); + return 1; + } + + /* + * submit some bulk jobs + */ + if (!(jt = create_job_template(job_path, 5, 1))) { + fprintf(stderr, "create_job_template() failed\n"); + return 1; + } + for (i=0; i +#include "drmaa.h" + +int main (int argc, char **argv) { + char error[DRMAA_ERROR_STRING_BUFFER]; + int errnum = 0; + + errnum = drmaa_init (NULL, error, DRMAA_ERROR_STRING_BUFFER); + + if (errnum != DRMAA_ERRNO_SUCCESS) { + fprintf (stderr, "Could not initialize the DRMAA library: %s\n", error); + return 1; + } + + printf ("DRMAA library was started successfully\n"); + + errnum = drmaa_exit (error, DRMAA_ERROR_STRING_BUFFER); + + if (errnum != DRMAA_ERRNO_SUCCESS) { + fprintf (stderr, "Could not shut down the DRMAA library: %s\n", error); + return 1; + } + + return 0; +} diff --git a/examples/drmaa/howto1_1.c b/examples/drmaa/howto1_1.c new file mode 100755 index 0000000..f75637a --- /dev/null +++ b/examples/drmaa/howto1_1.c @@ -0,0 +1,81 @@ +/*___INFO__MARK_BEGIN__*/ +/************************************************************************* + * + * The Contents of this file are made available subject to the terms of + * the Sun Industry Standards Source License Version 1.2 + * + * Sun Microsystems Inc., March, 2001 + * + * + * Sun Industry Standards Source License Version 1.2 + * ================================================= + * The contents of this file are subject to the Sun Industry Standards + * Source License Version 1.2 (the "License"); You may not use this file + * except in compliance with the License. You may obtain a copy of the + * License at http://gridengine.sunsource.net/Gridengine_SISSL_license.html + * + * Software provided under this License is provided on an "AS IS" basis, + * WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, + * WITHOUT LIMITATION, WARRANTIES THAT THE SOFTWARE IS FREE OF DEFECTS, + * MERCHANTABLE, FIT FOR A PARTICULAR PURPOSE, OR NON-INFRINGING. + * See the License for the specific provisions governing your rights and + * obligations concerning the Software. + * + * The Initial Developer of the Original Code is: Sun Microsystems, Inc. + * + * Copyright: 2001 by Sun Microsystems, Inc. + * + * All Rights Reserved. + * + ************************************************************************/ +/*___INFO__MARK_END__*/ +#include +#include "drmaa.h" + +int main (int argc, char **argv) { + char error[DRMAA_ERROR_STRING_BUFFER]; + int errnum = 0; + char contact[DRMAA_CONTACT_BUFFER]; + + errnum = drmaa_init (NULL, error, DRMAA_ERROR_STRING_BUFFER); + + if (errnum != DRMAA_ERRNO_SUCCESS) { + fprintf (stderr, "Could not initialize the DRMAA library: %s\n", error); + return 1; + } + + printf ("DRMAA library was started successfully\n"); + + errnum = drmaa_get_contact (contact, DRMAA_CONTACT_BUFFER, error, + DRMAA_ERROR_STRING_BUFFER); + + if (errnum != DRMAA_ERRNO_SUCCESS) { + fprintf (stderr, "Could not get the contact string: %s\n", error); + return 1; + } + + errnum = drmaa_exit (error, DRMAA_ERROR_STRING_BUFFER); + + if (errnum != DRMAA_ERRNO_SUCCESS) { + fprintf (stderr, "Could not shut down the DRMAA library: %s\n", error); + return 1; + } + + errnum = drmaa_init (contact, error, DRMAA_ERROR_STRING_BUFFER); + + if (errnum != DRMAA_ERRNO_SUCCESS) { + fprintf (stderr, "Could not reinitialize the DRMAA library: %s\n", error); + return 1; + } + + printf ("DRMAA library was restarted successfully\n"); + + errnum = drmaa_exit (error, DRMAA_ERROR_STRING_BUFFER); + + if (errnum != DRMAA_ERRNO_SUCCESS) { + fprintf (stderr, "Could not shut down the DRMAA library: %s\n", error); + return 1; + } + + return 0; +} diff --git a/examples/drmaa/howto2.c b/examples/drmaa/howto2.c new file mode 100755 index 0000000..7ea06c6 --- /dev/null +++ b/examples/drmaa/howto2.c @@ -0,0 +1,100 @@ +/*___INFO__MARK_BEGIN__*/ +/************************************************************************* + * + * The Contents of this file are made available subject to the terms of + * the Sun Industry Standards Source License Version 1.2 + * + * Sun Microsystems Inc., March, 2001 + * + * + * Sun Industry Standards Source License Version 1.2 + * ================================================= + * The contents of this file are subject to the Sun Industry Standards + * Source License Version 1.2 (the "License"); You may not use this file + * except in compliance with the License. You may obtain a copy of the + * License at http://gridengine.sunsource.net/Gridengine_SISSL_license.html + * + * Software provided under this License is provided on an "AS IS" basis, + * WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, + * WITHOUT LIMITATION, WARRANTIES THAT THE SOFTWARE IS FREE OF DEFECTS, + * MERCHANTABLE, FIT FOR A PARTICULAR PURPOSE, OR NON-INFRINGING. + * See the License for the specific provisions governing your rights and + * obligations concerning the Software. + * + * The Initial Developer of the Original Code is: Sun Microsystems, Inc. + * + * Copyright: 2001 by Sun Microsystems, Inc. + * + * All Rights Reserved. + * + ************************************************************************/ +/*___INFO__MARK_END__*/ +#include +#include "drmaa.h" + +int main (int argc, char **argv) { + char error[DRMAA_ERROR_STRING_BUFFER]; + int errnum = 0; + drmaa_job_template_t *jt = NULL; + + errnum = drmaa_init (NULL, error, DRMAA_ERROR_STRING_BUFFER); + + if (errnum != DRMAA_ERRNO_SUCCESS) { + fprintf (stderr, "Could not initialize the DRMAA library: %s\n", error); + return 1; + } + + errnum = drmaa_allocate_job_template (&jt, error, DRMAA_ERROR_STRING_BUFFER); + + if (errnum != DRMAA_ERRNO_SUCCESS) { + fprintf (stderr, "Could not create job template: %s\n", error); + } + else { + errnum = drmaa_set_attribute (jt, DRMAA_REMOTE_COMMAND, "sleeper.sh", + error, DRMAA_ERROR_STRING_BUFFER); + + if (errnum != DRMAA_ERRNO_SUCCESS) { + fprintf (stderr, "Could not set attribute \"%s\": %s\n", + DRMAA_REMOTE_COMMAND, error); + } + else { + const char *args[2] = {"5", NULL}; + + errnum = drmaa_set_vector_attribute (jt, DRMAA_V_ARGV, args, error, + DRMAA_ERROR_STRING_BUFFER); + } + + if (errnum != DRMAA_ERRNO_SUCCESS) { + fprintf (stderr, "Could not set attribute \"%s\": %s\n", + DRMAA_REMOTE_COMMAND, error); + } + else { + char jobid[DRMAA_JOBNAME_BUFFER]; + + errnum = drmaa_run_job (jobid, DRMAA_JOBNAME_BUFFER, jt, error, + DRMAA_ERROR_STRING_BUFFER); + + if (errnum != DRMAA_ERRNO_SUCCESS) { + fprintf (stderr, "Could not submit job: %s\n", error); + } + else { + printf ("Your job has been submitted with id %s\n", jobid); + } + } /* else */ + + errnum = drmaa_delete_job_template (jt, error, DRMAA_ERROR_STRING_BUFFER); + + if (errnum != DRMAA_ERRNO_SUCCESS) { + fprintf (stderr, "Could not delete job template: %s\n", error); + } + } /* else */ + + errnum = drmaa_exit (error, DRMAA_ERROR_STRING_BUFFER); + + if (errnum != DRMAA_ERRNO_SUCCESS) { + fprintf (stderr, "Could not shut down the DRMAA library: %s\n", error); + return 1; + } + + return 0; +} diff --git a/examples/drmaa/howto2_1.c b/examples/drmaa/howto2_1.c new file mode 100755 index 0000000..de7fc42 --- /dev/null +++ b/examples/drmaa/howto2_1.c @@ -0,0 +1,105 @@ +/*___INFO__MARK_BEGIN__*/ +/************************************************************************* + * + * The Contents of this file are made available subject to the terms of + * the Sun Industry Standards Source License Version 1.2 + * + * Sun Microsystems Inc., March, 2001 + * + * + * Sun Industry Standards Source License Version 1.2 + * ================================================= + * The contents of this file are subject to the Sun Industry Standards + * Source License Version 1.2 (the "License"); You may not use this file + * except in compliance with the License. You may obtain a copy of the + * License at http://gridengine.sunsource.net/Gridengine_SISSL_license.html + * + * Software provided under this License is provided on an "AS IS" basis, + * WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, + * WITHOUT LIMITATION, WARRANTIES THAT THE SOFTWARE IS FREE OF DEFECTS, + * MERCHANTABLE, FIT FOR A PARTICULAR PURPOSE, OR NON-INFRINGING. + * See the License for the specific provisions governing your rights and + * obligations concerning the Software. + * + * The Initial Developer of the Original Code is: Sun Microsystems, Inc. + * + * Copyright: 2001 by Sun Microsystems, Inc. + * + * All Rights Reserved. + * + ************************************************************************/ +/*___INFO__MARK_END__*/ +#include +#include "drmaa.h" + +int main (int argc, char **argv) { + char error[DRMAA_ERROR_STRING_BUFFER]; + int errnum = 0; + drmaa_job_template_t *jt = NULL; + + errnum = drmaa_init (NULL, error, DRMAA_ERROR_STRING_BUFFER); + + if (errnum != DRMAA_ERRNO_SUCCESS) { + fprintf (stderr, "Could not initialize the DRMAA library: %s\n", error); + return 1; + } + + errnum = drmaa_allocate_job_template (&jt, error, DRMAA_ERROR_STRING_BUFFER); + + if (errnum != DRMAA_ERRNO_SUCCESS) { + fprintf (stderr, "Could not create job template: %s\n", error); + } + else { + errnum = drmaa_set_attribute (jt, DRMAA_REMOTE_COMMAND, "sleeper.sh", + error, DRMAA_ERROR_STRING_BUFFER); + + if (errnum != DRMAA_ERRNO_SUCCESS) { + fprintf (stderr, "Could not set attribute \"%s\": %s\n", + DRMAA_REMOTE_COMMAND, error); + } + else { + const char *args[2] = {"5", NULL}; + + errnum = drmaa_set_vector_attribute (jt, DRMAA_V_ARGV, args, error, + DRMAA_ERROR_STRING_BUFFER); + } + + if (errnum != DRMAA_ERRNO_SUCCESS) { + fprintf (stderr, "Could not set attribute \"%s\": %s\n", + DRMAA_REMOTE_COMMAND, error); + } + else { + drmaa_job_ids_t *ids = NULL; + + errnum = drmaa_run_bulk_jobs (&ids, jt, 1, 30, 2, error, DRMAA_ERROR_STRING_BUFFER); + + if (errnum != DRMAA_ERRNO_SUCCESS) { + fprintf (stderr, "Could not submit job: %s\n", error); + } + else { + char jobid[DRMAA_JOBNAME_BUFFER]; + + while (drmaa_get_next_job_id (ids, jobid, DRMAA_JOBNAME_BUFFER) == DRMAA_ERRNO_SUCCESS) { + printf ("A job task has been submitted with id %s\n", jobid); + } + } + + drmaa_release_job_ids (ids); + } + + errnum = drmaa_delete_job_template (jt, error, DRMAA_ERROR_STRING_BUFFER); + + if (errnum != DRMAA_ERRNO_SUCCESS) { + fprintf (stderr, "Could not delete job template: %s\n", error); + } + } /* else */ + + errnum = drmaa_exit (error, DRMAA_ERROR_STRING_BUFFER); + + if (errnum != DRMAA_ERRNO_SUCCESS) { + fprintf (stderr, "Could not shut down the DRMAA library: %s\n", error); + return 1; + } + + return 0; +} diff --git a/examples/drmaa/howto3.c b/examples/drmaa/howto3.c new file mode 100755 index 0000000..fdfbf64 --- /dev/null +++ b/examples/drmaa/howto3.c @@ -0,0 +1,156 @@ +/*___INFO__MARK_BEGIN__*/ +/************************************************************************* + * + * The Contents of this file are made available subject to the terms of + * the Sun Industry Standards Source License Version 1.2 + * + * Sun Microsystems Inc., March, 2001 + * + * + * Sun Industry Standards Source License Version 1.2 + * ================================================= + * The contents of this file are subject to the Sun Industry Standards + * Source License Version 1.2 (the "License"); You may not use this file + * except in compliance with the License. You may obtain a copy of the + * License at http://gridengine.sunsource.net/Gridengine_SISSL_license.html + * + * Software provided under this License is provided on an "AS IS" basis, + * WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, + * WITHOUT LIMITATION, WARRANTIES THAT THE SOFTWARE IS FREE OF DEFECTS, + * MERCHANTABLE, FIT FOR A PARTICULAR PURPOSE, OR NON-INFRINGING. + * See the License for the specific provisions governing your rights and + * obligations concerning the Software. + * + * The Initial Developer of the Original Code is: Sun Microsystems, Inc. + * + * Copyright: 2001 by Sun Microsystems, Inc. + * + * All Rights Reserved. + * + ************************************************************************/ +/*___INFO__MARK_END__*/ +#include +#include "drmaa.h" + +int main (int argc, char **argv) { + char error[DRMAA_ERROR_STRING_BUFFER]; + int errnum = 0; + drmaa_job_template_t *jt = NULL; + + errnum = drmaa_init (NULL, error, DRMAA_ERROR_STRING_BUFFER); + + if (errnum != DRMAA_ERRNO_SUCCESS) { + fprintf (stderr, "Could not initialize the DRMAA library: %s\n", error); + return 1; + } + + errnum = drmaa_allocate_job_template (&jt, error, DRMAA_ERROR_STRING_BUFFER); + + if (errnum != DRMAA_ERRNO_SUCCESS) { + fprintf (stderr, "Could not create job template: %s\n", error); + } + else { + errnum = drmaa_set_attribute (jt, DRMAA_REMOTE_COMMAND, "sleeper.sh", + error, DRMAA_ERROR_STRING_BUFFER); + + if (errnum != DRMAA_ERRNO_SUCCESS) { + fprintf (stderr, "Could not set attribute \"%s\": %s\n", + DRMAA_REMOTE_COMMAND, error); + } + else { + const char *args[2] = {"5", NULL}; + + errnum = drmaa_set_vector_attribute (jt, DRMAA_V_ARGV, args, error, + DRMAA_ERROR_STRING_BUFFER); + } + + if (errnum != DRMAA_ERRNO_SUCCESS) { + fprintf (stderr, "Could not set attribute \"%s\": %s\n", + DRMAA_REMOTE_COMMAND, error); + } + else { + char jobid[DRMAA_JOBNAME_BUFFER]; + char jobid_out[DRMAA_JOBNAME_BUFFER]; + int status = 0; + drmaa_attr_values_t *rusage = NULL; + + errnum = drmaa_run_job (jobid, DRMAA_JOBNAME_BUFFER, jt, error, + DRMAA_ERROR_STRING_BUFFER); + + if (errnum != DRMAA_ERRNO_SUCCESS) { + fprintf (stderr, "Could not submit job: %s\n", error); + } + else { + printf ("Your job has been submitted with id %s\n", jobid); + + errnum = drmaa_wait (jobid, jobid_out, DRMAA_JOBNAME_BUFFER, &status, + DRMAA_TIMEOUT_WAIT_FOREVER, &rusage, error, + DRMAA_ERROR_STRING_BUFFER); + + if (errnum != DRMAA_ERRNO_SUCCESS) { + fprintf (stderr, "Could not wait for job: %s\n", error); + } + else { + char usage[DRMAA_ERROR_STRING_BUFFER]; + int aborted = 0; + + drmaa_wifaborted(&aborted, status, NULL, 0); + + if (aborted == 1) { + printf("Job %s never ran\n", jobid); + } + else { + int exited = 0; + + drmaa_wifexited(&exited, status, NULL, 0); + + if (exited == 1) { + int exit_status = 0; + + drmaa_wexitstatus(&exit_status, status, NULL, 0); + printf("Job %s finished regularly with exit status %d\n", jobid, exit_status); + } + else { + int signaled = 0; + + drmaa_wifsignaled(&signaled, status, NULL, 0); + + if (signaled == 1) { + char termsig[DRMAA_SIGNAL_BUFFER+1]; + + drmaa_wtermsig(termsig, DRMAA_SIGNAL_BUFFER, status, NULL, 0); + printf("Job %s finished due to signal %s\n", jobid, termsig); + } + else { + printf("Job %s finished with unclear conditions\n", jobid); + } + } /* else */ + } /* else */ + + printf ("Job Usage:\n"); + + while (drmaa_get_next_attr_value (rusage, usage, DRMAA_ERROR_STRING_BUFFER) == DRMAA_ERRNO_SUCCESS) { + printf (" %s\n", usage); + } + + drmaa_release_attr_values (rusage); + } /* else */ + } /* else */ + } /* else */ + + errnum = drmaa_delete_job_template (jt, error, DRMAA_ERROR_STRING_BUFFER); + + if (errnum != DRMAA_ERRNO_SUCCESS) { + fprintf (stderr, "Could not delete job template: %s\n", error); + } + } /* else */ + + errnum = drmaa_exit (error, DRMAA_ERROR_STRING_BUFFER); + + if (errnum != DRMAA_ERRNO_SUCCESS) { + fprintf (stderr, "Could not shut down the DRMAA library: %s\n", error); + return 1; + } + + return 0; +} diff --git a/examples/drmaa/howto3_1.c b/examples/drmaa/howto3_1.c new file mode 100755 index 0000000..5bf1ca1 --- /dev/null +++ b/examples/drmaa/howto3_1.c @@ -0,0 +1,116 @@ +/*___INFO__MARK_BEGIN__*/ +/************************************************************************* + * + * The Contents of this file are made available subject to the terms of + * the Sun Industry Standards Source License Version 1.2 + * + * Sun Microsystems Inc., March, 2001 + * + * + * Sun Industry Standards Source License Version 1.2 + * ================================================= + * The contents of this file are subject to the Sun Industry Standards + * Source License Version 1.2 (the "License"); You may not use this file + * except in compliance with the License. You may obtain a copy of the + * License at http://gridengine.sunsource.net/Gridengine_SISSL_license.html + * + * Software provided under this License is provided on an "AS IS" basis, + * WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, + * WITHOUT LIMITATION, WARRANTIES THAT THE SOFTWARE IS FREE OF DEFECTS, + * MERCHANTABLE, FIT FOR A PARTICULAR PURPOSE, OR NON-INFRINGING. + * See the License for the specific provisions governing your rights and + * obligations concerning the Software. + * + * The Initial Developer of the Original Code is: Sun Microsystems, Inc. + * + * Copyright: 2001 by Sun Microsystems, Inc. + * + * All Rights Reserved. + * + ************************************************************************/ +/*___INFO__MARK_END__*/ +#include +#include "drmaa.h" + +int main (int argc, char **argv) { + char error[DRMAA_ERROR_STRING_BUFFER]; + int errnum = 0; + drmaa_job_template_t *jt = NULL; + + errnum = drmaa_init (NULL, error, DRMAA_ERROR_STRING_BUFFER); + + if (errnum != DRMAA_ERRNO_SUCCESS) { + fprintf (stderr, "Could not initialize the DRMAA library: %s\n", error); + return 1; + } + + errnum = drmaa_allocate_job_template (&jt, error, DRMAA_ERROR_STRING_BUFFER); + + if (errnum != DRMAA_ERRNO_SUCCESS) { + fprintf (stderr, "Could not create job template: %s\n", error); + } + else { + errnum = drmaa_set_attribute (jt, DRMAA_REMOTE_COMMAND, "sleeper.sh", + error, DRMAA_ERROR_STRING_BUFFER); + + if (errnum != DRMAA_ERRNO_SUCCESS) { + fprintf (stderr, "Could not set attribute \"%s\": %s\n", + DRMAA_REMOTE_COMMAND, error); + } + else { + const char *args[2] = {"5", NULL}; + + errnum = drmaa_set_vector_attribute (jt, DRMAA_V_ARGV, args, error, + DRMAA_ERROR_STRING_BUFFER); + } + + if (errnum != DRMAA_ERRNO_SUCCESS) { + fprintf (stderr, "Could not set attribute \"%s\": %s\n", + DRMAA_REMOTE_COMMAND, error); + } + else { + drmaa_job_ids_t *ids = NULL; + + errnum = drmaa_run_bulk_jobs (&ids, jt, 1, 30, 2, error, DRMAA_ERROR_STRING_BUFFER); + + if (errnum != DRMAA_ERRNO_SUCCESS) { + fprintf (stderr, "Could not submit job: %s\n", error); + } + else { + char jobid[DRMAA_JOBNAME_BUFFER]; + const char *jobids[2] = {DRMAA_JOB_IDS_SESSION_ALL, NULL}; + + while (drmaa_get_next_job_id (ids, jobid, DRMAA_JOBNAME_BUFFER) == DRMAA_ERRNO_SUCCESS) { + printf ("A job task has been submitted with id %s\n", jobid); + } + + errnum = drmaa_synchronize (jobids, DRMAA_TIMEOUT_WAIT_FOREVER, + 1, error, DRMAA_ERROR_STRING_BUFFER); + + if (errnum != DRMAA_ERRNO_SUCCESS) { + fprintf (stderr, "Could not wait for jobs: %s\n", error); + } + else { + printf ("All job tasks have finished.\n"); + } + } /* else */ + + drmaa_release_job_ids (ids); + } /* else */ + + errnum = drmaa_delete_job_template (jt, error, DRMAA_ERROR_STRING_BUFFER); + + if (errnum != DRMAA_ERRNO_SUCCESS) { + fprintf (stderr, "Could not delete job template: %s\n", error); + } + } /* else */ + + errnum = drmaa_exit (error, DRMAA_ERROR_STRING_BUFFER); + + if (errnum != DRMAA_ERRNO_SUCCESS) { + fprintf (stderr, "Could not shut down the DRMAA library: %s\n", error); + return 1; + } + + return 0; +} diff --git a/examples/drmaa/howto3_2.c b/examples/drmaa/howto3_2.c new file mode 100755 index 0000000..7fadea0 --- /dev/null +++ b/examples/drmaa/howto3_2.c @@ -0,0 +1,182 @@ +/*___INFO__MARK_BEGIN__*/ +/************************************************************************* + * + * The Contents of this file are made available subject to the terms of + * the Sun Industry Standards Source License Version 1.2 + * + * Sun Microsystems Inc., March, 2001 + * + * + * Sun Industry Standards Source License Version 1.2 + * ================================================= + * The contents of this file are subject to the Sun Industry Standards + * Source License Version 1.2 (the "License"); You may not use this file + * except in compliance with the License. You may obtain a copy of the + * License at http://gridengine.sunsource.net/Gridengine_SISSL_license.html + * + * Software provided under this License is provided on an "AS IS" basis, + * WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, + * WITHOUT LIMITATION, WARRANTIES THAT THE SOFTWARE IS FREE OF DEFECTS, + * MERCHANTABLE, FIT FOR A PARTICULAR PURPOSE, OR NON-INFRINGING. + * See the License for the specific provisions governing your rights and + * obligations concerning the Software. + * + * The Initial Developer of the Original Code is: Sun Microsystems, Inc. + * + * Copyright: 2001 by Sun Microsystems, Inc. + * + * All Rights Reserved. + * + ************************************************************************/ +/*___INFO__MARK_END__*/ +#include +#include "drmaa.h" + +int main (int argc, char **argv) { + char error[DRMAA_ERROR_STRING_BUFFER]; + int errnum = 0; + drmaa_job_template_t *jt = NULL; + + errnum = drmaa_init (NULL, error, DRMAA_ERROR_STRING_BUFFER); + + if (errnum != DRMAA_ERRNO_SUCCESS) { + fprintf (stderr, "Could not initialize the DRMAA library: %s\n", error); + return 1; + } + + errnum = drmaa_allocate_job_template (&jt, error, DRMAA_ERROR_STRING_BUFFER); + + if (errnum != DRMAA_ERRNO_SUCCESS) { + fprintf (stderr, "Could not create job template: %s\n", error); + } + else { + errnum = drmaa_set_attribute (jt, DRMAA_REMOTE_COMMAND, "sleeper.sh", + error, DRMAA_ERROR_STRING_BUFFER); + + if (errnum != DRMAA_ERRNO_SUCCESS) { + fprintf (stderr, "Could not set attribute \"%s\": %s\n", + DRMAA_REMOTE_COMMAND, error); + } + else { + const char *args[2] = {"5", NULL}; + + errnum = drmaa_set_vector_attribute (jt, DRMAA_V_ARGV, args, error, + DRMAA_ERROR_STRING_BUFFER); + } + + if (errnum != DRMAA_ERRNO_SUCCESS) { + fprintf (stderr, "Could not set attribute \"%s\": %s\n", + DRMAA_REMOTE_COMMAND, error); + } + else { + drmaa_job_ids_t *ids = NULL; + int start = 1; + int end = 30; + int step = 2; + + errnum = drmaa_run_bulk_jobs (&ids, jt, start, end, step, error, + DRMAA_ERROR_STRING_BUFFER); + + if (errnum != DRMAA_ERRNO_SUCCESS) { + fprintf (stderr, "Could not submit job: %s\n", error); + } + else { + char jobid[DRMAA_JOBNAME_BUFFER]; + const char *jobids[2] = {DRMAA_JOB_IDS_SESSION_ALL, NULL}; + + while (drmaa_get_next_job_id (ids, jobid, DRMAA_JOBNAME_BUFFER) + == DRMAA_ERRNO_SUCCESS) { + printf ("A job task has been submitted with id %s\n", jobid); + } + + errnum = drmaa_synchronize (jobids, DRMAA_TIMEOUT_WAIT_FOREVER, + 0, error, DRMAA_ERROR_STRING_BUFFER); + + if (errnum != DRMAA_ERRNO_SUCCESS) { + fprintf (stderr, "Could not wait for jobs: %s\n", error); + } + else { + char jobid[DRMAA_JOBNAME_BUFFER]; + int status = 0; + drmaa_attr_values_t *rusage = NULL; + int count = 0; + + for (count = start; count < end; count += step) { + errnum = drmaa_wait (DRMAA_JOB_IDS_SESSION_ANY, jobid, + DRMAA_JOBNAME_BUFFER, &status, + DRMAA_TIMEOUT_WAIT_FOREVER, &rusage, + error, DRMAA_ERROR_STRING_BUFFER); + + if (errnum != DRMAA_ERRNO_SUCCESS) { + fprintf (stderr, "Could not wait for job: %s\n", error); + } + else { + char usage[DRMAA_ERROR_STRING_BUFFER]; + int aborted = 0; + + drmaa_wifaborted(&aborted, status, NULL, 0); + + if (aborted == 1) { + printf("Job %s never ran\n", jobid); + } + else { + int exited = 0; + + drmaa_wifexited(&exited, status, NULL, 0); + + if (exited == 1) { + int exit_status = 0; + + drmaa_wexitstatus(&exit_status, status, NULL, 0); + printf("Job %s finished regularly with exit status %d\n", + jobid, exit_status); + } + else { + int signaled = 0; + + drmaa_wifsignaled(&signaled, status, NULL, 0); + + if (signaled == 1) { + char termsig[DRMAA_SIGNAL_BUFFER+1]; + + drmaa_wtermsig(termsig, DRMAA_SIGNAL_BUFFER, status, NULL, 0); + printf("Job %s finished due to signal %s\n", jobid, termsig); + } + else { + printf("Job %s finished with unclear conditions\n", jobid); + } + } /* else */ + } /* else */ + + printf ("Job Usage:\n"); + + while (drmaa_get_next_attr_value (rusage, usage, DRMAA_ERROR_STRING_BUFFER) + == DRMAA_ERRNO_SUCCESS) { + printf (" %s\n", usage); + } + + drmaa_release_attr_values (rusage); + } /* else */ + } /* for */ + } /* else */ + } /* else */ + + drmaa_release_job_ids (ids); + } /* else */ + + errnum = drmaa_delete_job_template (jt, error, DRMAA_ERROR_STRING_BUFFER); + + if (errnum != DRMAA_ERRNO_SUCCESS) { + fprintf (stderr, "Could not delete job template: %s\n", error); + } + } /* else */ + + errnum = drmaa_exit (error, DRMAA_ERROR_STRING_BUFFER); + + if (errnum != DRMAA_ERRNO_SUCCESS) { + fprintf (stderr, "Could not shut down the DRMAA library: %s\n", error); + return 1; + } + + return 0; +} diff --git a/examples/drmaa/howto4.c b/examples/drmaa/howto4.c new file mode 100755 index 0000000..18d3079 --- /dev/null +++ b/examples/drmaa/howto4.c @@ -0,0 +1,110 @@ +/*___INFO__MARK_BEGIN__*/ +/************************************************************************* + * + * The Contents of this file are made available subject to the terms of + * the Sun Industry Standards Source License Version 1.2 + * + * Sun Microsystems Inc., March, 2001 + * + * + * Sun Industry Standards Source License Version 1.2 + * ================================================= + * The contents of this file are subject to the Sun Industry Standards + * Source License Version 1.2 (the "License"); You may not use this file + * except in compliance with the License. You may obtain a copy of the + * License at http://gridengine.sunsource.net/Gridengine_SISSL_license.html + * + * Software provided under this License is provided on an "AS IS" basis, + * WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, + * WITHOUT LIMITATION, WARRANTIES THAT THE SOFTWARE IS FREE OF DEFECTS, + * MERCHANTABLE, FIT FOR A PARTICULAR PURPOSE, OR NON-INFRINGING. + * See the License for the specific provisions governing your rights and + * obligations concerning the Software. + * + * The Initial Developer of the Original Code is: Sun Microsystems, Inc. + * + * Copyright: 2001 by Sun Microsystems, Inc. + * + * All Rights Reserved. + * + ************************************************************************/ +/*___INFO__MARK_END__*/ +#include +#include "drmaa.h" + +int main (int argc, char **argv) { + char error[DRMAA_ERROR_STRING_BUFFER]; + int errnum = 0; + drmaa_job_template_t *jt = NULL; + + errnum = drmaa_init (NULL, error, DRMAA_ERROR_STRING_BUFFER); + + if (errnum != DRMAA_ERRNO_SUCCESS) { + fprintf (stderr, "Could not initialize the DRMAA library: %s\n", error); + return 1; + } + + errnum = drmaa_allocate_job_template (&jt, error, DRMAA_ERROR_STRING_BUFFER); + + if (errnum != DRMAA_ERRNO_SUCCESS) { + fprintf (stderr, "Could not create job template: %s\n", error); + } + else { + errnum = drmaa_set_attribute (jt, DRMAA_REMOTE_COMMAND, "sleeper.sh", + error, DRMAA_ERROR_STRING_BUFFER); + + if (errnum != DRMAA_ERRNO_SUCCESS) { + fprintf (stderr, "Could not set attribute \"%s\": %s\n", + DRMAA_REMOTE_COMMAND, error); + } + else { + const char *args[2] = {"60", NULL}; + + errnum = drmaa_set_vector_attribute (jt, DRMAA_V_ARGV, args, error, + DRMAA_ERROR_STRING_BUFFER); + } + + if (errnum != DRMAA_ERRNO_SUCCESS) { + fprintf (stderr, "Could not set attribute \"%s\": %s\n", + DRMAA_REMOTE_COMMAND, error); + } + else { + char jobid[DRMAA_JOBNAME_BUFFER]; + + errnum = drmaa_run_job (jobid, DRMAA_JOBNAME_BUFFER, jt, error, + DRMAA_ERROR_STRING_BUFFER); + + if (errnum != DRMAA_ERRNO_SUCCESS) { + fprintf (stderr, "Could not submit job: %s\n", error); + } + else { + printf ("Your job has been submitted with id %s\n", jobid); + + errnum = drmaa_control (jobid, DRMAA_CONTROL_TERMINATE, error, + DRMAA_ERROR_STRING_BUFFER); + + if (errnum != DRMAA_ERRNO_SUCCESS) { + fprintf (stderr, "Could not delete job: %s\n", error); + } + else { + printf ("Your job has been deleted\n"); + } + } + } /* else */ + + errnum = drmaa_delete_job_template (jt, error, DRMAA_ERROR_STRING_BUFFER); + + if (errnum != DRMAA_ERRNO_SUCCESS) { + fprintf (stderr, "Could not delete job template: %s\n", error); + } + } /* else */ + + errnum = drmaa_exit (error, DRMAA_ERROR_STRING_BUFFER); + + if (errnum != DRMAA_ERRNO_SUCCESS) { + fprintf (stderr, "Could not shut down the DRMAA library: %s\n", error); + return 1; + } + + return 0; +} diff --git a/examples/drmaa/howto5.c b/examples/drmaa/howto5.c new file mode 100755 index 0000000..5ba40d5 --- /dev/null +++ b/examples/drmaa/howto5.c @@ -0,0 +1,149 @@ +/*___INFO__MARK_BEGIN__*/ +/************************************************************************* + * + * The Contents of this file are made available subject to the terms of + * the Sun Industry Standards Source License Version 1.2 + * + * Sun Microsystems Inc., March, 2001 + * + * + * Sun Industry Standards Source License Version 1.2 + * ================================================= + * The contents of this file are subject to the Sun Industry Standards + * Source License Version 1.2 (the "License"); You may not use this file + * except in compliance with the License. You may obtain a copy of the + * License at http://gridengine.sunsource.net/Gridengine_SISSL_license.html + * + * Software provided under this License is provided on an "AS IS" basis, + * WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, + * WITHOUT LIMITATION, WARRANTIES THAT THE SOFTWARE IS FREE OF DEFECTS, + * MERCHANTABLE, FIT FOR A PARTICULAR PURPOSE, OR NON-INFRINGING. + * See the License for the specific provisions governing your rights and + * obligations concerning the Software. + * + * The Initial Developer of the Original Code is: Sun Microsystems, Inc. + * + * Copyright: 2001 by Sun Microsystems, Inc. + * + * All Rights Reserved. + * + ************************************************************************/ +/*___INFO__MARK_END__*/ +#include +#include +#include "drmaa.h" + +int main (int argc, char **argv) { + char error[DRMAA_ERROR_STRING_BUFFER]; + int errnum = 0; + drmaa_job_template_t *jt = NULL; + + errnum = drmaa_init (NULL, error, DRMAA_ERROR_STRING_BUFFER); + + if (errnum != DRMAA_ERRNO_SUCCESS) { + fprintf (stderr, "Could not initialize the DRMAA library: %s\n", error); + return 1; + } + + errnum = drmaa_allocate_job_template (&jt, error, DRMAA_ERROR_STRING_BUFFER); + + if (errnum != DRMAA_ERRNO_SUCCESS) { + fprintf (stderr, "Could not create job template: %s\n", error); + } + else { + errnum = drmaa_set_attribute (jt, DRMAA_REMOTE_COMMAND, "sleeper.sh", + error, DRMAA_ERROR_STRING_BUFFER); + + if (errnum != DRMAA_ERRNO_SUCCESS) { + fprintf (stderr, "Could not set attribute \"%s\": %s\n", + DRMAA_REMOTE_COMMAND, error); + } + else { + const char *args[2] = {"60", NULL}; + + errnum = drmaa_set_vector_attribute (jt, DRMAA_V_ARGV, args, error, + DRMAA_ERROR_STRING_BUFFER); + } + + if (errnum != DRMAA_ERRNO_SUCCESS) { + fprintf (stderr, "Could not set attribute \"%s\": %s\n", + DRMAA_REMOTE_COMMAND, error); + } + else { + char jobid[DRMAA_JOBNAME_BUFFER]; + + errnum = drmaa_run_job (jobid, DRMAA_JOBNAME_BUFFER, jt, error, + DRMAA_ERROR_STRING_BUFFER); + + if (errnum != DRMAA_ERRNO_SUCCESS) { + fprintf (stderr, "Could not submit job: %s\n", error); + } + else { + int status = 0; + + printf ("Your job has been submitted with id %s\n", jobid); + + sleep (20); + + errnum = drmaa_job_ps (jobid, &status, error, + DRMAA_ERROR_STRING_BUFFER); + + if (errnum != DRMAA_ERRNO_SUCCESS) { + fprintf (stderr, "Could not get job' status: %s\n", error); + } + else { + switch (status) { + case DRMAA_PS_UNDETERMINED: + printf ("Job status cannot be determined\n"); + break; + case DRMAA_PS_QUEUED_ACTIVE: + printf ("Job is queued and active\n"); + break; + case DRMAA_PS_SYSTEM_ON_HOLD: + printf ("Job is queued and in system hold\n"); + break; + case DRMAA_PS_USER_ON_HOLD: + printf ("Job is queued and in user hold\n"); + break; + case DRMAA_PS_USER_SYSTEM_ON_HOLD: + printf ("Job is queued and in user and system hold\n"); + break; + case DRMAA_PS_RUNNING: + printf ("Job is running\n"); + break; + case DRMAA_PS_SYSTEM_SUSPENDED: + printf ("Job is system suspended\n"); + break; + case DRMAA_PS_USER_SUSPENDED: + printf ("Job is user suspended\n"); + break; + case DRMAA_PS_USER_SYSTEM_SUSPENDED: + printf ("Job is user and system suspended\n"); + break; + case DRMAA_PS_DONE: + printf ("Job finished normally\n"); + break; + case DRMAA_PS_FAILED: + printf ("Job finished, but failed\n"); + break; + } /* switch */ + } /* else */ + } /* else */ + } /* else */ + + errnum = drmaa_delete_job_template (jt, error, DRMAA_ERROR_STRING_BUFFER); + + if (errnum != DRMAA_ERRNO_SUCCESS) { + fprintf (stderr, "Could not delete job template: %s\n", error); + } + } /* else */ + + errnum = drmaa_exit (error, DRMAA_ERROR_STRING_BUFFER); + + if (errnum != DRMAA_ERRNO_SUCCESS) { + fprintf (stderr, "Could not shut down the DRMAA library: %s\n", error); + return 1; + } + + return 0; +} diff --git a/examples/drmaa/howto6.c b/examples/drmaa/howto6.c new file mode 100755 index 0000000..c17831c --- /dev/null +++ b/examples/drmaa/howto6.c @@ -0,0 +1,128 @@ +/*___INFO__MARK_BEGIN__*/ +/************************************************************************* + * + * The Contents of this file are made available subject to the terms of + * the Sun Industry Standards Source License Version 1.2 + * + * Sun Microsystems Inc., March, 2001 + * + * + * Sun Industry Standards Source License Version 1.2 + * ================================================= + * The contents of this file are subject to the Sun Industry Standards + * Source License Version 1.2 (the "License"); You may not use this file + * except in compliance with the License. You may obtain a copy of the + * License at http://gridengine.sunsource.net/Gridengine_SISSL_license.html + * + * Software provided under this License is provided on an "AS IS" basis, + * WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, + * WITHOUT LIMITATION, WARRANTIES THAT THE SOFTWARE IS FREE OF DEFECTS, + * MERCHANTABLE, FIT FOR A PARTICULAR PURPOSE, OR NON-INFRINGING. + * See the License for the specific provisions governing your rights and + * obligations concerning the Software. + * + * The Initial Developer of the Original Code is: Sun Microsystems, Inc. + * + * Copyright: 2001 by Sun Microsystems, Inc. + * + * All Rights Reserved. + * + ************************************************************************/ +/*___INFO__MARK_END__*/ +#include +#include "drmaa.h" + +int main (int argc, char **argv) { + char error[DRMAA_ERROR_STRING_BUFFER]; + int errnum = 0; + char contact[DRMAA_CONTACT_BUFFER]; + char drm_system[DRMAA_DRM_SYSTEM_BUFFER]; + char drmaa_impl[DRMAA_DRM_SYSTEM_BUFFER]; + unsigned int major = 0; + unsigned int minor = 0; + + errnum = drmaa_get_contact (contact, DRMAA_CONTACT_BUFFER, error, + DRMAA_ERROR_STRING_BUFFER); + + if (errnum != DRMAA_ERRNO_SUCCESS) { + fprintf (stderr, "Could not get the contact string list: %s\n", error); + } + else { + printf ("Supported contact strings: \"%s\"\n", contact); + } + + errnum = drmaa_get_DRM_system (drm_system, DRMAA_DRM_SYSTEM_BUFFER, error, + DRMAA_ERROR_STRING_BUFFER); + + if (errnum != DRMAA_ERRNO_SUCCESS) { + fprintf (stderr, "Could not get the DRM system list: %s\n", error); + } + else { + printf ("Supported DRM systems: \"%s\"\n", drm_system); + } + + errnum = drmaa_get_DRMAA_implementation (drmaa_impl, DRMAA_DRM_SYSTEM_BUFFER, + error, DRMAA_ERROR_STRING_BUFFER); + + if (errnum != DRMAA_ERRNO_SUCCESS) { + fprintf (stderr, "Could not get the DRMAA implementation list: %s\n", error); + } + else { + printf ("Supported DRMAA implementations: \"%s\"\n", drmaa_impl); + } + + errnum = drmaa_init (NULL, error, DRMAA_ERROR_STRING_BUFFER); + + if (errnum != DRMAA_ERRNO_SUCCESS) { + fprintf (stderr, "Could not initialize the DRMAA library: %s\n", error); + return 1; + } + + errnum = drmaa_get_contact (contact, DRMAA_CONTACT_BUFFER, error, + DRMAA_ERROR_STRING_BUFFER); + + if (errnum != DRMAA_ERRNO_SUCCESS) { + fprintf (stderr, "Could not get the contact string: %s\n", error); + } + else { + printf ("Connected contact string: \"%s\"\n", contact); + } + + errnum = drmaa_get_DRM_system (drm_system, DRMAA_CONTACT_BUFFER, error, + DRMAA_ERROR_STRING_BUFFER); + + if (errnum != DRMAA_ERRNO_SUCCESS) { + fprintf (stderr, "Could not get the DRM system: %s\n", error); + } + else { + printf ("Connected DRM system: \"%s\"\n", drm_system); + } + + errnum = drmaa_get_DRMAA_implementation (drmaa_impl, DRMAA_DRM_SYSTEM_BUFFER, + error, DRMAA_ERROR_STRING_BUFFER); + + if (errnum != DRMAA_ERRNO_SUCCESS) { + fprintf (stderr, "Could not get the DRMAA implementation list: %s\n", error); + } + else { + printf ("Supported DRMAA implementations: \"%s\"\n", drmaa_impl); + } + + errnum = drmaa_version (&major, &minor, error, DRMAA_ERROR_STRING_BUFFER); + + if (errnum != DRMAA_ERRNO_SUCCESS) { + fprintf (stderr, "Could not get the DRMAA version: %s\n", error); + } + else { + printf ("Using DRMAA version %d.%d\n", major, minor); + } + + errnum = drmaa_exit (error, DRMAA_ERROR_STRING_BUFFER); + + if (errnum != DRMAA_ERRNO_SUCCESS) { + fprintf (stderr, "Could not shut down the DRMAA library: %s\n", error); + return 1; + } + + return 0; +} diff --git a/examples/drmaa/ruby/array.rb b/examples/drmaa/ruby/array.rb new file mode 100755 index 0000000..98b51f7 --- /dev/null +++ b/examples/drmaa/ruby/array.rb @@ -0,0 +1,77 @@ +#!/usr/bin/ruby + +######################################################################### +# +# The Contents of this file are made available subject to the terms of +# the Sun Industry Standards Source License Version 1.2 +# +# Sun Microsystems Inc., March, 2006 +# +# +# Sun Industry Standards Source License Version 1.2 +# ================================================= +# The contents of this file are subject to the Sun Industry Standards +# Source License Version 1.2 (the "License"); You may not use this file +# except in compliance with the License. You may obtain a copy of the +# License at http://gridengine.sunsource.net/Gridengine_SISSL_license.html +# +# Software provided under this License is provided on an "AS IS" basis, +# WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, +# WITHOUT LIMITATION, WARRANTIES THAT THE SOFTWARE IS FREE OF DEFECTS, +# MERCHANTABLE, FIT FOR A PARTICULAR PURPOSE, OR NON-INFRINGING. +# See the License for the specific provisions governing your rights and +# obligations concerning the Software. +# +# The Initial Developer of the Original Code is: Sun Microsystems, Inc. +# +# Copyright: 2006 by Sun Microsystems, Inc. +# +# All Rights Reserved. +# +######################################################################### + +require 'drmaa' + +class Sleeper < DRMAA::JobTemplate + def initialize + super + self.command = "/bin/sleep" + self.arg = ["1"] + self.stdout = ":/dev/null" + self.join = true + end +end + +# Two array jobs are submitted. The second array task remains in +# hold until the predecessor task was run. Demonstrate possible +# use of hold/release. + +NTASKS = 30 +session = DRMAA::Session.new + +jt = Sleeper.new +pre = session.run_bulk(jt, 1, NTASKS, 1) +suc = session.run_bulk(jt, 1, NTASKS, 1) + +h = Hash.new +for i in 0 .. NTASKS-1 do + h[pre[i]] = suc[i] +end + +session.wait_each{ |info| + job = info.job + if h.has_key?(job) + session.release(h[job]) + end + + if info.wifexited? + puts job + " returned with " + info.wexitstatus.to_s + # info.rusage.each { |u| puts "usage " + u } + elsif info.wifaborted? + puts job + " aborted" + elsif info.wifsignaled? + puts job + " died from " + info.wtermsig + end +} + +exit 0 diff --git a/examples/drmaa/ruby/attributes.rb b/examples/drmaa/ruby/attributes.rb new file mode 100755 index 0000000..44b3cca --- /dev/null +++ b/examples/drmaa/ruby/attributes.rb @@ -0,0 +1,49 @@ +#!/usr/bin/ruby + +######################################################################### +# +# The Contents of this file are made available subject to the terms of +# the Sun Industry Standards Source License Version 1.2 +# +# Sun Microsystems Inc., March, 2006 +# +# +# Sun Industry Standards Source License Version 1.2 +# ================================================= +# The contents of this file are subject to the Sun Industry Standards +# Source License Version 1.2 (the "License"); You may not use this file +# except in compliance with the License. You may obtain a copy of the +# License at http://gridengine.sunsource.net/Gridengine_SISSL_license.html +# +# Software provided under this License is provided on an "AS IS" basis, +# WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, +# WITHOUT LIMITATION, WARRANTIES THAT THE SOFTWARE IS FREE OF DEFECTS, +# MERCHANTABLE, FIT FOR A PARTICULAR PURPOSE, OR NON-INFRINGING. +# See the License for the specific provisions governing your rights and +# obligations concerning the Software. +# +# The Initial Developer of the Original Code is: Sun Microsystems, Inc. +# +# Copyright: 2006 by Sun Microsystems, Inc. +# +# All Rights Reserved. +# +######################################################################### + +require 'drmaa' + +version = DRMAA.version +drm = DRMAA.drm_system +impl = DRMAA.drmaa_implementation +contact = DRMAA.contact +puts "DRMAA: #{drm} version #{version} impl #{impl} contact #{contact}" + +session = DRMAA::Session.new + +puts "supported DRMAA job template attributes:" +attrs = DRMAA.attributes.each { |n| puts " #{n}" } +puts "supported DRMAA job template vector attributes:" +attrs = DRMAA.vector_attributes.each { |n| puts " #{n}" } + + +exit 0 diff --git a/examples/drmaa/ruby/example.rb b/examples/drmaa/ruby/example.rb new file mode 100755 index 0000000..310e453 --- /dev/null +++ b/examples/drmaa/ruby/example.rb @@ -0,0 +1,70 @@ +#!/usr/bin/ruby + +######################################################################### +# +# The Contents of this file are made available subject to the terms of +# the Sun Industry Standards Source License Version 1.2 +# +# Sun Microsystems Inc., March, 2006 +# +# +# Sun Industry Standards Source License Version 1.2 +# ================================================= +# The contents of this file are subject to the Sun Industry Standards +# Source License Version 1.2 (the "License"); You may not use this file +# except in compliance with the License. You may obtain a copy of the +# License at http://gridengine.sunsource.net/Gridengine_SISSL_license.html +# +# Software provided under this License is provided on an "AS IS" basis, +# WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, +# WITHOUT LIMITATION, WARRANTIES THAT THE SOFTWARE IS FREE OF DEFECTS, +# MERCHANTABLE, FIT FOR A PARTICULAR PURPOSE, OR NON-INFRINGING. +# See the License for the specific provisions governing your rights and +# obligations concerning the Software. +# +# The Initial Developer of the Original Code is: Sun Microsystems, Inc. +# +# Copyright: 2006 by Sun Microsystems, Inc. +# +# All Rights Reserved. +# +######################################################################### + +require 'drmaa' + +class Sleeper < DRMAA::JobTemplate + def initialize + super + self.command = "/bin/sleep" + self.arg = ["1"] + self.stdout = ":/dev/null" + self.join = true + end +end + +version = DRMAA.version +drm = DRMAA.drm_system +impl = DRMAA.drmaa_implementation +contact = DRMAA.contact +puts "DRMAA #{drm} v #{version} impl #{impl} contact #{contact}" + +session = DRMAA::Session.new + +t = Sleeper.new + +jobid = session.run(t) +puts "job: " + jobid + +session.run_bulk(t, 1, 20).each { |job| + puts "job: " + job +} + +session.wait_each{ |info| + if ! info.wifexited? + puts "failed: " + info.job + else + puts info.job + " returned with " + info.wexitstatus.to_s + end +} + +exit 0 diff --git a/examples/drmaa/ruby/flow/README b/examples/drmaa/ruby/flow/README new file mode 100755 index 0000000..f49cb40 --- /dev/null +++ b/examples/drmaa/ruby/flow/README @@ -0,0 +1,39 @@ +== Workflow interpreter and processor + + flow.rb is a utility for running job workflows in + DRMAA-compliant DRM systems. Workflows are specified in + flowfiles that allow expression of + + * concurrent and sequential execution of sub-flows + * multiple runs of sub-flows with varying parameter sets + * actual jobs are defined in terms of DRMAA attributes + + in addition any subflow or sets of subflows can be run + as used with make(1) by specifying it as target. + +=== Job defaults + + To minimize the extent of attributes necessarily + specified in flowfiles, flow.rb provides defaults for + jobs' command path, stdout/stdin path, current working + directory and job name. + +=== Workflow verification + + The -verify option can be used to print dependencies and + job attributes for diagnosis purposes. To ensure each + workflow job can be run, a number of verifications is + performed before the first job gets submitted. + +=== Job streaming + + Large workflows are automatically run in job streaming mode + upon DRM saturation and a job maximum can be set in .flowrc.rb + to place an upper limit of jobs be kept concurrently in the + DRM for each workflow. + +=== Pre-submission plug-in + + Enforcement of site-specific policies can easily be + achieved through pre-submission procedures that allow + any job attribute to be modified freely. diff --git a/examples/drmaa/ruby/flow/flow.rb b/examples/drmaa/ruby/flow/flow.rb new file mode 100755 index 0000000..552020b --- /dev/null +++ b/examples/drmaa/ruby/flow/flow.rb @@ -0,0 +1,911 @@ +#!/usr/bin/ruby + +######################################################################### +# +# The Contents of this file are made available subject to the terms of +# the Sun Industry Standards Source License Version 1.2 +# +# Sun Microsystems Inc., March, 2006 +# +# +# Sun Industry Standards Source License Version 1.2 +# ================================================= +# The contents of this file are subject to the Sun Industry Standards +# Source License Version 1.2 (the "License"); You may not use this file +# except in compliance with the License. You may obtain a copy of the +# License at http://gridengine.sunsource.net/Gridengine_SISSL_license.html +# +# Software provided under this License is provided on an "AS IS" basis, +# WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, +# WITHOUT LIMITATION, WARRANTIES THAT THE SOFTWARE IS FREE OF DEFECTS, +# MERCHANTABLE, FIT FOR A PARTICULAR PURPOSE, OR NON-INFRINGING. +# See the License for the specific provisions governing your rights and +# obligations concerning the Software. +# +# The Initial Developer of the Original Code is: Sun Microsystems, Inc. +# +# Copyright: 2006 by Sun Microsystems, Inc. +# +# All Rights Reserved. +# +######################################################################### +# TODO: +# - provide means to restart entire flows with failed flowjobs be rerun only +# - support bulk jobs +# - allow DRMAA user hold be used despite user hold be used by flow itself +######################################################################### + +require 'drmaa' + + +# ------------------------------------------------------------------------------------------ +# Exceptions thrown during parsing stage + +class ParsingFunction < ArgumentError ; end +class ParsingFormat < ArgumentError ; end + + +# ------------------------------------------------------------------------------------------ +# The FlowFunction classes represent the entities found in the flowfile. + +class FlowFunction +end +class JobsInParallel < FlowFunction + attr_accessor :par + def make(key, vars, depend, depth, select) + do_it = select_func?(key, vars, select) + + all_jobs = Array.new + @par.each { |sub| + name = sub[0] + if do_it + flowprint(depth, "PARALLEL: " + name) + end + new_vars = sub[1] + sub_vars = vars.dup + if ! new_vars.nil? + new_vars.each_pair { |var,val| sub_vars[var] = val } + end + j = $flowfunction[name] + if j.nil? + raise ParsingFunction.new("#{key}(): flow function \"#{name}\" does not exit") + end + if do_it + jobs = j.make(name, sub_vars, depend, depth+1, nil) + else + jobs = j.make(name, sub_vars, depend, depth+1, select) + end + if ! jobs.nil? + all_jobs += jobs + end + } + if all_jobs.size != 0 + return all_jobs + else + return nil + end + end +end + +class JobsInSequence < FlowFunction + attr_accessor :seq + def make(key, vars, depend, depth, select) + do_it = select_func?(key, vars, select) + first = true + @seq.each { |sub| + name = sub[0] + flowprint(depth, "SEQUENTIAL: " + name) if do_it + new_vars = sub[1] + sub_vars = vars.dup + if ! new_vars.nil? + new_vars.each_pair { |var,val| sub_vars[var] = val } + end + j = $flowfunction[name] + if j.nil? + raise ParsingFunction.new("#{key}: flow function \"#{name}\" does not exit") + end + if do_it + depend = j.make(name, sub_vars, depend, depth+1, nil) + else + depend = j.make(name, sub_vars, depend, depth+1, select) + end + } + return depend + end +end + +class RunnableJob < FlowFunction + attr_accessor :attrs, :njobs + def initialize + @njobs = 0 + end + + def make(key, vars, depend, depth, select) + @njobs += 1 + job_key = key + "#" + @njobs.to_s + + do_it = select_func?(key, vars, select) + + fj_attrs = Array.new + @attrs.each_pair { |name,t| + value = substitute(t, vars) + fj_attrs.push([ name, value ]) + } + if depend.nil? + f = FlowJob.new(nil, fj_attrs) + flowprint(depth, job_key + "(" + comma_vars(vars) + ")") if do_it + else + f = FlowJob.new(depend.dup, fj_attrs) + flowprint(depth, job_key + "(" + comma_vars(vars) + ") waiting for " + comma_jobs(f.depend, ", ")) if do_it + end + fj_attrs.each { |a| flowprint(depth+1, a[0] + "=\"" + a[1] + "\"") } if do_it + f.presubproc(job_key) + f.verify(job_key) + + if ! do_it + $not_selected += 1 + return [ ] + end + + $flowjob[job_key] = f + return [ job_key ] + end +end + +def flowprint(depth, s) + return if ! $parse_only + (depth*3).times { putc " " } ; puts s +end + +def comma_vars(vars) +s = "" +first = true +vars.each_pair { |var,val| + if first == false + s += ", " + else + first = false + end + s += var + "=" + val +} +return s +end + +def comma_jobs(jobs, sep = ",") +s = "" +first = true +jobs.each { |job| + if first == false + s += sep + else + first = false + end + s += job +} +return s +end + +def substitute(s, vars) +vars.each_pair { |var,val| + s = s.sub(var, val) +} +return s +end + +# parses name1=value1,... into a Hash +# used both for params and attrs +def var_list(str) + vars = Hash.new + if ! str.nil? + str.strip.scan(/[^,][^,]*/) { |vardef| + n = vardef.strip.scan(/[^=][^=]*/) + vars[n[0].strip] = n[1].strip + } + end + return vars +end + +# decide if a paricular flow call was selected as target +def select_func?(k1, vrs1, select) + return true if select.nil? + + k2 = select[0] + vrs2 = select[1] + if k1 != k2 or vrs1.size < vrs2.size + return false + end + + vrs2.each_pair { |k,v| + if ! vrs1.has_key?(k) or vrs1[k] != v + return false + end + } + + return true +end + +# return name of first function +def parse_flow(file) + all = nil + begin + IO::foreach(file) { |line| + case line + when /^#/ + next + else + # crack line + function = line.sub(/[ ]*=.*$/, "").strip + val = line.sub(/^[^=]*=/, "").strip + if all.nil? + all = function + end + + # runnable job + if ! val.index("{").nil? + r = RunnableJob.new + jobdef = val.scan(/[^{}][^{}]*/)[0].strip + r.attrs = var_list(jobdef) + $flowfunction[function] = r + + # jobs in parallel + elsif ! val.index("&").nil? + p = JobsInParallel.new + p.par = Array.new + val.scan(/[^&][^&]*/) { |sub| p.par << parse_flowcall(sub) } + $flowfunction[function] = p + + # jobs in sequence + elsif ! val.index("|").nil? + s = JobsInSequence.new + s.seq = Array.new + val.scan(/[^|][^|]*/) { |sub| s.seq << parse_flowcall(sub) } + $flowfunction[function] = s + + else + # parsing code possibly is not yet good enoug -- sorryh + raise ParsingFormat.new("flow file may not have empty lines") + end + end + } + end + return all +end + +def parse_flowcall(s) + jobdef = s.strip.scan(/[^()][^()]*/) + key = jobdef[0].strip + vars = var_list(jobdef[1]) + return [ key, vars ] +end + + +# ------------------------------------------------------------------------------------------ +# At end of parsing stage there is one FlowJob for each job to be run. +# The FlowJob also keeps state information, dependency information and +# job finish information. + +class FlowJob + # configuration + attr_accessor :attrs, :depend + # state information + attr_accessor :jobid, :info + def initialize(depend, attrs) + @depend = depend + @attrs = attrs + end + # -- verification + def verify(key) + cmd = false + @attrs.each { |a| + name = a[0] + value = a[1] + if value.index('$') + raise ParsingFunction.new("#{key}: #{name}=#{value} contains \"$\"") + end + case name + when "cmd" + if value.index('/') == 0 + if ! File.executable?(value) + raise ParsingFunction.new("#{key}: cmd=#{value} must be executable") + end + else + if executable_cmd(value).nil? + raise ParsingFunction.new("#{key}: could't find cmd=#{value} in CMDPATH") + end + end + cmd = true + when "join", "nomail" + true_or_false?(key, name, value) + when "args", "name", "nat", "cat", "wd", "in", "out", "err", "join", "trans", "mail" + else + # bug: must use DRMAA.get_attribute_names() to detect use of invalid attributes + raise ParsingFunction.new("#{key}: unknown attribute \"#{name}\"") + end + } + if !cmd + raise ParsingFunction.new("#{key}: missing mandatory attribute \"cmd\"") + end + end + def presubproc(job_key) + if defined? FlowRC.presubmit_proc + FlowRC.presubmit_proc(job_key, @attrs) + end + end + def executable_cmd(cmd) + path = nil + $CMDPATH.each { |p| + if File.executable?(p + "/" + cmd) + path = p + "/" + cmd + break + end + } + return path + end + def true_or_false?(key, name, value) + case value + when "0", "false", "no", "n" + return false + when "1", "true", "yes", "y" + return true + else + raise ParsingFunction.new("#{key}: \"#{name}=#{value}\" is neither \"true\" nor \"false\"") + end + end + + def submit(key, predecessors) + if $MAX_JOBS != 0 and $jobs_in_drm == $MAX_JOBS + return false + end + jt = DRMAA::JobTemplate.new + + # job defaults + jt.name = key # flow job name + if $flowdir.nil? + jt.wd = $wd + jt.stdout = ":/dev/null" + jt.join = true + else + jt.wd = $flowdir + jt.stdout = ":#{$flowdir}/#{key}.o" + jt.stderr = ":#{$flowdir}/#{key}.e" + jt.join = false + end + + native = nil + + attrs.each { |a| + name = a[0] + value = a[1] + case name + when "cmd" + if value.index("/") == 0 + jt.command = value + else + jt.command = executable_cmd(value) + end + when "args" + jt.arg = value.split(" ") + when "env" + jt.env = value.split(",") + when "name" + jt.name = value + when "nat" + native = value + when "cat" + jt.category = value + when "hold" + # careful! hold is used by flow itself + # jt.hold = true_or_false?(key, name, value) + when "wd" + jt.wd = value + when "in" + jt.stdin = value + when "out" + jt.stdout = value + when "err" + jt.stderr = value + when "join" + jt.join = true_or_false?(key, name, value) + when "trans" + jt.transfer = value + + when "mail" + jt.mail = value.split(",") + when "nomail" + jt.block_mail = true_or_false?(key, name, value) + end + } + + if ! predecessors.nil? + if $drm_depend + if native.nil? + jt.native = "-hold_jid " + predecessors + else + jt.native = native + " -hold_jid " + predecessors + end + else + jt.hold = true + jt.native = native unless native.nil? + end + else + jt.native = native unless native.nil? + end + + begin + jobid = $session.run(jt) + $already_submitted += 1 + $last_submission = Time.now + @jobid = jobid + if ! predecessors.nil? + puts "#{key} " + jobid + " submitted depending on " + predecessors + else + puts "#{key} " + jobid + " submitted" + end + rescue DRMAA::DRMAATryLater + STDERR.puts "... try later (#{key})" + return false + end + $jobs_in_drm += 1 + return true + end + + # true, if all predecessors done + def is_due? + return true if @depend.nil? + + self.depend.each { |key| + info = $flowjob[key].info + if info.nil? + return false # not yet finished + end + if ! info.wifexited? or info.wexitstatus != 0 + return false # failed + end + } + + return true + end + + def can_submit + # now --> [0, jobids] + # later --> [1, nil] + # never --> [2, nil] + r = 0 + jobids = nil + self.depend.each { |key| + node = $flowjob[key] + + info = node.info + if ! info.nil? + if !info.wifexited? or info.wexitstatus != 0 + return [ 2, nil] # failed + else + next # done + end + end + + jobid = node.jobid + if jobid.nil? + r = 1 # predecessor not yet submitted + else + # collect jobids + if jobids.nil? + jobids = jobid + else + jobids += "," + jobid + end + end + } + if r == 1 + return [1,nil] + else + return [0,jobids] + end + end +end + + +# ------------------------------------------------------------------------------------------ +# The functions below are used by main to run the workflow and cause +# successor jobs be submitted/released once they are due. + +# Workflow optimization requires job be submitted in order +# pass (1): jobs without predecessors or with all predecessors run +# pass (2): jobs whose predecessors are submitted +# aims is as broad as possible flow submission. +def submit_jobs(flush) + + if $flowjob.size == $already_submitted or $terminate_session + # STDERR.puts "all jobs submitted" + return true # all submitted + end + + if ! flush + if $last_submission != 0 and (Time.now - $last_submission) < $STREAMING_RETRY + # puts "... retry not yet reached" + return false # retry not yet reached + end + end + + # STDERR.puts "1st pass" + $flowjob.each_pair { |key,fj| + next if ! fj.jobid.nil? # already submitted + next if ! fj.info.nil? # already finished + + # all predecessors done + next if ! fj.is_due? + + if ! fj.submit(key, nil) + return false # try again + end + + if $terminate_program + exit 1 + elsif $terminate_session + terminate() + return true + end + } + + begin + # STDERR.puts "2nd pass" + all_submitted = true + + $flowjob.each_pair { |key,fj| + next if ! fj.jobid.nil? # already submitted + next if ! fj.info.nil? # already finished + + # analyze predecessors + status = fj.can_submit() + if status[0] != 0 + all_submitted = false if status[0] == 1 + next + end + predecessors = status[1] + + if ! fj.submit(key, predecessors) + return false # try again + end + + if $terminate_program + exit 1 + elsif $terminate_session + terminate() + return true + end + } + end until all_submitted + + return true # all submitted +end + +def reap_jobs + + $session.wait_each(1) { |info| + + # delete workflow upon user interrupt + if $terminate_program + exit 1 + elsif $terminate_session + terminate() + end + + # nothing happend + if info.nil? + submit_jobs(false) + next + end + $jobs_in_drm -= 1 + + # interpret job finish information + if info.wifaborted? + failed = true + happend = "aborted" + caused = "terminated" + elsif info.wifsignaled? + failed = true + happend = "died from " + info.wtermsig + happend += " (core dump)" if info.wcoredump? + caused = "terminated" + elsif info.wifexited? + exit_status = info.wexitstatus + if exit_status != 0 + failed = true + happend = "exited with " + exit_status.to_s + caused = "terminated" + else + failed = false + happend = "done" + caused = "released" + end + end + + # search flow job + job_key = nil + fjob = nil + $flowjob.each_pair { |k,v| + if v.jobid.nil? + next + end + if v.jobid == info.job + job_key = k + fjob = v + break + end + } + if fjob.nil? + puts "missing flow job for finished job " + info.job + exit 1 + end + + # mark flow job as done + fjob.info = info + fjob.jobid = nil + + trigger = Array.new + if ! $terminate_session + # drive conclusions + $flowjob.each_pair { |k,v| + # finished and non-blocked ones: skip + next if ! v.info.nil? or v.depend.nil? or v.jobid.nil? + # dependend to others: skip + next if ! v.depend.include?(job_key) + + if failed + begin + $session.terminate(v.jobid) + rescue DRMAA::DRMAAInvalidJobError + end + trigger << v.jobid + else + do_rls = true + v.depend.each { |k| + do_rls = false if $flowjob[k].info.nil? + } + if do_rls and ! $drm_depend + $session.release(v.jobid) + trigger << v.jobid + end + end + } + end + + # report what happend + if trigger.size == 0 + puts "#{job_key} #{info.job} " + happend + else + puts "#{job_key} #{info.job} " + happend + " " + caused + " " + comma_jobs(trigger, ", ") + end + + submit_jobs(false) + } +end + +# show final statistics +def final_report + nfailed = 0 + nrun = 0 + nnotrun = 0 + + rusage = Hash.new + $flowjob.each_pair { |k,v| + if v.info.nil? + nnotrun += 1 + next + end + if ! v.info.wifexited? or v.info.wexitstatus != 0 + nfailed += 1 + else + nrun += 1 + end + usage = v.info.rusage + next if usage.nil? + usage.each_pair { |name,value| + if $USAGE_REPORT.include?(name) + if ! rusage.has_key?(name) + rusage[name] = value.to_f + else + rusage[name] += value.to_f + end + end + } + } + puts "# ---- final report" + rusage.each_pair { |name,value| + printf("usage: #{name} = %-7.2f\n", value) + } + puts "run: #{nrun} failed: #{nfailed} notrun: #{nnotrun}" +end + +def terminate + if ! $did_terminate + STDERR.puts "Terminate!" + $session.terminate + $did_terminate = true + end +end + +def handle_signal + if ! $terminate_session + $terminate_session = true + elsif ! $terminate_program + $terminate_program = true + end +end + +def usage(ret) + if ret == 0 + out = STDOUT + else + out = STDERR + end + out.puts "usage: flow.rb [options] workflow.ff [start]" + out.puts " options: -verify only parse and verify the flow" + out.puts " -dd use DRM dependencies" + out.puts " -flowdir flowdir is used as defaults" + out.puts " start: --> TEST or TEST($arch=solaris)" + exit ret +end + +# ------------------------------------------------------------------------------------------ +# main + +# use defaults +# (1) from ./.flowrc.rb +# (2) from $HOME/.flowrc.rb +# (3) or built-in ones + +read_rc_file = false +if FileTest.exist?('.flowrc.rb') + require '.flowrc' + read_rc_file = true +elsif FileTest.exist?(ENV["HOME"] + "/.flowrc.rb") + require ENV["HOME"] + "/.flowrc.rb" + read_rc_file = true +end + +if ! read_rc_file + $CMDPATH = Dir::getwd() + $STREAMING_RETRY = 5 + $USAGE_REPORT = [ ] + $MAX_JOBS = 0 +else + $CMDPATH = FlowRC::CMDPATH + $STREAMING_RETRY = FlowRC::STREAMING_RETRY + $USAGE_REPORT = FlowRC::USAGE_REPORT + $MAX_JOBS = FlowRC::MAX_JOBS +end + +# The flowdir is used in a number of cases to have reasonable +# defaults. Thus it makes some difference if flowdir was +# specified or not: +# +# wd (drmaa_wd) +# The flowdir is used as jobs' default working directory. +# Without flowdir the current working directory is simply +# used. Though each jobs' working directory can also be +# specified within the flowfile, but if they have to that +# would make them harder to read by humans. +# +# out/err/join (drmaa- stdout_path/stderr_path/join) +# Without flowdir "/dev/null" is used as default for 'out' +# and 'join' is true. Reason is there were no better +# default to store job output/error files than the +# current working directory, but if that were used +# it might incidentally happen that masses of job +# output files are dumped in some directory. If flowdir +# was specified at command line it is used as default +# for storing job output and error separately in +# $flowdir/.o and $flowdir/.o. +# +# cmd (drmaa_remote_command) +# args (drmaa_argv) +# env (drmaa_env) + + +$parse_only = false +$drm_depend = false +$flowdir = nil + +# command line parsing +while ARGV.length >= 2 do + case ARGV[0] + when "-verify" + $parse_only = true + ARGV.shift + when "-dd" + $drm_depend = true + ARGV.shift + when "-flowdir" + ARGV.shift + usage(1) if $flowdir or ARGV.length < 2 + $flowdir = ARGV[0] + ARGV.shift + when "-h", "-help" + usage 0 + else + break + end +end +if ARGV.length >= 1 + flowfile=ARGV.shift + if ! FileTest.readable?(flowfile) + STDERR.puts flowfile + " does not exit" + exit 1 + end +else + usage(1) +end +if ARGV.length == 1 + target = parse_flowcall(ARGV.shift) +end +usage(1) unless ARGV.length == 0 + +# flow parsing and verification +begin + $wd = Dir::getwd + + $flowfunction = Hash.new + all = parse_flow(flowfile) + j = $flowfunction[all] + + $flowjob = Hash.new + $not_selected = 0 + target = parse_flowcall(all) if target.nil? + j.make(all, vars = Hash.new, nil, 0, target) + if $flowjob.size == 0 + raise ParsingFormat.new("flow start \"#{target[0]}\" does not exist in #{flowfile}") + end + puts "---+ doing #{$flowjob.size} of #{$flowjob.size+$not_selected} jobs with #{target[0]} as flow target" + + STDOUT.flush + exit 0 if $parse_only +rescue ParsingFunction => msg + STDERR.puts "Error in " + msg + exit 1 +rescue ParsingFormat => msg + STDERR.puts "Format error: " + msg + exit 1 +end + +# run the workflow +t1 = Time.now +begin + $terminate_session = $terminate_program = false + trap("INT") { handle_signal } + trap("TERM") { handle_signal } + + $session = DRMAA::Session.new + # puts "# ----- submitting jobs" + $already_submitted = $last_submission = 0 + $jobs_in_drm = 0 + + # May not stop reaping before all jobs + # are submitted in case of streaming. + first = true + begin + all_reaped = false + all_submitted = submit_jobs(true) + if first + # puts "# ----- reaping jobs" + first = false + else + if all_submitted + all_reaped = true + else + sleep $STREAMING_RETRY + end + end + reap_jobs() + end until all_reaped + +rescue DRMAA::DRMAAException => msg + puts msg + exit 1 +end + +final_report() + +t2 = Time.now +printf("total: %7.1f seconds\n", t2-t1) +exit 0 diff --git a/examples/drmaa/ruby/flow/samples/README b/examples/drmaa/ruby/flow/samples/README new file mode 100755 index 0000000..7113387 --- /dev/null +++ b/examples/drmaa/ruby/flow/samples/README @@ -0,0 +1,46 @@ +== Sample flowfiles + + The samples comprise four different flowfiles + + * tiny.ff (one single job) + * small.ff (29 jobs) + * large.ff (780 jobs) + * huge.ff (>40000 jobs) + +== Sample jobs + + The flow require a number of job scripts + + * do_make + * do_test + * do_inst + * do_uninst + * do_final + * do_report + + each of which simply does a sleep. + +== Pre-submission procedure + + In addition a sample .flowrc.rb file can be found. Besides + a couple of parameters it contains a pre-submission procedure. + +== Assumptions according the DRM setup + + Note: For running the flows it is necessary to configure + the DRM in a way that + + -q gridware.q + -q irix.q + -q solaris.q + -q linux.q + -q darwin.q + + and + + -P fast (.flowrc.rb) + + can be passed as "nat" (i.e. "drmaa_native_specification"). + + Yet as a matter of course the set-up requirements easily can + be changed, if the sample files are modified accordingly. diff --git a/examples/drmaa/ruby/flow/samples/do_final b/examples/drmaa/ruby/flow/samples/do_final new file mode 100755 index 0000000..ef57186 --- /dev/null +++ b/examples/drmaa/ruby/flow/samples/do_final @@ -0,0 +1,8 @@ +#!/bin/sh +me=`basename $0` +echo "# -- args $* -- #" +echo "# -- starting $me -- #" +sleep 1 +ret=$? +echo "# -- finished $me -- #" +exit $ret diff --git a/examples/drmaa/ruby/flow/samples/do_inst b/examples/drmaa/ruby/flow/samples/do_inst new file mode 100755 index 0000000..ea119f3 --- /dev/null +++ b/examples/drmaa/ruby/flow/samples/do_inst @@ -0,0 +1,8 @@ +#!/bin/sh +me=`basename $0` +echo "# -- args $* -- #" +echo "# -- starting $me -- #" +sleep $1 +ret=$? +echo "# -- finished $me -- #" +exit $ret diff --git a/examples/drmaa/ruby/flow/samples/do_make b/examples/drmaa/ruby/flow/samples/do_make new file mode 100755 index 0000000..ef57186 --- /dev/null +++ b/examples/drmaa/ruby/flow/samples/do_make @@ -0,0 +1,8 @@ +#!/bin/sh +me=`basename $0` +echo "# -- args $* -- #" +echo "# -- starting $me -- #" +sleep 1 +ret=$? +echo "# -- finished $me -- #" +exit $ret diff --git a/examples/drmaa/ruby/flow/samples/do_report b/examples/drmaa/ruby/flow/samples/do_report new file mode 100755 index 0000000..ef57186 --- /dev/null +++ b/examples/drmaa/ruby/flow/samples/do_report @@ -0,0 +1,8 @@ +#!/bin/sh +me=`basename $0` +echo "# -- args $* -- #" +echo "# -- starting $me -- #" +sleep 1 +ret=$? +echo "# -- finished $me -- #" +exit $ret diff --git a/examples/drmaa/ruby/flow/samples/do_test b/examples/drmaa/ruby/flow/samples/do_test new file mode 100755 index 0000000..ef57186 --- /dev/null +++ b/examples/drmaa/ruby/flow/samples/do_test @@ -0,0 +1,8 @@ +#!/bin/sh +me=`basename $0` +echo "# -- args $* -- #" +echo "# -- starting $me -- #" +sleep 1 +ret=$? +echo "# -- finished $me -- #" +exit $ret diff --git a/examples/drmaa/ruby/flow/samples/do_uninst b/examples/drmaa/ruby/flow/samples/do_uninst new file mode 100755 index 0000000..ea119f3 --- /dev/null +++ b/examples/drmaa/ruby/flow/samples/do_uninst @@ -0,0 +1,8 @@ +#!/bin/sh +me=`basename $0` +echo "# -- args $* -- #" +echo "# -- starting $me -- #" +sleep $1 +ret=$? +echo "# -- finished $me -- #" +exit $ret diff --git a/examples/drmaa/ruby/flow/samples/huge.ff b/examples/drmaa/ruby/flow/samples/huge.ff new file mode 100755 index 0000000..a9f469c --- /dev/null +++ b/examples/drmaa/ruby/flow/samples/huge.ff @@ -0,0 +1,36 @@ +# ------------------------------------------------------------------------------------------ +ALL = ALLFLOWS | REPORT +ALLFLOWS = FLOW($arch=solaris) & FLOW($arch=linux) & FLOW($arch=irix) & FLOW($arch=darwin) +FLOW = BUILD | INST | TESTS | FINAL +# ------------------------------------------------------------------------------------------ +BUILD = { cmd=do_make, nat=-q $arch.q, args= 5 } +INST = { cmd=do_inst, nat=-q gridware.q, args=4 -local -bin $arch, name=I$arch } +TESTS = SEVEN & SEVEN & SEVEN & SEVEN +SEVEN = DAY($day=mon) & DAY($day=tue) & DAY($day=wed) & DAY($day=thu) & DAY($day=fri) & DAY($day=sat) & DAY($day=sun) +DAY = T & T & T & T +T = S1 & S2 & S3 & S4 & S1 & S2 & S3 & S4 +S1 = TT1 | TT2 | TT3 +S2 = TT1 | TT2 | TT3 +S3 = TT1 | TT2 | TT3 +S4 = TT1 | TT2 | TT3 +TT1 = T1 & T2 & T3 & T4 +TT2 = T1 & T2 & T3 & T4 +TT3 = T1 & T2 & T3 & T4 +TT4 = T1 & T2 & T3 & T4 +TT5 = T1 & T2 & T3 & T4 +T1 = { cmd=do_test, nat= -q $arch.q, args=1, args=$day } +T2 = { cmd=do_test, nat= -q $arch.q, args=2, args=$day } +T3 = { cmd=do_test, nat= -q $arch.q, args=3, args=$day } +T4 = { cmd=do_test, nat= -q $arch.q, args=4, args=$day } +FINAL = { cmd=do_final, nat=-q $arch.q, name=FIN$arch } +# ------------------------------------------------------------------------------------------ +REPORT = LANG($whom=engineering) & LANG($whom=markting) & LANG($whom=sales) +LANG = RR1($lang=ger) & RR2($lang=eng) & RR3($lang=jap) +RR1 = R1($size=1G) | R2($size=2G) | R3($size=4G) +RR2 = R1($size=1G) | R2($size=2G) | R3($size=4G) +RR3 = R1($size=1G) | R2($size=2G) | R3($size=4G) +R1 = R($format=html) & R($format=wiki) & R($format=pdf) & R($format=soffice ) +R2 = R($format=html) & R($format=wiki) & R($format=pdf) & R($format=soffice ) +R3 = R($format=html) & R($format=wiki) & R($format=pdf) & R($format=soffice ) +R = { cmd=do_report, nat=-q gridware.q, args=$lang $size $format } +# ------------------------------------------------------------------------------------------ diff --git a/examples/drmaa/ruby/flow/samples/large.ff b/examples/drmaa/ruby/flow/samples/large.ff new file mode 100755 index 0000000..27b4c6d --- /dev/null +++ b/examples/drmaa/ruby/flow/samples/large.ff @@ -0,0 +1,21 @@ +# ------------------------------------------------------------------------------------------ +ALL = FLOW($arch=solaris) & FLOW($arch=linux) & FLOW($arch=irix) & FLOW($arch=darwin) +FLOW = BUILD | INST | TESTS | FINAL +TESTS = T & T & T & T +T = S1 & S2 & S3 & S4 +S1 = TT1 | TT2 | TT3 +S2 = TT1 | TT2 | TT3 +S3 = TT1 | TT2 | TT3 +S4 = TT1 | TT2 | TT3 +TT1 = T1 & T2 & T3 & T4 +TT2 = T1 & T2 & T3 & T4 +TT3 = T1 & T2 & T3 & T4 +# ------------------------------------------------------------------------------------------ +BUILD = { cmd=do_make, nat=-q $arch.q, args=5 } +INST = { cmd=do_inst, nat = -q gridware.q, args=1 -local -bin $arch, name=I$arch } +FINAL = { cmd=do_final, name=FIN$arch, args=1 } +T1 = { cmd=do_test, nat= -q $arch.q, args=1 } +T2 = { cmd=do_test, nat= -q $arch.q, args=2 } +T3 = { cmd=do_test, nat= -q $arch.q, args=3 } +T4 = { cmd=do_test, nat= -q $arch.q, args=4 } +# ------------------------------------------------------------------------------------------ diff --git a/examples/drmaa/ruby/flow/samples/small.ff b/examples/drmaa/ruby/flow/samples/small.ff new file mode 100755 index 0000000..80c0a89 --- /dev/null +++ b/examples/drmaa/ruby/flow/samples/small.ff @@ -0,0 +1,15 @@ +# ------------------------------------------------------------------------------------------ +ALL = ALLFLOWS | REPORT +# ------------------------------------------------------------------------------------------ +ALLFLOWS = FLOW($arch=darwin) & FLOW($arch=linux) & FLOW($arch=irix) & FLOW($arch=solaris) +FLOW = BUILD | INST | TESTS | FINAL +TESTS = T1 & T2 & T3 & T4 +# ------------------------------------------------------------------------------------------ +BUILD = { cmd=do_make, nat=-q $arch.q, args=5 } +INST = { cmd=do_inst, nat=-q gridware.q, args=1 -local -bin $arch, name=I$arch } +FINAL = { cmd=do_uninst, nat=-q $arch.q, args=1, name=FIN$arch } +T1 = { cmd=do_test, nat = -q $arch.q, args = 1 } +T2 = { cmd=do_test, nat = -q $arch.q, args = 2 } +T3 = { cmd=do_test, nat = -q $arch.q, args = 3 } +T4 = { cmd=do_test, nat = -q $arch.q, args = 4 } +REPORT = { cmd=do_report } diff --git a/examples/drmaa/ruby/flow/samples/tiny.ff b/examples/drmaa/ruby/flow/samples/tiny.ff new file mode 100755 index 0000000..af836b5 --- /dev/null +++ b/examples/drmaa/ruby/flow/samples/tiny.ff @@ -0,0 +1 @@ +TEST = {cmd=do_test, args=-w 15} diff --git a/examples/drmaa/ruby/sig.rb b/examples/drmaa/ruby/sig.rb new file mode 100755 index 0000000..bd6d7c1 --- /dev/null +++ b/examples/drmaa/ruby/sig.rb @@ -0,0 +1,66 @@ +#!/usr/bin/ruby + +######################################################################### +# +# The Contents of this file are made available subject to the terms of +# the Sun Industry Standards Source License Version 1.2 +# +# Sun Microsystems Inc., March, 2006 +# +# +# Sun Industry Standards Source License Version 1.2 +# ================================================= +# The contents of this file are subject to the Sun Industry Standards +# Source License Version 1.2 (the "License"); You may not use this file +# except in compliance with the License. You may obtain a copy of the +# License at http://gridengine.sunsource.net/Gridengine_SISSL_license.html +# +# Software provided under this License is provided on an "AS IS" basis, +# WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, +# WITHOUT LIMITATION, WARRANTIES THAT THE SOFTWARE IS FREE OF DEFECTS, +# MERCHANTABLE, FIT FOR A PARTICULAR PURPOSE, OR NON-INFRINGING. +# See the License for the specific provisions governing your rights and +# obligations concerning the Software. +# +# The Initial Developer of the Original Code is: Sun Microsystems, Inc. +# +# Copyright: 2006 by Sun Microsystems, Inc. +# +# All Rights Reserved. +# +######################################################################### + +require 'drmaa' + +if ARGV.length < 1 + puts "usage: sig.rb " + exit 1 +end + +s = DRMAA::Session.new + +t = DRMAA::JobTemplate.new +t.command = ARGV[0] +ARGV.shift +t.arg = ARGV +t.stdout = ":/dev/null" +t.join = true + +job = s.run(t) + +puts "job: " + job + +info = s.wait(job) + +if info.wifexited? + puts info.job + " returned with " + info.wexitstatus.to_s +elsif info.wifsignaled? + if info.wcoredump? + puts info.job + " returned died from " + info.wtermsig.to_s + " (core dumped)" + else + puts info.job + " returned died from " + info.wtermsig.to_s + end +elsif info.wifaborted? + puts "aborted: " + info.job +end +info.rusage.each_pair { |name,value| puts "usage " + name + " " + value } diff --git a/examples/drmaa/ruby/stream_and_trap.rb b/examples/drmaa/ruby/stream_and_trap.rb new file mode 100755 index 0000000..e82ca53 --- /dev/null +++ b/examples/drmaa/ruby/stream_and_trap.rb @@ -0,0 +1,99 @@ +#!/usr/bin/ruby + +######################################################################### +# +# The Contents of this file are made available subject to the terms of +# the Sun Industry Standards Source License Version 1.2 +# +# Sun Microsystems Inc., March, 2006 +# +# +# Sun Industry Standards Source License Version 1.2 +# ================================================= +# The contents of this file are subject to the Sun Industry Standards +# Source License Version 1.2 (the "License"); You may not use this file +# except in compliance with the License. You may obtain a copy of the +# License at http://gridengine.sunsource.net/Gridengine_SISSL_license.html +# +# Software provided under this License is provided on an "AS IS" basis, +# WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, +# WITHOUT LIMITATION, WARRANTIES THAT THE SOFTWARE IS FREE OF DEFECTS, +# MERCHANTABLE, FIT FOR A PARTICULAR PURPOSE, OR NON-INFRINGING. +# See the License for the specific provisions governing your rights and +# obligations concerning the Software. +# +# The Initial Developer of the Original Code is: Sun Microsystems, Inc. +# +# Copyright: 2006 by Sun Microsystems, Inc. +# +# All Rights Reserved. +# +######################################################################### + + +require 'drmaa' + +class Sleeper < DRMAA::JobTemplate + def initialize + super + self.command = "/bin/sleep" + self.arg = ["1"] + self.stdout = ":/dev/null" + self.join = true + end +end + + +$terminate_session = $terminate_program = false +def handle_signal + if ! $terminate_session + $terminate_session = true + elsif ! $terminate_program + $terminate_program = true + end +end +trap("INT") { handle_signal } +trap("TERM") { handle_signal } + +session = DRMAA::Session.new + +# causes DRMAA::Session:run() and DRMAA::Session:run_bulk() +# to sleep and retry in case of DRMAA::DRMAATryAgain. +# That way we implement job streaming. +session.retry = 5 + +t = Sleeper.new + +jobs = Array.new +for i in 1 .. 20 do + job = session.run(t) + puts "job: " + job + jobs << job + break if $terminate_session +end +for i in 1 .. 10 + bulk = session.run_bulk(t, 1, 2) + bulk.each { |job| puts "job: " + job } + jobs += bulk + break if $terminate_session +end + +while jobs.size > 0 do + info = session.wait_any(1) + if ! info.nil? + if ! info.wifexited? + puts "failed: " + info.job + else + puts info.job + " returned with " + info.wexitstatus.to_s + end + jobs.delete(info.job) + else + if $terminate_program + jobs.clear + elsif $terminate_session + session.terminate + end + end +end + +exit 0 diff --git a/examples/drmaa/ruby/test_all.sh b/examples/drmaa/ruby/test_all.sh new file mode 100755 index 0000000..5b9abd2 --- /dev/null +++ b/examples/drmaa/ruby/test_all.sh @@ -0,0 +1,9 @@ +#!/bin/sh +./example.rb && ./array.rb && ./sig.rb /bin/sleep 1 && ./stream_and_trap.rb && ./threads.rb && ./attributes.rb +ret=$? +if [ $ret -ne 0 ]; then + echo "##### failed #####" +else + echo "##### success #####" +fi +exit $ret diff --git a/examples/drmaa/ruby/threads.rb b/examples/drmaa/ruby/threads.rb new file mode 100755 index 0000000..c23c41f --- /dev/null +++ b/examples/drmaa/ruby/threads.rb @@ -0,0 +1,80 @@ +#!/usr/bin/ruby + +######################################################################### +# +# The Contents of this file are made available subject to the terms of +# the Sun Industry Standards Source License Version 1.2 +# +# Sun Microsystems Inc., March, 2006 +# +# +# Sun Industry Standards Source License Version 1.2 +# ================================================= +# The contents of this file are subject to the Sun Industry Standards +# Source License Version 1.2 (the "License"); You may not use this file +# except in compliance with the License. You may obtain a copy of the +# License at http://gridengine.sunsource.net/Gridengine_SISSL_license.html +# +# Software provided under this License is provided on an "AS IS" basis, +# WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, +# WITHOUT LIMITATION, WARRANTIES THAT THE SOFTWARE IS FREE OF DEFECTS, +# MERCHANTABLE, FIT FOR A PARTICULAR PURPOSE, OR NON-INFRINGING. +# See the License for the specific provisions governing your rights and +# obligations concerning the Software. +# +# The Initial Developer of the Original Code is: Sun Microsystems, Inc. +# +# Copyright: 2006 by Sun Microsystems, Inc. +# +# All Rights Reserved. +# +######################################################################### + +require 'drmaa' +require 'thread' + +class Sleeper < DRMAA::JobTemplate + def initialize + super + self.command = "/bin/sleep" + self.arg = ["1"] + self.stdout = ":/dev/null" + self.join = true + end +end + +# Submit a bunch of jobs from a number of threads +# and wait for them in main thread. +# +# Note: Ruby threads are not identical with operating +# system threads. + +version = DRMAA.version +drm = DRMAA.drm_system +puts "DRMAA #{drm} v #{version}" + +session = DRMAA::Session.new +t = Sleeper.new + +i = 0 +while i<4 do + Thread.start do + j = 0 + while j<20 do + puts "job: " + session.run(t) + j += 1 + end + end + i += 1 +end + +session.wait_each{ |info| + job = info.job + if ! info.wifexited? + puts "failed: " + info.job + else + puts info.job + " returned with " + info.wexitstatus.to_s + end +} + +exit 0 diff --git a/examples/jobs/array_submitter.sh b/examples/jobs/array_submitter.sh new file mode 100755 index 0000000..0526445 --- /dev/null +++ b/examples/jobs/array_submitter.sh @@ -0,0 +1,106 @@ +#!/bin/sh +# +#___INFO__MARK_BEGIN__ +########################################################################## +# +# The Contents of this file are made available subject to the terms of +# the Sun Industry Standards Source License Version 1.2 +# +# Sun Microsystems Inc., March, 2001 +# +# +# Sun Industry Standards Source License Version 1.2 +# ================================================= +# The contents of this file are subject to the Sun Industry Standards +# Source License Version 1.2 (the "License"); You may not use this file +# except in compliance with the License. You may obtain a copy of the +# License at http://gridengine.sunsource.net/Gridengine_SISSL_license.html +# +# Software provided under this License is provided on an "AS IS" basis, +# WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, +# WITHOUT LIMITATION, WARRANTIES THAT THE SOFTWARE IS FREE OF DEFECTS, +# MERCHANTABLE, FIT FOR A PARTICULAR PURPOSE, OR NON-INFRINGING. +# See the License for the specific provisions governing your rights and +# obligations concerning the Software. +# +# The Initial Developer of the Original Code is: Sun Microsystems, Inc. +# +# Copyright: 2001 by Sun Microsystems, Inc. +# +# All Rights Reserved. +# +########################################################################## +#___INFO__MARK_END__ + +# +# This sample consists of three scripts belonging toghether +# +# array_submitter.sh +# step_A_array_submitter.sh +# step_B_array_submitter.sh +# +# The number passed as an argument to the interactively started +# array_submitter.sh is used to specify the the size of the two array +# jobs step_A_array_submitter.sh/step_B_array_submitter.sh which are +# submitted. Each single job of array job B is not scheduled before +# array job A has not passed the section where qalter is used to release +# the succesor task. Refer to qsub(1) for more information about array +# jobs. +# +# This is a typical scenario in DCC industry where schemes like this +# are used to control sequence of large rendering jobs. +# Note that it is necessary that all hosts where A jobs are started +# must be submit hosts to allow the qalter happen. +# + +#$ -S /bin/sh + +if [ x$SGE_ROOT = x ]; then + SGE_ROOT=/usr/SGE +fi +if [ ! -d $SGE_ROOT ]; then + echo "error: SGE_ROOT directory $SGE_ROOT does not exist" + exit 1 +fi + +ARC=`$SGE_ROOT/util/arch` + +QSUB=$SGE_ROOT/bin/$ARC/qsub +QALTER=$SGE_ROOT/bin/$ARC/qalter + +if [ ! -x $QSUB ]; then + echo "error: cannot execute qsub command under $QSUB" + exit 1 +fi + +if [ ! -x $QALTER ]; then + echo "error: cannot execute qalter command under $QALTER" + exit 1 +fi + +tasks=0 + +while [ "$1" != "" ]; do + case "$1" in + [0-9]*) + tasks=$1 + shift + ;; + esac +done + +if [ $tasks = 0 ]; then + echo "usage: array_submitter.sh " + exit 1 +fi + +# submit step A jobarray +jobid_a=`$QSUB -t 1-$tasks -r y -N StepA $SGE_ROOT/examples/jobs/step_A_array_submitter.sh | cut -f3 -d" "|cut -f1 -d.` +echo "submission result: jobid_a = $jobid_a" + +# submit step B jobarray with hold state +jobid_b=`$QSUB -t 1-$tasks -h -r y -N StepB $SGE_ROOT/examples/jobs/step_B_array_submitter.sh | cut -f3 -d" "|cut -f1 -d.` +echo "submission result: jobid_b = $jobid_b" + +# put jobid of step B into context of step A +$QALTER -ac succ=$jobid_b $jobid_a diff --git a/examples/jobs/env-tester.sh b/examples/jobs/env-tester.sh new file mode 100755 index 0000000..325dc5a --- /dev/null +++ b/examples/jobs/env-tester.sh @@ -0,0 +1,36 @@ +#!/bin/sh +#$ -S /bin/sh +#___INFO__MARK_BEGIN__ +########################################################################## +# +# The Contents of this file are made available subject to the terms of +# the Sun Industry Standards Source License Version 1.2 +# +# Sun Microsystems Inc., March, 2001 +# +# +# Sun Industry Standards Source License Version 1.2 +# ================================================= +# The contents of this file are subject to the Sun Industry Standards +# Source License Version 1.2 (the "License"); You may not use this file +# except in compliance with the License. You may obtain a copy of the +# License at http://gridengine.sunsource.net/Gridengine_SISSL_license.html +# +# Software provided under this License is provided on an "AS IS" basis, +# WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, +# WITHOUT LIMITATION, WARRANTIES THAT THE SOFTWARE IS FREE OF DEFECTS, +# MERCHANTABLE, FIT FOR A PARTICULAR PURPOSE, OR NON-INFRINGING. +# See the License for the specific provisions governing your rights and +# obligations concerning the Software. +# +# The Initial Developer of the Original Code is: Sun Microsystems, Inc. +# +# Copyright: 2001 by Sun Microsystems, Inc. +# +# All Rights Reserved. +# +########################################################################## +#___INFO__MARK_END__ +echo ------------------------------------ +env +echo ------------------------------------ diff --git a/examples/jobs/jobnet_submitter.sh b/examples/jobs/jobnet_submitter.sh new file mode 100755 index 0000000..871d330 --- /dev/null +++ b/examples/jobs/jobnet_submitter.sh @@ -0,0 +1,77 @@ +#!/bin/sh +# +# +#___INFO__MARK_BEGIN__ +########################################################################## +# +# The Contents of this file are made available subject to the terms of +# the Sun Industry Standards Source License Version 1.2 +# +# Sun Microsystems Inc., March, 2001 +# +# +# Sun Industry Standards Source License Version 1.2 +# ================================================= +# The contents of this file are subject to the Sun Industry Standards +# Source License Version 1.2 (the "License"); You may not use this file +# except in compliance with the License. You may obtain a copy of the +# License at http://gridengine.sunsource.net/Gridengine_SISSL_license.html +# +# Software provided under this License is provided on an "AS IS" basis, +# WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, +# WITHOUT LIMITATION, WARRANTIES THAT THE SOFTWARE IS FREE OF DEFECTS, +# MERCHANTABLE, FIT FOR A PARTICULAR PURPOSE, OR NON-INFRINGING. +# See the License for the specific provisions governing your rights and +# obligations concerning the Software. +# +# The Initial Developer of the Original Code is: Sun Microsystems, Inc. +# +# Copyright: 2001 by Sun Microsystems, Inc. +# +# All Rights Reserved. +# +########################################################################## +#___INFO__MARK_END__ + +QSUB=$SGE_ROOT/bin/$ARC/qsub +name_base=Net +hold="" +jobs=5 + +while [ "$1" != "" ]; do + case "$1" in + -N) + shift + name_base=$1 + shift + ;; + -h) + hold=-h + shift + ;; + [0-9]*) + jobs=$1 + shift + ;; + esac +done + +echo "going to submit $jobs jobs" + +jobid=0 +REQUEST="" + +i=1 +while [ $i -le $jobs ]; do + if [ $i -ne 1 ]; then + opt="-hold_jid $jobid" + fi + + jobid=`$QSUB $REQUEST -r y -N $name_base$i $hold $opt $SGE_ROOT/examples/jobs/sleeper.sh 10 | cut -f3 -d" "` + if [ $i -ne 1 ]; then + echo submitted job \#$i name = $name_base$i with jobid $jobid and $opt + else + echo submitted job \#$i name = $name_base$i with jobid $jobid + fi + i=`expr $i + 1` +done diff --git a/examples/jobs/matlab_script.sh b/examples/jobs/matlab_script.sh new file mode 120000 index 0000000..7c990ba --- /dev/null +++ b/examples/jobs/matlab_script.sh @@ -0,0 +1 @@ +../../local/examples/jobs/matlab_script.sh \ No newline at end of file diff --git a/examples/jobs/pascal.sh b/examples/jobs/pascal.sh new file mode 100755 index 0000000..dff39a9 --- /dev/null +++ b/examples/jobs/pascal.sh @@ -0,0 +1,107 @@ +#!/bin/sh +# +#___INFO__MARK_BEGIN__ +########################################################################## +# +# The Contents of this file are made available subject to the terms of +# the Sun Industry Standards Source License Version 1.2 +# +# Sun Microsystems Inc., March, 2001 +# +# +# Sun Industry Standards Source License Version 1.2 +# ================================================= +# The contents of this file are subject to the Sun Industry Standards +# Source License Version 1.2 (the "License"); You may not use this file +# except in compliance with the License. You may obtain a copy of the +# License at http://gridengine.sunsource.net/Gridengine_SISSL_license.html +# +# Software provided under this License is provided on an "AS IS" basis, +# WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, +# WITHOUT LIMITATION, WARRANTIES THAT THE SOFTWARE IS FREE OF DEFECTS, +# MERCHANTABLE, FIT FOR A PARTICULAR PURPOSE, OR NON-INFRINGING. +# See the License for the specific provisions governing your rights and +# obligations concerning the Software. +# +# The Initial Developer of the Original Code is: Sun Microsystems, Inc. +# +# Copyright: 2001 by Sun Microsystems, Inc. +# +# All Rights Reserved. +# +########################################################################## +#___INFO__MARK_END__ +# +# This is a sample script to demonstrate use of job dependencies. The +# sample submits one job for each node in the pascal triangle: +# +# 1 depth 1 +# / \ +# 1 1 depth 2 +# / \ / \ +# 1 2 1 depth 3 +# / \ / \ / \ +# 1 3 3 1 depth 4 +# +# : : : : +# +# Data exchange between jobs is done via files in jobnet_dir. +# +# Usage: pascal.sh + +jobnet_dir=$HOME/pascal_jobnet + +if [ $# -ne 1 ]; then + echo "usage: pascal.sh " >&2 + exit 1 +fi +n=$1 +i=1 + +mkdir $jobnet_dir +rm $jobnet_dir/* + +while [ $i -le $n ]; do + j=1 + while [ $j -le $i ]; do + prev_line=`expr $i - 1` + + # specify own jobname + submit_args="-N P${i}_${j}" + + if [ $j -gt 1 -a $j -lt $i ]; then + depend1=P${prev_line}_`expr ${j} - 1` + depend2=P${prev_line}_${j} + depend="$depend1 $depend2" + submit_args="$submit_args -hold_jid $depend1,$depend2" + elif [ $j -gt 1 ]; then + depend=P${prev_line}_`expr ${j} - 1` + submit_args="$submit_args -hold_jid $depend" + elif [ $j -lt $i ]; then + depend=P${prev_line}_${j} + submit_args="$submit_args -hold_jid $depend" + fi + + echo "qsub -j y -o $jobnet_dir $submit_args -- $jobnet_dir $depend" + qsub -r y -j y -o $jobnet_dir $submit_args -- $jobnet_dir $depend << EOF +#!/bin/sh +#$ -S /bin/sh +result=0 +jobnet_dir=\$1 +shift +while [ \$# -gt 0 ]; do + depend=\$1 + shift + to_add=\`cat \$jobnet_dir/DATA_\$depend\` + result=\`expr \$result + \$to_add\` + echo "\$REQUEST: adding \$to_add found in \$jobnet_dir/DATA_\$depend results in \$result" +done +if [ \$result = 0 ]; then + result=1 +fi +echo \$result > \$jobnet_dir/DATA_\$REQUEST +EOF + j=`expr $j + 1` + done + i=`expr $i + 1` +done diff --git a/examples/jobs/periodic_sleeper.sh b/examples/jobs/periodic_sleeper.sh new file mode 120000 index 0000000..be0a3ec --- /dev/null +++ b/examples/jobs/periodic_sleeper.sh @@ -0,0 +1 @@ +../../local/examples/jobs/periodic_sleeper.sh \ No newline at end of file diff --git a/examples/jobs/pminiworm.sh b/examples/jobs/pminiworm.sh new file mode 100755 index 0000000..06eb050 --- /dev/null +++ b/examples/jobs/pminiworm.sh @@ -0,0 +1,79 @@ +#!/bin/sh +#___INFO__MARK_BEGIN__ +########################################################################## +# +# The Contents of this file are made available subject to the terms of +# the Sun Industry Standards Source License Version 1.2 +# +# Sun Microsystems Inc., March, 2001 +# +# +# Sun Industry Standards Source License Version 1.2 +# ================================================= +# The contents of this file are subject to the Sun Industry Standards +# Source License Version 1.2 (the "License"); You may not use this file +# except in compliance with the License. You may obtain a copy of the +# License at http://gridengine.sunsource.net/Gridengine_SISSL_license.html +# +# Software provided under this License is provided on an "AS IS" basis, +# WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, +# WITHOUT LIMITATION, WARRANTIES THAT THE SOFTWARE IS FREE OF DEFECTS, +# MERCHANTABLE, FIT FOR A PARTICULAR PURPOSE, OR NON-INFRINGING. +# See the License for the specific provisions governing your rights and +# obligations concerning the Software. +# +# The Initial Developer of the Original Code is: Sun Microsystems, Inc. +# +# Copyright: 2001 by Sun Microsystems, Inc. +# +# All Rights Reserved. +# +########################################################################## +#___INFO__MARK_END__ + +# +# + +# ------------------------------------------- +# -- use Bourne shell -- +#$ -S /bin/sh +# -- our name -- +#$ -N PMiniWorm +# ------------------------------------------- +# -- send mail if the job exits abnormally -- +#$ -m a +# ------------------------------------------- +# -- What to redirect to where -- +#$ -e /dev/null +#$ -o /dev/null + +QSUB=$SGE_ROOT/bin/$ARC/qsub +SLEEP=120 + +echo using $QSUB as qsub command + +if [ "$1" = "" ]; then + arg=1 +else + arg=`expr $1 + 1` +fi +NAME=W$arch$arg + +# started by SGE or manually +if [ "$JOB_ID" = "" ]; then + echo "submitting $NAME" +else + sleep $SLEEP +fi + +# first try +# cmd="$QSUB -N $NAME -l arch=$arch $SGE_ROOT/examples/jobs/pminiworm.sh $arg" +cmd="$QSUB -N $NAME $SGE_ROOT/examples/jobs/pminiworm.sh $arg" +$cmd + +# repeat until success +while [ "x$?" != "x0" ]; do + echo "pminiworm.sh: qsub failed - retrying .." >&2 + sleep $SLEEP + $cmd +done diff --git a/examples/jobs/simple.sh b/examples/jobs/simple.sh new file mode 100755 index 0000000..fe0bbdd --- /dev/null +++ b/examples/jobs/simple.sh @@ -0,0 +1,47 @@ +#!/bin/sh +# +# +#___INFO__MARK_BEGIN__ +########################################################################## +# +# The Contents of this file are made available subject to the terms of +# the Sun Industry Standards Source License Version 1.2 +# +# Sun Microsystems Inc., March, 2001 +# +# +# Sun Industry Standards Source License Version 1.2 +# ================================================= +# The contents of this file are subject to the Sun Industry Standards +# Source License Version 1.2 (the "License"); You may not use this file +# except in compliance with the License. You may obtain a copy of the +# License at http://gridengine.sunsource.net/Gridengine_SISSL_license.html +# +# Software provided under this License is provided on an "AS IS" basis, +# WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, +# WITHOUT LIMITATION, WARRANTIES THAT THE SOFTWARE IS FREE OF DEFECTS, +# MERCHANTABLE, FIT FOR A PARTICULAR PURPOSE, OR NON-INFRINGING. +# See the License for the specific provisions governing your rights and +# obligations concerning the Software. +# +# The Initial Developer of the Original Code is: Sun Microsystems, Inc. +# +# Copyright: 2001 by Sun Microsystems, Inc. +# +# All Rights Reserved. +# +########################################################################## +#___INFO__MARK_END__ + +# This is a simple example of a SGE batch script + +# request Bourne shell as shell for job +#$ -S /bin/sh + +# +# print date and time +date +# Sleep for 20 seconds +sleep 20 +# print date and time again +date diff --git a/examples/jobs/simple_conda_test.sh b/examples/jobs/simple_conda_test.sh new file mode 120000 index 0000000..381e6fe --- /dev/null +++ b/examples/jobs/simple_conda_test.sh @@ -0,0 +1 @@ +../../local/examples/jobs/simple_conda_test.sh \ No newline at end of file diff --git a/examples/jobs/sleeper.sh b/examples/jobs/sleeper.sh new file mode 100755 index 0000000..1161c55 --- /dev/null +++ b/examples/jobs/sleeper.sh @@ -0,0 +1,63 @@ +#!/bin/sh +# +#___INFO__MARK_BEGIN__ +########################################################################## +# +# The Contents of this file are made available subject to the terms of +# the Sun Industry Standards Source License Version 1.2 +# +# Sun Microsystems Inc., March, 2001 +# +# +# Sun Industry Standards Source License Version 1.2 +# ================================================= +# The contents of this file are subject to the Sun Industry Standards +# Source License Version 1.2 (the "License"); You may not use this file +# except in compliance with the License. You may obtain a copy of the +# License at http://gridengine.sunsource.net/Gridengine_SISSL_license.html +# +# Software provided under this License is provided on an "AS IS" basis, +# WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, +# WITHOUT LIMITATION, WARRANTIES THAT THE SOFTWARE IS FREE OF DEFECTS, +# MERCHANTABLE, FIT FOR A PARTICULAR PURPOSE, OR NON-INFRINGING. +# See the License for the specific provisions governing your rights and +# obligations concerning the Software. +# +# The Initial Developer of the Original Code is: Sun Microsystems, Inc. +# +# Copyright: 2001 by Sun Microsystems, Inc. +# +# All Rights Reserved. +# +########################################################################## +#___INFO__MARK_END__ + +# +# Usage: sleeper.sh [time [do_echo]] +# default for time is 60 seconds +# default for do_echo is 1 (=true) +# + +# -- our name --- +#$ -N Sleeper +#$ -S /bin/sh + + +time=60 +do_echo=1 +if [ $# -ge 1 ]; then + time=$1 +fi +if [ $# -ge 2 ]; then + do_echo=$2 +fi + +if [ $do_echo -ne 0 ]; then + /bin/echo Here I am: `hostname`. Sleeping now at: `date` +fi + +sleep $time + +if [ $do_echo -ne 0 ]; then + echo Now it is: `date` +fi diff --git a/examples/jobs/ssession.sh b/examples/jobs/ssession.sh new file mode 100755 index 0000000..c755474 --- /dev/null +++ b/examples/jobs/ssession.sh @@ -0,0 +1,187 @@ +#!/bin/sh +#$ -S /bin/sh +#$ -pe make 1 +#$ -N SSession +#$ -v PATH + +#___INFO__MARK_BEGIN__ +########################################################################## +# +# The Contents of this file are made available subject to the terms of +# the Sun Industry Standards Source License Version 1.2 +# +# Sun Microsystems Inc., March, 2001 +# +# +# Sun Industry Standards Source License Version 1.2 +# ================================================= +# The contents of this file are subject to the Sun Industry Standards +# Source License Version 1.2 (the "License"); You may not use this file +# except in compliance with the License. You may obtain a copy of the +# License at http://gridengine.sunsource.net/Gridengine_SISSL_license.html +# +# Software provided under this License is provided on an "AS IS" basis, +# WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, +# WITHOUT LIMITATION, WARRANTIES THAT THE SOFTWARE IS FREE OF DEFECTS, +# MERCHANTABLE, FIT FOR A PARTICULAR PURPOSE, OR NON-INFRINGING. +# See the License for the specific provisions governing your rights and +# obligations concerning the Software. +# +# The Initial Developer of the Original Code is: Sun Microsystems, Inc. +# +# Copyright: 2009 by Sun Microsystems, Inc. +# +# All Rights Reserved. +# +########################################################################## +#___INFO__MARK_END__ + + +ARCH=`$SGE_ROOT/util/arch` +ECHO="$SGE_ROOT/utilbin/$ARCH/echo_raw -e" + +ssession_logging_enabled="false" # is logging enabled? +ssession_logfile="/tmp/ssession.log" # logfile +tfile="taskfile.txt" # default taskfile name if not other specified +mfile="" # makefile name +isource="tfile" # type of onput "tfile" or "mfile" + +ssession_show_usage() +{ + echo "usage: ssession [ taskfile | -mf makefile ]" + echo + echo " If there is neither a taskfile nor a makefile specified then" + echo " this script assumes that there is taskfile named taskfile.txt" + echo " in the current working directory." + echo + echo " taskfile - taskfile containing the tasks to be executed in the session" + echo " makefile - makefile containing the tasks an depedency definition" +} + +# add start rule to makefile +ssession_makefile_add_all() +{ + taskfile=$1 + makefile=$2 + + start="all:" + line_i=1 + max=`wc -l $taskfile|cut -c 1-8` + while [ $line_i -le $max ]; do + line=`head -$line_i $taskfile | tail -1` + + start=`echo $start task${line_i}` + line_i=`expr $line_i + 1` + done + + echo $start >>$makefile + echo "" >>$makefile + + unset makefile + unset start + unset line_i +} + +# add one rule for each task in taskfile +ssession_makefile_add_task() +{ + taskfile=$1 + makefile=$2 + + line_i=1 + max_lines=`wc -l $taskfile|cut -c 1-8` + while [ $line_i -le $max_lines ]; do + command=`head -$line_i $taskfile | tail -1` + + echo "task${line_i}:" >>$makefile + $ECHO "\t${command}" >>$makefile + echo "" >>$makefile + line_i=`expr $line_i + 1` + done + + unset max_lines + unset taskfile + unset makefile + unset line_i +} + +# create the makefile +ssession_makefile_create() +{ + makefile=$1 + + if [ -f $makefile ]; then + rm -f $makefile + echo rm + fi + touch $makefile + + unset makefile +} + +# destroy the taskfile +ssession_makefile_destroy() +{ + makefile=$1 + +# rm -f $makefile + unset makefile +} + +# start a qmake job that executes tasks in taskfile +ssession_start_qmake() +{ + makefile=$1 + + qmake -inherit -- -f $makefile +} + +ssession_log() +{ + if [ $ssession_logging_enabled = true ]; then + echo "$@" >>$ssession_logfile + fi +} + +if [ $# = 1 ]; then + if [ -f "$1" ]; then + tfile="$1" + else + ssession_show_usage + exit + fi +elif [ $# = 2 ]; then + if [ "$1" = "-mf" ]; then + mfile="$2" + isource="mfile" + else + ssession_show_usage + exit + fi +else + tfile="taskfile.txt" +fi + +if [ "$mfile" = "" ]; then + if [ -d "$TMPDIR" ]; then + mfile="${TMPDIR}/Makefile.$$" + else + mfile="/tmp/Makefile.$$" + fi +fi + +if [ "$isource" = "tfile" ]; then + ssession_log "Using taskfile \"$tfile\"" + ssession_log "Creating makefile \"$mfile\"" + + ssession_makefile_create $mfile + ssession_makefile_add_all $tfile $mfile + ssession_makefile_add_task $tfile $mfile + ssession_start_qmake $mfile + ssession_makefile_destroy $mfile +else + ssession_log "Using makefile \"$mfile\"" + + ssession_start_qmake $mfile +fi + diff --git a/examples/jobs/step_A_array_submitter.sh b/examples/jobs/step_A_array_submitter.sh new file mode 100755 index 0000000..74e9685 --- /dev/null +++ b/examples/jobs/step_A_array_submitter.sh @@ -0,0 +1,47 @@ +#!/bin/sh +# +# +#___INFO__MARK_BEGIN__ +########################################################################## +# +# The Contents of this file are made available subject to the terms of +# the Sun Industry Standards Source License Version 1.2 +# +# Sun Microsystems Inc., March, 2001 +# +# +# Sun Industry Standards Source License Version 1.2 +# ================================================= +# The contents of this file are subject to the Sun Industry Standards +# Source License Version 1.2 (the "License"); You may not use this file +# except in compliance with the License. You may obtain a copy of the +# License at http://gridengine.sunsource.net/Gridengine_SISSL_license.html +# +# Software provided under this License is provided on an "AS IS" basis, +# WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, +# WITHOUT LIMITATION, WARRANTIES THAT THE SOFTWARE IS FREE OF DEFECTS, +# MERCHANTABLE, FIT FOR A PARTICULAR PURPOSE, OR NON-INFRINGING. +# See the License for the specific provisions governing your rights and +# obligations concerning the Software. +# +# The Initial Developer of the Original Code is: Sun Microsystems, Inc. +# +# Copyright: 2001 by Sun Microsystems, Inc. +# +# All Rights Reserved. +# +########################################################################## +#___INFO__MARK_END__ + +# request "/bin/sh" as shell for job +#$ -S /bin/sh + +QSTAT=$SGE_ROOT/bin/$ARC/qstat +QALTER=$SGE_ROOT/bin/$ARC/qalter + +# find out successor jobid +# must be set by submission script +successor=`$QSTAT -j $JOB_ID | grep context |cut -f2 -d=` + +# release appropriate succesor task +$QALTER -h U $successor.$SGE_TASK_ID diff --git a/examples/jobs/step_B_array_submitter.sh b/examples/jobs/step_B_array_submitter.sh new file mode 100755 index 0000000..53c9d46 --- /dev/null +++ b/examples/jobs/step_B_array_submitter.sh @@ -0,0 +1,39 @@ +#!/bin/sh +# +# +#___INFO__MARK_BEGIN__ +########################################################################## +# +# The Contents of this file are made available subject to the terms of +# the Sun Industry Standards Source License Version 1.2 +# +# Sun Microsystems Inc., March, 2001 +# +# +# Sun Industry Standards Source License Version 1.2 +# ================================================= +# The contents of this file are subject to the Sun Industry Standards +# Source License Version 1.2 (the "License"); You may not use this file +# except in compliance with the License. You may obtain a copy of the +# License at http://gridengine.sunsource.net/Gridengine_SISSL_license.html +# +# Software provided under this License is provided on an "AS IS" basis, +# WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, +# WITHOUT LIMITATION, WARRANTIES THAT THE SOFTWARE IS FREE OF DEFECTS, +# MERCHANTABLE, FIT FOR A PARTICULAR PURPOSE, OR NON-INFRINGING. +# See the License for the specific provisions governing your rights and +# obligations concerning the Software. +# +# The Initial Developer of the Original Code is: Sun Microsystems, Inc. +# +# Copyright: 2001 by Sun Microsystems, Inc. +# +# All Rights Reserved. +# +########################################################################## +#___INFO__MARK_END__ + +# request "/bin/sh" as shell for job +#$ -S /bin/sh + +echo $JOB_ID.$SGE_TASK_ID diff --git a/examples/jobsbin/.gitkeep b/examples/jobsbin/.gitkeep new file mode 100644 index 0000000..e69de29