[51] | 1 | /* $Id: example.c 49 2011-12-08 07:36:40Z mmamonski $ */ |
---|
| 2 | /* |
---|
| 3 | * DRMAA library for Torque/PBS |
---|
| 4 | * Copyright (C) 2006-2007 |
---|
| 5 | * |
---|
| 6 | * FedStage Systems <http://www.fedstage.com/>, |
---|
| 7 | * Poznan Supercomputing and Networking Center <http://www.man.poznan.pl/>, |
---|
| 8 | * and the OpenDSP project <http://sourceforge.net/projects/opendsp/> |
---|
| 9 | * |
---|
| 10 | * This library is free software; you can redistribute it and/or |
---|
| 11 | * modify it under the terms of the GNU Lesser General Public |
---|
| 12 | * License as published by the Free Software Foundation; either |
---|
| 13 | * version 2.1 of the License, or (at your option) any later version. |
---|
| 14 | * |
---|
| 15 | * This library is distributed in the hope that it will be useful, |
---|
| 16 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
---|
| 17 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
---|
| 18 | * Lesser General Public License for more details. |
---|
| 19 | * |
---|
| 20 | * You should have received a copy of the GNU Lesser General Public |
---|
| 21 | * License along with this library; if not, write to the Free Software |
---|
| 22 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA |
---|
| 23 | */ |
---|
| 24 | /** |
---|
| 25 | * @file test.c |
---|
| 26 | * DRMAA library test / usage example. |
---|
| 27 | */ |
---|
| 28 | |
---|
| 29 | #include <drmaa.h> |
---|
| 30 | |
---|
| 31 | #include <unistd.h> |
---|
| 32 | #include <stdlib.h> |
---|
| 33 | #include <stdio.h> |
---|
| 34 | #include <string.h> |
---|
| 35 | #include <time.h> |
---|
| 36 | #include <limits.h> |
---|
| 37 | #include <errno.h> |
---|
| 38 | |
---|
| 39 | |
---|
| 40 | #define ERR_LEN DRMAA_ERROR_STRING_BUFFER |
---|
| 41 | #define JOB_ID_LEN 256 |
---|
| 42 | |
---|
| 43 | #define errno_error( func ) do{ \ |
---|
| 44 | fprintf( stderr, "%s:%d: %s: %s\n", \ |
---|
| 45 | __FILE__, __LINE__, func, strerror(errno) ); \ |
---|
| 46 | exit( 1 ); \ |
---|
| 47 | } while(0) |
---|
| 48 | |
---|
| 49 | #define drmaa_error( func ) do{ \ |
---|
| 50 | fprintf( stderr, "%s:%d: %s: %s\n> %s\n", \ |
---|
| 51 | __FILE__, __LINE__, func, \ |
---|
| 52 | drmaa_strerror(rc), err_msg ); \ |
---|
| 53 | exit(1); \ |
---|
| 54 | }while(0) |
---|
| 55 | |
---|
| 56 | void |
---|
| 57 | test_1(void); |
---|
| 58 | |
---|
| 59 | drmaa_job_template_t * |
---|
| 60 | construct_job( char *argv[], char *fds[3], const char *cwd ); |
---|
| 61 | |
---|
| 62 | void |
---|
| 63 | time_fmt( time_t t, char *buf, size_t buflen ); |
---|
| 64 | |
---|
| 65 | |
---|
| 66 | int |
---|
| 67 | main( int argc, char *argv[] ) |
---|
| 68 | { |
---|
| 69 | char err_msg[ ERR_LEN ] = ""; |
---|
| 70 | char job_id[128] = ""; |
---|
| 71 | drmaa_attr_values_t *rusage; |
---|
| 72 | int rc, stat; |
---|
| 73 | |
---|
| 74 | |
---|
| 75 | rc = drmaa_init( NULL, err_msg, ERR_LEN ); |
---|
| 76 | if( rc ) |
---|
| 77 | drmaa_error("drmaa_init"); |
---|
| 78 | |
---|
| 79 | rc = drmaa_wait( argv[1], job_id, sizeof(job_id), &stat, DRMAA_TIMEOUT_WAIT_FOREVER, &rusage, err_msg, ERR_LEN ); |
---|
| 80 | if( rc ) |
---|
| 81 | drmaa_error( "drmaa_job_wait" ); |
---|
| 82 | |
---|
| 83 | rc = drmaa_exit( err_msg, ERR_LEN ); |
---|
| 84 | if( rc ) |
---|
| 85 | drmaa_error("drmaa_exit"); |
---|
| 86 | |
---|
| 87 | printf( "stat=%d\n", stat ); |
---|
| 88 | |
---|
| 89 | return 0; |
---|
| 90 | } |
---|
| 91 | |
---|