(git:9ca3469)
Loading...
Searching...
No Matches
dbm_shard.h
Go to the documentation of this file.
1/*----------------------------------------------------------------------------*/
2/* CP2K: A general program to perform molecular dynamics simulations */
3/* Copyright 2000-2026 CP2K developers group <https://cp2k.org> */
4/* */
5/* SPDX-License-Identifier: BSD-3-Clause */
6/*----------------------------------------------------------------------------*/
7#ifndef DBM_SHARD_H
8#define DBM_SHARD_H
9
10#include <omp.h>
11
12#ifdef __cplusplus
13extern "C" {
14#endif
15
16/*******************************************************************************
17 * \brief Internal struct for storing a block's metadata.
18 * \author Ole Schuett
19 ******************************************************************************/
20typedef struct {
21 int row;
22 int col;
23 int offset;
25
26/*******************************************************************************
27 * \brief Internal struct for storing a matrix shard.
28 * \author Ole Schuett
29 ******************************************************************************/
30typedef struct {
34
35 int hashtable_size; // should be a power of two
36 int hashtable_prime; // should be a coprime of hashtable_size
37 int *hashtable; // maps row/col to block numbers
38
39 int data_promised; // ref'd by dbm_block_t.offset (not yet allocated)
40 int data_allocated; // actually allocated (capacity of data buffer)
41 int data_size; // actually allocated and initialized
42 double *data; // potentially over-allocated (to amortize resizing)
43
44 omp_lock_t lock; // used by dbm_put_block
46
47/*******************************************************************************
48 * \brief Internal routine for initializing a shard.
49 * \author Ole Schuett
50 ******************************************************************************/
51void dbm_shard_init(dbm_shard_t *shard);
52
53/*******************************************************************************
54 * \brief Internal routine for copying content of shard_b into shard_a.
55 * \author Ole Schuett
56 ******************************************************************************/
57void dbm_shard_copy(dbm_shard_t *shard_a, const dbm_shard_t *shard_b);
58
59/*******************************************************************************
60 * \brief Internal routine for releasing a shard.
61 * \author Ole Schuett
62 ******************************************************************************/
64
65/*******************************************************************************
66 * \brief Internal routine for looking up a block from a shard.
67 * \author Ole Schuett
68 ******************************************************************************/
69dbm_block_t *dbm_shard_lookup(const dbm_shard_t *shard, const int row,
70 const int col);
71
72/*******************************************************************************
73 * \brief Internal routine for allocating the metadata of a new block.
74 * \author Ole Schuett
75 ******************************************************************************/
77 const int col, const int block_size);
78
79/*******************************************************************************
80 * \brief Internal routine for allocating and zeroing any promised block's data.
81 * \author Ole Schuett
82 ******************************************************************************/
84
85/*******************************************************************************
86 * \brief Internal routine for getting block or promising a new one.
87 * \author Ole Schuett
88 ******************************************************************************/
90 const int col,
91 const int block_size);
92
93/*******************************************************************************
94 * \brief Internal routine for getting block or allocating a new one.
95 * \author Ole Schuett
96 ******************************************************************************/
98 const int col,
99 const int block_size);
100
101#ifdef __cplusplus
102}
103#endif
104
105#endif
106
107// EOF
void dbm_shard_release(dbm_shard_t *shard)
Internal routine for releasing a shard.
Definition dbm_shard.c:128
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.
Definition dbm_shard.c:278
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.
Definition dbm_shard.c:200
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.
Definition dbm_shard.c:178
void dbm_shard_allocate_promised_blocks(dbm_shard_t *shard)
Internal routine for allocating and zeroing any promised block's data.
Definition dbm_shard.c:234
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.
Definition dbm_shard.c:263
void dbm_shard_init(dbm_shard_t *shard)
Internal routine for initializing a shard.
Definition dbm_shard.c:64
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.
Definition dbm_shard.c:80
Internal struct for storing a block's metadata.
Definition dbm_shard.h:20
Internal struct for storing a matrix shard.
Definition dbm_shard.h:30
double * data
Definition dbm_shard.h:42
int * hashtable
Definition dbm_shard.h:37
omp_lock_t lock
Definition dbm_shard.h:44
int nblocks_allocated
Definition dbm_shard.h:32
dbm_block_t * blocks
Definition dbm_shard.h:33
int hashtable_prime
Definition dbm_shard.h:36
int data_allocated
Definition dbm_shard.h:40
int data_size
Definition dbm_shard.h:41
int hashtable_size
Definition dbm_shard.h:35
int data_promised
Definition dbm_shard.h:39