Debian Codegraph @

src/atlas/parallel/omp/omp.h

raw
1 /*
2 * (C) Copyright 2013 ECMWF.
3 *
4 * This software is licensed under the terms of the Apache Licence Version 2.0
5 * which can be obtained at http://www.apache.org/licenses/LICENSE-2.0.
6 * In applying this licence, ECMWF does not waive the privileges and immunities
7 * granted to it by virtue of its status as an intergovernmental organisation
8 * nor does it submit to any jurisdiction.
9 */
10
11 #pragma once
12
13 #include "atlas/library/config.h"
14
15 void atlas_omp_set_num_threads(int num_threads);
16 int atlas_omp_get_num_threads(void);
17 int atlas_omp_get_max_threads(void);
18 int atlas_omp_get_thread_num(void);
19 int atlas_omp_get_num_procs(void);
20 int atlas_omp_in_parallel(void);
21 void atlas_omp_set_dynamic(int dynamic_threads);
22 int atlas_omp_get_dynamic(void);
23 void atlas_omp_set_nested(int nested);
24 int atlas_omp_get_nested(void);
25
26 #if ATLAS_HAVE_OMP
27 #define ATLAS_OMP_STR(x) #x
28 #define ATLAS_OMP_STRINGIFY(x) ATLAS_OMP_STR(x)
29 #define atlas_omp_pragma(x) _Pragma(ATLAS_OMP_STRINGIFY(x))
30 #else
31 #define atlas_omp_pragma(x)
32 #endif
33
34 #define atlas_omp_parallel_for atlas_omp_pragma(omp parallel for) for
35 #define atlas_omp_for atlas_omp_pragma(omp for) for
36 #define atlas_omp_parallel atlas_omp_pragma(omp parallel)
37 #define atlas_omp_critical atlas_omp_pragma(omp critical)
38
39 #ifndef DOXYGEN_SHOULD_SKIP_THIS
40 template <typename T>
41 class atlas_omp_scoped_helper {
42 public:
43 atlas_omp_scoped_helper(T p): value(p), once_(true) {}
44 bool once() const { return once_; }
45 void done() { once_ = false; }
46 T value;
47
48 private:
49 bool once_;
50 };
51
52 #define _atlas_omp_scoped(T, VAR, VAL) for (atlas_omp_scoped_helper<T> VAR(VAL); VAR.once(); VAR.done())
53 #endif
54
55 #define atlas_omp_critical_ordered \
56 _atlas_omp_scoped(const size_t, _nthreads, atlas_omp_get_num_threads()) \
57 atlas_omp_pragma( omp for ordered schedule(static,1) )\
58 for( size_t _thread=0; _thread<_nthreads.value; ++_thread )\
59 atlas_omp_pragma( omp ordered )
60
61 #undef _atlas_omp_scoped