ampsci
High-precision calculations for one- and two-valence atomic systems
omp.hpp
Go to the documentation of this file.
1#pragma once
2/*! @file
3 @brief Include instead of `<omp.h>` to allow compilation with or without OpenMP.
4
5 @details
6 If OpenMP is not available, stub macros are provided so `#pragma omp`
7 directives are silently ignored, and the common `omp_*thread` functions return
8 0 or 1.
9*/
10#include <string>
11
12#if defined(_OPENMP)
13#include <omp.h>
14namespace qip {
15//! True if compiled with OpenMP support, false otherwise.
16constexpr bool use_omp = true;
17} // namespace qip
18#else
19#pragma GCC diagnostic ignored "-Wunknown-pragmas"
20namespace qip {
21//! True if compiled with OpenMP support, false otherwise.
22constexpr bool use_omp = false;
23} // namespace qip
24#define omp_get_thread_num() 0
25#define omp_get_max_threads() 1
26#define omp_get_num_threads() 1
27#endif
28
29namespace qip {
30//! Returns a short string describing the threading status, e.g.
31//! "Using OpenMP with 8 threads." or "Single-threaded."
32inline std::string omp_details() {
33 return use_omp ? "Using OpenMP with " +
34 std::to_string(omp_get_max_threads()) + " threads." :
35 "Single-threaded.";
36}
37} // namespace qip
General-purpose utility library.
Definition Array.hpp:23
constexpr bool use_omp
True if compiled with OpenMP support, false otherwise.
Definition omp.hpp:22
std::string omp_details()
Returns a short string describing the threading status, e.g. "Using OpenMP with 8 threads....
Definition omp.hpp:32