SkelGIS
3.0
|
00001 /*! \file apply_binary.hpp 00002 * \brief Definitions of the skeleton object ApplyBinary. This skeleton takes a user function and two DMatrix as inputs and return a new DMatrix as output. 00003 */ 00004 #ifndef APPLY_BINARY_H 00005 #define APPLY_BINARY_H 00006 00007 namespace skelgis{ 00008 00009 //================================================================================ 00010 //Types of user functions 00011 //================================================================================ 00012 //! _ApplyBinary_Func structure 00013 /*! 00014 These objects are not directly used by the user, but the macros used by the user, to define its functions, uses these. Four specializations of this structure are available. 00015 \tparam T is the type of data to store in the first input DMatrix 00016 \tparam R is the overlap distance needed by the calculation for the two input DMatrix. It has to be the same for the two inputs. 00017 \tparam T2 is the type of data to store in the second inputDMatrix 00018 \tparam T3 is the type of data to store in the output DMatrix 00019 \tparam line is the parallel distribution wanted, the default value is true, then the parallel distribution will be divided along height but not along width 00020 */ 00021 //------------------------------------------------------------------------------- 00022 template <typename T,int R, typename T2, typename T3,int R3,bool line=true> struct _ApplyBinary_Func 00023 //------------------------------------------------------------------------------- 00024 { 00025 virtual void operator()(DMatrix <T,R>&, DMatrix<T2,R>&, DMatrix<T3,R3>&) const =0; 00026 }; 00027 //================================================================================ 00028 //! _ApplyBinary_Func structure 00029 /*! 00030 \tparam T is the type of data to store in the first input DMatrix 00031 R overlap template parameter is not asked and specialized to 0 00032 \tparam T2 is the type of data to store in the second inputDMatrix 00033 \tparam T3 is the type of data to store in the output DMatrix 00034 The default value of line is used (true). 00035 */ 00036 //------------------------------------------------------------------------------- 00037 template <typename T, typename T2, typename T3,int R3> struct _ApplyBinary_Func<T,0,T2,T3,R3> 00038 //------------------------------------------------------------------------------- 00039 { 00040 virtual void operator()(DMatrix <T,0>&, DMatrix<T2,0>&,DMatrix<T3,R3>&) const =0; 00041 }; 00042 //================================================================================ 00043 //! _ApplyBinary_Func structure 00044 /*! 00045 \tparam T is the type of data to store in the first input DMatrix 00046 \tparam R is the overlap distance needed by the calculation for the two input DMatrix. It has to be the same for the two inputs. 00047 \tparam T2 is the type of data to store in the second inputDMatrix 00048 \tparam T3 is the type of data to store in the output DMatrix 00049 The line template parameter is specialized with the false value. In this case the parallel data distribution will be done along height and width (by block). 00050 */ 00051 //------------------------------------------------------------------------------- 00052 template <typename T,int R, typename T2, typename T3,int R3> struct _ApplyBinary_Func<T,R,T2,T3,R3,false> 00053 //------------------------------------------------------------------------------- 00054 { 00055 virtual void operator()(DMatrix <T,R,false>&, DMatrix<T2,R,false>&, DMatrix<T3,R3,false>&) const =0; 00056 }; 00057 //================================================================================ 00058 //! _ApplyBinary_Func structure 00059 /*! 00060 \tparam T is the type of data to store in the first input DMatrix 00061 R overlap template parameter is not asked and specialized to 0 00062 \tparam T2 is the type of data to store in the second inputDMatrix 00063 \tparam T3 is the type of data to store in the output DMatrix 00064 The line template parameter is specialized with the false value. In this case the parallel data distribution will be done along height and width (by block). 00065 */ 00066 //------------------------------------------------------------------------------- 00067 template <typename T, typename T2, typename T3,int R3> struct _ApplyBinary_Func<T,0,T2,T3,R3,false> 00068 //------------------------------------------------------------------------------- 00069 { 00070 virtual void operator()(DMatrix <T,0,false>&, DMatrix<T2,0,false>&,DMatrix<T3,R3,false>&) const =0; 00071 }; 00072 //------------------------------------------------------------------------------- 00073 00074 00075 //================================================================================ 00076 //Specializations of skeleton ApplyBinary 00077 //================================================================================ 00078 //! ApplyBinary structure 00079 /*! 00080 These objects are directly called by the user to apply a function on two inputs DMatrix. 00081 \tparam T is the type of data to store in the first input DMatrix 00082 \tparam R is the overlap distance needed by the calculation for the two input DMatrix. It has to be the same for the two inputs. 00083 \tparam T2 is the type of data to store in the second inputDMatrix 00084 \tparam T3 is the type of data to store in the output DMatrix 00085 \tparam line is the parallel distribution wanted, the default value is true, then the parallel distribution will be divided along height but not along width 00086 \tparam local is a particular choice if it is explicitely indicate to not make any MPI exchanges. The default behavior is to make normaly MPI exchanges. 00087 */ 00088 //------------------------------------------------------------------------------- 00089 template<class T,int R,class T2,class T3,int R3,bool line=true,bool local=false> struct ApplyBinary{}; 00090 //------------------------------------------------------------------------------- 00091 00092 //================================================================================ 00093 //! ApplyBinary structure 00094 /*! 00095 First specialization with line and local default values. 00096 \tparam T is the type of data to store in the first input DMatrix 00097 \tparam R is the overlap distance needed by the calculation for the two input DMatrix. It has to be the same for the two inputs. 00098 \tparam T2 is the type of data to store in the second inputDMatrix 00099 \tparam T3 is the type of data to store in the output DMatrix 00100 */ 00101 //------------------------------------------------------------------------------- 00102 template<class T,int R,class T2,class T3,int R3> struct ApplyBinary<T,R,T2,T3,R3> 00103 //------------------------------------------------------------------------------- 00104 { 00105 //need an operator=(DMatrixw<...> m) in dmatrix.hpp 00106 /*inline static DMatrix<T3,R3> apply(const _ApplyBinary_Func<T,R,T2,T3,R3>& func, DMatrix<T,R>& m, DMatrix<T2,R>& m2) 00107 { 00108 DMatrix<T3,R3> m3(m.getGlobalHeader(),0); 00109 m.getBorders(); 00110 m2.getBorders(); 00111 func(m,m2,m3); 00112 return m3; 00113 }*/ 00114 00115 inline static void apply(const _ApplyBinary_Func<T,R,T2,T3,R3>& func, DMatrix<T,R>& m, DMatrix<T2,R>& m2, DMatrix<T3,R3>& m3) 00116 { 00117 m.getBorders(); 00118 m2.getBorders(); 00119 func(m,m2,m3); 00120 } 00121 }; 00122 //------------------------------------------------------------------------------- 00123 00124 //================================================================================ 00125 //! ApplyBinary structure 00126 /*! 00127 Second specialization with line and local default values and R=0 00128 \tparam T is the type of data to store in the first input DMatrix 00129 R overlap template parameter is not asked and specialized to 0 00130 \tparam T2 is the type of data to store in the second inputDMatrix 00131 \tparam T3 is the type of data to store in the output DMatrix 00132 */ 00133 //------------------------------------------------------------------------------- 00134 template<class T,class T2,class T3,int R3> struct ApplyBinary<T,0,T2,T3,R3> 00135 //------------------------------------------------------------------------------- 00136 { 00137 //need an operator=(DMatrixw<...> m) in dmatrix.hpp 00138 /*inline static DMatrix<T3,R3> apply(const _ApplyBinary_Func<T,0,T2,T3,R3>& func, DMatrix<T,0>& m, DMatrix<T2,0>& m2) 00139 { 00140 DMatrix<T3,R3> m3(m.getGlobalHeader(),0); 00141 func(m,m2,m3); 00142 return m3; 00143 }*/ 00144 00145 inline static void apply(const _ApplyBinary_Func<T,0,T2,T3,R3>& func, DMatrix<T,0>& m, DMatrix<T2,0>& m2, DMatrix<T3,R3>& m3) 00146 { 00147 func(m,m2,m3); 00148 } 00149 }; 00150 //------------------------------------------------------------------------------- 00151 00152 //================================================================================ 00153 //! ApplyBinary structure 00154 /*! 00155 Third specialization with line=true and local=true 00156 \tparam T is the type of data to store in the first input DMatrix 00157 \tparam R is the overlap distance needed by the calculation for the two input DMatrix. It has to be the same for the two inputs. 00158 \tparam T2 is the type of data to store in the second inputDMatrix 00159 \tparam T3 is the type of data to store in the output DMatrix 00160 */ 00161 //------------------------------------------------------------------------------- 00162 template<class T,int R,class T2,class T3,int R3> struct ApplyBinary<T,R,T2,T3,R3,true,true> 00163 //------------------------------------------------------------------------------- 00164 { 00165 //need an operator=(DMatrixw<...> m) in dmatrix.hpp 00166 /*inline static DMatrix<T3,R3> apply(const _ApplyBinary_Func<T,R,T2,T3,R3>& func, DMatrix<T,R>& m, DMatrix<T2,R>& m2) 00167 { 00168 DMatrix<T3,R3> m3(m.getGlobalHeader(),0); 00169 func(m,m2,m3); 00170 return m3; 00171 }*/ 00172 00173 inline static void apply(const _ApplyBinary_Func<T,R,T2,T3,R3>& func, DMatrix<T,R>& m, DMatrix<T2,R>& m2, DMatrix<T3,R3>& m3) 00174 { 00175 func(m,m2,m3); 00176 } 00177 }; 00178 //------------------------------------------------------------------------------- 00179 00180 //================================================================================ 00181 //! ApplyBinary structure 00182 /*! 00183 Fourth specialization with line=true and local=true and R=0 00184 \tparam T is the type of data to store in the first input DMatrix 00185 R overlap template parameter is not asked and specialized to 0 00186 \tparam T2 is the type of data to store in the second inputDMatrix 00187 \tparam T3 is the type of data to store in the output DMatrix 00188 */ 00189 //------------------------------------------------------------------------------- 00190 template<class T,class T2,class T3,int R3> struct ApplyBinary<T,0,T2,T3,R3,true,true> 00191 //------------------------------------------------------------------------------- 00192 { 00193 //need an operator=(DMatrixw<...> m) in dmatrix.hpp 00194 /*inline static DMatrix<T3,R3> apply(const _ApplyBinary_Func<T,0,T2,T3,R3>& func, DMatrix<T,0>& m, DMatrix<T2,0>& m2) 00195 { 00196 DMatrix<T3,R3> m3(m.getGlobalHeader(),0); 00197 func(m,m2,m3); 00198 return m3; 00199 }*/ 00200 00201 inline static void apply(const _ApplyBinary_Func<T,0,T2,T3,R3>& func, DMatrix<T,0>& m, DMatrix<T2,0>& m2, DMatrix<T3,R3>& m3) 00202 { 00203 func(m,m2,m3); 00204 } 00205 }; 00206 //------------------------------------------------------------------------------- 00207 00208 //================================================================================ 00209 //! ApplyBinary structure 00210 /*! 00211 Fith specialization with line=false and local=false default value 00212 \tparam T is the type of data to store in the first input DMatrix 00213 \tparam R is the overlap distance needed by the calculation, in other words, the size of the physical border needed 00214 \tparam T2 is the type of data to store in the second inputDMatrix 00215 \tparam T3 is the type of data to store in the output DMatrix 00216 */ 00217 //------------------------------------------------------------------------------- 00218 template<class T,int R,class T2,class T3,int R3> struct ApplyBinary<T,R,T2,T3,R3,false> 00219 //------------------------------------------------------------------------------- 00220 { 00221 //need an operator=(DMatrixw<...> m) in dmatrix.hpp 00222 /*inline static DMatrix<T3,R3,false> apply(const _ApplyBinary_Func<T,R,T2,T3,R3,false>& func, DMatrix<T,R,false>& m, DMatrix<T2,R,false>& m2) 00223 { 00224 DMatrix<T3,R3,false> m3(m.getGlobalHeader(),0); 00225 m.getBorders(); 00226 m2.getBorders(); 00227 func(m,m2,m3); 00228 return m3; 00229 }*/ 00230 00231 inline static void apply(const _ApplyBinary_Func<T,R,T2,T3,R3,false>& func, DMatrix<T,R,false>& m, DMatrix<T2,R,false>& m2, DMatrix<T3,R3,false>& m3) 00232 { 00233 m.getBorders(); 00234 m2.getBorders(); 00235 func(m,m2,m3); 00236 } 00237 }; 00238 //------------------------------------------------------------------------------- 00239 00240 //================================================================================ 00241 //! ApplyBinary structure 00242 /*! 00243 Sixth specialization with line=false and local=false default value and R=0 00244 \tparam T is the type of data to store in the first input DMatrix 00245 R overlap template parameter is not asked and specialized to 0 00246 \tparam T2 is the type of data to store in the second inputDMatrix 00247 \tparam T3 is the type of data to store in the output DMatrix 00248 */ 00249 //------------------------------------------------------------------------------- 00250 template<class T,class T2,class T3,int R3> struct ApplyBinary<T,0,T2,T3,R3,false> 00251 //------------------------------------------------------------------------------- 00252 { 00253 //need an operator=(DMatrixw<...> m) in dmatrix.hpp 00254 /*inline static DMatrix<T3,R3,false> apply(const _ApplyBinary_Func<T,0,T2,T3,R3,false>& func, DMatrix<T,0,false>& m, DMatrix<T2,0,false>& m2) 00255 { 00256 DMatrix<T3,R3,false> m3(m.getGlobalHeader(),0); 00257 func(m,m2,m3); 00258 return m3; 00259 }*/ 00260 00261 inline static void apply(const _ApplyBinary_Func<T,0,T2,T3,R3,false>& func, DMatrix<T,0,false>& m, DMatrix<T2,0,false>& m2, DMatrix<T3,R3,false>& m3) 00262 { 00263 func(m,m2,m3); 00264 } 00265 }; 00266 //------------------------------------------------------------------------------- 00267 00268 //================================================================================ 00269 //! ApplyBinary structure 00270 /*! 00271 Seventh specialization with line=false and local=true 00272 \tparam T is the type of data to store in the first input DMatrix 00273 \tparam R is the overlap distance needed by the calculation, in other words, the size of the physical border needed 00274 \tparam T2 is the type of data to store in the second inputDMatrix 00275 \tparam T3 is the type of data to store in the output DMatrix 00276 */ 00277 //------------------------------------------------------------------------------- 00278 template<class T,int R,class T2,class T3,int R3> struct ApplyBinary<T,R,T2,T3,R3,false,true> 00279 //------------------------------------------------------------------------------- 00280 { 00281 //need an operator=(DMatrixw<...> m) in dmatrix.hpp 00282 /*inline static DMatrix<T3,R3,false> apply(const _ApplyBinary_Func<T,R,T2,T3,R3,false>& func, DMatrix<T,R,false>& m, DMatrix<T2,R,false>& m2) 00283 { 00284 DMatrix<T3,R3,false> m3(m.getGlobalHeader(),0); 00285 func(m,m2,m3); 00286 return m3; 00287 }*/ 00288 00289 inline static void apply(const _ApplyBinary_Func<T,R,T2,T3,R3,false>& func, DMatrix<T,R,false>& m, DMatrix<T2,R,false>& m2, DMatrix<T3,R3,false>& m3) 00290 { 00291 func(m,m2,m3); 00292 } 00293 }; 00294 //------------------------------------------------------------------------------- 00295 00296 //================================================================================ 00297 //! ApplyBinary structure 00298 /*! 00299 Eighth specialization with line=false and local=true and R=0 00300 \tparam T is the type of data to store in the first input DMatrix 00301 R overlap template parameter is not asked and specialized to 0 00302 \tparam T2 is the type of data to store in the second inputDMatrix 00303 \tparam T3 is the type of data to store in the output DMatrix 00304 */ 00305 //------------------------------------------------------------------------------- 00306 template<class T,class T2,class T3,int R3> struct ApplyBinary<T,0,T2,T3,R3,false,true> 00307 //------------------------------------------------------------------------------- 00308 { 00309 //need an operator=(DMatrixw<...> m) in dmatrix.hpp 00310 /*inline static DMatrix<T3,R3,false> apply(const _ApplyBinary_Func<T,0,T2,T3,R3,false>& func, DMatrix<T,0,false>& m, DMatrix<T2,0,false>& m2) 00311 { 00312 DMatrix<T3,R3,false> m3(m.getGlobalHeader(),0); 00313 func(m,m2,m3); 00314 return m3; 00315 }*/ 00316 00317 inline static void apply(const _ApplyBinary_Func<T,0,T2,T3,R3,false>& func, DMatrix<T,0,false>& m, DMatrix<T2,0,false>& m2, DMatrix<T3,R3,false>& m3) 00318 { 00319 func(m,m2,m3); 00320 } 00321 }; 00322 //------------------------------------------------------------------------------- 00323 00324 } 00325 00326 #endif