OpenMP.h
Go to the documentation of this file.
1 /*!
2  *
3  *
4  * \brief Set of macros to help usage of OpenMP with Shark
5  *
6  *
7  *
8  *
9  * \author Oswin Krause
10  * \date 2012
11  *
12  *
13  * \par Copyright 1995-2017 Shark Development Team
14  *
15  * <BR><HR>
16  * This file is part of Shark.
17  * <http://shark-ml.org/>
18  *
19  * Shark is free software: you can redistribute it and/or modify
20  * it under the terms of the GNU Lesser General Public License as published
21  * by the Free Software Foundation, either version 3 of the License, or
22  * (at your option) any later version.
23  *
24  * Shark is distributed in the hope that it will be useful,
25  * but WITHOUT ANY WARRANTY; without even the implied warranty of
26  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
27  * GNU Lesser General Public License for more details.
28  *
29  * You should have received a copy of the GNU Lesser General Public License
30  * along with Shark. If not, see <http://www.gnu.org/licenses/>.
31  *
32  */
33 #ifndef SHARK_CORE_OPENMP_H
34 #define SHARK_CORE_OPENMP_H
35 
36 #include <shark/Core/Shark.h>
37 
38 #ifdef SHARK_USE_OPENMP
39 #include <omp.h>
40 #include <boost/config.hpp>
41 
42 #if defined(BOOST_MSVC) || defined(__INTEL_COMPILER)
43 #define SHARK_PARALLEL_FOR __pragma(omp parallel for)\
44 for
45 
46 #define SHARK_CRITICAL_REGION __pragma(omp critical)
47 
48 #else
49 #define SHARK_PARALLEL_FOR \
50 _Pragma ( "omp parallel for" )\
51 for
52 
53 #define SHARK_CRITICAL_REGION _Pragma("omp critical (globalSharkLock)")
54 #endif
55 
56 #define SHARK_NUM_THREADS (std::size_t)(omp_in_parallel()?omp_get_num_threads():omp_get_max_threads())
57 #define SHARK_THREAD_NUM (std::size_t)(omp_in_parallel()?omp_get_thread_num():0)
58 
59 #else
60 #define SHARK_PARALLEL_FOR for
61 #define SHARK_CRITICAL_REGION
62 #define SHARK_NUM_THREADS (std::size_t)1
63 #define SHARK_THREAD_NUM (std::size_t)0
64 #endif
65 
66 #endif