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
40
NS_MIA_BEGIN
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
{
54
tbb::parallel_for(range, body);
55
}
56
57
template
<
typename
Range,
typename
Value,
58
typename
Func,
typename
Reduction>
59
Value
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
65
NS_MIA_END
66
67
#else // no TBB: use C++ 11 thread
68
69
#include <
mia/core/parallelcxx11.hh
>
70
71
#endif
72
73
74
#endif
CMutex
std::mutex CMutex
Definition:
parallelcxx11.hh:34
NS_MIA_BEGIN
#define NS_MIA_BEGIN
conveniance define to start the mia namespace
Definition:
defines.hh:33
pfor
void pfor(Range range, const Func &f)
Definition:
parallelcxx11.hh:159
NS_MIA_END
#define NS_MIA_END
conveniance define to end the mia namespace
Definition:
defines.hh:36
CRecursiveMutex
std::recursive_mutex CRecursiveMutex
Definition:
parallelcxx11.hh:35
CScopedLock
TScopedLock< CMutex > CScopedLock
Definition:
parallelcxx11.hh:80
parallelcxx11.hh
CRecursiveScopedLock
TScopedLock< CRecursiveMutex > CRecursiveScopedLock
Definition:
parallelcxx11.hh:81
C1DParallelRange
Definition:
parallelcxx11.hh:83
preduce
Value preduce(Range range, Value identity, const Func &f, Reduce r)
Definition:
parallelcxx11.hh:224
defines.hh
mia
core
parallel.hh
Generated by
1.8.17