(git:33f85d8)
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-2025 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; // referenced by a dbm_block_t.offset, but not yet
40 // allocated
41 int data_allocated; // over-allocated to amortize the cost of resizing
42 int data_size; // actually allocated and initialized
43 double *data;
44
45 omp_lock_t lock; // used by dbm_put_block
47
48/*******************************************************************************
49 * \brief Internal routine for initializing a shard.
50 * \author Ole Schuett
51 ******************************************************************************/
52void dbm_shard_init(dbm_shard_t *shard);
53
54/*******************************************************************************
55 * \brief Internal routine for copying content of shard_b into shard_a.
56 * \author Ole Schuett
57 ******************************************************************************/
58void dbm_shard_copy(dbm_shard_t *shard_a, const dbm_shard_t *shard_b);
59
60/*******************************************************************************
61 * \brief Internal routine for releasing a shard.
62 * \author Ole Schuett
63 ******************************************************************************/
65
66/*******************************************************************************
67 * \brief Internal routine for looking up a block from a shard.
68 * \author Ole Schuett
69 ******************************************************************************/
70dbm_block_t *dbm_shard_lookup(const dbm_shard_t *shard, const int row,
71 const int col);
72
73/*******************************************************************************
74 * \brief Internal routine for allocating the metadata of a new block.
75 * \author Ole Schuett
76 ******************************************************************************/
78 const int col, const int block_size);
79
80/*******************************************************************************
81 * \brief Internal routine for allocating and zeroing any promised block's data.
82 * \author Ole Schuett
83 ******************************************************************************/
85
86/*******************************************************************************
87 * \brief Internal routine for getting block or promising a new one.
88 * \author Ole Schuett
89 ******************************************************************************/
91 const int col,
92 const int block_size);
93
94/*******************************************************************************
95 * \brief Internal routine for getting block or allocating a new one.
96 * \author Ole Schuett
97 ******************************************************************************/
99 const int col,
100 const int block_size);
101
102#ifdef __cplusplus
103}
104#endif
105
106#endif
107
108// EOF
void dbm_shard_release(dbm_shard_t *shard)
Internal routine for releasing a shard.
Definition dbm_shard.c:125
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:274
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:197
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:175
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:231
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:259
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:43
int * hashtable
Definition dbm_shard.h:37
omp_lock_t lock
Definition dbm_shard.h:45
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:41
int data_size
Definition dbm_shard.h:42
int hashtable_size
Definition dbm_shard.h:35
int data_promised
Definition dbm_shard.h:39