(git:9aade48)
Loading...
Searching...
No Matches
grid_dgemm_utils.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
8#ifndef GRID_DGEMM_UTILS_H
9#define GRID_DGEMM_UTILS_H
10
11#include <stdbool.h>
12#include <stdio.h>
13#include <string.h>
14
15#if defined(__MKL)
16#include <mkl.h>
17#include <mkl_cblas.h>
18#endif
19
20#include "../common/grid_common.h"
23
24/* inverse of the factorials */
25static const double inv_fac[] = {1.0,
26 1.0,
27 0.5,
28 0.166666666666666666666666666667,
29 0.0416666666666666666666666666667,
30 0.00833333333333333333333333333333,
31 0.00138888888888888888888888888889,
32 0.000198412698412698412698412698413,
33 0.0000248015873015873015873015873016,
34 2.7557319223985890652557319224e-6,
35 2.7557319223985890652557319224e-7,
36 2.50521083854417187750521083854e-8,
37 2.08767569878680989792100903212e-9,
38 1.60590438368216145993923771702e-10,
39 1.14707455977297247138516979787e-11,
40 7.64716373181981647590113198579e-13,
41 4.77947733238738529743820749112e-14,
42 2.81145725434552076319894558301e-15,
43 1.56192069685862264622163643501e-16,
44 8.22063524662432971695598123687e-18,
45 4.11031762331216485847799061844e-19,
46 1.95729410633912612308475743735e-20,
47 8.8967913924505732867488974425e-22,
48 3.86817017063068403771691193152e-23,
49 1.6117375710961183490487133048e-24,
50 6.4469502843844733961948532192e-26,
51 2.47959626322479746007494354585e-27,
52 9.18368986379554614842571683647e-29,
53 3.27988923706983791015204172731e-30,
54 1.13099628864477169315587645769e-31,
55 3.76998762881590564385292152565e-33};
56
57inline int coset_without_offset(int lx, int ly, int lz) {
58 const int l = lx + ly + lz;
59 if (l == 0) {
60 return 0;
61 } else {
62 return ((l - lx) * (l - lx + 1)) / 2 + lz;
63 }
64}
65
66typedef struct dgemm_params_ {
67 char storage;
68 char op1;
69 char op2;
70 double alpha;
71 double beta;
72 double *a, *b, *c;
73 int m, n, k, lda, ldb, ldc;
74 int x, y, z;
75 int x1, y1, z1;
77
78extern void dgemm_simplified(dgemm_params *const m);
79
80/*******************************************************************************
81 * \brief Prototype for BLAS dgemm.
82 * \author Ole Schuett
83 ******************************************************************************/
84void dgemm_(const char *transa, const char *transb, const int *m, const int *n,
85 const int *k, const double *alpha, const double *a, const int *lda,
86 const double *b, const int *ldb, const double *beta, double *c,
87 const int *ldc);
88
89extern void extract_sub_grid(const int *lower_corner, const int *upper_corner,
90 const int *position, const tensor *const grid,
91 tensor *const subgrid);
92extern void add_sub_grid(const int *lower_corner, const int *upper_corner,
93 const int *position, const tensor *subgrid,
94 tensor *grid);
95extern void return_cube_position(const int *lb_grid, const int *cube_center,
96 const int *lower_boundaries_cube,
97 const int *period, int *const position);
98
99extern void verify_orthogonality(const double dh[3][3], bool orthogonal[3]);
100
101extern int compute_cube_properties(const bool ortho, const double radius,
102 const double dh[3][3],
103 const double dh_inv[3][3], const double *rp,
104 double *disr_radius, double *roffset,
105 int *cubecenter, int *lb_cube, int *ub_cube,
106 int *cube_size);
107
108inline int return_offset_l(const int l) {
109 static const int offset_[] = {1, 4, 7, 11, 16, 22, 29,
110 37, 46, 56, 67, 79, 92, 106,
111 121, 137, 154, 172, 191, 211, 232};
112 return offset_[l];
113}
114
115inline int return_linear_index_from_exponents(const int alpha, const int beta,
116 const int gamma) {
117 const int l = alpha + beta + gamma;
118 return return_offset_l(l) + (l - alpha) * (l - alpha + 1) / 2 + gamma;
119}
120
121static inline void *grid_allocate_scratch(size_t size) { return malloc(size); }
122
123static inline void grid_free_scratch(void *ptr) { free(ptr); }
124
125/* even openblas and lapack has cblas versions of lapack and blas. */
126#ifndef __MKL
133enum CBLAS_UPLO { CblasUpper = 121, CblasLower = 122 };
134enum CBLAS_DIAG { CblasNonUnit = 131, CblasUnit = 132 };
135enum CBLAS_SIDE { CblasLeft = 141, CblasRight = 142 };
136
141
142double cblas_ddot(const int N, const double *X, const int incX, const double *Y,
143 const int incY);
144
145void cblas_dger(const CBLAS_LAYOUT Layout, const int M, const int N,
146 const double alpha, const double *X, const int incX,
147 const double *Y, const int incY, double *A, const int lda);
148
149void cblas_daxpy(const int N, const double alpha, const double *X,
150 const int incX, double *Y, const int incY);
151
152void cblas_dgemv(const CBLAS_LAYOUT Layout, const CBLAS_TRANSPOSE TransA,
153 const int M, const int N, const double alpha, const double *A,
154 const int lda, const double *X, const int incX,
155 const double beta, double *Y, const int incY);
156
157#endif
158
159extern void compute_interval(const int *const map, const int full_size,
160 const int size, const int cube_size, const int x1,
161 int *x, int *const lower_corner,
162 int *const upper_corner, Interval window);
163#endif
static void const int const int const int const int const int const double const int const int const int int GRID_CONST_WHEN_COLLOCATE double GRID_CONST_WHEN_INTEGRATE double * grid
static void const int const int const int const int const int const double const int map[3][2 *cmax+1]
int compute_cube_properties(const bool ortho, const double radius, const double dh[3][3], const double dh_inv[3][3], const double *rp, double *disr_radius, double *roffset, int *cubecenter, int *lb_cube, int *ub_cube, int *cube_size)
double cblas_ddot(const int N, const double *X, const int incX, const double *Y, const int incY)
@ CblasLower
@ CblasUpper
int coset_without_offset(int lx, int ly, int lz)
static void * grid_allocate_scratch(size_t size)
void extract_sub_grid(const int *lower_corner, const int *upper_corner, const int *position, const tensor *const grid, tensor *const subgrid)
static const double inv_fac[]
CBLAS_TRANSPOSE
@ CblasNoTrans
@ CblasTrans
@ CblasConjTrans
@ CblasRight
@ CblasLeft
CBLAS_LAYOUT
@ CblasColMajor
@ CblasRowMajor
void compute_interval(const int *const map, const int full_size, const int size, const int cube_size, const int x1, int *x, int *const lower_corner, int *const upper_corner, Interval window)
struct dgemm_params_ dgemm_params
void cblas_dgemv(const CBLAS_LAYOUT Layout, const CBLAS_TRANSPOSE TransA, const int M, const int N, const double alpha, const double *A, const int lda, const double *X, const int incX, const double beta, double *Y, const int incY)
void cblas_dger(const CBLAS_LAYOUT Layout, const int M, const int N, const double alpha, const double *X, const int incX, const double *Y, const int incY, double *A, const int lda)
@ CblasUnit
@ CblasNonUnit
static void grid_free_scratch(void *ptr)
void cblas_daxpy(const int N, const double alpha, const double *X, const int incX, double *Y, const int incY)
void dgemm_(const char *transa, const char *transb, const int *m, const int *n, const int *k, const double *alpha, const double *a, const int *lda, const double *b, const int *ldb, const double *beta, double *c, const int *ldc)
Prototype for BLAS dgemm.
void verify_orthogonality(const double dh[3][3], bool orthogonal[3])
int return_offset_l(const int l)
void return_cube_position(const int *lb_grid, const int *cube_center, const int *lower_boundaries_cube, const int *period, int *const position)
void dgemm_simplified(dgemm_params *const m)
void add_sub_grid(const int *lower_corner, const int *upper_corner, const int *position, const tensor *subgrid, tensor *grid)
int return_linear_index_from_exponents(const int alpha, const int beta, const int gamma)
Calculation of the incomplete Gamma function F_n(t) for multi-center integrals over Cartesian Gaussia...
Definition gamma.F:15