MPQC  3.0.0-alpha
macros.h
1 //
2 // macros.h
3 //
4 // Copyright (C) 2014 David Hollman
5 //
6 // Author: David Hollman
7 // Maintainer: DSH
8 // Created: Mar 5, 2014
9 //
10 // This file is part of the SC Toolkit.
11 //
12 // The SC Toolkit is free software; you can redistribute it and/or modify
13 // it under the terms of the GNU Library General Public License as published by
14 // the Free Software Foundation; either version 2, or (at your option)
15 // any later version.
16 //
17 // The SC Toolkit is distributed in the hope that it will be useful,
18 // but WITHOUT ANY WARRANTY; without even the implied warranty of
19 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
20 // GNU Library General Public License for more details.
21 //
22 // You should have received a copy of the GNU Library General Public License
23 // along with the SC Toolkit; see the file COPYING.LIB. If not, write to
24 // the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.
25 //
26 // The U.S. Government is granted a limited license as per AL 91-7.
27 //
28 
29 #ifndef _chemistry_qc_scf_cadf_macros_h
30 #define _chemistry_qc_scf_cadf_macros_h
31 
32 // TODO Move this to a more global, reasonable place
33 #define DECLARE_ATTRIBUTE_LESS_STRUCT_NAMED(struct_name, attr_name) \
34  template<typename T> \
35  struct struct_name \
36  { \
37  bool operator()(const T& a, const T& b) const { \
38  return a.##attr_name < b.##attr_name; \
39  } \
40  }
41 #define DECLARE_ATTRIBUTE_LESS_STRUCT(attr_name) \
42  DECLARE_ATTRIBUTE_LESS_STRUCT_NAMED(attr_name##_less, attr_name)
43 
44 
45 #define M_DUMP(M) std::cout << #M << " is " << M.rows() << " x " << M.cols() << std::endl;
46 
47 #define M_ELEM_DUMP(M, r, c) \
48  ExEnv::out0() << #M << " is " << M.rows() << " x " << M.cols() << ", trying to access element (" \
49  << r << ", " << c << ")." << std::endl;
50 
51 #define M_ROW_ASSERT(M1, M2) \
52  if(M1.rows() != M2.rows()) { \
53  boost::lock_guard<boost::mutex> _tmp(debug_print_mutex); \
54  cout << "assertion failed. Rows not equal: M1 => " << M1.rows() << " x " << M1.cols() << ", M2 => " << M2.rows() << " x " << M2.cols() << endl; \
55  assert(false); \
56  }
57 #define M_COL_ASSERT(M1, M2) \
58  if(M1.cols() != M2.cols()) { \
59  boost::lock_guard<boost::mutex> _tmp(debug_print_mutex); \
60  cout << "assertion failed. Cols not equal: M1 => " << M1.rows() << " x " << M1.cols() << ", M2 => " << M2.rows() << " x " << M2.cols() << endl; \
61  assert(false); \
62  }
63 
64 #define M_PROD_CHECK(R, M1, M2) \
65  if(R.rows() != M1.rows() || R.cols() != M2.cols() || M1.cols() != M2.rows()) { \
66  boost::lock_guard<boost::mutex> _tmp(debug_print_mutex); \
67  cout << "can't perform multiplication: (" << R.rows() << " x " << R.cols() << ") = (" << M1.rows() << " x " << M1.cols() << ") * (" << M2.rows() << " x " << M2.cols() << ")" << endl; \
68  assert(false); \
69  }
70 
71 #define M_DOT_CHECK(M1, M2) \
72  if(1 != M1.rows() || 1 != M2.cols() || M1.cols() != M2.rows()) { \
73  boost::lock_guard<boost::mutex> _tmp(debug_print_mutex); \
74  cout << "can't perform multiplication: (" << 1 << " x " << 1 << ") = (" << M1.rows() << " x " << M1.cols() << ") * (" << M2.rows() << " x " << M2.cols() << ")" << endl; \
75  assert(false); \
76  }
77 
78 #define DECOMP_PRINT(D, M) \
79  {\
80  boost::lock_guard<boost::mutex> _tmp(debug_print_mutex); \
81  cout << "Decomposition: " << D.matrixQR().rows() << " x " << D.matrixQR().cols() << ", M => " << M.rows() << " x " << M.cols() << endl; \
82  }
83 
84 #define M_EQ_ASSERT(M1, M2) M_ROW_ASSERT(M1, M2); M_COL_ASSERT(M1, M2);
85 
86 #define M_BLOCK_ASSERT(M, b1a, b1b, b2a, b2b) \
87  if(b1a < 0) { \
88  std::cout << "assertion 1 failed. data: " << "(" << M.rows() << ", " << M.cols() << ", " << b1a << ", " << b1b << ", " << b2a << ", " << b2b << ")" << std::endl; \
89  } \
90  else if(b1b < 0) { \
91  std::cout << "assertion 2 failed. data: " << "(" << M.rows() << ", " << M.cols() << ", " << b1a << ", " << b1b << ", " << b2a << ", " << b2b << ")" << std::endl; \
92  } \
93  else if(b1a > M.rows() - b2a) { \
94  std::cout << "assertion 3 failed. data: " << "(" << M.rows() << ", " << M.cols() << ", " << b1a << ", " << b1b << ", " << b2a << ", " << b2b << ")" << std::endl; \
95  } \
96  else if(b1b > M.cols() - b2b) { \
97  std::cout << "assertion 4 failed. data: " << "(" << M.rows() << ", " << M.cols() << ", " << b1a << ", " << b1b << ", " << b2a << ", " << b2b << ")" << std::endl; \
98  }
99 
100 #define DUMP(expr) sc::ExEnv::out0() << #expr << " = " << (expr) << std::endl;
101 #define DUMPme(expr) sc::ExEnv::outn() << " Node " << scf_grp_->me() << ": " << #expr << " = " << (expr) << std::endl;
102 #define DUMPn(expr) \
103  { \
104  scf_grp_->sync(); \
105  sc::ExEnv::out0() << "Dumping expression " << #expr << " from all nodes:" << std::endl; \
106  for(int __inode = 0; __inode < scf_grp_->n(); ++__inode) {\
107  if(__inode == scf_grp_->me()) { \
108  sc::ExEnv::outn() << " Node " << scf_grp_->me() << ": " << #expr << " = " << expr << std::endl; \
109  } \
110  scf_grp_->sync(); \
111  }}
112 #define DUMP2(expr1, expr2) sc::ExEnv::out0() << #expr1 << " = " << (expr1) << ", " << #expr2 << " = " << (expr2) << std::endl;
113 #define DUMP2n(expr1, expr2) sc::ExEnv::outn() << "me = " << scf_grp_->me() << ", " << #expr1 << " = " << (expr1) << ", " << #expr2 << " = " << (expr2) << std::endl;
114 #define DUMP3(expr1, expr2, expr3) sc::ExEnv::out0() << #expr1 << " = " << (expr1) << ", " << #expr2 << " = " << (expr2) << ", " << #expr3 << " = " << (expr3) << std::endl;
115 #define DUMP4(expr1, expr2, expr3, expr4) ExEnv::out0() << #expr1 << " = " << (expr1) << ", " << #expr2 << " = " << (expr2) << ", " << #expr3 << " = " << (expr3) << ", " << #expr4 << " = " << (expr4) << std::endl;
116 #define DUMP5(expr1, expr2, expr3, expr4, expr5) std::cout << #expr1 << " = " << (expr1) << ", " << #expr2 << " = " << (expr2) << ", " << #expr3 << " = " << (expr3) << ", " << #expr4 << " = " << (expr4) << ", " << #expr5 << " = " << (expr5) << std::endl;
117 #define out_assert(a, op, b) assert(a op b || ((ExEnv::out0() << "Failed assertion output: " << #a << " ( = " << a << ") " << #op << " " << #b << " ( = " << b << ")" << std::endl), false))
118 #define DEBUG_DELETE_THIS
119 
120 #define resize_and_zero_matrix(mat, nrows, ncols) mat.resize(nrows, ncols); mat = std::remove_reference<decltype(mat)>::type::Zero(nrows, ncols)
121 #define declare_and_zero_matrix(type, mat, nrows, ncols) type mat(nrows, ncols); mat = type::Zero(nrows, ncols)
122 
123 #define MAKE_MATRIX(type, name, rows, cols) type name(rows, cols); auto __##name##_mem_holder = hold_memory(rows*cols*sizeof(Eigen::internal::traits<type>::Scalar) + sizeof(type));
124 
125 //#define PRINT_AS_GRID(o, itervar, iterable, expr, fmt, nperline) \
126 // { int __numdone = 0; \
127 // for(auto&& itervar : iterable) { \
128 // if(__numdone != 0 && __numdone % nperline == 0) { o << std::endl << sc::indent; } \
129 // o << std::string(sc::scprintf(fmt, (expr))); \
130 // ++__numdone; \
131 // } \
132 // }
133 
134 #define PRINT_STRING_AS_GRID(o, itervar, iterable, str, nperline) \
135  { int __numdone = 0; \
136  for(auto&& itervar : iterable) { \
137  if(__numdone != 0 && __numdone % nperline == 0) { o << std::endl << sc::indent; } \
138  o << str << " "; \
139  ++__numdone; \
140  } \
141  }
142 
143 #define PRINT_AS_GRID(o, itervar, iterable, expr, fmt, nperline) PRINT_STRING_AS_GRID(o, itervar, iterable, (std::string(sc::scprintf(fmt, (expr)).str())), nperline)
144 
145 #endif /* _chemistry_qc_scf_cadf_macros_h */

Generated at Sun Jan 26 2020 23:23:57 for MPQC 3.0.0-alpha using the documentation package Doxygen 1.8.16.