[12] | 1 | /* $Id$ */ |
---|
[1] | 2 | /* |
---|
[81] | 3 | * PSNC DRMAA 2.0 for Torque/PBS Pro |
---|
| 4 | * Copyright (C) 2012 Poznan Supercomputing and Networking Center |
---|
[1] | 5 | * |
---|
| 6 | * This program is free software: you can redistribute it and/or modify |
---|
| 7 | * it under the terms of the GNU General Public License as published by |
---|
| 8 | * the Free Software Foundation, either version 3 of the License, or |
---|
| 9 | * (at your option) any later version. |
---|
| 10 | * |
---|
| 11 | * This program is distributed in the hope that it will be useful, |
---|
| 12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
---|
| 13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
---|
| 14 | * GNU General Public License for more details. |
---|
| 15 | * |
---|
| 16 | * You should have received a copy of the GNU General Public License |
---|
| 17 | * along with this program. If not, see <http://www.gnu.org/licenses/>. |
---|
| 18 | */ |
---|
| 19 | |
---|
| 20 | #ifdef HAVE_CONFIG_H |
---|
| 21 | # include <config.h> |
---|
| 22 | #endif |
---|
| 23 | |
---|
| 24 | #include <drmaa_utils/drmaa_base.h> |
---|
| 25 | |
---|
| 26 | |
---|
[81] | 27 | |
---|
| 28 | #if 0 |
---|
[1] | 29 | static fsd_drmaa_session_t * |
---|
| 30 | pbsdrmaa_new_session( fsd_drmaa_singletone_t *self, const char *contact ) |
---|
| 31 | { |
---|
| 32 | return pbsdrmaa_session_new( contact ); |
---|
| 33 | } |
---|
| 34 | |
---|
| 35 | static fsd_template_t * |
---|
| 36 | pbsdrmaa_new_job_template( fsd_drmaa_singletone_t *self ) |
---|
| 37 | { |
---|
| 38 | return drmaa_template_new(); |
---|
| 39 | } |
---|
| 40 | |
---|
| 41 | static const char * |
---|
| 42 | pbsdrmaa_get_contact( fsd_drmaa_singletone_t *self ) |
---|
| 43 | { |
---|
| 44 | const char *contact = NULL; |
---|
| 45 | fsd_mutex_lock( &self->session_mutex ); |
---|
| 46 | if( self->session ) |
---|
| 47 | contact = self->session->contact; |
---|
| 48 | if( contact == NULL ) |
---|
| 49 | contact = "localhost"; |
---|
| 50 | fsd_mutex_unlock( &self->session_mutex ); |
---|
| 51 | return contact; |
---|
| 52 | } |
---|
| 53 | |
---|
| 54 | static void |
---|
| 55 | pbsdrmaa_get_version( fsd_drmaa_singletone_t *self, |
---|
| 56 | unsigned *major, unsigned *minor ) |
---|
| 57 | { |
---|
| 58 | *major = 1; *minor = 0; |
---|
| 59 | } |
---|
| 60 | |
---|
| 61 | static const char * |
---|
| 62 | pbsdrmaa_get_DRM_system( fsd_drmaa_singletone_t *self ) |
---|
| 63 | { |
---|
| 64 | #ifdef PBS_PROFESSIONAL |
---|
| 65 | return "PBS Professional"; |
---|
| 66 | #else |
---|
| 67 | return "Torque"; |
---|
| 68 | #endif |
---|
| 69 | } |
---|
| 70 | |
---|
| 71 | static const char * |
---|
| 72 | pbsdrmaa_get_DRMAA_implementation( fsd_drmaa_singletone_t *self ) |
---|
| 73 | { |
---|
| 74 | return PACKAGE_NAME" v. "PACKAGE_VERSION |
---|
| 75 | " <http://sourceforge.net/projects/pbspro-drmaa/>"; |
---|
| 76 | } |
---|
| 77 | |
---|
| 78 | |
---|
| 79 | fsd_iter_t * |
---|
| 80 | pbsdrmaa_get_attribute_names( fsd_drmaa_singletone_t *self ) |
---|
| 81 | { |
---|
| 82 | static const char *attribute_names[] = { |
---|
| 83 | DRMAA_REMOTE_COMMAND, |
---|
| 84 | DRMAA_JS_STATE, |
---|
| 85 | DRMAA_WD, |
---|
| 86 | DRMAA_JOB_CATEGORY, |
---|
| 87 | DRMAA_NATIVE_SPECIFICATION, |
---|
| 88 | DRMAA_BLOCK_EMAIL, |
---|
| 89 | DRMAA_START_TIME, |
---|
| 90 | DRMAA_JOB_NAME, |
---|
| 91 | DRMAA_INPUT_PATH, |
---|
| 92 | DRMAA_OUTPUT_PATH, |
---|
| 93 | DRMAA_ERROR_PATH, |
---|
| 94 | DRMAA_JOIN_FILES, |
---|
| 95 | DRMAA_TRANSFER_FILES, |
---|
| 96 | DRMAA_WCT_HLIMIT, |
---|
| 97 | DRMAA_DURATION_HLIMIT, |
---|
| 98 | NULL |
---|
| 99 | }; |
---|
| 100 | return fsd_iter_new_const( attribute_names, -1 ); |
---|
| 101 | } |
---|
| 102 | |
---|
| 103 | fsd_iter_t * |
---|
| 104 | pbsdrmaa_get_vector_attribute_names( fsd_drmaa_singletone_t *self ) |
---|
| 105 | { |
---|
| 106 | static const char *attribute_names[] = { |
---|
| 107 | DRMAA_V_ARGV, |
---|
| 108 | DRMAA_V_ENV, |
---|
| 109 | DRMAA_V_EMAIL, |
---|
| 110 | NULL |
---|
| 111 | }; |
---|
| 112 | return fsd_iter_new_const( attribute_names, -1 ); |
---|
| 113 | } |
---|
| 114 | |
---|
| 115 | static int |
---|
| 116 | pbsdrmaa_wifexited( |
---|
| 117 | int *exited, int stat, |
---|
| 118 | char *error_diagnosis, size_t error_diag_len |
---|
| 119 | ) |
---|
| 120 | { |
---|
| 121 | *exited = (stat <= 125); |
---|
| 122 | return DRMAA_ERRNO_SUCCESS; |
---|
| 123 | } |
---|
| 124 | |
---|
| 125 | static int |
---|
| 126 | pbsdrmaa_wexitstatus( |
---|
| 127 | int *exit_status, int stat, |
---|
| 128 | char *error_diagnosis, size_t error_diag_len |
---|
| 129 | ) |
---|
| 130 | { |
---|
| 131 | *exit_status = stat & 0xff; |
---|
| 132 | return DRMAA_ERRNO_SUCCESS; |
---|
| 133 | } |
---|
| 134 | |
---|
| 135 | static int |
---|
| 136 | pbsdrmaa_wifsignaled( |
---|
| 137 | int *signaled, int stat, |
---|
| 138 | char *error_diagnosis, size_t error_diag_len |
---|
| 139 | ) |
---|
| 140 | { |
---|
| 141 | *signaled = (stat > 128 ); |
---|
| 142 | return DRMAA_ERRNO_SUCCESS; |
---|
| 143 | } |
---|
| 144 | |
---|
| 145 | static int |
---|
| 146 | pbsdrmaa_wtermsig( |
---|
| 147 | char *signal, size_t signal_len, int stat, |
---|
| 148 | char *error_diagnosis, size_t error_diag_len |
---|
| 149 | ) |
---|
| 150 | { |
---|
| 151 | int sig = stat & 0x7f; |
---|
| 152 | strlcpy( signal, fsd_strsignal(sig), signal_len ); |
---|
| 153 | return DRMAA_ERRNO_SUCCESS; |
---|
| 154 | } |
---|
| 155 | |
---|
| 156 | static int |
---|
| 157 | pbsdrmaa_wcoredump( |
---|
| 158 | int *core_dumped, int stat, |
---|
| 159 | char *error_diagnosis, size_t error_diag_len |
---|
| 160 | ) |
---|
| 161 | { |
---|
| 162 | *core_dumped = 0; |
---|
| 163 | return DRMAA_ERRNO_SUCCESS; |
---|
| 164 | } |
---|
| 165 | |
---|
| 166 | static int |
---|
| 167 | pbsdrmaa_wifaborted( |
---|
| 168 | int *aborted, int stat, |
---|
| 169 | char *error_diagnosis, size_t error_diag_len |
---|
| 170 | ) |
---|
| 171 | { |
---|
| 172 | fsd_log_debug(("wifaborted(%d)", stat)); |
---|
| 173 | |
---|
| 174 | if ( stat == -1 ) |
---|
| 175 | { |
---|
| 176 | *aborted = true; |
---|
| 177 | } |
---|
| 178 | else if ( stat <= 125 ) |
---|
| 179 | { |
---|
| 180 | *aborted = false; |
---|
| 181 | } |
---|
| 182 | else if ( stat == 126 || stat == 127 ) |
---|
| 183 | { |
---|
| 184 | *aborted = true; |
---|
| 185 | } |
---|
| 186 | else switch( stat & 0x7f ) |
---|
| 187 | { |
---|
| 188 | case SIGTERM: case SIGKILL: |
---|
| 189 | *aborted = true; |
---|
| 190 | break; |
---|
| 191 | default: |
---|
| 192 | *aborted = false; |
---|
| 193 | break; |
---|
| 194 | } |
---|
| 195 | return DRMAA_ERRNO_SUCCESS; |
---|
| 196 | } |
---|
| 197 | |
---|
| 198 | |
---|
| 199 | fsd_drmaa_singletone_t _fsd_drmaa_singletone = { |
---|
| 200 | NULL, |
---|
| 201 | FSD_MUTEX_INITIALIZER, |
---|
| 202 | |
---|
| 203 | pbsdrmaa_new_session, |
---|
| 204 | pbsdrmaa_new_job_template, |
---|
| 205 | |
---|
| 206 | pbsdrmaa_get_contact, |
---|
| 207 | pbsdrmaa_get_version, |
---|
| 208 | pbsdrmaa_get_DRM_system, |
---|
| 209 | pbsdrmaa_get_DRMAA_implementation, |
---|
| 210 | |
---|
| 211 | pbsdrmaa_get_attribute_names, |
---|
| 212 | pbsdrmaa_get_vector_attribute_names, |
---|
| 213 | |
---|
| 214 | pbsdrmaa_wifexited, |
---|
| 215 | pbsdrmaa_wexitstatus, |
---|
| 216 | pbsdrmaa_wifsignaled, |
---|
| 217 | pbsdrmaa_wtermsig, |
---|
| 218 | pbsdrmaa_wcoredump, |
---|
| 219 | pbsdrmaa_wifaborted |
---|
| 220 | }; |
---|
| 221 | |
---|
[81] | 222 | #endif |
---|