Skip to content

Commit

Permalink
Michael Gutteridge <michael.gutteridge@gmail.com> patch for "mincpus"…
Browse files Browse the repository at this point in the history
… calculations.
  • Loading branch information
atombaby authored and pkopta committed Apr 22, 2014
1 parent 32d4f9c commit 8acc159
Show file tree
Hide file tree
Showing 3 changed files with 49 additions and 18 deletions.
9 changes: 8 additions & 1 deletion slurm_drmaa/job.c
Original file line number Diff line number Diff line change
Expand Up @@ -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 )
Expand All @@ -673,6 +680,6 @@ slurmdrmaa_job_create(
slurmdrmaa_parse_native(job_desc, value);
}

}
}


15 changes: 6 additions & 9 deletions slurm_drmaa/session.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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++ )
Expand All @@ -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]) );
Expand All @@ -139,16 +135,17 @@ 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)){
fsd_exc_raise_fmt(
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*/

Expand Down
43 changes: 35 additions & 8 deletions slurm_drmaa/util.c
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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:
Expand Down Expand Up @@ -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));
Expand Down Expand Up @@ -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");
Expand All @@ -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));
Expand All @@ -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);
}
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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);
}
Expand Down

0 comments on commit 8acc159

Please sign in to comment.