SkePU(integratedwithStarPU)  0.8.1
 All Classes Namespaces Files Functions Enumerations Friends Macros Groups Pages
farm.h
Go to the documentation of this file.
1 
5 #ifndef FARM_H
6 #define FARM_H
7 
8 #include <iostream>
9 #include "task.h"
10 #include "src/environment.h"
11 
12 namespace skepu
13 {
14 
15 
43 {
44  starpu_task_wait_for_all();
45  getTagIds().clear();
46 }
47 
54 void join_farm()
55 {
56  std::vector<unsigned int> *v= &(getTagIds());
57 
58  std::vector<unsigned int>::iterator it = v->begin();
59  for(; it!= v->end(); it++)
60  {
61  starpu_tag_wait(*it);
62  }
63  v->clear();
64 }
65 
66 
67 /*
68 * unary compose, just offload maybe, also serves as base case
69 */
70 template<typename Function1>
71 void farm(Function1 *f1)
72 {
73 // setIsFormCall(true);
74  ((Task*)f1)->run_async(); //call f1
75 // setIsFormCall(false);
76 }
77 
78 #ifdef __GXX_EXPERIMENTAL_CXX0X__
79 
80 
84 unsigned count_arguments()
85 {
86  return 0;
87 }
88 
92 template<typename Function1, typename... FurtherFunctions>
93 unsigned count_arguments(Function1 *f1, FurtherFunctions... further_functions)
94 {
95  return 1 + count_arguments(std::forward<FurtherFunctions>(further_functions)...);
96 }
97 
101 void call_with_task()
102 {
103 }
104 
108 template<typename Function1, typename... FurtherFunctions>
109 void call_with_task(Function1 *f1, FurtherFunctions... further_functions)
110 {
111  ((Task*)f1)->run_async();
112 
113  //call rest
114  call_with_task(std::forward<FurtherFunctions>(further_functions)...);
115 }
116 
117 
121 template<typename... Functions>
122 void farm(Functions... functions)
123 {
124  setIsFormCall(true);
125 
126  call_with_task(functions...);
127 
128  setIsFormCall(false);
129 
130  if(!getUseTagId()) // join before returning control, but only if in normal mode
131  starpu_task_wait_for_all();
132 }
133 
134 #else
135 
139 template<typename Function1, typename Function2>
140 void farm(Function1 *f1, Function2 *f2)
141 {
142  setIsFormCall(true);
143 
144  ((Task*)f1)->run_async();
145  ((Task*)f2)->run_async();
146 
147  setIsFormCall(false);
148 
149  if(!getUseTagId()) // join before returning control, but only if in normal mode
150  starpu_task_wait_for_all();
151 }
152 #endif
153 
154 
155 }
156 
157 #endif
158 
void join_farm()
Definition: farm.h:54
Contains a class definition for Task.
A class representing a Task for the farm skeleton.
Definition: task.h:31
Contains a class declaration for Environment class.
void join_farm_all()
Definition: farm.h:42