parallel_foreach.h 7.23 KB
Newer Older
Sylvain Thery's avatar
Sylvain Thery committed
1
2
3
/*******************************************************************************
* CGoGN: Combinatorial and Geometric modeling with Generic N-dimensional Maps  *
* version 0.1                                                                  *
4
* Copyright (C) 2009-2012, IGG Team, LSIIT, University of Strasbourg           *
Sylvain Thery's avatar
Sylvain Thery committed
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
*                                                                              *
* This library is free software; you can redistribute it and/or modify it      *
* under the terms of the GNU Lesser General Public License as published by the *
* Free Software Foundation; either version 2.1 of the License, or (at your     *
* option) any later version.                                                   *
*                                                                              *
* This library is distributed in the hope that it will be useful, but WITHOUT  *
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or        *
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License  *
* for more details.                                                            *
*                                                                              *
* You should have received a copy of the GNU Lesser General Public License     *
* along with this library; if not, write to the Free Software Foundation,      *
* Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301 USA.           *
*                                                                              *
20
* Web site: http://cgogn.unistra.fr/                                           *
Sylvain Thery's avatar
Sylvain Thery committed
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
* Contact information: cgogn@unistra.fr                                        *
*                                                                              *
*******************************************************************************/

#include "Topology/generic/functor.h"

#ifndef __PARALLEL_FOREACH__
#define __PARALLEL_FOREACH__

