36 template <
typename Functor>
38 const Functor& functor;
44 virtual FXint
run(){ functor();
return 0; }
52 template <
typename Functor1,
typename Functor2>
53 void FXParallelInvoke(FXThreadPool* pool,
const Functor1& fun1,
const Functor2& fun2){
54 FXTaskGroup group(pool);
55 FXParallelCallFunctor<Functor1> task1(fun1);
56 FXParallelCallFunctor<Functor2> task2(fun2);
57 group.execute(&task1);
58 group.executeAndWait(&task2);
67 template <
typename Functor1,
typename Functor2>
68 void FXParallelInvoke(
const Functor1& fun1,
const Functor2& fun2){
77 template <
typename Functor1,
typename Functor2,
typename Functor3>
78 void FXParallelInvoke(FXThreadPool* pool,
const Functor1& fun1,
const Functor2& fun2,
const Functor3& fun3){
79 FXTaskGroup group(pool);
80 FXParallelCallFunctor<Functor1> task1(fun1);
81 FXParallelCallFunctor<Functor2> task2(fun2);
82 FXParallelCallFunctor<Functor3> task3(fun3);
83 group.execute(&task1);
84 group.execute(&task2);
85 group.executeAndWait(&task3);
94 template <
typename Functor1,
typename Functor2,
typename Functor3>
95 void FXParallelInvoke(
const Functor1& fun1,
const Functor2& fun2,
const Functor3& fun3){
104 template <
typename Functor1,
typename Functor2,
typename Functor3,
typename Functor4>
105 void FXParallelInvoke(FXThreadPool* pool,
const Functor1& fun1,
const Functor2& fun2,
const Functor3& fun3,
const Functor4& fun4){
106 FXTaskGroup group(pool);
107 FXParallelCallFunctor<Functor1> task1(fun1);
108 FXParallelCallFunctor<Functor2> task2(fun2);
109 FXParallelCallFunctor<Functor3> task3(fun3);
110 FXParallelCallFunctor<Functor4> task4(fun4);
111 group.execute(&task1);
112 group.execute(&task2);
113 group.execute(&task3);
114 group.executeAndWait(&task4);
122 template <
typename Functor1,
typename Functor2,
typename Functor3,
typename Functor4>
123 void FXParallelInvoke(
const Functor1& fun1,
const Functor2& fun2,
const Functor3& fun3,
const Functor4& fun4){
132 template <
typename Functor1,
typename Functor2,
typename Functor3,
typename Functor4,
typename Functor5>
133 void FXParallelInvoke(FXThreadPool* pool,
const Functor1& fun1,
const Functor2& fun2,
const Functor3& fun3,
const Functor4& fun4,
const Functor4& fun5){
134 FXTaskGroup group(pool);
135 FXParallelCallFunctor<Functor1> task1(fun1);
136 FXParallelCallFunctor<Functor2> task2(fun2);
137 FXParallelCallFunctor<Functor3> task3(fun3);
138 FXParallelCallFunctor<Functor4> task4(fun4);
139 FXParallelCallFunctor<Functor5> task5(fun5);
140 group.execute(&task1);
141 group.execute(&task2);
142 group.execute(&task3);
143 group.execute(&task4);
144 group.executeAndWait(&task5);
152 template <
typename Functor1,
typename Functor2,
typename Functor3,
typename Functor4,
typename Functor5>
153 void FXParallelInvoke(
const Functor1& fun1,
const Functor2& fun2,
const Functor3& fun3,
const Functor4& fun4,
const Functor4& fun5){
162 template <
typename Functor1,
typename Functor2,
typename Functor3,
typename Functor4,
typename Functor5,
typename Functor6>
163 void FXParallelInvoke(FXThreadPool* pool,
const Functor1& fun1,
const Functor2& fun2,
const Functor3& fun3,
const Functor4& fun4,
const Functor5& fun5,
const Functor6& fun6){
164 FXTaskGroup group(pool);
165 FXParallelCallFunctor<Functor1> task1(fun1);
166 FXParallelCallFunctor<Functor2> task2(fun2);
167 FXParallelCallFunctor<Functor3> task3(fun3);
168 FXParallelCallFunctor<Functor4> task4(fun4);
169 FXParallelCallFunctor<Functor5> task5(fun5);
170 FXParallelCallFunctor<Functor6> task6(fun6);
171 group.execute(&task1);
172 group.execute(&task2);
173 group.execute(&task3);
174 group.execute(&task4);
175 group.execute(&task5);
176 group.executeAndWait(&task6);
185 template <
typename Functor1,
typename Functor2,
typename Functor3,
typename Functor4,
typename Functor5,
typename Functor6>
186 void FXParallelInvoke(Functor1& fun1,
const Functor2& fun2,
const Functor3& fun3,
const Functor4& fun4,
const Functor5& fun5,
const Functor6& fun6){
195 template <
typename Functor1,
typename Functor2,
typename Functor3,
typename Functor4,
typename Functor5,
typename Functor6,
typename Functor7>
196 void FXParallelInvoke(FXThreadPool* pool,
const Functor1& fun1,
const Functor2& fun2,
const Functor3& fun3,
const Functor4& fun4,
const Functor5& fun5,
const Functor6& fun6,
const Functor7& fun7){
197 FXTaskGroup group(pool);
198 FXParallelCallFunctor<Functor1> task1(fun1);
199 FXParallelCallFunctor<Functor2> task2(fun2);
200 FXParallelCallFunctor<Functor3> task3(fun3);
201 FXParallelCallFunctor<Functor4> task4(fun4);
202 FXParallelCallFunctor<Functor5> task5(fun5);
203 FXParallelCallFunctor<Functor6> task6(fun6);
204 FXParallelCallFunctor<Functor7> task7(fun7);
205 group.execute(&task1);
206 group.execute(&task2);
207 group.execute(&task3);
208 group.execute(&task4);
209 group.execute(&task5);
210 group.execute(&task6);
211 group.executeAndWait(&task7);
220 template <
typename Functor1,
typename Functor2,
typename Functor3,
typename Functor4,
typename Functor5,
typename Functor6,
typename Functor7>
221 void FXParallelInvoke(Functor1& fun1,
const Functor2& fun2,
const Functor3& fun3,
const Functor4& fun4,
const Functor5& fun5,
const Functor6& fun6,
const Functor7& fun7){
231 template <
typename Functor1,
typename Functor2,
typename Functor3,
typename Functor4,
typename Functor5,
typename Functor6,
typename Functor7,
typename Functor8>
232 void FXParallelInvoke(FXThreadPool* pool,
const Functor1& fun1,
const Functor2& fun2,
const Functor3& fun3,
const Functor4& fun4,
const Functor5& fun5,
const Functor6& fun6,
const Functor7& fun7,
const Functor8& fun8){
233 FXTaskGroup group(pool);
234 FXParallelCallFunctor<Functor1> task1(fun1);
235 FXParallelCallFunctor<Functor2> task2(fun2);
236 FXParallelCallFunctor<Functor3> task3(fun3);
237 FXParallelCallFunctor<Functor4> task4(fun4);
238 FXParallelCallFunctor<Functor5> task5(fun5);
239 FXParallelCallFunctor<Functor6> task6(fun6);
240 FXParallelCallFunctor<Functor7> task7(fun7);
241 FXParallelCallFunctor<Functor8> task8(fun8);
242 group.execute(&task1);
243 group.execute(&task2);
244 group.execute(&task3);
245 group.execute(&task4);
246 group.execute(&task5);
247 group.execute(&task6);
248 group.execute(&task7);
249 group.executeAndWait(&task8);
258 template <
typename Functor1,
typename Functor2,
typename Functor3,
typename Functor4,
typename Functor5,
typename Functor6,
typename Functor7,
typename Functor8>
259 void FXParallelInvoke(Functor1& fun1,
const Functor2& fun2,
const Functor3& fun3,
const Functor4& fun4,
const Functor5& fun5,
const Functor6& fun6,
const Functor7& fun7,
const Functor8& fun8){
269 template <
typename Functor,
typename Index>
271 const Functor& functor;
279 FXParallelForFunctor(
const Functor& fun,Index f,Index t,Index b):functor(fun),fm(f),to(t),by(b){ }
280 virtual FXint
run(){
for(Index ix=fm;ix<to;ix+=by){ functor(ix); }
return 0; }
289 template <
typename Functor,
typename Index>
290 void FXParallelFor(FXThreadPool* pool,Index fm,Index to,Index by,Index nc,
const Functor& fun){
291 const FXuval size=(
sizeof(FXParallelForFunctor<Functor,Index>)+
sizeof(FXulong)-1)/
sizeof(FXulong);
294 FXTaskGroup group(pool);
295 FXulong space[FXParallelMax*((
sizeof(FXParallelForFunctor<Functor,Index>)+
sizeof(FXulong)-1)/
sizeof(FXulong))];
296 Index nits=1+(to-fm-1)/by,ni,c;
297 if(nc>FXParallelMax) nc=FXParallelMax;
299 for(c=0; c<nc; fm+=ni*by,++c){
301 group.execute(
new (&space[c*size]) FXParallelForFunctor<Functor,Index>(fun,fm,fm+ni*by,by));
317 template <
typename Functor,
typename Index>
318 void FXParallelFor(Index fm,Index to,Index by,Index nc,
const Functor& fun){
328 template <
typename Functor,
typename Index>
329 void FXParallelFor(FXThreadPool* pool,Index fm,Index to,Index by,
const Functor& fun){
330 FXParallelFor(pool,fm,to,by,(Index)pool->getMaximumThreads(),fun);
340 template <
typename Functor,
typename Index>
341 void FXParallelFor(Index fm,Index to,Index by,
const Functor& fun){
static FXThreadPool * instance()
Return calling thread's thread pool.
virtual FXint run()
Subclasses should overload this function to perform actual work.
Definition: FXParallel.h:44
Definition: FX4Splitter.h:28
virtual FXint run()
Subclasses should overload this function to perform actual work.
Definition: FXParallel.h:280
FXParallelLoopFunctor is a helper for FXParallelFor.
Definition: FXParallel.h:270
FXParallelCallFunctor is a helper for FXParallelInvoke.
Definition: FXParallel.h:37
FXRunnable represents a generic runnable thing.
Definition: FXRunnable.h:33