24 while (candidate < start) {
35 int candidate = start, divisor = 0;
36 while (divisor < candidate) {
37 for (divisor = 2; divisor < candidate; divisor++) {
38 if (candidate % divisor == 0) {
73 omp_init_lock(&shard->
lock);
81 assert(shard_a != NULL && shard_b != NULL);
87 assert(shard_a->
blocks != NULL);
104 assert(shard_a->
data != NULL);
108 if (shard_a->
blocks != NULL) {
116 if (shard_a->
data != NULL) {
129 omp_destroy_lock(&shard->
lock);
139static inline unsigned int hash(
const unsigned int row,
140 const unsigned int col) {
141 return (row + col) * (row + col + 1) / 2 + row;
157 assert(0 <= block_idx && block_idx < shard->nblocks);
159 const unsigned int h =
hash(blk->
row, blk->
col);
181 if (block_idx == 0) {
184 assert(0 < block_idx && block_idx <= shard->nblocks);
186 if (blk->
row == row && blk->
col == col) {
198 const int col,
const int block_size) {
205 assert(shard->
blocks != NULL);
215 const int new_block_idx = shard->
nblocks;
218 new_block->
row = row;
219 new_block->
col = col;
235 const double *data = shard->
data;
240 assert(shard->
data != NULL);
241 memcpy(shard->
data, data, shard->
data_size *
sizeof(
double));
250 memset(shard->
data + shard->
data_size, 0, tail *
sizeof(
double));
261 const int block_size) {
263 if (existing_blk != NULL) {
276 const int block_size) {
278 if (existing_blk != NULL) {
#define DBM_ALLOCATION_FACTOR
#define DBM_HASHTABLE_FACTOR
void dbm_mempool_host_free(const void *memory)
Internal routine for releasing memory back to the pool.
void * dbm_mempool_host_malloc(size_t size)
Internal routine for allocating host memory from the pool.
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.
static int hashtable_mask(const dbm_shard_t *shard)
Internal routine for masking a slot in the hash-table.
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.
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.
static unsigned int hash(const unsigned int row, const unsigned int col)
Private hash function based on Cantor pairing function. https://en.wikipedia.org/wiki/Pairing_functio...
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 void const int const int i
Internal struct for storing a block's metadata.
Internal struct for storing a matrix shard.