LCOV - code coverage report
Current view: top level - src/grid/dgemm - grid_dgemm_tensor_local.c (source / functions) Hit Total Coverage
Test: CP2K Regtests (git:b195825) Lines: 21 25 84.0 %
Date: 2024-04-20 06:29:22 Functions: 3 3 100.0 %

          Line data    Source code
       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             : 
       8             : #include "grid_dgemm_tensor_local.h"
       9             : #include "../common/grid_common.h"
      10             : #include "grid_dgemm_utils.h"
      11             : 
      12      504788 : size_t realloc_tensor(tensor *t) {
      13      504788 :   assert(t);
      14             : 
      15      504788 :   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      504788 :   if ((t->old_alloc_size_ >= t->alloc_size_) && (t->data != NULL))
      22             :     return t->alloc_size_;
      23             : 
      24          98 :   if ((t->old_alloc_size_ < t->alloc_size_) && (t->data != NULL)) {
      25          62 :     free(t->data);
      26             :   }
      27             : 
      28          98 :   t->data = NULL;
      29             : 
      30          98 :   if (t->data == NULL) {
      31          98 :     t->data = malloc(sizeof(double) * t->alloc_size_);
      32          98 :     if (!t->data)
      33           0 :       abort();
      34          98 :     t->old_alloc_size_ = t->alloc_size_;
      35             :   }
      36             : 
      37          98 :   return t->alloc_size_;
      38             : }
      39             : 
      40       14032 : void alloc_tensor(tensor *t) {
      41       14032 :   if (t == NULL) {
      42           0 :     abort();
      43             :   }
      44             : 
      45       14032 :   t->data = malloc(sizeof(double) * t->alloc_size_);
      46       14032 :   if (!t->data)
      47           0 :     abort();
      48       14032 :   t->old_alloc_size_ = t->alloc_size_;
      49       14032 : }
      50             : 
      51        1256 : void tensor_copy(tensor *const b, const tensor *const a) {
      52        1256 :   memcpy(b, a, sizeof(tensor));
      53        1256 : }

Generated by: LCOV version 1.15