24 while (candidate < start) {
35 int candidate = start;
37 for (
int divisor = 2; divisor <= candidate / divisor; divisor++) {
38 if (candidate % divisor == 0) {
72 omp_init_lock(&shard->
lock);
80 assert(shard_a != NULL && shard_b != NULL);
86 assert(shard_a->
blocks != NULL);
103 assert(shard_a->
data != NULL);
109 assert(shard_a->
blocks != NULL && shard_b->
blocks != NULL);
119 assert(shard_a->
data != NULL && shard_b->
data != NULL);
132 omp_destroy_lock(&shard->
lock);
140 assert(0 <= block_idx && block_idx < shard->nblocks);
166 const int block_idx = shard->
hashtable[slot];
167 if (block_idx == 0) {
170 assert(0 < block_idx && block_idx <= shard->nblocks);
172 if (blk->
row == row && blk->
col == col) {
189 assert(nblocks <= shard->nblocks_allocated);
192 assert(shard->
blocks != NULL);
210 const int col,
const int block_size) {
213 const int new_block_idx = shard->
nblocks;
216 new_block->
row = row;
217 new_block->
col = col;
232 const double *data = shard->
data;
237 assert(shard->
data != NULL);
239 memcpy(shard->
data, data, shard->
data_size *
sizeof(
double));
249 memset(shard->
data + shard->
data_size, 0, tail *
sizeof(
double));
260 const int block_size) {
262 if (existing_blk != NULL) {
275 const int block_size) {
277 if (existing_blk != NULL) {
#define DBM_ALLOCATION_FACTOR
#define DBM_HASHTABLE_FACTOR
static void hashtable_insert(dbm_shard_t *shard, const int block_idx)
Private routine for inserting a block into a shard's hashtable.
static void hashtable_init(dbm_shard_t *shard)
Internal routine for initializing a shard's hashtable.
void dbm_shard_release(dbm_shard_t *shard)
Internal routine for releasing a shard.
static int next_prime(const int start)
Internal routine for finding a prime greater equal than given number.
dbm_block_t * dbm_shard_get_or_allocate_block(dbm_shard_t *shard, const int row, const int col, const int block_size)
Internal routine for getting block or allocating a new one.
static int next_power2(const int start)
Internal routine for finding a power of two greater than given number.
void dbm_shard_reserve(dbm_shard_t *shard, const int nblocks)
Internal routine for growing the block metadata of a shard such that it holds nblocks blocks in total...
dbm_block_t * dbm_shard_promise_new_block(dbm_shard_t *shard, const int row, const int col, const int block_size)
Internal routine for allocating the metadata of a new block.
dbm_block_t * dbm_shard_lookup(const dbm_shard_t *shard, const int row, const int col)
Internal routine for looking up a block from a shard.
void dbm_shard_allocate_promised_blocks(dbm_shard_t *shard)
Internal routine for allocating and zeroing any promised block's data.
dbm_block_t * dbm_shard_get_or_promise_block(dbm_shard_t *shard, const int row, const int col, const int block_size)
Internal routine for getting block or promising a new one.
void dbm_shard_init(dbm_shard_t *shard)
Internal routine for initializing a shard.
void dbm_shard_copy(dbm_shard_t *shard_a, const dbm_shard_t *shard_b)
Internal routine for copying content of shard_b into shard_a.
static int dbm_shard_slot(const dbm_shard_t *shard, const int row, const int col)
Internal routine for the slot of a block in the shard's hashtable.
static int dbm_shard_nextslot(const dbm_shard_t *shard, const int slot)
Internal routine for the slot following the given one (probing).
static void const int const int i
void offload_mempool_host_free(const void *memory)
Internal routine for releasing memory back to the pool.
void * offload_mempool_host_malloc(const size_t size)
Internal routine for allocating host memory from the pool.
Internal struct for storing a block's metadata.
Internal struct for storing a matrix shard.