/* Compute resource usage for the given job on all available resources * * IN: job_ptr - pointer to the job requesting resources * IN: node_map - bitmap of available nodes * IN/OUT: core_map - bitmap of available cores * IN: cr_node_cnt - total number of nodes in the cluster * IN: cr_type - resource type * OUT: cpu_cnt - number of cpus that can be used by this job * IN: test_only - ignore allocated memory check * RET SLURM_SUCCESS index of selected node or -1 if none */ static int _get_res_usage(struct job_record *job_ptr, bitstr_t *node_map, bitstr_t *core_map, uint32_t cr_node_cnt, struct node_use_record *node_usage, uint16_t cr_type, uint16_t **cpu_cnt_ptr, bool test_only) { uint16_t *cpu_cnt, max_cpu_cnt = 0, part_lln_flag = 0; int i, i_first, i_last; int node_inx = -1; if (cr_node_cnt != node_record_count) { error("select/serial: node count inconsistent with slurmctld"); return SLURM_ERROR; } if (!job_ptr) { error("select/serial: NULL job pointer"); return SLURM_ERROR; } if (job_ptr->part_ptr && (job_ptr->part_ptr->flags & PART_FLAG_LLN)) part_lln_flag = 1; if (job_ptr->details && job_ptr->details->req_node_bitmap) bit_and(node_map, job_ptr->details->req_node_bitmap); cpu_cnt = xmalloc(cr_node_cnt * sizeof(uint16_t)); i_first = bit_ffs(node_map); if (i_first >= 0) i_last = bit_fls(node_map); else i_last = -2; for (i = i_first; i <= i_last; i++) { if (!bit_test(node_map, i)) continue; cpu_cnt[i] = _can_job_run_on_node(job_ptr, core_map, i, node_usage, cr_type, test_only); if (!(cr_type & CR_LLN) && !part_lln_flag && cpu_cnt[i]) { bit_nclear(node_map, 0, (node_record_count - 1)); bit_set(node_map, i); node_inx = i; break; /* select/serial: only need one node */ } } if ((cr_type & CR_LLN) || part_lln_flag) { for (i = i_first; i <= i_last; i++) { if (cpu_cnt[i] > max_cpu_cnt) { max_cpu_cnt = cpu_cnt[i]; node_inx = i; } } if (node_inx >= 0) { bit_nclear(node_map, 0, (node_record_count - 1)); bit_set(node_map, node_inx); } } *cpu_cnt_ptr = cpu_cnt; return node_inx; }
/* Compute resource usage for the given job on all available resources * * IN: job_ptr - pointer to the job requesting resources * IN: node_map - bitmap of available nodes * IN/OUT: core_map - bitmap of available cores * IN: cr_node_cnt - total number of nodes in the cluster * IN: cr_type - resource type * OUT: cpu_cnt - number of cpus that can be used by this job * IN: test_only - ignore allocated memory check * RET SLURM_SUCCESS index of selected node or -1 if none */ static int _get_res_usage(struct job_record *job_ptr, bitstr_t *node_map, bitstr_t *core_map, uint32_t cr_node_cnt, struct node_use_record *node_usage, uint16_t cr_type, uint16_t **cpu_cnt_ptr, bool test_only) { uint16_t *cpu_cnt; uint32_t n; int i_first, i_last; int node_inx = -1; if (cr_node_cnt != node_record_count) { error("select/serial: node count inconsistent with slurmctld"); return SLURM_ERROR; } if (job_ptr->details && job_ptr->details->req_node_bitmap) bit_and(node_map, job_ptr->details->req_node_bitmap); cpu_cnt = xmalloc(cr_node_cnt * sizeof(uint16_t)); i_first = bit_ffs(node_map); if (i_first >= 0) i_last = bit_fls(node_map); else i_last = -2; for (n = i_first; n <= i_last; n++) { if (!bit_test(node_map, n)) continue; cpu_cnt[n] = _can_job_run_on_node(job_ptr, core_map, n, node_usage, cr_type, test_only); if (cpu_cnt[n]) { bit_nclear(node_map, 0, (node_record_count - 1)); bit_set(node_map, n); node_inx = n; break; /* select/serial: only need one node */ } } *cpu_cnt_ptr = cpu_cnt; return node_inx; }