(git:e7e05ae)
grid_task_list.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 GRID_TASK_LIST_H
8 #define GRID_TASK_LIST_H
9 
10 #include <stdbool.h>
11 
12 #include "../offload/offload_buffer.h"
13 #include "../offload/offload_runtime.h"
14 #include "common/grid_basis_set.h"
15 #include "common/grid_constants.h"
16 #include "cpu/grid_cpu_task_list.h"
18 #include "gpu/grid_gpu_task_list.h"
19 #include "hip/grid_hip_task_list.h"
20 #include "ref/grid_ref_task_list.h"
21 
22 /*******************************************************************************
23  * \brief Internal representation of a task list, abstracting various backends.
24  * \author Ole Schuett
25  ******************************************************************************/
26 typedef struct {
27  int backend;
28  int nlevels;
29  int (*npts_local)[3];
33 #if defined(__OFFLOAD) && !defined(__NO_OFFLOAD_GRID)
34  grid_gpu_task_list *gpu;
35 #endif
36 #if defined(__OFFLOAD_HIP) && !defined(__NO_OFFLOAD_GRID)
37  grid_hip_task_list *hip;
38 #endif
39  // more backends to be added here
41 
42 /*******************************************************************************
43  * \brief Allocates a task list which can be passed to grid_collocate_task_list.
44  *
45  * \param orthorhombic Whether simulation box is orthorhombic.
46  * \param ntasks Number of tasks, ie. length of the task list.
47  * \param nlevels Number of grid levels.
48  * \param natoms Number of atoms.
49  * \param nkinds Number of atomic kinds.
50  * \param nblocks Number of local matrix blocks.
51  * \param block_offsets Offset of each block within the buffer (zero based).
52  * \param atom_positions Position of the atoms.
53  * \param atom_kinds Mapping from atom to atomic kind (one based).
54  * \param basis_sets Mapping from atomic kind to basis sets.
55  *
56  * The following params are given for each task:
57  *
58  * \param level_list Index of grid level (one based).
59  * \param iatom_list Index of first atom (one based).
60  * \param jatom_list Index of second atom (one based).
61  * \param iset_list Index of first set (one based).
62  * \param jset_list Index of second set (one based).
63  * \param ipgf_list Index of first exponent (one based).
64  * \param jpgf_list Index of second exponent (one based).
65  * \param border_mask_list Bit-pattern determining border regions to exclude.
66  * \param block_num_list Index into the block_offsets array (one based).
67  * \param radius_list Radius where Gaussian becomes smaller than threshold.
68  * \param rab_list Vector between atoms, encodes the virtual image.
69  *
70  * The following params are given for each grid level:
71  *
72  * \param npts_global Number of global grid points in each direction.
73  * \param npts_local Number of local grid points in each direction.
74  * \param shift_local Number of points local grid is shifted wrt global grid
75  * \param border_width Width of halo region in grid points in each direction.
76  * \param dh Incremental grid matrix.
77  * \param dh_inv Inverse incremental grid matrix.
78  *
79  * \param task_list Handle to the created task list.
80  *
81  * \author Ole Schuett
82  ******************************************************************************/
84  const bool orthorhombic, const int ntasks, const int nlevels,
85  const int natoms, const int nkinds, const int nblocks,
86  const int block_offsets[nblocks], const double atom_positions[natoms][3],
87  const int atom_kinds[natoms], const grid_basis_set *basis_sets[nkinds],
88  const int level_list[ntasks], const int iatom_list[ntasks],
89  const int jatom_list[ntasks], const int iset_list[ntasks],
90  const int jset_list[ntasks], const int ipgf_list[ntasks],
91  const int jpgf_list[ntasks], const int border_mask_list[ntasks],
92  const int block_num_list[ntasks], const double radius_list[ntasks],
93  const double rab_list[ntasks][3], const int npts_global[nlevels][3],
94  const int npts_local[nlevels][3], const int shift_local[nlevels][3],
95  const int border_width[nlevels][3], const double dh[nlevels][3][3],
96  const double dh_inv[nlevels][3][3], grid_task_list **task_list);
97 
98 /*******************************************************************************
99  * \brief Deallocates given task list, basis_sets have to be freed separately.
100  * \author Ole Schuett
101  ******************************************************************************/
102 void grid_free_task_list(grid_task_list *task_list);
103 
104 /*******************************************************************************
105  * \brief Collocate all tasks of in given list onto given grids.
106  *
107  * \param task_list Task list to collocate.
108  * \param func Function to be collocated, see grid_prepare_pab.h
109  * \param nlevels Number of grid levels.
110  *
111  * The remaining params are given for each grid level:
112  *
113  * \param npts_local Number of local grid points in each direction.
114  * \param pab_blocks Buffer that contains the density matrix blocks.
115  * \param grids The output grid array to collocate into.
116  *
117  * \author Ole Schuett
118  ******************************************************************************/
119 void grid_collocate_task_list(const grid_task_list *task_list,
120  const enum grid_func func, const int nlevels,
121  const int npts_local[nlevels][3],
122  const offload_buffer *pab_blocks,
123  offload_buffer *grids[nlevels]);
124 
125 /*******************************************************************************
126  * \brief Integrate all tasks of in given list from given grids.
127  *
128  * \param task_list Task list to collocate.
129  * \param compute_tau When true then <nabla a| V | nabla b> is computed.
130  * \param natoms Number of atoms.
131  * \param nlevels Number of grid levels.
132  *
133  * The remaining params are given for each grid level:
134  *
135  * \param npts_local Number of local grid points in each direction.
136  * \param grids Grid array to integrate from.
137  *
138  * \param pab_blocks Optional density blocks, needed for forces and virial.
139  *
140  * \param hab_blocks Output buffer with the Hamiltonian matrix blocks.
141  * \param forces Optional output forces, requires pab_blocks.
142  * \param virial Optional output virials, requires pab_blocks.
143  *
144  * \author Ole Schuett
145  ******************************************************************************/
147  const grid_task_list *task_list, const bool compute_tau, const int natoms,
148  const int nlevels, const int npts_local[nlevels][3],
149  const offload_buffer *pab_blocks, const offload_buffer *grids[nlevels],
150  offload_buffer *hab_blocks, double forces[natoms][3], double virial[3][3]);
151 
152 #endif
153 
154 // EOF
grid_func
static void const int const int const int const int const int const double const int const int const int npts_local[3]
void grid_collocate_task_list(const grid_task_list *task_list, const enum grid_func func, const int nlevels, const int npts_local[nlevels][3], const offload_buffer *pab_blocks, offload_buffer *grids[nlevels])
Collocate all tasks of in given list onto given grids.
void grid_free_task_list(grid_task_list *task_list)
Deallocates given task list, basis_sets have to be freed separately.
void grid_integrate_task_list(const grid_task_list *task_list, const bool compute_tau, const int natoms, const int nlevels, const int npts_local[nlevels][3], const offload_buffer *pab_blocks, const offload_buffer *grids[nlevels], offload_buffer *hab_blocks, double forces[natoms][3], double virial[3][3])
Integrate all tasks of in given list from given grids.
void grid_create_task_list(const bool orthorhombic, const int ntasks, const int nlevels, const int natoms, const int nkinds, const int nblocks, const int block_offsets[nblocks], const double atom_positions[natoms][3], const int atom_kinds[natoms], const grid_basis_set *basis_sets[nkinds], const int level_list[ntasks], const int iatom_list[ntasks], const int jatom_list[ntasks], const int iset_list[ntasks], const int jset_list[ntasks], const int ipgf_list[ntasks], const int jpgf_list[ntasks], const int border_mask_list[ntasks], const int block_num_list[ntasks], const double radius_list[ntasks], const double rab_list[ntasks][3], const int npts_global[nlevels][3], const int npts_local[nlevels][3], const int shift_local[nlevels][3], const int border_width[nlevels][3], const double dh[nlevels][3][3], const double dh_inv[nlevels][3][3], grid_task_list **task_list)
Allocates a task list which can be passed to grid_collocate_task_list.
Internal representation of a basis set.
Internal representation of a task list.
Internal representation of a task list.
Internal representation of a task list, abstracting various backends.
grid_ref_task_list * ref
grid_dgemm_task_list * dgemm
grid_cpu_task_list * cpu
Internal representation of a buffer.