parallel_impl.h

00001 #ifndef VVELIB_ALGORITHMS_PARALLEL_IMPL_H
00002 #define VVELIB_ALGORITHMS_PARALLEL_IMPL_H
00003 
00004 #include <config.h>
00005 #include <iterator>
00006 
00008 
00009 #include <vector>
00010 
00011 namespace parallel
00012 {
00013 
00014   template <typename Function>
00015   struct FunctionReduce0 : public ThreadEval
00016   {
00017     FunctionReduce0(const Function& f)
00018       : fct(f)
00019     { }
00020 
00021     void operator()() const
00022     {
00023       return fct();
00024     }
00025 
00026     const Function& fct;
00027   };
00028 
00029   template <typename Function>
00030   FunctionReduce0<Function>* functionReduce(const Function& f)
00031   {
00032     return new FunctionReduce0<Function>(f);
00033   }
00034 
00035   template <typename Function>
00036   struct FunctionReduce1 : public ThreadEval
00037   {
00038     typedef ONLY_ARG(Function) Arg;
00039     typedef void result_type;
00040     FunctionReduce1(const Function& f, Arg a)
00041       : fct(f)
00042       , arg(a)
00043     { }
00044 
00045     void operator()() const
00046     {
00047       return fct(arg);
00048     }
00049 
00050     const Function& fct;
00051     Arg arg;
00052   };
00053 
00054   template <typename Function>
00055   FunctionReduce1<Function>* functionReduce(const Function& f, ONLY_ARG(Function) arg)
00056   {
00057     return new FunctionReduce1<Function>(f, arg);
00058   }
00059 
00060   template <typename Function>
00061   struct FunctionReduce2 : public ThreadEval
00062   {
00063     typedef FIRST_ARG(Function) Arg1;
00064     typedef SECOND_ARG(Function) Arg2;
00065     typedef void result_type;
00066     FunctionReduce2(const Function& f, Arg1 a1, Arg2 a2)
00067       : fct(f)
00068       , arg1(a1)
00069       , arg2(a2)
00070     { }
00071 
00072     void operator()() const
00073     {
00074       return fct(arg1, arg2);
00075     }
00076 
00077     const Function& fct;
00078     Arg1 arg1;
00079     Arg2 arg2;
00080   };
00081 
00082   template <typename Function>
00083   FunctionReduce2<Function>* functionReduce(const Function& f, FIRST_ARG(Function) arg1, SECOND_ARG(Function) arg2)
00084   {
00085     return new FunctionReduce2<Function>(f, arg1, arg2);
00086   }
00087 
00088   template <typename Function>
00089   struct FunctionReduce3 : public ThreadEval
00090   {
00091     typedef FIRST_ARG(Function) Arg1;
00092     typedef SECOND_ARG(Function) Arg2;
00093     typedef THIRD_ARG(Function) Arg3;
00094     typedef void result_type;
00095     FunctionReduce3(const Function& f, Arg1 a1, Arg2 a2, Arg3 a3)
00096       : fct(f)
00097       , arg1(a1)
00098       , arg2(a2)
00099       , arg3(a3)
00100     { }
00101 
00102     void operator()() const
00103     {
00104       return fct(arg1, arg2, arg3);
00105     }
00106 
00107     const Function& fct;
00108     Arg1 arg1;
00109     Arg2 arg2;
00110     Arg3 arg3;
00111   };
00112 
00113   template <typename Function>
00114   FunctionReduce3<Function>* functionReduce(const Function& f, FIRST_ARG(Function) arg1, SECOND_ARG(Function) arg2, THIRD_ARG(Function) arg3)
00115   {
00116     return new FunctionReduce3<Function>(f, arg1, arg2, arg3);
00117   }
00118 
00119   template <typename Function>
00120   struct FunctionReduce4 : public ThreadEval
00121   {
00122     typedef FIRST_ARG(Function) Arg1;
00123     typedef SECOND_ARG(Function) Arg2;
00124     typedef THIRD_ARG(Function) Arg3;
00125     typedef FOURTH_ARG(Function) Arg4;
00126     typedef void result_type;
00127     FunctionReduce4(const Function& f, Arg1 a1, Arg2 a2, Arg3 a3, Arg4 a4)
00128       : fct(f)
00129       , arg1(a1)
00130       , arg2(a2)
00131       , arg3(a3)
00132       , arg4(a4)
00133     { }
00134 
00135     void operator()() const
00136     {
00137       return fct(arg1, arg2, arg3, arg4);
00138     }
00139 
00140     const Function& fct;
00141     Arg1 arg1;
00142     Arg2 arg2;
00143     Arg3 arg3;
00144     Arg4 arg4;
00145   };
00146 
00147   template <typename Function>
00148   FunctionReduce4<Function>* functionReduce(const Function& f, FIRST_ARG(Function) arg1, SECOND_ARG(Function) arg2, THIRD_ARG(Function) arg3, FOURTH_ARG(Function) arg4)
00149   {
00150     return new FunctionReduce4<Function>(f, arg1, arg2, arg3, arg4);
00151   }
00152 
00153   template <typename Function>
00154   void threadEval(const Function& fct)
00155   {
00156     ThreadPool::eval(functionReduce(fct));
00157   }
00158 
00159   template <typename Function>
00160   void threadEval(const Function& fct, ONLY_ARG(Function) a)
00161   {
00162     ThreadPool::eval(functionReduce(fct, a));
00163   }
00164 
00165   template <typename Function>
00166   void threadEval(const Function& fct, FIRST_ARG(Function) a1, SECOND_ARG(Function) a2)
00167   {
00168     ThreadPool::eval(functionReduce(fct, a1, a2));
00169   }
00170 
00171   template <typename Function>
00172   void threadEval(const Function& fct, FIRST_ARG(Function) a1, SECOND_ARG(Function) a2, THIRD_ARG(Function) a3)
00173   {
00174     ThreadPool::eval(functionReduce(fct, a1, a2, a3));
00175   }
00176 
00177   template <typename Function>
00178   void threadEval(const Function& fct, FIRST_ARG(Function) a1, SECOND_ARG(Function) a2, THIRD_ARG(Function) a3, FOURTH_ARG(Function) a4)
00179   {
00180     ThreadPool::eval(functionReduce(fct, a1, a2, a3, a4));
00181   }
00182 
00183 //  template <typename Function, typename Container>
00184 //  struct ThreadTransform : public ThreadEval
00185 //  {
00186 //    ThreadTransform(const Function& f)
00187 //      : fct(f)
00188 //    { }
00189 
00190 //    void operator()()
00191 //    {
00192 //      for(typename Container::iterator it = container.begin() ;
00193 //          it != container.end() ; ++it)
00194 //      {
00195 //        f(*it);
00196 //      }
00197 //    }
00198 
00199 //    const Function& f;
00200 //    Container& container;
00201 //  };
00202 
00203 //  template <typename Function, typename Container>
00204 //  void threadTransform(const Function& fct, Container& container)
00205 //  {
00206 //    return new ThreadTransform(fct, container);
00207 //  }
00208 
00209 //  template <typename Function, typename Container>
00210 //  void threadTransform(const Function& fct, SECOND_ARG(Function) a2, Container& container)
00211 //  {
00212 //  }
00213 
00214 //  template <typename Function, typename Container>
00215 //  void threadTransform(const Function& fct, SECOND_ARG(Function) a2, THIRD_ARG(Function) a3, Container& container)
00216 //  {
00217 //  }
00218 
00219 //  template <typename Function, typename Container>
00220 //  void threadTransform(const Function& fct, SECOND_ARG(Function) a2, THIRD_ARG(Function) a3, FOURTH_ARG(Function) a4, Container& container)
00221 //  {
00222 //  }
00223 
00224 }
00225 
00227 
00228 #endif // VVELIB_ALGORITHMS_PARALLEL_IMPL_H
00229 
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines
Generated on Fri May 31 15:37:50 2013 for VVE by  doxygen 1.6.3