Line data Source code
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 : #include "grid_dgemm_tensor_local.h"
9 : #include "../common/grid_common.h"
10 : #include "grid_dgemm_utils.h"
11 :
12 518968 : size_t realloc_tensor(tensor *t) {
13 518968 : assert(t != NULL);
14 :
15 518968 : if (t->alloc_size_ == 0) {
16 : /* there is a mistake somewhere. We can not have t->old_alloc_size_ != 0 and
17 : * no allocation */
18 0 : abort();
19 : }
20 :
21 518968 : if ((t->old_alloc_size_ >= t->alloc_size_) && (t->data != NULL))
22 : return t->alloc_size_;
23 :
24 94 : if ((t->old_alloc_size_ < t->alloc_size_) && (t->data != NULL)) {
25 62 : free(t->data);
26 : }
27 :
28 94 : t->data = NULL;
29 :
30 94 : if (t->data == NULL) {
31 94 : t->data = malloc(sizeof(double) * t->alloc_size_);
32 94 : assert(t->data != NULL);
33 94 : t->old_alloc_size_ = t->alloc_size_;
34 : }
35 :
36 94 : return t->alloc_size_;
37 : }
38 :
39 13842 : void alloc_tensor(tensor *t) {
40 13842 : assert(t != NULL);
41 :
42 13842 : t->data = malloc(sizeof(double) * t->alloc_size_);
43 13842 : assert(t->data != NULL);
44 13842 : t->old_alloc_size_ = t->alloc_size_;
45 13842 : }
46 :
47 1208 : void tensor_copy(tensor *const b, const tensor *const a) {
48 1208 : memcpy(b, a, sizeof(tensor));
49 1208 : }
|