/** * @brief allocate space for a pbs_bitmap (and possibly the bitmap itself) * @param pbm - bitmap to allocate space for. NULL to allocate a new bitmap * @param num_bits - number of bits to allocate * @return pbs_bitmap * * @retval bitmap which was allocated * @retval NULL on error */ pbs_bitmap * pbs_bitmap_alloc(pbs_bitmap *pbm, long num_bits) { pbs_bitmap *bm; unsigned long *tmp_bits; long prev_longs; if(num_bits <= 0) return NULL; if(pbm == NULL) { bm = calloc(1, sizeof(pbs_bitmap)); if(bm == NULL) return NULL; } else bm = pbm; /* shrinking bitmap, clear previously used bits */ if (num_bits < bm->num_bits) { int i; i = num_bits / BYTES_TO_BITS(sizeof(unsigned long)) + 1; for ( ; i < bm->num_longs; i++) bm->bits[i] = 0; for (i = pbs_bitmap_next_on_bit(bm, num_bits); i != -1; i = pbs_bitmap_next_on_bit(bm, i)) pbs_bitmap_bit_off(bm, i); } /* If we have enough unused bits available, we don't need to allocate */ if (bm->num_longs * BYTES_TO_BITS(sizeof(unsigned long)) >= num_bits) { bm->num_bits = num_bits; return bm; } prev_longs = bm->num_longs; bm->num_bits = num_bits; bm->num_longs = num_bits / BYTES_TO_BITS(sizeof(unsigned long)); if (num_bits % BYTES_TO_BITS(sizeof(unsigned long)) > 0) bm->num_longs++; tmp_bits = calloc(bm->num_longs, sizeof(unsigned long)); if (tmp_bits == NULL) { if(pbm == NULL) /* we allocated the memory */ pbs_bitmap_free(bm); return NULL; } if(bm->bits != NULL) { int i; for(i = 0; i < prev_longs; i++) tmp_bits[i] = bm->bits[i]; free(bm->bits); } bm->bits = tmp_bits; return bm; }
/** * @brief update the node buckets associated with a node partition on * job/resv run/end * * @param[in] bkts - the buckets to update * @param[in] ninfo_arr - the nodes of the job/resv */ void update_buckets_for_node_array(node_bucket **bkts, node_info **ninfo_arr) { int i, j; if (bkts == NULL || ninfo_arr == NULL) return; for (i = 0; ninfo_arr[i] != NULL; i++) { for (j = 0; bkts[j] != NULL; j++) { int node_ind = ninfo_arr[i]->node_ind; /* Is this node in the bucket? */ if (pbs_bitmap_get_bit(bkts[j]->bkt_nodes, node_ind)) { /* First turn off the current bit */ if (pbs_bitmap_get_bit(bkts[j]->free_pool->truth, node_ind)) { pbs_bitmap_bit_off(bkts[j]->free_pool->truth, node_ind); bkts[j]->free_pool->truth_ct--; } else if (pbs_bitmap_get_bit(bkts[j]->busy_later_pool->truth, node_ind)) { pbs_bitmap_bit_off(bkts[j]->busy_later_pool->truth, node_ind); bkts[j]->busy_later_pool->truth_ct--; } else if (pbs_bitmap_get_bit(bkts[j]->busy_pool->truth, node_ind)) { pbs_bitmap_bit_off(bkts[j]->busy_pool->truth, node_ind); bkts[j]->busy_pool->truth_ct--; } /* Next, turn on the correct bit */ if (ninfo_arr[i]->num_jobs > 0 || ninfo_arr[i]->num_run_resv > 0) { pbs_bitmap_bit_on(bkts[j]->busy_pool->truth, node_ind); bkts[j]->busy_pool->truth_ct++; } else { if (ninfo_arr[i]->node_events != NULL) { pbs_bitmap_bit_on(bkts[j]->busy_later_pool->truth, node_ind); bkts[j]->busy_later_pool->truth_ct++; } else { pbs_bitmap_bit_on(bkts[j]->free_pool->truth, node_ind); bkts[j]->free_pool->truth_ct++; } } } } } }