(git:374b731)
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-2024 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_mask; // should be hashtable_size - 1, ie. a bit-mask
37 int hashtable_prime; // should be a coprime of hashtable_size
38 int *hashtable; // maps row/col to block numbers
39
40 int data_promised; // referenced by a dbm_block_t.offset, but not yet
41 // allocated
42 int data_allocated; // over-allocated to amortize the cost of resizing
43 int data_size; // actually allocated and initialized
44 double *data;
45
46 omp_lock_t lock; // used by dbm_put_block
48
49/*******************************************************************************
50 * \brief Internal routine for initializing a shard.
51 * \author Ole Schuett
52 ******************************************************************************/
53void dbm_shard_init(dbm_shard_t *shard);
54
55/*******************************************************************************
56 * \brief Internal routine for copying content of shard_b into shard_a.
57 * \author Ole Schuett
58 ******************************************************************************/
59void dbm_shard_copy(dbm_shard_t *shard_a, const dbm_shard_t *shard_b);
60
61/*******************************************************************************
62 * \brief Internal routine for releasing a shard.
63 * \author Ole Schuett
64 ******************************************************************************/
66
67/*******************************************************************************
68 * \brief Internal routine for looking up a block from a shard.
69 * \author Ole Schuett
70 ******************************************************************************/
71dbm_block_t *dbm_shard_lookup(const dbm_shard_t *shard, const int row,
72 const int col);
73
74/*******************************************************************************
75 * \brief Internal routine for allocating the metadata of a new block.
76 * \author Ole Schuett
77 ******************************************************************************/
79 const int col, const int block_size);
80
81/*******************************************************************************
82 * \brief Internal routine for allocating and zeroing any promised block's data.
83 * \author Ole Schuett
84 ******************************************************************************/
86
87/*******************************************************************************
88 * \brief Internal routine for getting block or promising a new one.
89 * \author Ole Schuett
90 ******************************************************************************/
92 const int col,
93 const int block_size);
94
95/*******************************************************************************
96 * \brief Internal routine for getting block or allocating a new one.
97 * \author Ole Schuett
98 ******************************************************************************/
100 const int col,
101 const int block_size);
102
103#ifdef __cplusplus
104}
105#endif
106
107#endif
108
109// EOF
void dbm_shard_release(dbm_shard_t *shard)
Internal routine for releasing a shard.
Definition dbm_shard.c:107
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:240
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:171
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:149
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:203
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:225
void dbm_shard_init(dbm_shard_t *shard)
Internal routine for initializing a shard.
Definition dbm_shard.c:63
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:44
int * hashtable
Definition dbm_shard.h:38
omp_lock_t lock
Definition dbm_shard.h:46
int nblocks_allocated
Definition dbm_shard.h:32
dbm_block_t * blocks
Definition dbm_shard.h:33
int hashtable_prime
Definition dbm_shard.h:37
int data_allocated
Definition dbm_shard.h:42
int data_size
Definition dbm_shard.h:43
int hashtable_size
Definition dbm_shard.h:35
int data_promised
Definition dbm_shard.h:40
int hashtable_mask
Definition dbm_shard.h:36