diff --git a/src/common/select_job_res.c b/src/common/select_job_res.c index cbae86035a55df2b9321f9ad7442c2cf438a6cd9..6ef494c5fd6c5cb0bba1ac904f9ad2414de7ebc1 100644 --- a/src/common/select_job_res.c +++ b/src/common/select_job_res.c @@ -113,7 +113,7 @@ extern int build_select_job_res(select_job_res_t select_job_res, } /* Rebuild cpu_array_cnt, cpu_array_value, and cpu_array_reps based upon the - * values of cpus in an existing data structure */ + * values of nhosts and cpus in an existing data structure */ extern int build_select_job_res_cpu_array(select_job_res_t select_job_res_ptr) { int i; @@ -122,7 +122,7 @@ extern int build_select_job_res_cpu_array(select_job_res_t select_job_res_ptr) if (select_job_res_ptr->nhosts == 0) return SLURM_SUCCESS; /* no work to do */ if (select_job_res_ptr->cpus == NULL) { - error("build_select_job_res_cpu_array cpus==NULL"); + error("build_select_job_res_cpu_array: cpus==NULL"); return SLURM_ERROR; } @@ -152,6 +152,52 @@ extern int build_select_job_res_cpu_array(select_job_res_t select_job_res_ptr) return SLURM_SUCCESS; } +/* Rebuild cpus array based upon the values of nhosts, cpu_array_value and + * cpu_array_reps in an existing data structure */ +extern int build_select_job_res_cpus_array(select_job_res_t select_job_res_ptr) +{ + int cpu_inx, i, j; + + if (select_job_res_ptr->nhosts == 0) + return SLURM_SUCCESS; /* no work to do */ + if (select_job_res_ptr->cpu_array_cnt == 0) { + error("build_select_job_res_cpus_array: cpu_array_cnt==0"); + return SLURM_ERROR; + } + if (select_job_res_ptr->cpu_array_value == NULL) { + error("build_select_job_res_cpus_array: cpu_array_value==NULL"); + return SLURM_ERROR; + } + if (select_job_res_ptr->cpu_array_reps == NULL) { + error("build_select_job_res_cpus_array: cpu_array_reps==NULL"); + return SLURM_ERROR; + } + + /* clear vestigial data and create new arrays of max size */ + xfree(select_job_res_ptr->cpus); + select_job_res_ptr->cpus = + xmalloc(select_job_res_ptr->nhosts * sizeof(uint16_t)); + + cpu_inx = 0; + for (i=0; i<select_job_res_ptr->cpu_array_cnt; i++) { + for (j=0; j<select_job_res_ptr->cpu_array_reps[i]; j++) { + if (cpu_inx >= select_job_res_ptr->nhosts) { + error("build_select_job_res_cpus_array: " + "cpu_array is too long"); + return SLURM_ERROR; + } + select_job_res_ptr->cpus[cpu_inx++] = + select_job_res_ptr->cpus[i]; + } + } + if (cpu_inx < select_job_res_ptr->nhosts) { + error("build_select_job_res_cpus_array: " + "cpu_array is incomplete"); + return SLURM_ERROR; + } + return SLURM_SUCCESS; +} + extern int valid_select_job_res(select_job_res_t select_job_res, void *node_rec_table, uint16_t fast_schedule) @@ -510,7 +556,7 @@ extern void pack_select_job_res(select_job_res_t select_job_res_ptr, xassert(core_cnt == bit_size(select_job_res_ptr->core_bitmap_used)); pack_bit_fmt(select_job_res_ptr->core_bitmap_used, buffer); host_cnt = bit_size(select_job_res_ptr->node_bitmap); - /* FIXME: don't pack the node_bitmap, but recreate it based upon + /* FIXME: don't pack the node_bitmap, but rebuild it based upon * select_job_res_ptr->node_list */ pack32(host_cnt, buffer); pack_bit_fmt(select_job_res_ptr->node_bitmap, buffer); diff --git a/src/common/select_job_res.h b/src/common/select_job_res.h index 0d32f6435629164d28a0e69955391c17f89c0681..cc0a10011f31683f4b9578468db250e2fe8f8c05 100644 --- a/src/common/select_job_res.h +++ b/src/common/select_job_res.h @@ -139,6 +139,10 @@ extern int build_select_job_res(select_job_res_t select_job_res_ptr, * values of cpus in an existing data structure */ extern int build_select_job_res_cpu_array(select_job_res_t select_job_res_ptr); +/* Rebuild cpus array based upon the values of nhosts, cpu_array_value and + * cpu_array_reps in an existing data structure */ +extern int build_select_job_res_cpus_array(select_job_res_t select_job_res_ptr); + /* Validate a select_job_res data structure originally built using * build_select_job_res() is still valid based upon slurmctld state. * NOTE: Reset the node_bitmap field before calling this function.