parallel.hh
Go to the documentation of this file.
1 /* -*- mia-c++ -*-
2  *
3  * This file is part of MIA - a toolbox for medical image analysis
4  * Copyright (c) Leipzig, Madrid 1999-2017 Gert Wollny
5  *
6  * MIA is free software; you can redistribute it and/or modify
7  * it under the terms of the GNU General Public License as published by
8  * the Free Software Foundation; either version 3 of the License, or
9  * (at your option) any later version.
10  *
11  * This program is distributed in the hope that it will be useful,
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14  * GNU General Public License for more details.
15  *
16  * You should have received a copy of the GNU General Public License
17  * along with MIA; if not, see <http://www.gnu.org/licenses/>.
18  *
19  */
20 
21 #ifndef mia_core_parallel_hh
22 #define mia_core_parallel_hh
23 
24 
25 #include <miaconfig.h>
26 
27 #include <mia/core/defines.hh>
28 
29 #ifdef HAVE_TBB
30 
31 #include <tbb/task_scheduler_init.h>
32 #include <tbb/recursive_mutex.h>
33 #include <tbb/mutex.h>
34 #include <tbb/parallel_for.h>
35 #include <tbb/parallel_reduce.h>
36 #include <tbb/blocked_range.h>
37 #include <tbb/recursive_mutex.h>
38 #include <tbb/spin_mutex.h>
39 
41 
42 typedef tbb::blocked_range<int> C1DParallelRange;
43 typedef tbb::mutex CMutex;
44 typedef tbb::mutex::scoped_lock CScopedLock;
45 
46 typedef tbb::recursive_mutex CRecursiveMutex;
47 typedef tbb::recursive_mutex::scoped_lock CRecursiveScopedLock;
48 
49 #define ATOMIC tbb::atomic
50 
51 template <typename Range, typename Func>
52 void pfor(const Range& range, Func body) {
53  tbb::parallel_for(range, body);
54 }
55 
56 template<typename Range, typename Value,
57  typename Func, typename Reduction>
58 Value preduce( const Range& range, const Value& identity,
59  const Func& func, const Reduction& reduction) {
60  return tbb::parallel_reduce(range, identity, func, reduction);
61 };
62 
64 
65 #else // no TBB: use C++ 11 thread
66 
68 
69 #endif
70 
71 
72 #endif
void pfor(Range range, const Func &f)
TScopedLock< CRecursiveMutex > CRecursiveScopedLock
#define NS_MIA_BEGIN
conveniance define to start the mia namespace
Definition: defines.hh:33
std::recursive_mutex CRecursiveMutex
Value preduce(Range range, Value identity, const Func &f, Reduce r)
TScopedLock< CMutex > CScopedLock
std::mutex CMutex
#define NS_MIA_END
conveniance define to end the mia namespace
Definition: defines.hh:36