My Project
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
42typedef tbb::blocked_range<int> C1DParallelRange;
43typedef tbb::mutex CMutex;
44typedef tbb::mutex::scoped_lock CScopedLock;
45
46typedef tbb::recursive_mutex CRecursiveMutex;
47typedef tbb::recursive_mutex::scoped_lock CRecursiveScopedLock;
48
49#define ATOMIC tbb::atomic
50
51template <typename Range, typename Func>
52void pfor(const Range& range, Func body)
53{
54 tbb::parallel_for(range, body);
55}
56
57template<typename Range, typename Value,
58 typename Func, typename Reduction>
59Value preduce( const Range& range, const Value& identity,
60 const Func& func, const Reduction& reduction)
61{
62 return tbb::parallel_reduce(range, identity, func, reduction);
63};
64
66
67#else // no TBB: use C++ 11 thread
68
70
71#endif
72
73
74#endif
#define NS_MIA_BEGIN
conveniance define to start the mia namespace
Definition: defines.hh:33
#define NS_MIA_END
conveniance define to end the mia namespace
Definition: defines.hh:36
std::recursive_mutex CRecursiveMutex
void pfor(Range range, const Func &f)
TScopedLock< CRecursiveMutex > CRecursiveScopedLock
std::mutex CMutex
Value preduce(Range range, Value identity, const Func &f, Reduce r)
TScopedLock< CMutex > CScopedLock