diff --git a/slurm_drmaa/job.c b/slurm_drmaa/job.c index cf2d0ed..9ee0f91 100755 --- a/slurm_drmaa/job.c +++ b/slurm_drmaa/job.c @@ -665,6 +665,13 @@ slurmdrmaa_job_create( } } + /* set defaults for constraints - ref: slurm.h */ + fsd_log_debug(("# Setting defaults for tasks and processors" )); + job_desc->num_tasks = 1; + job_desc->min_cpus = 0; + job_desc->cpus_per_task = 0; + job_desc->pn_min_cpus = 0; + /* native specification */ value = jt->get_attr( jt, DRMAA_NATIVE_SPECIFICATION ); if( value ) @@ -673,6 +680,6 @@ slurmdrmaa_job_create( slurmdrmaa_parse_native(job_desc, value); } -} +} diff --git a/slurm_drmaa/session.c b/slurm_drmaa/session.c index d2d318e..86686ee 100755 --- a/slurm_drmaa/session.c +++ b/slurm_drmaa/session.c @@ -92,7 +92,7 @@ slurmdrmaa_session_run_bulk( { fsd_job_t *volatile job = NULL; char **volatile job_ids = NULL; - unsigned n_jobs = 0; + unsigned n_jobs = 1; volatile bool connection_lock = false; fsd_environ_t *volatile env = NULL; job_desc_msg_t job_desc; @@ -102,14 +102,11 @@ slurmdrmaa_session_run_bulk( { if( start != end ) - n_jobs = (end - start) / incr + 1; - else - n_jobs = 1; - - if( start != end ) { unsigned idx, i; + n_jobs = (end - start) / incr + 1; + fsd_calloc( job_ids, n_jobs+1, char* ); for( idx = start, i = 0; idx <= (unsigned)end; idx += incr, i++ ) @@ -124,7 +121,6 @@ slurmdrmaa_session_run_bulk( fsd_log_debug(("job %u submitted", submit_response->job_id)); connection_lock = fsd_mutex_unlock( &self->drm_connection_mutex ); - job_ids[i] = fsd_asprintf("%d",submit_response->job_id); /*TODO */ job = slurmdrmaa_job_new( fsd_strdup(job_ids[i]) ); @@ -139,7 +135,7 @@ slurmdrmaa_session_run_bulk( else /* ! bulk */ { fsd_calloc( job_ids, n_jobs+1, char* ); - + connection_lock = fsd_mutex_lock( &self->drm_connection_mutex ); slurmdrmaa_job_create_req( self, jt, (fsd_environ_t**)&env , &job_desc, 0); if(slurm_submit_batch_job(&job_desc,&submit_response)){ @@ -147,8 +143,9 @@ slurmdrmaa_session_run_bulk( FSD_ERRNO_INTERNAL_ERROR,"slurm_submit_batch_job: %s",slurm_strerror(slurm_get_errno())); } - fsd_log_debug(("job %u submitted", submit_response->job_id)); connection_lock = fsd_mutex_unlock( &self->drm_connection_mutex ); + + fsd_log_debug(("job %u submitted", submit_response->job_id)); job_ids[0] = fsd_asprintf( "%d", submit_response->job_id); /* .0*/ diff --git a/slurm_drmaa/util.c b/slurm_drmaa/util.c index b33f699..74c7ea6 100755 --- a/slurm_drmaa/util.c +++ b/slurm_drmaa/util.c @@ -117,6 +117,7 @@ enum slurm_native { SLURM_NATIVE_COMMENT, SLURM_NATIVE_CONSTRAINT, SLURM_NATIVE_CONTIGUOUS, + SLURM_NATIVE_CPUS_PER_TASK, SLURM_NATIVE_EXCLUSIVE, SLURM_NATIVE_MEM, SLURM_NATIVE_MEM_PER_CPU, @@ -210,6 +211,10 @@ slurmdrmaa_add_attribute(job_desc_msg_t *job_desc, unsigned attr, const char *va fsd_log_debug(( "# contiguous = 1")); job_desc->contiguous = 1; break; + case SLURM_NATIVE_CPUS_PER_TASK: + fsd_log_debug(( "# cpus_per_task = %s", value)); + job_desc->cpus_per_task = fsd_atoi(value); + break; case SLURM_NATIVE_EXCLUSIVE: fsd_log_debug(( "# exclusive -> shared = 0")); job_desc->shared = 0; @@ -251,8 +256,8 @@ slurmdrmaa_add_attribute(job_desc_msg_t *job_desc, unsigned attr, const char *va fsd_log_debug(("# job_min_cpus = %s",value)); job_desc->job_min_cpus = fsd_atoi(value); #else - fsd_log_debug(("# min_cpus = %s",value)); - job_desc->min_cpus = fsd_atoi(value); + fsd_log_debug(("# pn_min_cpus = %s",value)); + job_desc->pn_min_cpus = fsd_atoi(value); #endif break; case SLURM_NATIVE_NODELIST: @@ -310,7 +315,6 @@ slurmdrmaa_add_attribute(job_desc_msg_t *job_desc, unsigned attr, const char *va case SLURM_NATIVE_NTASKS: fsd_log_debug(("# ntasks = %s",value)); job_desc->num_tasks = fsd_atoi(value); - slurmdrmaa_add_attribute(job_desc,SLURM_NATIVE_MINCPUS,value); break; case SLURM_NATIVE_TIME_LIMIT: fsd_log_debug(("# time_limit = %s",value)); @@ -346,11 +350,11 @@ slurmdrmaa_add_attribute(job_desc_msg_t *job_desc, unsigned attr, const char *va break; case SLURM_NATIVE_TMP: fsd_log_debug(("# tmp = %s", value)); - #if SLURM_VERSION_NUMBER >= SLURM_VERSION_NUM(2,3,0) - job_desc->pn_min_tmp_disk = fsd_atoi(value); - #else - job_desc->job_min_tmp_disk = fsd_atoi(value); - #endif + #if SLURM_VERSION_NUMBER >= SLURM_VERSION_NUM(2,3,0) + job_desc->pn_min_tmp_disk = fsd_atoi(value); + #else + job_desc->job_min_tmp_disk = fsd_atoi(value); + #endif break; default: fsd_exc_raise_fmt(FSD_DRMAA_ERRNO_INVALID_ATTRIBUTE_VALUE,"Invalid attribute"); @@ -365,6 +369,8 @@ slurmdrmaa_parse_additional_attr(job_desc_msg_t *job_desc,const char *add_attr) char *ctxt = NULL; char * volatile add_attr_copy = fsd_strdup(add_attr); + fsd_log_enter(( "" )); + TRY { name = fsd_strdup(strtok_r(add_attr_copy, "=", &ctxt)); @@ -391,6 +397,9 @@ slurmdrmaa_parse_additional_attr(job_desc_msg_t *job_desc,const char *add_attr) else if (strcmp(name,"contiguous") == 0) { slurmdrmaa_add_attribute(job_desc,SLURM_NATIVE_CONTIGUOUS,NULL); } + else if (strcmp(name,"cpus-per-task") == 0) { + slurmdrmaa_add_attribute(job_desc,SLURM_NATIVE_CPUS_PER_TASK,value); + } else if(strcmp(name,"exclusive") == 0) { slurmdrmaa_add_attribute(job_desc,SLURM_NATIVE_EXCLUSIVE,NULL); } @@ -472,6 +481,7 @@ slurmdrmaa_parse_additional_attr(job_desc_msg_t *job_desc,const char *add_attr) fsd_free(add_attr_copy); } END_TRY + fsd_log_return(( "" )); } void @@ -507,6 +517,9 @@ slurmdrmaa_parse_native(job_desc_msg_t *job_desc, const char * value) case 'C' : slurmdrmaa_add_attribute(job_desc,SLURM_NATIVE_CONSTRAINT, arg); break; + case 'c' : + slurmdrmaa_add_attribute(job_desc,SLURM_NATIVE_CPUS_PER_TASK, arg); + break; case 'N' : slurmdrmaa_add_attribute(job_desc,SLURM_NATIVE_NODES, arg); break; @@ -562,6 +575,20 @@ slurmdrmaa_parse_native(job_desc_msg_t *job_desc, const char * value) } FINALLY { + fsd_log_debug(( "finalizing job constraints" )); + if( job_desc->cpus_per_task > 0 ) { + job_desc->min_cpus = job_desc->num_tasks * job_desc->cpus_per_task ; + fsd_log_debug(( + "set min_cpus to ntasks*cpus_per_task: %d", + job_desc->min_cpus + )); + } else { + job_desc->min_cpus = job_desc->num_tasks ; + fsd_log_debug(( + "set min_cpus to ntasks: %d", + job_desc->min_cpus + )); + } fsd_free(native_spec_copy); fsd_free(native_specification); }