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