ergo
common.h
Go to the documentation of this file.
1 /* Ergo, version 3.7, a program for linear scaling electronic structure
2  * calculations.
3  * Copyright (C) 2018 Elias Rudberg, Emanuel H. Rubensson, Pawel Salek,
4  * and Anastasia Kruchinina.
5  *
6  * This program is free software: you can redistribute it and/or modify
7  * it under the terms of the GNU General Public License as published by
8  * the Free Software Foundation, either version 3 of the License, or
9  * (at your option) any later version.
10  *
11  * This program is distributed in the hope that it will be useful,
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14  * GNU General Public License for more details.
15  *
16  * You should have received a copy of the GNU General Public License
17  * along with this program. If not, see <http://www.gnu.org/licenses/>.
18  *
19  * Primary academic reference:
20  * Ergo: An open-source program for linear-scaling electronic structure
21  * calculations,
22  * Elias Rudberg, Emanuel H. Rubensson, Pawel Salek, and Anastasia
23  * Kruchinina,
24  * SoftwareX 7, 107 (2018),
25  * <http://dx.doi.org/10.1016/j.softx.2018.03.005>
26  *
27  * For further information about Ergo, see <http://www.ergoscf.org>.
28  */
29 
41 #ifndef COMMON_H
42 #define COMMON_H
43 #include <cassert>
44 
45 #define ALWAYS_INLINE __attribute__((__always_inline__))
46 //#define ALWAYS_INLINE
47 
48 //#define DEBUG_ON
49 
53 template<bool>
56 };
60 template<>
61 struct CompileTimeChecker<false> {
62 };
63 #define STATIC_ASSERT_ALWAYS(expr, msg) \
64  { \
65  class ERROR_##msg {}; \
66  (CompileTimeChecker<(expr) != 0>(ERROR_##msg())); \
67  }
68 
69 #ifdef DEBUG_ON
70 #define STATIC_ASSERT_DEBUG(expr, msg) STATIC_ASSERT_ALWAYS(expr, msg)
71 #else
72 #define STATIC_ASSERT_DEBUG(expr, msg)
73 #endif
74 
75 // (void)sizeof(CompileTimeChecker<(expr) != 0>((ERROR_##msg()))); \
76 
77 
78 // Store leading dimension (template argument) as static const
79 // Then one can either use "get" function (ROWS, COLS args not needed?) or
80 // specialize templates depending on the type (transposed or regular).
81 
82 
90  inline static int get( int const row, int const col,
91  int const rows, int const cols ) {
92  return row * cols + col;
93  }
94  template<int T_row, int T_col, int T_rows, int T_cols>
95  struct Get {
96  static int const index = T_row * T_cols + T_col;
97  };
98 
99 };
100 
105  inline static int get( int const row, int const col,
106  int const rows, int const cols ) {
107  return row + col * rows;
108  }
109  template<int T_row, int T_col, int T_rows, int T_cols>
110  struct Get {
111  static int const index = T_row + T_col * T_rows;
112  };
113 };
114 
115 
116 #endif
Class template for use in static asserts.
Definition: common.h:54
CompileTimeChecker(...)
Definition: common.h:55
Struct for access to matrix elements stored in row wise order.
Definition: common.h:89
mat::SizesAndBlocks rows
Definition: test.cc:51
mat::SizesAndBlocks cols
Definition: test.cc:52
static int const index
Definition: common.h:96
static int const index
Definition: common.h:111
Struct for access to matrix elements stored in column wise order.
Definition: common.h:104
Definition: common.h:110
Definition: common.h:95