ergo
common.h
Go to the documentation of this file.
1 /* Ergo, version 3.3, a program for linear scaling electronic structure
2  * calculations.
3  * Copyright (C) 2013 Elias Rudberg, Emanuel H. Rubensson, and Pawel Salek.
4  *
5  * This program is free software: you can redistribute it and/or modify
6  * it under the terms of the GNU General Public License as published by
7  * the Free Software Foundation, either version 3 of the License, or
8  * (at your option) any later version.
9  *
10  * This program is distributed in the hope that it will be useful,
11  * but WITHOUT ANY WARRANTY; without even the implied warranty of
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13  * GNU General Public License for more details.
14  *
15  * You should have received a copy of the GNU General Public License
16  * along with this program. If not, see <http://www.gnu.org/licenses/>.
17  *
18  * Primary academic reference:
19  * Kohn−Sham Density Functional Theory Electronic Structure Calculations
20  * with Linearly Scaling Computational Time and Memory Usage,
21  * Elias Rudberg, Emanuel H. Rubensson, and Pawel Salek,
22  * J. Chem. Theory Comput. 7, 340 (2011),
23  * <http://dx.doi.org/10.1021/ct100611z>
24  *
25  * For further information about Ergo, see <http://www.ergoscf.org>.
26  */
27 #ifndef COMMON_H
28 #define COMMON_H
29 #include <cassert>
30 
31 #define ALWAYS_INLINE __attribute__((__always_inline__))
32 //#define ALWAYS_INLINE
33 
34 //#define DEBUG_ON
35 
39 template<bool>
42 };
46 template<>
47 struct CompileTimeChecker<false> {
48 };
49 #define STATIC_ASSERT_ALWAYS(expr, msg) \
50  { \
51  class ERROR_##msg {}; \
52  (CompileTimeChecker<(expr) != 0>(ERROR_##msg())); \
53  }
54 
55 #ifdef DEBUG_ON
56 #define STATIC_ASSERT_DEBUG(expr, msg) STATIC_ASSERT_ALWAYS(expr, msg)
57 #else
58 #define STATIC_ASSERT_DEBUG(expr, msg)
59 #endif
60 
61 // (void)sizeof(CompileTimeChecker<(expr) != 0>((ERROR_##msg()))); \
62 
63 
64 // Store leading dimension (template argument) as static const
65 // Then one can either use "get" function (ROWS, COLS args not needed?) or
66 // specialize templates depending on the type (transposed or regular).
67 
68 
76  inline static int get( int const row, int const col,
77  int const rows, int const cols ) {
78  return row * cols + col;
79  }
80  template<int T_row, int T_col, int T_rows, int T_cols>
81  struct Get {
82  static int const index = T_row * T_cols + T_col;
83  };
84 
85 };
86 
91  inline static int get( int const row, int const col,
92  int const rows, int const cols ) {
93  return row + col * rows;
94  }
95  template<int T_row, int T_col, int T_rows, int T_cols>
96  struct Get {
97  static int const index = T_row + T_col * T_rows;
98  };
99 };
100 
101 
102 #endif
Class template for use in static asserts.
Definition: common.h:40
CompileTimeChecker(...)
Definition: common.h:41
Struct for access to matrix elements stored in row wise order.
Definition: common.h:75
static int const index
Definition: common.h:82
static int const index
Definition: common.h:97
Struct for access to matrix elements stored in column wise order.
Definition: common.h:90
Definition: common.h:96
Definition: common.h:81