[1] | 1 | /* $Id: drmaa_base.c 2 2009-10-12 09:51:22Z mamonski $ */ |
---|
| 2 | /* |
---|
| 3 | * FedStage DRMAA utilities library |
---|
| 4 | * Copyright (C) 2006-2008 FedStage Systems |
---|
| 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 | /** |
---|
| 21 | * @file drmaa_base.c |
---|
| 22 | * DRM independant part of DRMAA library. |
---|
| 23 | */ |
---|
| 24 | |
---|
| 25 | #ifdef HAVE_CONFIG_H |
---|
| 26 | # include <config.h> |
---|
| 27 | #endif |
---|
| 28 | |
---|
| 29 | #include <stdlib.h> |
---|
| 30 | #include <string.h> |
---|
| 31 | |
---|
| 32 | #include <drmaa_utils/common.h> |
---|
| 33 | #include <drmaa_utils/conf.h> |
---|
| 34 | #include <drmaa_utils/drmaa_attrib.h> |
---|
| 35 | #include <drmaa_utils/drmaa_base.h> |
---|
| 36 | #include <drmaa_utils/drmaa_util.h> |
---|
| 37 | #include <drmaa_utils/iter.h> |
---|
| 38 | #include <drmaa_utils/job.h> |
---|
| 39 | #include <drmaa_utils/logging.h> |
---|
| 40 | #include <drmaa_utils/lookup3.h> |
---|
| 41 | #include <drmaa_utils/session.h> |
---|
| 42 | #include <drmaa_utils/template.h> |
---|
| 43 | #include <drmaa_utils/util.h> |
---|
| 44 | |
---|
| 45 | #ifndef lint |
---|
| 46 | static char rcsid[] |
---|
| 47 | # ifdef __GNUC__ |
---|
| 48 | __attribute__ ((unused)) |
---|
| 49 | # endif |
---|
| 50 | = "$Id: drmaa_base.c 2 2009-10-12 09:51:22Z mamonski $"; |
---|
| 51 | #endif |
---|
| 52 | |
---|
| 53 | |
---|
| 54 | #define DRMAA_API_BEGIN \ |
---|
| 55 | volatile int rc = -1; \ |
---|
| 56 | TRY \ |
---|
| 57 | { |
---|
| 58 | #define DRMAA_API_END \ |
---|
| 59 | rc = DRMAA_ERRNO_SUCCESS; \ |
---|
| 60 | } \ |
---|
| 61 | EXCEPT_DEFAULT \ |
---|
| 62 | { \ |
---|
| 63 | const fsd_exc_t *e = fsd_exc_get(); \ |
---|
| 64 | rc = fsd_drmaa_code( e->code(e) ); \ |
---|
| 65 | strlcpy( error_diagnosis, FSD_SAFE_STR(e->message(e)), error_diag_len ); \ |
---|
| 66 | fsd_log_return(( "=%d: %s", rc, e->message(e) )); \ |
---|
| 67 | } \ |
---|
| 68 | END_TRY \ |
---|
| 69 | if( rc < 0 ) \ |
---|
| 70 | { \ |
---|
| 71 | rc = DRMAA_ERRNO_NO_MEMORY; \ |
---|
| 72 | strlcpy( error_diagnosis, drmaa_strerror(rc), error_diag_len ); \ |
---|
| 73 | } \ |
---|
| 74 | return rc; |
---|
| 75 | |
---|
| 76 | |
---|
| 77 | int |
---|
| 78 | drmaa_init( |
---|
| 79 | const char *contact, |
---|
| 80 | char *error_diagnosis, size_t error_diag_len |
---|
| 81 | ) |
---|
| 82 | { |
---|
| 83 | DRMAA_API_BEGIN |
---|
| 84 | fsd_drmaa_singletone_t *global = &_fsd_drmaa_singletone; |
---|
| 85 | fsd_log_enter(( "(contact=%s)", contact )); |
---|
| 86 | |
---|
| 87 | fsd_mutex_lock( &global->session_mutex ); |
---|
| 88 | TRY |
---|
| 89 | { |
---|
| 90 | if( global->session != NULL ) |
---|
| 91 | fsd_exc_raise_code( FSD_DRMAA_ERRNO_ALREADY_ACTIVE_SESSION ); |
---|
| 92 | global->session = global->new_session( global, contact ); |
---|
| 93 | } |
---|
| 94 | FINALLY |
---|
| 95 | { fsd_mutex_unlock( &global->session_mutex ); } |
---|
| 96 | END_TRY |
---|
| 97 | |
---|
| 98 | fsd_log_return(( " =0" )); |
---|
| 99 | DRMAA_API_END |
---|
| 100 | } |
---|
| 101 | |
---|
| 102 | |
---|
| 103 | int |
---|
| 104 | drmaa_exit( char *error_diagnosis, size_t error_diag_len ) |
---|
| 105 | { |
---|
| 106 | DRMAA_API_BEGIN |
---|
| 107 | fsd_drmaa_singletone_t *global = &_fsd_drmaa_singletone; |
---|
| 108 | fsd_log_enter(( "()" )); |
---|
| 109 | |
---|
| 110 | fsd_mutex_lock( &global->session_mutex ); |
---|
| 111 | TRY |
---|
| 112 | { |
---|
| 113 | if( global->session != NULL ) |
---|
| 114 | { |
---|
| 115 | global->session->destroy( global->session ); |
---|
| 116 | global->session = NULL; |
---|
| 117 | } |
---|
| 118 | else |
---|
| 119 | { |
---|
| 120 | fsd_exc_raise_code( FSD_DRMAA_ERRNO_NO_ACTIVE_SESSION ); |
---|
| 121 | } |
---|
| 122 | } |
---|
| 123 | FINALLY |
---|
| 124 | { fsd_mutex_unlock( &global->session_mutex ); } |
---|
| 125 | END_TRY |
---|
| 126 | |
---|
| 127 | fsd_log_return(( " =0" )); |
---|
| 128 | DRMAA_API_END |
---|
| 129 | } |
---|
| 130 | |
---|
| 131 | |
---|
| 132 | int |
---|
| 133 | drmaa_allocate_job_template( |
---|
| 134 | drmaa_job_template_t **p_jt, |
---|
| 135 | char *error_diagnosis, size_t error_diag_len |
---|
| 136 | ) |
---|
| 137 | { |
---|
| 138 | DRMAA_API_BEGIN |
---|
| 139 | fsd_drmaa_singletone_t *global = &_fsd_drmaa_singletone; |
---|
| 140 | fsd_log_enter(("")); |
---|
| 141 | *p_jt = (drmaa_job_template_t*)global->new_job_template( global ); |
---|
| 142 | fsd_log_return(( " =0: jt=%p", (void*)*p_jt )); |
---|
| 143 | DRMAA_API_END |
---|
| 144 | } |
---|
| 145 | |
---|
| 146 | |
---|
| 147 | int |
---|
| 148 | drmaa_delete_job_template( |
---|
| 149 | drmaa_job_template_t *drmaa_jt, |
---|
| 150 | char *error_diagnosis, size_t error_diag_len |
---|
| 151 | ) |
---|
| 152 | { |
---|
| 153 | DRMAA_API_BEGIN |
---|
| 154 | fsd_template_t *jt = (fsd_template_t*)drmaa_jt; |
---|
| 155 | fsd_log_enter(( "(%p)", (void*)jt )); |
---|
| 156 | if( jt != NULL ) |
---|
| 157 | jt->destroy( jt ); |
---|
| 158 | fsd_log_return(( " =0" )); |
---|
| 159 | DRMAA_API_END |
---|
| 160 | } |
---|
| 161 | |
---|
| 162 | |
---|
| 163 | int |
---|
| 164 | drmaa_set_attribute( |
---|
| 165 | drmaa_job_template_t *drmaa_jt, |
---|
| 166 | const char *name, const char *value, |
---|
| 167 | char *error_diagnosis, size_t error_diag_len |
---|
| 168 | ) |
---|
| 169 | { |
---|
| 170 | DRMAA_API_BEGIN |
---|
| 171 | fsd_template_t *jt = (fsd_template_t*)drmaa_jt; |
---|
| 172 | fsd_log_enter(( "(jt=%p, name='%s', value='%s')", |
---|
| 173 | (void*)drmaa_jt, name, value )); |
---|
| 174 | if( jt != NULL && name != NULL ) |
---|
| 175 | jt->set_attr( jt, name, value ); |
---|
| 176 | else |
---|
| 177 | fsd_exc_raise_code( FSD_ERRNO_INVALID_ARGUMENT ); |
---|
| 178 | fsd_log_return(( " =0" )); |
---|
| 179 | DRMAA_API_END |
---|
| 180 | } |
---|
| 181 | |
---|
| 182 | |
---|
| 183 | int |
---|
| 184 | drmaa_get_attribute( |
---|
| 185 | drmaa_job_template_t *drmaa_jt, |
---|
| 186 | const char *name, char *value, size_t value_len, |
---|
| 187 | char *error_diagnosis, size_t error_diag_len |
---|
| 188 | ) |
---|
| 189 | { |
---|
| 190 | DRMAA_API_BEGIN |
---|
| 191 | fsd_template_t *jt = (fsd_template_t*)drmaa_jt; |
---|
| 192 | const char *v = NULL; |
---|
| 193 | fsd_log_enter(( "(jt=%p, name='%s')", (void*)drmaa_jt, name )); |
---|
| 194 | if( jt == NULL || name == NULL || value == NULL ) |
---|
| 195 | fsd_exc_raise_code( FSD_ERRNO_INVALID_ARGUMENT ); |
---|
| 196 | v = jt->get_attr( jt, name ); |
---|
| 197 | if( v == NULL ) |
---|
| 198 | v = ""; |
---|
| 199 | strlcpy( value, v, value_len ); |
---|
| 200 | fsd_log_return(( " =0: '%s'", value )); |
---|
| 201 | DRMAA_API_END |
---|
| 202 | } |
---|
| 203 | |
---|
| 204 | |
---|
| 205 | int |
---|
| 206 | drmaa_set_vector_attribute( |
---|
| 207 | drmaa_job_template_t *drmaa_jt, |
---|
| 208 | const char *name, const char *value[], |
---|
| 209 | char *error_diagnosis, size_t error_diag_len |
---|
| 210 | ) |
---|
| 211 | { |
---|
| 212 | DRMAA_API_BEGIN |
---|
| 213 | fsd_template_t *jt = (fsd_template_t*)drmaa_jt; |
---|
| 214 | fsd_log_enter(( "(jt=%p, name='%s', value=...)", |
---|
| 215 | (void*)drmaa_jt, name )); |
---|
| 216 | if( jt == NULL || name == NULL ) |
---|
| 217 | fsd_exc_raise_code( FSD_ERRNO_INVALID_ARGUMENT ); |
---|
| 218 | jt->set_v_attr( jt, name, value ); |
---|
| 219 | fsd_log_return(( " =0" )); |
---|
| 220 | DRMAA_API_END |
---|
| 221 | } |
---|
| 222 | |
---|
| 223 | |
---|
| 224 | int |
---|
| 225 | drmaa_get_vector_attribute( |
---|
| 226 | drmaa_job_template_t *drmaa_jt, |
---|
| 227 | const char *name, drmaa_attr_values_t **out_values, |
---|
| 228 | char *error_diagnosis, size_t error_diag_len |
---|
| 229 | ) |
---|
| 230 | { |
---|
| 231 | DRMAA_API_BEGIN |
---|
| 232 | fsd_template_t *jt = (fsd_template_t*)drmaa_jt; |
---|
| 233 | |
---|
| 234 | fsd_log_enter(( "(jt=%p, name='%s')", (void*)drmaa_jt, name )); |
---|
| 235 | if( jt == NULL || name == NULL || out_values == NULL ) |
---|
| 236 | fsd_exc_raise_code( FSD_ERRNO_INVALID_ARGUMENT ); |
---|
| 237 | *out_values = NULL; |
---|
| 238 | *out_values = (drmaa_attr_values_t*)fsd_iter_new( |
---|
| 239 | fsd_copy_vector( jt->get_v_attr( jt, name ) ), -1 ); |
---|
| 240 | fsd_log_return(( " =0" )); |
---|
| 241 | |
---|
| 242 | DRMAA_API_END |
---|
| 243 | } |
---|
| 244 | |
---|
| 245 | |
---|
| 246 | int |
---|
| 247 | drmaa_get_attribute_names( |
---|
| 248 | drmaa_attr_names_t **values, |
---|
| 249 | char *error_diagnosis, size_t error_diag_len ) |
---|
| 250 | { |
---|
| 251 | DRMAA_API_BEGIN |
---|
| 252 | fsd_drmaa_singletone_t *global = &_fsd_drmaa_singletone; |
---|
| 253 | *values = (drmaa_attr_names_t*)global->get_attribute_names( global ); |
---|
| 254 | DRMAA_API_END |
---|
| 255 | } |
---|
| 256 | |
---|
| 257 | |
---|
| 258 | int |
---|
| 259 | drmaa_get_vector_attribute_names( |
---|
| 260 | drmaa_attr_names_t **values, |
---|
| 261 | char *error_diagnosis, size_t error_diag_len ) |
---|
| 262 | { |
---|
| 263 | DRMAA_API_BEGIN |
---|
| 264 | fsd_drmaa_singletone_t *global = &_fsd_drmaa_singletone; |
---|
| 265 | *values = (drmaa_attr_names_t*)global->get_vector_attribute_names( global ); |
---|
| 266 | DRMAA_API_END |
---|
| 267 | } |
---|
| 268 | |
---|
| 269 | |
---|
| 270 | #define iter_function(name, type) \ |
---|
| 271 | int drmaa_get_next_##name( type *values, char *value, size_t value_len ) \ |
---|
| 272 | { \ |
---|
| 273 | char error_diagnosis[1]; \ |
---|
| 274 | size_t error_diag_len = sizeof(error_diagnosis); \ |
---|
| 275 | DRMAA_API_BEGIN \ |
---|
| 276 | fsd_iter_t *iter = (fsd_iter_t*)values; \ |
---|
| 277 | strlcpy( value, iter->next(iter), value_len ); \ |
---|
| 278 | DRMAA_API_END \ |
---|
| 279 | } \ |
---|
| 280 | int drmaa_get_num_##name##s( type *values, size_t *size ) \ |
---|
| 281 | { \ |
---|
| 282 | char error_diagnosis[1]; \ |
---|
| 283 | size_t error_diag_len = sizeof(error_diagnosis); \ |
---|
| 284 | DRMAA_API_BEGIN \ |
---|
| 285 | fsd_iter_t *iter = (fsd_iter_t*)values; \ |
---|
| 286 | *size = iter->len(iter); \ |
---|
| 287 | DRMAA_API_END \ |
---|
| 288 | } \ |
---|
| 289 | void drmaa_release_##name##s( type *values ) \ |
---|
| 290 | { \ |
---|
| 291 | fsd_iter_t *iter = (fsd_iter_t*)values; \ |
---|
| 292 | iter->destroy(iter); \ |
---|
| 293 | } |
---|
| 294 | |
---|
| 295 | iter_function(attr_name, drmaa_attr_names_t) |
---|
| 296 | iter_function(attr_value, drmaa_attr_values_t) |
---|
| 297 | iter_function(job_id, drmaa_job_ids_t) |
---|
| 298 | |
---|
| 299 | #undef iter_function |
---|
| 300 | |
---|
| 301 | |
---|
| 302 | int |
---|
| 303 | drmaa_control( |
---|
| 304 | const char *job_id, int action, |
---|
| 305 | char *error_diagnosis, size_t error_diag_len |
---|
| 306 | ) |
---|
| 307 | { |
---|
| 308 | DRMAA_API_BEGIN |
---|
| 309 | fsd_drmaa_session_t *volatile session = NULL; |
---|
| 310 | |
---|
| 311 | fsd_log_enter(( "(job_id=%s, action=%s)", |
---|
| 312 | job_id, drmaa_control_to_str(action) )); |
---|
| 313 | |
---|
| 314 | if( job_id == NULL ) |
---|
| 315 | fsd_exc_raise_code( FSD_ERRNO_INVALID_ARGUMENT ); |
---|
| 316 | |
---|
| 317 | TRY |
---|
| 318 | { |
---|
| 319 | session = fsd_drmaa_session_get(); |
---|
| 320 | session->control_job( session, job_id, action ); |
---|
| 321 | } |
---|
| 322 | FINALLY |
---|
| 323 | { |
---|
| 324 | if( session ) |
---|
| 325 | session->release( session ); |
---|
| 326 | } |
---|
| 327 | END_TRY |
---|
| 328 | |
---|
| 329 | fsd_log_return(( " =0" )); |
---|
| 330 | DRMAA_API_END |
---|
| 331 | } |
---|
| 332 | |
---|
| 333 | |
---|
| 334 | |
---|
| 335 | int |
---|
| 336 | drmaa_job_ps( |
---|
| 337 | const char *job_id, int *remote_ps, |
---|
| 338 | char *error_diagnosis, size_t error_diag_len |
---|
| 339 | ) |
---|
| 340 | { |
---|
| 341 | DRMAA_API_BEGIN |
---|
| 342 | fsd_drmaa_session_t *volatile session = NULL; |
---|
| 343 | |
---|
| 344 | fsd_log_enter(( "(job_id=%s)", job_id )); |
---|
| 345 | if( job_id == NULL ) |
---|
| 346 | fsd_exc_raise_code( FSD_ERRNO_INVALID_ARGUMENT ); |
---|
| 347 | |
---|
| 348 | TRY |
---|
| 349 | { |
---|
| 350 | session = fsd_drmaa_session_get(); |
---|
| 351 | session->job_ps( session, job_id, remote_ps ); |
---|
| 352 | } |
---|
| 353 | FINALLY |
---|
| 354 | { |
---|
| 355 | if( session ) |
---|
| 356 | session->release( session ); |
---|
| 357 | } |
---|
| 358 | END_TRY |
---|
| 359 | |
---|
| 360 | fsd_log_return(( "(job_id=%s) =0: remote_ps=%s (0x%02x)", |
---|
| 361 | job_id, drmaa_job_ps_to_str(*remote_ps), *remote_ps )); |
---|
| 362 | DRMAA_API_END |
---|
| 363 | } |
---|
| 364 | |
---|
| 365 | |
---|
| 366 | |
---|
| 367 | int |
---|
| 368 | drmaa_run_job( |
---|
| 369 | char *job_id, size_t job_id_len, |
---|
| 370 | const drmaa_job_template_t *jt, |
---|
| 371 | char *error_diagnosis, size_t error_diag_len |
---|
| 372 | ) |
---|
| 373 | { |
---|
| 374 | DRMAA_API_BEGIN |
---|
| 375 | fsd_drmaa_session_t *volatile session = NULL; |
---|
| 376 | char *volatile job_id_buf = NULL; |
---|
| 377 | fsd_log_enter(( "(jt=%p)", (void*)jt )); |
---|
| 378 | TRY |
---|
| 379 | { |
---|
| 380 | session = fsd_drmaa_session_get(); |
---|
| 381 | job_id_buf = session->run_job( session, (fsd_template_t*)jt ), |
---|
| 382 | strlcpy( job_id, job_id_buf, job_id_len ); |
---|
| 383 | } |
---|
| 384 | FINALLY |
---|
| 385 | { |
---|
| 386 | if( session ) |
---|
| 387 | session->release( session ); |
---|
| 388 | fsd_free( job_id_buf ); |
---|
| 389 | } |
---|
| 390 | END_TRY |
---|
| 391 | |
---|
| 392 | fsd_log_return(( " =0: job_id=%s", job_id )); |
---|
| 393 | DRMAA_API_END |
---|
| 394 | } |
---|
| 395 | |
---|
| 396 | |
---|
| 397 | int |
---|
| 398 | drmaa_run_bulk_jobs( |
---|
| 399 | drmaa_job_ids_t **job_ids, |
---|
| 400 | const drmaa_job_template_t *jt, |
---|
| 401 | int start, int end, int incr, |
---|
| 402 | char *error_diagnosis, size_t error_diag_len |
---|
| 403 | ) |
---|
| 404 | { |
---|
| 405 | DRMAA_API_BEGIN |
---|
| 406 | fsd_drmaa_session_t *volatile session = NULL; |
---|
| 407 | fsd_log_enter(( "(jt=%p, start=%d, end=%d, incr=%d)", |
---|
| 408 | (void*)jt, start, end, incr )); |
---|
| 409 | TRY |
---|
| 410 | { |
---|
| 411 | if( incr > 0 ) |
---|
| 412 | { |
---|
| 413 | if( !(0 < start && start <= end) ) |
---|
| 414 | fsd_exc_raise_code( FSD_ERRNO_INVALID_ARGUMENT ); |
---|
| 415 | } |
---|
| 416 | else if( incr < 0 ) |
---|
| 417 | { |
---|
| 418 | if( !(start >= end && end > 0) ) |
---|
| 419 | fsd_exc_raise_code( FSD_ERRNO_INVALID_ARGUMENT ); |
---|
| 420 | } |
---|
| 421 | else |
---|
| 422 | fsd_exc_raise_code( FSD_ERRNO_INVALID_ARGUMENT ); |
---|
| 423 | |
---|
| 424 | session = fsd_drmaa_session_get(); |
---|
| 425 | *job_ids = (drmaa_job_ids_t*)session->run_bulk( |
---|
| 426 | session, (fsd_template_t*)jt, |
---|
| 427 | start, end, incr |
---|
| 428 | ); |
---|
| 429 | } |
---|
| 430 | EXCEPT_DEFAULT |
---|
| 431 | { |
---|
| 432 | *job_ids = NULL; |
---|
| 433 | fsd_exc_reraise(); |
---|
| 434 | } |
---|
| 435 | FINALLY |
---|
| 436 | { |
---|
| 437 | if( session ) |
---|
| 438 | session->release( session ); |
---|
| 439 | } |
---|
| 440 | END_TRY |
---|
| 441 | fsd_log_return(( " =0" )); |
---|
| 442 | DRMAA_API_END |
---|
| 443 | } |
---|
| 444 | |
---|
| 445 | |
---|
| 446 | |
---|
| 447 | static struct timespec * |
---|
| 448 | drmaa_timeout_time( signed long timeout, struct timespec *ts ) |
---|
| 449 | { |
---|
| 450 | if( timeout == DRMAA_TIMEOUT_WAIT_FOREVER ) |
---|
| 451 | return NULL; |
---|
| 452 | else |
---|
| 453 | { |
---|
| 454 | fsd_get_time( ts ); |
---|
| 455 | if( timeout != DRMAA_TIMEOUT_NO_WAIT ) |
---|
| 456 | ts->tv_sec += timeout; |
---|
| 457 | return ts; |
---|
| 458 | } |
---|
| 459 | } |
---|
| 460 | |
---|
| 461 | |
---|
| 462 | int |
---|
| 463 | drmaa_synchronize( |
---|
| 464 | const char **job_ids, signed long timeout, |
---|
| 465 | int dispose, |
---|
| 466 | char *error_diagnosis, size_t error_diag_len |
---|
| 467 | ) |
---|
| 468 | { |
---|
| 469 | DRMAA_API_BEGIN |
---|
| 470 | fsd_drmaa_session_t *volatile session = NULL; |
---|
| 471 | struct timespec ts; |
---|
| 472 | |
---|
| 473 | fsd_log_enter(( "(job_ids={...}, timeout=%ld, dispose=%d)", |
---|
| 474 | timeout, dispose )); |
---|
| 475 | |
---|
| 476 | if( job_ids == NULL ) |
---|
| 477 | fsd_exc_raise_code( FSD_ERRNO_INVALID_ARGUMENT ); |
---|
| 478 | |
---|
| 479 | TRY |
---|
| 480 | { |
---|
| 481 | session = fsd_drmaa_session_get(); |
---|
| 482 | session->synchronize( session, job_ids, |
---|
| 483 | drmaa_timeout_time(timeout, &ts), dispose ); |
---|
| 484 | } |
---|
| 485 | FINALLY |
---|
| 486 | { |
---|
| 487 | if( session ) |
---|
| 488 | session->release( session ); |
---|
| 489 | } |
---|
| 490 | END_TRY |
---|
| 491 | |
---|
| 492 | fsd_log_return(( " =0" )); |
---|
| 493 | DRMAA_API_END |
---|
| 494 | } |
---|
| 495 | |
---|
| 496 | |
---|
| 497 | int |
---|
| 498 | drmaa_wait( |
---|
| 499 | const char *job_id, char *job_id_out, size_t job_id_out_len, |
---|
| 500 | int *stat, signed long timeout, drmaa_attr_values_t **rusage, |
---|
| 501 | char *error_diagnosis, size_t error_diag_len |
---|
| 502 | ) |
---|
| 503 | { |
---|
| 504 | DRMAA_API_BEGIN |
---|
| 505 | fsd_drmaa_session_t *volatile session = NULL; |
---|
| 506 | struct timespec ts; |
---|
| 507 | char *result_job_id = NULL; |
---|
| 508 | |
---|
| 509 | fsd_log_enter(( "(job_id=%s, timeout=%ld)", job_id, timeout )); |
---|
| 510 | |
---|
| 511 | TRY |
---|
| 512 | { |
---|
| 513 | session = fsd_drmaa_session_get(); |
---|
| 514 | result_job_id = session->wait( |
---|
| 515 | session, job_id, drmaa_timeout_time(timeout, &ts), |
---|
| 516 | stat, (fsd_iter_t**)rusage |
---|
| 517 | ); |
---|
| 518 | strlcpy( job_id_out, result_job_id, job_id_out_len ); |
---|
| 519 | } |
---|
| 520 | FINALLY |
---|
| 521 | { |
---|
| 522 | fsd_free( result_job_id ); |
---|
| 523 | if( session ) |
---|
| 524 | session->release( session ); |
---|
| 525 | } |
---|
| 526 | END_TRY |
---|
| 527 | |
---|
| 528 | fsd_log_return(( " =0: job_id=%s", job_id_out )); |
---|
| 529 | DRMAA_API_END |
---|
| 530 | } |
---|
| 531 | |
---|
| 532 | |
---|
| 533 | #if 0 |
---|
| 534 | int |
---|
| 535 | drmaa_get_contact( |
---|
| 536 | char *contact, size_t contact_len, |
---|
| 537 | char *error_diagnosis, size_t error_diag_len |
---|
| 538 | ) |
---|
| 539 | { |
---|
| 540 | DRMAA_API_BEGIN |
---|
| 541 | drmaa_session_t *volatile session = NULL; |
---|
| 542 | const drmaa_implementation_info_t *impl_info = NULL; |
---|
| 543 | const char *result = NULL; |
---|
| 544 | |
---|
| 545 | impl_info = drmaa_get_implementation_info(); |
---|
| 546 | TRY |
---|
| 547 | { |
---|
| 548 | session = drmaa_session_get(); |
---|
| 549 | if( session->contact ) |
---|
| 550 | result = session->contact; |
---|
| 551 | else |
---|
| 552 | result = impl_info->default_contact; |
---|
| 553 | strlcpy( contact, result, contact_len ); |
---|
| 554 | } |
---|
| 555 | EXCEPT( FSD_DRMAA_ERRNO_NO_ACTIVE_SESSION ) |
---|
| 556 | { |
---|
| 557 | result = impl_info->default_contact; |
---|
| 558 | strlcpy( contact, result, contact_len ); |
---|
| 559 | } |
---|
| 560 | FINALLY |
---|
| 561 | { |
---|
| 562 | drmaa_session_release( session ); |
---|
| 563 | } |
---|
| 564 | END_TRY |
---|
| 565 | |
---|
| 566 | DRMAA_API_END |
---|
| 567 | } |
---|
| 568 | #endif |
---|
| 569 | |
---|
| 570 | |
---|
| 571 | int |
---|
| 572 | drmaa_get_contact( |
---|
| 573 | char *contact, size_t contact_len, |
---|
| 574 | char *error_diagnosis, size_t error_diag_len |
---|
| 575 | ) |
---|
| 576 | { |
---|
| 577 | DRMAA_API_BEGIN |
---|
| 578 | fsd_drmaa_singletone_t *global = &_fsd_drmaa_singletone; |
---|
| 579 | fsd_log_enter(( "" )); |
---|
| 580 | strlcpy( contact, global->get_contact( global ), contact_len ); |
---|
| 581 | fsd_log_return(( " =0: %s", contact )); |
---|
| 582 | DRMAA_API_END |
---|
| 583 | } |
---|
| 584 | |
---|
| 585 | |
---|
| 586 | int |
---|
| 587 | drmaa_version( |
---|
| 588 | unsigned int *major, unsigned int *minor, |
---|
| 589 | char *error_diagnosis, size_t error_diag_len |
---|
| 590 | ) |
---|
| 591 | { |
---|
| 592 | DRMAA_API_BEGIN |
---|
| 593 | fsd_drmaa_singletone_t *global = &_fsd_drmaa_singletone; |
---|
| 594 | fsd_log_enter(( "" )); |
---|
| 595 | global->get_version( global, major, minor ); |
---|
| 596 | fsd_log_return(( " =0: %d.%d", *major, *minor )); |
---|
| 597 | DRMAA_API_END |
---|
| 598 | } |
---|
| 599 | |
---|
| 600 | |
---|
| 601 | int |
---|
| 602 | drmaa_get_DRM_system( |
---|
| 603 | char *drm_system, size_t drm_system_len, |
---|
| 604 | char *error_diagnosis, size_t error_diag_len |
---|
| 605 | ) |
---|
| 606 | { |
---|
| 607 | DRMAA_API_BEGIN |
---|
| 608 | fsd_drmaa_singletone_t *global = &_fsd_drmaa_singletone; |
---|
| 609 | fsd_log_enter(( "" )); |
---|
| 610 | strlcpy( drm_system, global->get_DRM_system( global ), drm_system_len ); |
---|
| 611 | fsd_log_return(( " =0: %s", drm_system )); |
---|
| 612 | DRMAA_API_END |
---|
| 613 | } |
---|
| 614 | |
---|
| 615 | |
---|
| 616 | int |
---|
| 617 | drmaa_get_DRMAA_implementation( |
---|
| 618 | char *drmaa_impl, size_t drmaa_impl_len, |
---|
| 619 | char *error_diagnosis, size_t error_diag_len |
---|
| 620 | ) |
---|
| 621 | { |
---|
| 622 | DRMAA_API_BEGIN |
---|
| 623 | fsd_drmaa_singletone_t *global = &_fsd_drmaa_singletone; |
---|
| 624 | fsd_log_enter(( "" )); |
---|
| 625 | strlcpy( drmaa_impl, global->get_DRMAA_implementation( global ), |
---|
| 626 | drmaa_impl_len ); |
---|
| 627 | fsd_log_return(( " =0: %s", drmaa_impl )); |
---|
| 628 | DRMAA_API_END |
---|
| 629 | } |
---|
| 630 | |
---|
| 631 | |
---|
| 632 | const char * |
---|
| 633 | drmaa_strerror( int drmaa_errno ) |
---|
| 634 | { |
---|
| 635 | return fsd_drmaa_strerror( drmaa_errno ); |
---|
| 636 | } |
---|
| 637 | |
---|
| 638 | |
---|
| 639 | int |
---|
| 640 | drmaa_read_configuration_file( |
---|
| 641 | const char *filename, int must_exist, |
---|
| 642 | char *error_diagnosis, size_t error_diag_len |
---|
| 643 | ) |
---|
| 644 | { |
---|
| 645 | fsd_drmaa_session_t *volatile session = NULL; |
---|
| 646 | |
---|
| 647 | DRMAA_API_BEGIN |
---|
| 648 | fsd_log_enter(( "(filename=%s)", filename )); |
---|
| 649 | TRY |
---|
| 650 | { |
---|
| 651 | session = fsd_drmaa_session_get(); |
---|
| 652 | session->read_configuration( |
---|
| 653 | session, filename, must_exist, NULL, 0 ); |
---|
| 654 | } |
---|
| 655 | FINALLY |
---|
| 656 | { |
---|
| 657 | if( session ) |
---|
| 658 | session->release( session ); |
---|
| 659 | } |
---|
| 660 | END_TRY |
---|
| 661 | |
---|
| 662 | fsd_log_return(( " =0" )); |
---|
| 663 | DRMAA_API_END |
---|
| 664 | } |
---|
| 665 | |
---|
| 666 | |
---|
| 667 | int |
---|
| 668 | drmaa_read_configuration( |
---|
| 669 | const char *configuration, size_t configuration_len, |
---|
| 670 | char *error_diagnosis, size_t error_diag_len |
---|
| 671 | ) |
---|
| 672 | { |
---|
| 673 | DRMAA_API_BEGIN |
---|
| 674 | fsd_drmaa_session_t *volatile session = NULL; |
---|
| 675 | fsd_log_enter(( "(configuration=\"%.*s\")", |
---|
| 676 | (int)configuration_len, configuration )); |
---|
| 677 | TRY |
---|
| 678 | { |
---|
| 679 | session = fsd_drmaa_session_get(); |
---|
| 680 | session->read_configuration( |
---|
| 681 | session, NULL, false, configuration, configuration_len ); |
---|
| 682 | } |
---|
| 683 | FINALLY |
---|
| 684 | { |
---|
| 685 | if( session ) |
---|
| 686 | session->release( session ); |
---|
| 687 | } |
---|
| 688 | END_TRY |
---|
| 689 | fsd_log_return(( " =0" )); |
---|
| 690 | DRMAA_API_END |
---|
| 691 | } |
---|
| 692 | |
---|
| 693 | |
---|
| 694 | |
---|
| 695 | fsd_drmaa_session_t * |
---|
| 696 | fsd_drmaa_session_get(void) |
---|
| 697 | { |
---|
| 698 | fsd_drmaa_session_t *self = NULL; |
---|
| 699 | fsd_mutex_lock( &_fsd_drmaa_singletone.session_mutex ); |
---|
| 700 | self = _fsd_drmaa_singletone.session; |
---|
| 701 | fsd_mutex_unlock( &_fsd_drmaa_singletone.session_mutex ); |
---|
| 702 | if( self != NULL ) |
---|
| 703 | { |
---|
| 704 | fsd_mutex_lock( &self->mutex ); |
---|
| 705 | self->ref_cnt ++; |
---|
| 706 | fsd_mutex_unlock( &self->mutex ); |
---|
| 707 | } |
---|
| 708 | else |
---|
| 709 | fsd_exc_raise_code( FSD_DRMAA_ERRNO_NO_ACTIVE_SESSION ); |
---|
| 710 | return self; |
---|
| 711 | } |
---|
| 712 | |
---|
| 713 | |
---|
| 714 | #define wiffunc( name, args_decl, args_list ) \ |
---|
| 715 | int drmaa_##name args_decl \ |
---|
| 716 | { \ |
---|
| 717 | return _fsd_drmaa_singletone.name args_list;\ |
---|
| 718 | } |
---|
| 719 | |
---|
| 720 | wiffunc( |
---|
| 721 | wifexited, |
---|
| 722 | ( int *exited, int stat, char *error_diagnosis, size_t error_diag_len ), |
---|
| 723 | ( exited, stat, error_diagnosis, error_diag_len ) |
---|
| 724 | ) |
---|
| 725 | |
---|
| 726 | wiffunc( |
---|
| 727 | wexitstatus, |
---|
| 728 | ( int *exit_status, int stat, |
---|
| 729 | char *error_diagnosis, size_t error_diag_len ), |
---|
| 730 | ( exit_status, stat, error_diagnosis, error_diag_len ) |
---|
| 731 | ) |
---|
| 732 | |
---|
| 733 | wiffunc( |
---|
| 734 | wifsignaled, |
---|
| 735 | ( int *signaled, int stat, char *error_diagnosis, size_t error_diag_len ), |
---|
| 736 | ( signaled, stat, error_diagnosis, error_diag_len ) |
---|
| 737 | ) |
---|
| 738 | |
---|
| 739 | wiffunc( |
---|
| 740 | wtermsig, |
---|
| 741 | ( char *signal, size_t signal_len, int stat, |
---|
| 742 | char *error_diagnosis, size_t error_diag_len ), |
---|
| 743 | ( signal, signal_len, stat, error_diagnosis, error_diag_len ) |
---|
| 744 | ) |
---|
| 745 | |
---|
| 746 | wiffunc( |
---|
| 747 | wcoredump, |
---|
| 748 | ( int *core_dumped, int stat, |
---|
| 749 | char *error_diagnosis, size_t error_diag_len ), |
---|
| 750 | ( core_dumped, stat, error_diagnosis, error_diag_len ) |
---|
| 751 | ) |
---|
| 752 | |
---|
| 753 | wiffunc( |
---|
| 754 | wifaborted, |
---|
| 755 | ( int *aborted, int stat, char *error_diagnosis, size_t error_diag_len ), |
---|
| 756 | ( aborted, stat, error_diagnosis, error_diag_len ) |
---|
| 757 | ) |
---|
| 758 | |
---|