namespace CGoGN
{

namespace Algo
{

namespace Parallel
{

39
40
/// size of buffers to store darts or indexes in each threads
const unsigned int SIZE_BUFFER_THREAD = 8192;	// seems to be the best compromise
41
42

/**
43
 * @return How much threads has you computer
44
 */
45
inline unsigned int nbThreads();
46

Sylvain Thery's avatar
Sylvain Thery committed
47
/**
48
 * @return Number of core in fact (work only with quad core with/without hyper threading)
Sylvain Thery's avatar
Sylvain Thery committed
49
 */
50
inline unsigned int optimalNbThreads();
Sylvain Thery's avatar
Sylvain Thery committed
51

52

Sylvain Thery's avatar
Sylvain Thery committed
53
/**
54
55
 * Traverse cells of a map in parallel. Use quick traversal, cell markers or dart markers if available !
 * Use this version if you need to have acces to each functors after the traversal (to compute a sum or an average for example)
Sylvain Thery's avatar
Sylvain Thery committed
56
 * @param map the map
57
58
59
 * @param funcs the functors to apply (size of vector must be equal to nbth)
 * @param nbth number of threads
 * @param needMarkers set to yes if you want that each thread use different markers. Warning if set to false (default) do not use algo with thread id or markers !!
Sylvain Thery's avatar
Sylvain Thery committed
60
61
 * @param good a selector
 */
62
63
template <typename MAP, unsigned int ORBIT>
void foreach_cell(MAP& map, std::vector<FunctorMapThreaded<MAP>*>& funcs, unsigned int nbth, bool needMarkers = false, const FunctorSelect& good = allDarts, unsigned int currentThread = 0);
64
65

/**
66
67
 * Traverse cells of a map in parallel. Use quick traversal, cell markers or dart markers if available !
 * Use this version if you do not need to keep functors
68
69
 * @param map the map
 * @param func the functor to apply
70
71
 * @param nbth number of threads 0 for let the system choose
 * @param needMarkers set to yes if you want that each thread use different markers. Warning if set to false (default) do not use algo with thread id or markers !!
72
73
 * @param good a selector
 */
74
template <typename MAP, unsigned int ORBIT>
75
void foreach_cell(MAP& map, FunctorMapThreaded<MAP>& func, unsigned int nbth = 0, bool needMarkers = false, const FunctorSelect& good = allDarts, unsigned int currentThread = 0);
76
77

/**
78
79
 * Traverse darts of a map in parallel
 * Use this version if you need to have acces to each functors after the traversal (to compute a sum or an average for example)
80
 * @param map the map
81
82
83
 * @param funcs the functors to apply
 * @param nbth number of thread to use
 * @param needMarkers set to yes if you want that each thread use different markers.Warning if set to false (default) do not use algo with thread id or markers !!
84
85
 * @param good a selector
 */
86
87
88
template <typename MAP>
void foreach_dart(MAP& map, std::vector<FunctorMapThreaded<MAP>*>& funcs,  unsigned int nbth, bool needMarkers = false, const FunctorSelect& good = allDarts);

89
90

/**
91
 * Traverse darts of a map in parallel
92
 * @param map the map
93
94
95
 * @param funcs the functor
 * @param nbth number of thread to use, 0 for let the system choose
 * @param needMarkers set to yes if you want that each thread use different markers. Warning if set to false (default) do not use algo with thread id or markers !!
96
97
 * @param good a selector
 */
98
template <typename MAP>
99
void foreach_dart(MAP& map, FunctorMapThreaded<MAP>& func, unsigned int nbth = 0, bool needMarkers = false, const FunctorSelect& good = allDarts);
100
101
102


/**
103
104
105
106
 * Traverse all elements of an attribute container (attribute handler is placed in FunctorAttribThreaded)
 * @param attr_cont the attribute container to traverse
 * @param func the fonctors to use
 * @param nbth number of thread to use for computation
107
 */
108
void foreach_attrib(AttributeContainer& attr_cont, std::vector<FunctorAttribThreaded*> funcs, unsigned int nbth);
109
110

/**
111
112
113
114
 * Traverse all elements of an attribute container (attribute handler is placed in FunctorAttribThreaded
 * @param attr_cont the attribute container to traverse
 * @param func the functor to use
 * @param nbth number of thread to use for computation 0 for let the system choose
115
 */
116
void foreach_attrib(AttributeContainer& attr_cont, FunctorAttribThreaded& func, unsigned int nbth = 0);
117

118
119

/**
120
121
122
123
124
125
126
127
 * Optimized version for // foreach with to pass (2 functors), with several loops
 * Use this version if you need to keep functors
 * @param map the map
 * @param funcsFrontnBack nbth front pass functors followed by nbth back pass functors
 * @param nbLoops number of loops to execute
 * @param nbth number of threads to use
 * @param needMarkers set to yes if you want that each thread use different markers (markers are allocated if necessary)
 * @param good a selector
128
 */
129
130
template <typename MAP, unsigned int CELL>
void foreach_cell2Pass(MAP& map, std::vector<FunctorMapThreaded<MAP>*>& funcsFrontnBack, unsigned int nbLoops, unsigned int nbth, bool needMarkers = false, const FunctorSelect& good = allDarts);
131

132
/**
133
134
135
136
137
138
139
140
141
 * Optimized version for // foreach with to pass (2 functors), with several loops
 * Use this version if you do not need to keep functors
 * @param map the map
 * @param funcFront front pass functor
 * @param funcBack back pass functor
 * @param nbLoops number of loops to execute
 * @param nbth number of threads to use
 * @param needMarkers set to yes if you want that each thread use different markers (markers are allocated if necessary)
 * @param good a selector
142
 */
143
template <typename MAP, unsigned int CELL>
144
void foreach_cell2Pass(MAP& map, FunctorMapThreaded<MAP>& funcFront, FunctorMapThreaded<MAP>& funcBack, unsigned int nbLoops, unsigned int nbth, bool needMarkers = false, const FunctorSelect& good = allDarts);
145

146

Pierre Kraemer's avatar
Pierre Kraemer committed
147
} // namespace Parallel
Sylvain Thery's avatar
Sylvain Thery committed
148

Pierre Kraemer's avatar
Pierre Kraemer committed
149
} // namespace Algo
Sylvain Thery's avatar
Sylvain Thery committed
150

Pierre Kraemer's avatar
Pierre Kraemer committed
151
} // namespace CGoGN
Sylvain Thery's avatar
Sylvain Thery committed
152
153
154
155

#include "Algo/Parallel/parallel_foreach.hpp"

#endif