My Project
common.hpp
Go to the documentation of this file.
1 #pragma once
2 
8 #include <Eigen/Eigen>
9 #include <functional>
10 #include <iostream>
11 
12 #ifndef NDEBUG
14  #define check(condition, message) \
15  do { \
16  if (!condition) { \
17  std::cerr << "[FAILED ASSERTION]" << std::endl; \
18  std::cerr << " Condition: " << #condition << std::endl; \
19  std::cerr << " Message: " << (message) << std::endl; \
20  std::cerr << " File: " << __FILE__ << ", Line: " << __LINE__ << std::endl; \
21  std::cerr << " Aborting..." << std::endl; \
22  std::abort(); \
23  } \
24  } while (0)
25 
26 #else
28  #define check(condition, message) ((void)0)
29 #endif
30 
32 template <typename T> using GradFun = std::function<T(T)>;
33 
35 template <typename T, typename W> using VecFun = std::function<W(T)>;
36 
38 template <typename V, typename M> using HessFun = std::function<M(V)>;
39 
40 #ifdef _OPENMP
41  #include <omp.h>
42 #endif
43 
45 inline void checkParallelism() {
46  std::cout << "=== CHECK EIGEN PARALLELISM ===" << std::endl;
47 
48 #ifdef EIGEN_USE_OPENMP
49  std::cout << "[COMPILE] EIGEN_USE_OPENMP macro: ACTIVE (OK)" << std::endl;
50 #else
51  std::cout << "[COMPILE] EIGEN_USE_OPENMP macro: INACTIVE (Warning!)" << std::endl;
52 #endif
53 
54 #ifdef _OPENMP
55  std::cout << "[OPENMP] OpenMP detected." << std::endl;
56  std::cout << "[OPENMP] Max available threads: " << omp_get_max_threads() << std::endl;
57 #else
58  std::cout << "[OPENMP] OpenMP NOT detected by compiler." << std::endl;
59 #endif
60 
61  std::cout << "[EIGEN] Eigen will use: " << Eigen::nbThreads() << " threads." << std::endl;
62 
63  std::cout << "================================" << std::endl << std::endl;
64 }
std::function< T(T)> GradFun
Gradient function type alias (T -> T).
Definition: common.hpp:32
std::function< W(T)> VecFun
Objective function type alias (T -> W).
Definition: common.hpp:35
void checkParallelism()
Print Eigen/OpenMP parallelism settings for diagnostics.
Definition: common.hpp:45
std::function< M(V)> HessFun
Hessian function type alias (V -> M).
Definition: common.hpp:38