| 1 | /* |
| 2 | * SparseGrid_chunk_copy.hpp |
| 3 | * |
| 4 | * Created on: Mar 18, 2020 |
| 5 | * Author: i-bird |
| 6 | */ |
| 7 | |
| 8 | #ifndef SPARSEGRID_CHUNK_COPY_HPP_ |
| 9 | #define SPARSEGRID_CHUNK_COPY_HPP_ |
| 10 | |
| 11 | #if !defined(__NVCC__) || defined(CUDA_ON_CPU) |
| 12 | #include <Vc/Vc> |
| 13 | #endif |
| 14 | #include "util/mathutil.hpp" |
| 15 | |
| 16 | |
| 17 | /*! \brief Check if the point in the chunk exist |
| 18 | * |
| 19 | * \param h header |
| 20 | * \param sub_id index of the sub-domain |
| 21 | * |
| 22 | * \return true if exist, false if does not |
| 23 | * |
| 24 | */ |
| 25 | template<typename headerType> |
| 26 | inline bool exist_sub(headerType & h, int sub_id) |
| 27 | { |
| 28 | return h.mask[sub_id]; |
| 29 | } |
| 30 | |
| 31 | template<unsigned int v> |
| 32 | struct exist_sub_v_impl |
| 33 | { |
| 34 | typedef unsigned char type; |
| 35 | |
| 36 | template<typename headerType> |
| 37 | static inline void exist(headerType & h, int sub_id, unsigned char * pmask) |
| 38 | { |
| 39 | pmask[0] = h.mask[sub_id]; |
| 40 | } |
| 41 | }; |
| 42 | |
| 43 | template<> |
| 44 | struct exist_sub_v_impl<2> |
| 45 | { |
| 46 | typedef unsigned short type; |
| 47 | |
| 48 | template<typename headerType> |
| 49 | static inline void exist(headerType & h, int sub_id, unsigned char * pmask) |
| 50 | { |
| 51 | pmask[0] = h.mask[sub_id]; |
| 52 | pmask[1] = h.mask[sub_id+1]; |
| 53 | } |
| 54 | }; |
| 55 | |
| 56 | template<> |
| 57 | struct exist_sub_v_impl<4> |
| 58 | { |
| 59 | typedef unsigned int type; |
| 60 | |
| 61 | template<typename headerType> |
| 62 | static inline void exist(headerType & h, int sub_id, unsigned char * pmask) |
| 63 | { |
| 64 | pmask[0] = h.mask[sub_id]; |
| 65 | pmask[1] = h.mask[sub_id+1]; |
| 66 | pmask[2] = h.mask[sub_id+2]; |
| 67 | pmask[3] = h.mask[sub_id+3]; |
| 68 | } |
| 69 | }; |
| 70 | |
| 71 | template<> |
| 72 | struct exist_sub_v_impl<8> |
| 73 | { |
| 74 | typedef unsigned long int type; |
| 75 | |
| 76 | template<typename headerType> |
| 77 | static inline void exist(headerType & h, int sub_id, unsigned char * pmask) |
| 78 | { |
| 79 | pmask[0] = h.mask[sub_id]; |
| 80 | pmask[1] = h.mask[sub_id+1]; |
| 81 | pmask[2] = h.mask[sub_id+2]; |
| 82 | pmask[3] = h.mask[sub_id+3]; |
| 83 | pmask[4] = h.mask[sub_id+4]; |
| 84 | pmask[5] = h.mask[sub_id+5]; |
| 85 | pmask[6] = h.mask[sub_id+6]; |
| 86 | pmask[7] = h.mask[sub_id+7]; |
| 87 | } |
| 88 | }; |
| 89 | |
| 90 | /*! \brief Check if the point in the chunk exist (Vectorial form) |
| 91 | * |
| 92 | * \param h header |
| 93 | * \param sub_id index of the sub-domain |
| 94 | * |
| 95 | * \return true if exist, false if does not |
| 96 | * |
| 97 | */ |
| 98 | template<unsigned int v, typename headerType> |
| 99 | inline void exist_sub_v(headerType & h, int sub_id, unsigned char * pmask) |
| 100 | { |
| 101 | exist_sub_v_impl<v>::exist(h,sub_id,pmask); |
| 102 | } |
| 103 | |
| 104 | |
| 105 | //! Copy block in 3D |
| 106 | template<int layout_type, int prop, int stencil_size ,typename chunking,bool is_cross> |
| 107 | struct copy_xyz |
| 108 | { |
| 109 | template<unsigned int N1, typename T, typename headerType, typename chunkType> |
| 110 | inline static void copy(T ptr[N1], unsigned char mask[N1], headerType & h , const chunkType & chunk) |
| 111 | { |
| 112 | int s = stencil_size + stencil_size*(boost::mpl::at<typename chunking::type,boost::mpl::int_<0>>::type::value+2*stencil_size) + |
| 113 | stencil_size*(boost::mpl::at<typename chunking::type,boost::mpl::int_<0>>::type::value+2*stencil_size)*(boost::mpl::at<typename chunking::type,boost::mpl::int_<1>>::type::value+2*stencil_size); |
| 114 | |
| 115 | int s2 = 0; |
| 116 | |
| 117 | for (int v = 0 ; v < boost::mpl::at<typename chunking::type,boost::mpl::int_<2>>::type::value ; v++) |
| 118 | { |
| 119 | for (int j = 0 ; j < boost::mpl::at<typename chunking::type,boost::mpl::int_<1>>::type::value ; j++) |
| 120 | { |
| 121 | for (int k = 0 ; k < boost::mpl::at<typename chunking::type,boost::mpl::int_<0>>::type::value ; k++) |
| 122 | { |
| 123 | ptr[s] = chunk[s2]; |
| 124 | mask[s] = exist_sub(h,s2); |
| 125 | |
| 126 | s++; |
| 127 | s2++; |
| 128 | } |
| 129 | s += 2*stencil_size; |
| 130 | } |
| 131 | s+= 2*stencil_size*(boost::mpl::at<typename chunking::type,boost::mpl::int_<0>>::type::value+2*stencil_size); |
| 132 | } |
| 133 | } |
| 134 | |
| 135 | template<unsigned int N1, typename T, typename chunkType> |
| 136 | inline static void store(T ptr[N1] , chunkType & chunk) |
| 137 | { |
| 138 | int s2 = 0; |
| 139 | |
| 140 | for (int v = 0 ; v < boost::mpl::at<typename chunking::type,boost::mpl::int_<2>>::type::value ; v++) |
| 141 | { |
| 142 | for (int j = 0 ; j < boost::mpl::at<typename chunking::type,boost::mpl::int_<1>>::type::value ; j++) |
| 143 | { |
| 144 | for (int k = 0 ; k < boost::mpl::at<typename chunking::type,boost::mpl::int_<0>>::type::value ; k++) |
| 145 | { |
| 146 | chunk[s2] = ptr[s2]; |
| 147 | |
| 148 | s2++; |
| 149 | } |
| 150 | } |
| 151 | } |
| 152 | } |
| 153 | }; |
| 154 | |
| 155 | template<unsigned int i> |
| 156 | struct multi_mask |
| 157 | {}; |
| 158 | |
| 159 | template<> |
| 160 | struct multi_mask<1> |
| 161 | { |
| 162 | typedef unsigned char type; |
| 163 | }; |
| 164 | |
| 165 | template<> |
| 166 | struct multi_mask<2> |
| 167 | { |
| 168 | typedef unsigned short int type; |
| 169 | }; |
| 170 | |
| 171 | template<> |
| 172 | struct multi_mask<4> |
| 173 | { |
| 174 | typedef unsigned int type; |
| 175 | }; |
| 176 | |
| 177 | template<> |
| 178 | struct multi_mask<8> |
| 179 | { |
| 180 | typedef unsigned long int type; |
| 181 | }; |
| 182 | |
| 183 | template<> |
| 184 | struct multi_mask<16> |
| 185 | { |
| 186 | typedef unsigned long int type; |
| 187 | }; |
| 188 | |
| 189 | #ifndef __NVCC__ |
| 190 | |
| 191 | //! Copy block in 3D vectorized |
| 192 | template<int prop, int stencil_size ,typename chunking,bool is_cross> |
| 193 | struct copy_xyz<1,prop,stencil_size,chunking,is_cross> |
| 194 | { |
| 195 | template<unsigned int N1, typename T, typename headerType, typename chunkType> |
| 196 | inline static void copy(T ptr[N1], unsigned char mask[N1], headerType & h , const chunkType & chunk) |
| 197 | { |
| 198 | int s = stencil_size + stencil_size*(boost::mpl::at<typename chunking::type,boost::mpl::int_<0>>::type::value+2*stencil_size) + |
| 199 | stencil_size*(boost::mpl::at<typename chunking::type,boost::mpl::int_<0>>::type::value+2*stencil_size)*(boost::mpl::at<typename chunking::type,boost::mpl::int_<1>>::type::value+2*stencil_size); |
| 200 | |
| 201 | typedef boost::mpl::int_<boost::mpl::at<typename chunking::type,boost::mpl::int_<0>>::type::value * sizeof(chunk[0]) / |
| 202 | Vc::float_v::Size / sizeof(float)> n_it_lead; |
| 203 | |
| 204 | int s2 = 0; |
| 205 | |
| 206 | for (int v = 0 ; v < boost::mpl::at<typename chunking::type,boost::mpl::int_<2>>::type::value ; v++) |
| 207 | { |
| 208 | for (int j = 0 ; j < boost::mpl::at<typename chunking::type,boost::mpl::int_<1>>::type::value ; j++) |
| 209 | { |
| 210 | for (int k = 0 ; k < n_it_lead::value ; k+=4) |
| 211 | { |
| 212 | exist_sub_v<Vc::float_v::Size / (sizeof(chunk[0])/sizeof(float))>(h,s2,&mask[s]); |
| 213 | exist_sub_v<Vc::float_v::Size / (sizeof(chunk[0])/sizeof(float))>(h,s2+Vc::float_v::Size / (sizeof(chunk[0])/sizeof(float)),&mask[s+Vc::float_v::Size / (sizeof(chunk[0])/sizeof(float))]); |
| 214 | exist_sub_v<Vc::float_v::Size / (sizeof(chunk[0])/sizeof(float))>(h,s2+2*Vc::float_v::Size / (sizeof(chunk[0])/sizeof(float)),&mask[s+2*Vc::float_v::Size / (sizeof(chunk[0])/sizeof(float))]); |
| 215 | exist_sub_v<Vc::float_v::Size / (sizeof(chunk[0])/sizeof(float))>(h,s2+3*Vc::float_v::Size / (sizeof(chunk[0])/sizeof(float)),&mask[s+3*Vc::float_v::Size / (sizeof(chunk[0])/sizeof(float))]); |
| 216 | |
| 217 | Vc::float_v tmp = Vc::float_v((float *)&chunk[s2],Vc::Aligned); |
| 218 | Vc::float_v tmp2 = Vc::float_v((float *)&chunk[s2+Vc::float_v::Size / (sizeof(chunk[0])/sizeof(float))],Vc::Aligned); |
| 219 | Vc::float_v tmp3 = Vc::float_v((float *)&chunk[s2+2*Vc::float_v::Size / (sizeof(chunk[0])/sizeof(float))],Vc::Aligned); |
| 220 | Vc::float_v tmp4 = Vc::float_v((float *)&chunk[s2+3*Vc::float_v::Size / (sizeof(chunk[0])/sizeof(float))],Vc::Aligned); |
| 221 | tmp.store((float *)&ptr[s],Vc::Unaligned); |
| 222 | tmp2.store((float *)&ptr[s+Vc::float_v::Size / (sizeof(chunk[0])/sizeof(float))],Vc::Unaligned); |
| 223 | tmp3.store((float *)&ptr[s+2*Vc::float_v::Size / (sizeof(chunk[0])/sizeof(float))],Vc::Unaligned); |
| 224 | tmp4.store((float *)&ptr[s+3*Vc::float_v::Size / (sizeof(chunk[0])/sizeof(float))],Vc::Unaligned); |
| 225 | |
| 226 | s += 4*Vc::float_v::Size / (sizeof(chunk[0])/sizeof(float)); |
| 227 | s2 += 4*Vc::float_v::Size / (sizeof(chunk[0])/sizeof(float)); |
| 228 | } |
| 229 | s += 2*stencil_size ; |
| 230 | } |
| 231 | s+= 2*stencil_size*(boost::mpl::at<typename chunking::type,boost::mpl::int_<0>>::type::value+2*stencil_size); |
| 232 | } |
| 233 | } |
| 234 | |
| 235 | template<unsigned int N1, typename T, typename chunkType> |
| 236 | inline static void store(T ptr[N1] , chunkType & chunk) |
| 237 | { |
| 238 | typedef boost::mpl::int_<boost::mpl::at<typename chunking::type,boost::mpl::int_<0>>::type::value * sizeof(chunk[0]) / |
| 239 | Vc::float_v::Size / sizeof(float)> n_it_lead; |
| 240 | |
| 241 | int s2 = 0; |
| 242 | |
| 243 | for (int v = 0 ; v < boost::mpl::at<typename chunking::type,boost::mpl::int_<2>>::type::value ; v++) |
| 244 | { |
| 245 | for (int j = 0 ; j < boost::mpl::at<typename chunking::type,boost::mpl::int_<1>>::type::value ; j++) |
| 246 | { |
| 247 | for (int k = 0 ; k < n_it_lead::value ; k += 4) |
| 248 | { |
| 249 | Vc::float_v tmp = Vc::float_v((float *)&ptr[s2],Vc::Aligned); |
| 250 | Vc::float_v tmp1 = Vc::float_v((float *)&ptr[s2+1*Vc::float_v::Size / (sizeof(chunk[0])/sizeof(float))],Vc::Aligned); |
| 251 | Vc::float_v tmp2 = Vc::float_v((float *)&ptr[s2+2*Vc::float_v::Size / (sizeof(chunk[0])/sizeof(float))],Vc::Aligned); |
| 252 | Vc::float_v tmp3 = Vc::float_v((float *)&ptr[s2+3*Vc::float_v::Size / (sizeof(chunk[0])/sizeof(float))],Vc::Aligned); |
| 253 | |
| 254 | tmp.store((float *)&chunk[s2],Vc::Aligned); |
| 255 | tmp1.store((float *)&chunk[s2+1*Vc::float_v::Size / (sizeof(chunk[0])/sizeof(float))],Vc::Aligned); |
| 256 | tmp2.store((float *)&chunk[s2+2*Vc::float_v::Size / (sizeof(chunk[0])/sizeof(float))],Vc::Aligned); |
| 257 | tmp3.store((float *)&chunk[s2+3*Vc::float_v::Size / (sizeof(chunk[0])/sizeof(float))],Vc::Aligned); |
| 258 | |
| 259 | s2 += 4*Vc::float_v::Size / (sizeof(chunk[0])/sizeof(float)); |
| 260 | } |
| 261 | } |
| 262 | } |
| 263 | } |
| 264 | }; |
| 265 | |
| 266 | #endif |
| 267 | |
| 268 | //! Copy XY surface in 3D |
| 269 | template<int layout_type, int prop,int stencil_size, typename chunking,bool is_cross> |
| 270 | struct copy_xy_3 |
| 271 | { |
| 272 | template<unsigned int i_src, unsigned int i_dest, unsigned int N1, typename T, typename headerType, typename chunkType> |
| 273 | inline static void copy(T ptr[N1], unsigned char mask[N1], headerType & h , const chunkType & chunk) |
| 274 | { |
| 275 | int s = stencil_size + stencil_size*(boost::mpl::at<typename chunking::type,boost::mpl::int_<0>>::type::value+2*stencil_size) + |
| 276 | i_dest*(boost::mpl::at<typename chunking::type,boost::mpl::int_<0>>::type::value+2*stencil_size)*(boost::mpl::at<typename chunking::type,boost::mpl::int_<1>>::type::value+2*stencil_size); |
| 277 | |
| 278 | for (int v = 0 ; v < stencil_size ; v++) |
| 279 | { |
| 280 | for (int j = 0 ; j < boost::mpl::at<typename chunking::type,boost::mpl::int_<1>>::type::value ; j++) |
| 281 | { |
| 282 | for (int k = 0 ; k < boost::mpl::at<typename chunking::type,boost::mpl::int_<0>>::type::value ; k++) |
| 283 | { |
| 284 | const int id = Lin_vmpl<typename chunking::type>(k,j,i_src+v); |
| 285 | |
| 286 | ptr[s] = chunk.template get<prop>()[id]; |
| 287 | mask[s] = exist_sub(h,id); |
| 288 | |
| 289 | s++; |
| 290 | } |
| 291 | s += 2*stencil_size; |
| 292 | } |
| 293 | |
| 294 | s+= 2*stencil_size*(boost::mpl::at<typename chunking::type,boost::mpl::int_<0>>::type::value+2*stencil_size); |
| 295 | } |
| 296 | } |
| 297 | |
| 298 | template<unsigned int i_dest, unsigned int N1> |
| 299 | inline static void mask_null(unsigned char mask[N1]) |
| 300 | { |
| 301 | int s = stencil_size + stencil_size*(boost::mpl::at<typename chunking::type,boost::mpl::int_<0>>::type::value+2*stencil_size) + |
| 302 | i_dest*(boost::mpl::at<typename chunking::type,boost::mpl::int_<0>>::type::value+2*stencil_size)*(boost::mpl::at<typename chunking::type,boost::mpl::int_<1>>::type::value+2*stencil_size); |
| 303 | |
| 304 | for (int v = 0 ; v < stencil_size ; v++) |
| 305 | { |
| 306 | for (int j = 0 ; j < boost::mpl::at<typename chunking::type,boost::mpl::int_<1>>::type::value ; j++) |
| 307 | { |
| 308 | for (int k = 0 ; k < boost::mpl::at<typename chunking::type,boost::mpl::int_<0>>::type::value ; k++) |
| 309 | { |
| 310 | mask[s] = 0; |
| 311 | |
| 312 | s++; |
| 313 | } |
| 314 | s += 2*stencil_size; |
| 315 | } |
| 316 | |
| 317 | s+= 2*stencil_size*(boost::mpl::at<typename chunking::type,boost::mpl::int_<0>>::type::value+2*stencil_size); |
| 318 | } |
| 319 | } |
| 320 | }; |
| 321 | |
| 322 | #ifndef __NVCC__ |
| 323 | |
| 324 | //! Copy XY surface in 3D |
| 325 | template<int prop,int stencil_size, typename chunking,bool is_cross> |
| 326 | struct copy_xy_3<1,prop,stencil_size,chunking,is_cross> |
| 327 | { |
| 328 | template<unsigned int i_src, unsigned int i_dest, unsigned int N1, typename T, typename headerType, typename chunkType> |
| 329 | inline static void copy(T ptr[N1], unsigned char mask[N1], headerType & h , const chunkType & chunk) |
| 330 | { |
| 331 | int s = stencil_size + stencil_size*(boost::mpl::at<typename chunking::type,boost::mpl::int_<0>>::type::value+2*stencil_size) + |
| 332 | i_dest*(boost::mpl::at<typename chunking::type,boost::mpl::int_<0>>::type::value+2*stencil_size)*(boost::mpl::at<typename chunking::type,boost::mpl::int_<1>>::type::value+2*stencil_size); |
| 333 | |
| 334 | int s2 = i_src*(boost::mpl::at<typename chunking::type,boost::mpl::int_<0>>::type::value)*(boost::mpl::at<typename chunking::type,boost::mpl::int_<1>>::type::value); |
| 335 | |
| 336 | typedef boost::mpl::int_<boost::mpl::at<typename chunking::type,boost::mpl::int_<0>>::type::value * sizeof(chunk.template get<prop>()[0]) / |
| 337 | Vc::float_v::Size / sizeof(float)> n_it_lead; |
| 338 | |
| 339 | for (int v = 0 ; v < stencil_size ; v++) |
| 340 | { |
| 341 | for (int j = 0 ; j < boost::mpl::at<typename chunking::type,boost::mpl::int_<1>>::type::value ; j++) |
| 342 | { |
| 343 | for (int k = 0 ; k < n_it_lead::value ; k+=4) |
| 344 | { |
| 345 | exist_sub_v<Vc::float_v::Size / (sizeof(chunk.template get<prop>()[0])/sizeof(float))>(h,s2,&mask[s]); |
| 346 | exist_sub_v<Vc::float_v::Size / (sizeof(chunk.template get<prop>()[0])/sizeof(float))>(h,s2+1*Vc::float_v::Size / (sizeof(chunk.template get<prop>()[0])/sizeof(float)),&mask[s+1*Vc::float_v::Size / (sizeof(chunk.template get<prop>()[0])/sizeof(float))]); |
| 347 | exist_sub_v<Vc::float_v::Size / (sizeof(chunk.template get<prop>()[0])/sizeof(float))>(h,s2+2*Vc::float_v::Size / (sizeof(chunk.template get<prop>()[0])/sizeof(float)),&mask[s+2*Vc::float_v::Size / (sizeof(chunk.template get<prop>()[0])/sizeof(float))]); |
| 348 | exist_sub_v<Vc::float_v::Size / (sizeof(chunk.template get<prop>()[0])/sizeof(float))>(h,s2+3*Vc::float_v::Size / (sizeof(chunk.template get<prop>()[0])/sizeof(float)),&mask[s+3*Vc::float_v::Size / (sizeof(chunk.template get<prop>()[0])/sizeof(float))]); |
| 349 | |
| 350 | |
| 351 | Vc::float_v tmp = Vc::float_v((float *)&chunk.template get<prop>()[s2],Vc::Unaligned); |
| 352 | Vc::float_v tmp1 = Vc::float_v((float *)&chunk.template get<prop>()[s2+1*Vc::float_v::Size / (sizeof(chunk.template get<prop>()[0])/sizeof(float))],Vc::Unaligned); |
| 353 | Vc::float_v tmp2 = Vc::float_v((float *)&chunk.template get<prop>()[s2+2*Vc::float_v::Size / (sizeof(chunk.template get<prop>()[0])/sizeof(float))],Vc::Unaligned); |
| 354 | Vc::float_v tmp3 = Vc::float_v((float *)&chunk.template get<prop>()[s2+3*Vc::float_v::Size / (sizeof(chunk.template get<prop>()[0])/sizeof(float))],Vc::Unaligned); |
| 355 | tmp.store((float *)&ptr[s],Vc::Unaligned); |
| 356 | tmp1.store((float *)&ptr[s+1*Vc::float_v::Size / (sizeof(chunk.template get<prop>()[0])/sizeof(float))],Vc::Unaligned); |
| 357 | tmp2.store((float *)&ptr[s+2*Vc::float_v::Size / (sizeof(chunk.template get<prop>()[0])/sizeof(float))],Vc::Unaligned); |
| 358 | tmp3.store((float *)&ptr[s+3*Vc::float_v::Size / (sizeof(chunk.template get<prop>()[0])/sizeof(float))],Vc::Unaligned); |
| 359 | |
| 360 | s += 4*Vc::float_v::Size / (sizeof(chunk.template get<prop>()[0])/sizeof(float)); |
| 361 | s2 += 4*Vc::float_v::Size / (sizeof(chunk.template get<prop>()[0])/sizeof(float)); |
| 362 | } |
| 363 | s += 2*stencil_size; |
| 364 | |
| 365 | } |
| 366 | |
| 367 | s+= 2*stencil_size*(boost::mpl::at<typename chunking::type,boost::mpl::int_<0>>::type::value+2*stencil_size); |
| 368 | } |
| 369 | } |
| 370 | |
| 371 | template<unsigned int i_dest, unsigned int N1> |
| 372 | inline static void mask_null(unsigned char mask[N1]) |
| 373 | { |
| 374 | int s = stencil_size + stencil_size*(boost::mpl::at<typename chunking::type,boost::mpl::int_<0>>::type::value+2*stencil_size) + |
| 375 | i_dest*(boost::mpl::at<typename chunking::type,boost::mpl::int_<0>>::type::value+2*stencil_size)*(boost::mpl::at<typename chunking::type,boost::mpl::int_<1>>::type::value+2*stencil_size); |
| 376 | |
| 377 | for (int v = 0 ; v < stencil_size ; v++) |
| 378 | { |
| 379 | for (int j = 0 ; j < boost::mpl::at<typename chunking::type,boost::mpl::int_<1>>::type::value ; j++) |
| 380 | { |
| 381 | for (int k = 0 ; k < boost::mpl::at<typename chunking::type,boost::mpl::int_<0>>::type::value ; k++) |
| 382 | { |
| 383 | mask[s] = 0; |
| 384 | |
| 385 | s++; |
| 386 | } |
| 387 | s += 2*stencil_size; |
| 388 | } |
| 389 | |
| 390 | s+= 2*stencil_size*(boost::mpl::at<typename chunking::type,boost::mpl::int_<0>>::type::value+2*stencil_size); |
| 391 | } |
| 392 | } |
| 393 | }; |
| 394 | |
| 395 | #endif |
| 396 | |
| 397 | //! Copy XZ surface in 3D |
| 398 | template<int layout_type, int prop, int stencil_size, typename chunking,bool is_cross> |
| 399 | struct copy_xz_3 |
| 400 | { |
| 401 | template<unsigned int j_src, unsigned int j_dest, unsigned int N1, typename T, typename headerType , typename chunkType> |
| 402 | inline static void copy(T ptr[N1], unsigned char mask[N1], headerType & h , const chunkType & chunk) |
| 403 | { |
| 404 | int s = stencil_size + j_dest*(boost::mpl::at<typename chunking::type,boost::mpl::int_<0>>::type::value+2*stencil_size) + |
| 405 | stencil_size*(boost::mpl::at<typename chunking::type,boost::mpl::int_<0>>::type::value+2*stencil_size)*(boost::mpl::at<typename chunking::type,boost::mpl::int_<1>>::type::value+2*stencil_size); |
| 406 | |
| 407 | for (int v = 0 ; v < stencil_size ; v++) |
| 408 | { |
| 409 | for (int i = 0 ; i < boost::mpl::at<typename chunking::type,boost::mpl::int_<2>>::type::value ; i++) |
| 410 | { |
| 411 | for (int k = 0 ; k < boost::mpl::at<typename chunking::type,boost::mpl::int_<0>>::type::value ; k++) |
| 412 | { |
| 413 | const int id = Lin_vmpl<typename chunking::type>(k,j_src+v,i); |
| 414 | |
| 415 | ptr[s] = chunk.template get<prop>()[id]; |
| 416 | mask[s] = exist_sub(h,id); |
| 417 | |
| 418 | s++; |
| 419 | } |
| 420 | |
| 421 | s += (boost::mpl::at<typename chunking::type,boost::mpl::int_<0>>::type::value+2*stencil_size)*(boost::mpl::at<typename chunking::type,boost::mpl::int_<1>>::type::value + 2*stencil_size) - boost::mpl::at<typename chunking::type,boost::mpl::int_<0>>::type::value; |
| 422 | } |
| 423 | |
| 424 | s += (boost::mpl::at<typename chunking::type,boost::mpl::int_<0>>::type::value + 2*stencil_size) - boost::mpl::at<typename chunking::type,boost::mpl::int_<2>>::type::value*(boost::mpl::at<typename chunking::type,boost::mpl::int_<0>>::type::value+2*stencil_size)*(boost::mpl::at<typename chunking::type,boost::mpl::int_<1>>::type::value+2*stencil_size); |
| 425 | } |
| 426 | } |
| 427 | }; |
| 428 | |
| 429 | //! Copy XZ surface in 3D |
| 430 | template<int layout_type, int prop, typename chunking,bool is_cross> |
| 431 | struct copy_xz_3<layout_type,prop,1,chunking,is_cross> |
| 432 | { |
| 433 | template<unsigned int j_src, unsigned int j_dest, unsigned int N1, typename T, typename headerType , typename chunkType> |
| 434 | inline static void copy(T ptr[N1], unsigned char mask[N1], headerType & h , const chunkType & chunk) |
| 435 | { |
| 436 | int s = 1 + j_dest*(boost::mpl::at<typename chunking::type,boost::mpl::int_<0>>::type::value+2*1) + |
| 437 | 1*(boost::mpl::at<typename chunking::type,boost::mpl::int_<0>>::type::value+2*1)*(boost::mpl::at<typename chunking::type,boost::mpl::int_<1>>::type::value+2*1); |
| 438 | |
| 439 | for (int i = 0 ; i < boost::mpl::at<typename chunking::type,boost::mpl::int_<2>>::type::value ; i++) |
| 440 | { |
| 441 | for (int k = 0 ; k < boost::mpl::at<typename chunking::type,boost::mpl::int_<0>>::type::value ; k++) |
| 442 | { |
| 443 | const int id = Lin_vmpl<typename chunking::type>(k,j_src,i); |
| 444 | |
| 445 | ptr[s] = chunk.template get<prop>()[id]; |
| 446 | mask[s] = exist_sub(h,id); |
| 447 | |
| 448 | s++; |
| 449 | } |
| 450 | |
| 451 | s += 1 * (boost::mpl::at<typename chunking::type,boost::mpl::int_<0>>::type::value+2*1)*(boost::mpl::at<typename chunking::type,boost::mpl::int_<1>>::type::value + 2*1) - boost::mpl::at<typename chunking::type,boost::mpl::int_<0>>::type::value; |
| 452 | } |
| 453 | } |
| 454 | |
| 455 | template<unsigned int j_dest, unsigned int N1> |
| 456 | inline static void mask_null(unsigned char mask[N1]) |
| 457 | { |
| 458 | int s = 1 + j_dest*(boost::mpl::at<typename chunking::type,boost::mpl::int_<0>>::type::value+2*1) + |
| 459 | 1*(boost::mpl::at<typename chunking::type,boost::mpl::int_<0>>::type::value+2*1)*(boost::mpl::at<typename chunking::type,boost::mpl::int_<1>>::type::value+2*1); |
| 460 | |
| 461 | for (int i = 0 ; i < boost::mpl::at<typename chunking::type,boost::mpl::int_<2>>::type::value ; i++) |
| 462 | { |
| 463 | for (int k = 0 ; k < boost::mpl::at<typename chunking::type,boost::mpl::int_<0>>::type::value ; k++) |
| 464 | { |
| 465 | mask[s] = 0; |
| 466 | |
| 467 | s++; |
| 468 | } |
| 469 | |
| 470 | s += 1 * (boost::mpl::at<typename chunking::type,boost::mpl::int_<0>>::type::value+2*1)*(boost::mpl::at<typename chunking::type,boost::mpl::int_<1>>::type::value + 2*1) - boost::mpl::at<typename chunking::type,boost::mpl::int_<0>>::type::value; |
| 471 | } |
| 472 | } |
| 473 | }; |
| 474 | |
| 475 | //! Copy YZ surface in 3D |
| 476 | template<int layout_type, int prop, int stencil_size, typename chunking,bool is_cross> |
| 477 | struct copy_yz_3 |
| 478 | { |
| 479 | template<unsigned int k_src, unsigned int k_dest, unsigned int N1, typename T, typename headerType , typename chunkType> |
| 480 | inline static void copy(T ptr[N1], unsigned char mask[N1], headerType & h , const chunkType & chunk) |
| 481 | { |
| 482 | int s = k_dest + stencil_size*(boost::mpl::at<typename chunking::type,boost::mpl::int_<0>>::type::value+2*stencil_size) + |
| 483 | stencil_size*(boost::mpl::at<typename chunking::type,boost::mpl::int_<0>>::type::value+2*stencil_size)*(boost::mpl::at<typename chunking::type,boost::mpl::int_<1>>::type::value+2*stencil_size); |
| 484 | |
| 485 | for (int v = 0 ; v < stencil_size ; v++) |
| 486 | { |
| 487 | for (int i = 0 ; i < boost::mpl::at<typename chunking::type,boost::mpl::int_<2>>::type::value ; i++) |
| 488 | { |
| 489 | for (int j = 0 ; j < boost::mpl::at<typename chunking::type,boost::mpl::int_<1>>::type::value ; j++) |
| 490 | { |
| 491 | const int id = Lin_vmpl<typename chunking::type>(k_src+v,j,i); |
| 492 | |
| 493 | ptr[s] = chunk.template get<prop>()[id]; |
| 494 | mask[s] = exist_sub(h,id); |
| 495 | |
| 496 | s += (boost::mpl::at<typename chunking::type,boost::mpl::int_<0>>::type::value+2*stencil_size); |
| 497 | } |
| 498 | |
| 499 | s += (boost::mpl::at<typename chunking::type,boost::mpl::int_<0>>::type::value+2*stencil_size)*(boost::mpl::at<typename chunking::type,boost::mpl::int_<1>>::type::value + 2*stencil_size) - boost::mpl::at<typename chunking::type,boost::mpl::int_<1>>::type::value*(boost::mpl::at<typename chunking::type,boost::mpl::int_<0>>::type::value+2*stencil_size); |
| 500 | } |
| 501 | |
| 502 | s += 1 - boost::mpl::at<typename chunking::type,boost::mpl::int_<2>>::type::value*(boost::mpl::at<typename chunking::type,boost::mpl::int_<0>>::type::value+2*stencil_size)*(boost::mpl::at<typename chunking::type,boost::mpl::int_<1>>::type::value+2*stencil_size); |
| 503 | |
| 504 | } |
| 505 | } |
| 506 | }; |
| 507 | |
| 508 | //! Copy YZ surface in 3D |
| 509 | template<int layout_type, int prop, typename chunking,bool is_cross> |
| 510 | struct copy_yz_3<layout_type,prop,1,chunking,is_cross> |
| 511 | { |
| 512 | template<unsigned int k_src, unsigned int k_dest, unsigned int N1, typename T, typename headerType, typename chunkType> |
| 513 | inline static void copy(T ptr[N1], unsigned char mask[N1], headerType & h , const chunkType & chunk) |
| 514 | { |
| 515 | int s = k_dest + 1*(boost::mpl::at<typename chunking::type,boost::mpl::int_<0>>::type::value+2*1) + |
| 516 | 1*(boost::mpl::at<typename chunking::type,boost::mpl::int_<0>>::type::value+2*1)*(boost::mpl::at<typename chunking::type,boost::mpl::int_<1>>::type::value+2*1); |
| 517 | |
| 518 | for (int i = 0 ; i < boost::mpl::at<typename chunking::type,boost::mpl::int_<2>>::type::value ; i++) |
| 519 | { |
| 520 | for (int j = 0 ; j < boost::mpl::at<typename chunking::type,boost::mpl::int_<1>>::type::value ; j++) |
| 521 | { |
| 522 | const int id = Lin_vmpl<typename chunking::type>(k_src,j,i); |
| 523 | |
| 524 | ptr[s] = chunk.template get<prop>()[id]; |
| 525 | mask[s] = exist_sub(h,id); |
| 526 | |
| 527 | s += (boost::mpl::at<typename chunking::type,boost::mpl::int_<0>>::type::value+2*1); |
| 528 | } |
| 529 | |
| 530 | s += 1 * (boost::mpl::at<typename chunking::type,boost::mpl::int_<0>>::type::value+2*1)*(boost::mpl::at<typename chunking::type,boost::mpl::int_<1>>::type::value + 2*1) - boost::mpl::at<typename chunking::type,boost::mpl::int_<1>>::type::value*(boost::mpl::at<typename chunking::type,boost::mpl::int_<0>>::type::value+2*1); |
| 531 | } |
| 532 | } |
| 533 | |
| 534 | template<unsigned int k_dest, unsigned int N1> |
| 535 | inline static void mask_null(unsigned char mask[N1]) |
| 536 | { |
| 537 | int s = k_dest + 1*(boost::mpl::at<typename chunking::type,boost::mpl::int_<0>>::type::value+2*1) + |
| 538 | 1*(boost::mpl::at<typename chunking::type,boost::mpl::int_<0>>::type::value+2*1)*(boost::mpl::at<typename chunking::type,boost::mpl::int_<1>>::type::value+2*1); |
| 539 | |
| 540 | for (int i = 0 ; i < boost::mpl::at<typename chunking::type,boost::mpl::int_<2>>::type::value ; i++) |
| 541 | { |
| 542 | for (int j = 0 ; j < boost::mpl::at<typename chunking::type,boost::mpl::int_<1>>::type::value ; j++) |
| 543 | { |
| 544 | mask[s] = 0; |
| 545 | |
| 546 | s += (boost::mpl::at<typename chunking::type,boost::mpl::int_<0>>::type::value+2*1); |
| 547 | } |
| 548 | |
| 549 | s += 1 * (boost::mpl::at<typename chunking::type,boost::mpl::int_<0>>::type::value+2*1)*(boost::mpl::at<typename chunking::type,boost::mpl::int_<1>>::type::value + 2*1) - boost::mpl::at<typename chunking::type,boost::mpl::int_<1>>::type::value*(boost::mpl::at<typename chunking::type,boost::mpl::int_<0>>::type::value+2*1); |
| 550 | } |
| 551 | } |
| 552 | }; |
| 553 | |
| 554 | //! Copy x edge in 3D |
| 555 | template<int layout_type, int prop, int stencil_size, typename chunking,bool is_cross> |
| 556 | struct copy_x_3 |
| 557 | { |
| 558 | template<unsigned int i_src, unsigned int i_dest,unsigned int j_src, unsigned int j_dest , unsigned int N1, typename T, typename chunkType> |
| 559 | inline static void copy(T ptr[N1], const chunkType & chunk) |
| 560 | { |
| 561 | int s = stencil_size + j_dest*(boost::mpl::at<typename chunking::type,boost::mpl::int_<0>>::type::value+2*stencil_size) + |
| 562 | i_dest*(boost::mpl::at<typename chunking::type,boost::mpl::int_<0>>::type::value+2*stencil_size)*(boost::mpl::at<typename chunking::type,boost::mpl::int_<1>>::type::value+2*stencil_size); |
| 563 | |
| 564 | for (int v1 = 0 ; v1 < stencil_size ; v1++) |
| 565 | { |
| 566 | for (int v2 = 0 ; v2 < stencil_size ; v2++) |
| 567 | { |
| 568 | for (int k = 0 ; k < boost::mpl::at<typename chunking::type,boost::mpl::int_<0>>::type::value ; k++) |
| 569 | { |
| 570 | ptr[s] = chunk.template get<prop>()[Lin_vmpl<typename chunking::type>(k,j_src+v2,i_src+v1)]; |
| 571 | |
| 572 | s++; |
| 573 | } |
| 574 | |
| 575 | s+= 2*stencil_size; |
| 576 | } |
| 577 | |
| 578 | s+= (boost::mpl::at<typename chunking::type,boost::mpl::int_<0>>::type::value+2*stencil_size)*(boost::mpl::at<typename chunking::type,boost::mpl::int_<1>>::type::value+2*stencil_size) - stencil_size*(boost::mpl::at<typename chunking::type,boost::mpl::int_<0>>::type::value+2*stencil_size); |
| 579 | } |
| 580 | } |
| 581 | }; |
| 582 | |
| 583 | //! Copy x edge in 3D |
| 584 | template<int layout_type, int prop, typename chunking,bool is_cross> |
| 585 | struct copy_x_3<layout_type,prop,1,chunking,is_cross> |
| 586 | { |
| 587 | template<unsigned int i_src, unsigned int i_dest,unsigned int j_src, unsigned int j_dest , unsigned int N1, typename T, typename chunkType> |
| 588 | inline static void copy(T ptr[N1], const chunkType & chunk) |
| 589 | { |
| 590 | int s = 1 + j_dest*(boost::mpl::at<typename chunking::type,boost::mpl::int_<0>>::type::value+2*1) + |
| 591 | i_dest*(boost::mpl::at<typename chunking::type,boost::mpl::int_<0>>::type::value+2*1)*(boost::mpl::at<typename chunking::type,boost::mpl::int_<1>>::type::value+2*1); |
| 592 | |
| 593 | |
| 594 | for (int k = 0 ; k < boost::mpl::at<typename chunking::type,boost::mpl::int_<0>>::type::value ; k++) |
| 595 | { |
| 596 | ptr[s] = chunk.template get<prop>()[Lin_vmpl<typename chunking::type>(k,j_src,i_src)]; |
| 597 | |
| 598 | s++; |
| 599 | } |
| 600 | } |
| 601 | }; |
| 602 | |
| 603 | //! Copy x edge in 3D |
| 604 | template<int layout_type, int prop, int stencil_size, typename chunking> |
| 605 | struct copy_x_3<layout_type,prop,stencil_size,chunking,true> |
| 606 | { |
| 607 | template<unsigned int i_src, unsigned int i_dest,unsigned int j_src, unsigned int j_dest , unsigned int N1, typename T, typename chunkType> |
| 608 | inline static void copy(T ptr[N1], const chunkType & chunk) |
| 609 | {} |
| 610 | }; |
| 611 | |
| 612 | //! Copy y edge in 3D |
| 613 | template<int layout_type, int prop, int stencil_size, typename chunking,bool is_cross> |
| 614 | struct copy_y_3 |
| 615 | { |
| 616 | template<unsigned int i_src, unsigned int i_dest,unsigned int k_src, unsigned int k_dest , unsigned int N1, typename T, typename chunkType> |
| 617 | inline static void copy(T ptr[N1], const chunkType & chunk) |
| 618 | { |
| 619 | int s = k_dest + stencil_size*(boost::mpl::at<typename chunking::type,boost::mpl::int_<0>>::type::value+2*stencil_size) + |
| 620 | i_dest*(boost::mpl::at<typename chunking::type,boost::mpl::int_<0>>::type::value+2*stencil_size)*(boost::mpl::at<typename chunking::type,boost::mpl::int_<1>>::type::value+2*stencil_size); |
| 621 | |
| 622 | for (int v1 = 0 ; v1 < stencil_size ; v1++) |
| 623 | { |
| 624 | for (int j = 0 ; j < boost::mpl::at<typename chunking::type,boost::mpl::int_<1>>::type::value ; j++) |
| 625 | { |
| 626 | for (int v2 = 0 ; v2 < stencil_size ; v2++) |
| 627 | { |
| 628 | ptr[s] = chunk.template get<prop>()[Lin_vmpl<typename chunking::type>(k_src+v2,j,i_src+v1)]; |
| 629 | s+= 1; |
| 630 | } |
| 631 | |
| 632 | s += (boost::mpl::at<typename chunking::type,boost::mpl::int_<0>>::type::value+2*stencil_size) - stencil_size; |
| 633 | } |
| 634 | |
| 635 | s += (boost::mpl::at<typename chunking::type,boost::mpl::int_<0>>::type::value+2*stencil_size)*(boost::mpl::at<typename chunking::type,boost::mpl::int_<1>>::type::value+2*stencil_size) - boost::mpl::at<typename chunking::type,boost::mpl::int_<1>>::type::value*(boost::mpl::at<typename chunking::type,boost::mpl::int_<0>>::type::value+2*stencil_size); |
| 636 | } |
| 637 | } |
| 638 | }; |
| 639 | |
| 640 | //! Copy y edge in 3D |
| 641 | template<int layout_type, int prop, typename chunking,bool is_cross> |
| 642 | struct copy_y_3<layout_type,prop,1,chunking,is_cross> |
| 643 | { |
| 644 | template<unsigned int i_src, unsigned int i_dest,unsigned int k_src, unsigned int k_dest , unsigned int N1, typename T, typename chunkType> |
| 645 | inline static void copy(T ptr[N1], const chunkType & chunk) |
| 646 | { |
| 647 | int s = k_dest + 1*(boost::mpl::at<typename chunking::type,boost::mpl::int_<0>>::type::value+2*1) + |
| 648 | i_dest*(boost::mpl::at<typename chunking::type,boost::mpl::int_<0>>::type::value+2*1)*(boost::mpl::at<typename chunking::type,boost::mpl::int_<1>>::type::value+2*1); |
| 649 | |
| 650 | |
| 651 | for (int j = 0 ; j < boost::mpl::at<typename chunking::type,boost::mpl::int_<0>>::type::value ; j++) |
| 652 | { |
| 653 | ptr[s] = chunk.template get<prop>()[Lin_vmpl<typename chunking::type>(k_src,j,i_src)]; |
| 654 | |
| 655 | s += (boost::mpl::at<typename chunking::type,boost::mpl::int_<0>>::type::value+2*1); |
| 656 | } |
| 657 | } |
| 658 | }; |
| 659 | |
| 660 | //! Copy y edge in 3D |
| 661 | template<int layout_type, int prop, int stencil_size, typename chunking> |
| 662 | struct copy_y_3<layout_type,prop,stencil_size,chunking,true> |
| 663 | { |
| 664 | template<unsigned int i_src, unsigned int i_dest,unsigned int k_src, unsigned int k_dest , unsigned int N1, typename T, typename chunkType> |
| 665 | inline static void copy(T ptr[N1], const chunkType & chunk) |
| 666 | {} |
| 667 | }; |
| 668 | |
| 669 | |
| 670 | //! Copy z edge in 3D |
| 671 | template<int layout_type, int prop, int stencil_size, typename chunking,bool is_cross> |
| 672 | struct copy_z_3 |
| 673 | { |
| 674 | template<unsigned int j_src, unsigned int j_dest,unsigned int k_src, unsigned int k_dest , unsigned int N1, typename T, typename chunkType> |
| 675 | inline static void copy(T ptr[N1], const chunkType & chunk) |
| 676 | { |
| 677 | int s = k_dest + j_dest*(boost::mpl::at<typename chunking::type,boost::mpl::int_<0>>::type::value+2*stencil_size) + |
| 678 | stencil_size*(boost::mpl::at<typename chunking::type,boost::mpl::int_<0>>::type::value+2*stencil_size)*(boost::mpl::at<typename chunking::type,boost::mpl::int_<1>>::type::value+2*stencil_size); |
| 679 | |
| 680 | |
| 681 | for (int i = 0 ; i < boost::mpl::at<typename chunking::type,boost::mpl::int_<2>>::type::value ; i++) |
| 682 | { |
| 683 | for (int v1 = 0 ; v1 < stencil_size ; v1++) |
| 684 | { |
| 685 | for (int v2 = 0 ; v2 < stencil_size ; v2++) |
| 686 | { |
| 687 | ptr[s] = chunk.template get<prop>()[Lin_vmpl<typename chunking::type>(k_src+v2,j_src+v1,i)]; |
| 688 | |
| 689 | s++; |
| 690 | } |
| 691 | |
| 692 | s+= 2*stencil_size; |
| 693 | } |
| 694 | |
| 695 | s += (boost::mpl::at<typename chunking::type,boost::mpl::int_<0>>::type::value+2*stencil_size)*(boost::mpl::at<typename chunking::type,boost::mpl::int_<1>>::type::value+2*stencil_size); |
| 696 | } |
| 697 | } |
| 698 | }; |
| 699 | |
| 700 | //! Copy z edge in 3D |
| 701 | template<int layout_type, int prop, typename chunking,bool is_cross> |
| 702 | struct copy_z_3<layout_type,prop,1,chunking,is_cross> |
| 703 | { |
| 704 | template<unsigned int j_src, unsigned int j_dest,unsigned int k_src, unsigned int k_dest , unsigned int N1, typename T, typename chunkType> |
| 705 | inline static void copy(T ptr[N1], const chunkType & chunk) |
| 706 | { |
| 707 | int s = k_dest + j_dest*(boost::mpl::at<typename chunking::type,boost::mpl::int_<0>>::type::value+2*1) + |
| 708 | 1*(boost::mpl::at<typename chunking::type,boost::mpl::int_<0>>::type::value+2*1)*(boost::mpl::at<typename chunking::type,boost::mpl::int_<1>>::type::value+2*1); |
| 709 | |
| 710 | |
| 711 | for (int i = 0 ; i < boost::mpl::at<typename chunking::type,boost::mpl::int_<0>>::type::value ; i++) |
| 712 | { |
| 713 | ptr[s] = chunk.template get<prop>()[Lin_vmpl<typename chunking::type>(k_src,j_src,i)]; |
| 714 | |
| 715 | s += (boost::mpl::at<typename chunking::type,boost::mpl::int_<0>>::type::value+2*1)*(boost::mpl::at<typename chunking::type,boost::mpl::int_<1>>::type::value+2*1); |
| 716 | } |
| 717 | } |
| 718 | }; |
| 719 | |
| 720 | //! Copy z edge in 3D |
| 721 | template<int layout_type, int prop, int stencil_size, typename chunking> |
| 722 | struct copy_z_3<layout_type,prop,stencil_size,chunking,true> |
| 723 | { |
| 724 | template<unsigned int j_src, unsigned int j_dest,unsigned int k_src, unsigned int k_dest , unsigned int N1, typename T, typename chunkType> |
| 725 | inline static void copy(T ptr[N1], const chunkType & chunk) |
| 726 | {} |
| 727 | }; |
| 728 | |
| 729 | //! Copy point in 3D |
| 730 | template<int layout_type, int prop, int stencil_size, typename chunking,bool is_cross> |
| 731 | struct copy_corner_3 |
| 732 | { |
| 733 | template<unsigned int i_src, unsigned int i_dest,unsigned int j_src, unsigned int j_dest,unsigned int k_src, unsigned int k_dest , unsigned int N1, typename T, typename chunkType> |
| 734 | inline static void copy(T ptr[N1], const chunkType & chunk) |
| 735 | { |
| 736 | int s = k_dest + j_dest*(boost::mpl::at<typename chunking::type,boost::mpl::int_<0>>::type::value+2*stencil_size) + |
| 737 | i_dest*(boost::mpl::at<typename chunking::type,boost::mpl::int_<0>>::type::value+2*stencil_size)*(boost::mpl::at<typename chunking::type,boost::mpl::int_<1>>::type::value+2*stencil_size); |
| 738 | |
| 739 | |
| 740 | for (int i = 0 ; i < stencil_size ; i++) |
| 741 | { |
| 742 | for (int j = 0 ; j < stencil_size ; j++) |
| 743 | { |
| 744 | for (int k = 0 ; k < stencil_size ; k++) |
| 745 | { |
| 746 | ptr[s] = chunk.template get<prop>()[Lin_vmpl<typename chunking::type>(k_src+k,j_src+j,i_src+i)]; |
| 747 | |
| 748 | s++; |
| 749 | } |
| 750 | |
| 751 | s += (boost::mpl::at<typename chunking::type,boost::mpl::int_<0>>::type::value+2*stencil_size) - stencil_size; |
| 752 | } |
| 753 | |
| 754 | s += (boost::mpl::at<typename chunking::type,boost::mpl::int_<0>>::type::value+2*stencil_size)*(boost::mpl::at<typename chunking::type,boost::mpl::int_<1>>::type::value+2*stencil_size) - stencil_size*(boost::mpl::at<typename chunking::type,boost::mpl::int_<0>>::type::value+2*stencil_size); |
| 755 | } |
| 756 | } |
| 757 | }; |
| 758 | |
| 759 | //! Copy point in 3D |
| 760 | template<int layout_type, int prop, typename chunking,bool is_cross> |
| 761 | struct copy_corner_3<layout_type,prop,1,chunking,is_cross> |
| 762 | { |
| 763 | template<unsigned int i_src, unsigned int i_dest,unsigned int j_src, unsigned int j_dest,unsigned int k_src, unsigned int k_dest , unsigned int N1, typename T, typename chunkType> |
| 764 | inline static void copy(T ptr[N1], const chunkType & chunk) |
| 765 | { |
| 766 | int s = k_dest + j_dest*(boost::mpl::at<typename chunking::type,boost::mpl::int_<0>>::type::value+2*1) + |
| 767 | i_dest*(boost::mpl::at<typename chunking::type,boost::mpl::int_<0>>::type::value+2*1)*(boost::mpl::at<typename chunking::type,boost::mpl::int_<1>>::type::value+2*1); |
| 768 | |
| 769 | |
| 770 | ptr[s] = chunk.template get<prop>()[Lin_vmpl<typename chunking::type>(k_src,j_src,i_src)]; |
| 771 | } |
| 772 | }; |
| 773 | |
| 774 | //! Copy point in 3D |
| 775 | template<int layout_type, int prop, int stencil_size, typename chunking> |
| 776 | struct copy_corner_3<layout_type,prop,stencil_size,chunking,true> |
| 777 | { |
| 778 | template<unsigned int i_src, unsigned int i_dest,unsigned int j_src, unsigned int j_dest,unsigned int k_src, unsigned int k_dest , unsigned int N1, typename T, typename chunkType> |
| 779 | inline static void copy(T ptr[N1], const chunkType & chunk) |
| 780 | {} |
| 781 | }; |
| 782 | |
| 783 | ///////////////////////////////////////////////////////////////////////// Chunk missalignment mapping |
| 784 | |
| 785 | template<unsigned int dim> |
| 786 | struct key_int |
| 787 | { |
| 788 | unsigned char i; |
| 789 | grid_key_dx<dim,long int> k; |
| 790 | }; |
| 791 | |
| 792 | /*! to move chunks from one Sparse grid to another SparseGrid chunk can be miss-aligned this function create a map between |
| 793 | * the missaligned source and the destination chunks |
| 794 | * |
| 795 | * For example in an 8x8 chunk in which the chunk in the source sparse grid are shifted by two from the destination sparse-grid |
| 796 | * you will get a map like this |
| 797 | * |
| 798 | /verbatim |
| 799 | |
| 800 | 2 2 3 3 3 3 3 3 |
| 801 | 2 2 3 3 3 3 3 3 |
| 802 | 2 2 3 3 3 3 3 3 |
| 803 | 2 2 3 3 3 3 3 3 |
| 804 | 0 0 1 1 1 1 1 1 |
| 805 | 0 0 1 1 1 1 1 1 |
| 806 | |
| 807 | /endverbatim |
| 808 | * |
| 809 | * and a vk filled with {-1,-1},0 {0,-1},1 {-1,0},2 {0,0},3 |
| 810 | * |
| 811 | * in case we are comping a slice some of the index in vk can be filtered out. For example if we are copyng a slice in x = 0 |
| 812 | * the vector will only have: |
| 813 | * |
| 814 | * {-1,-1},0 {-1,0},2 |
| 815 | * |
| 816 | */ |
| 817 | template<unsigned int dim, unsigned int N, typename chunking> |
| 818 | void construct_chunk_missalign_map(unsigned char miss_al_map[N], |
| 819 | short int mp_off[N], |
| 820 | const Box<dim,long int> & b_src, |
| 821 | const Box<dim,long int> & b_dst, |
| 822 | openfpm::vector<key_int<dim>> & vk) |
| 823 | { |
| 824 | typedef typename vmpl_create_constant<dim,1>::type one_vmpl; |
| 825 | |
| 826 | get_block_sizes<dim,0,typename chunking::type,one_vmpl> gbs; |
| 827 | boost::mpl::for_each_ref< boost::mpl::range_c<int,0,dim> >(gbs); |
| 828 | |
| 829 | grid_key_dx<dim> k_src = b_src.getKP1(); |
| 830 | grid_key_dx<dim> k_dst = b_dst.getKP1(); |
| 831 | |
| 832 | grid_key_dx<dim,long int> kl1; |
| 833 | grid_key_dx<dim,long int> kl2; |
| 834 | |
| 835 | // shift the key |
| 836 | key_shift<dim,chunking>::shift(k_src,kl1); |
| 837 | |
| 838 | // shift the key |
| 839 | key_shift<dim,chunking>::shift(k_dst,kl2); |
| 840 | |
| 841 | grid_key_dx<dim,long int> key_sub; |
| 842 | |
| 843 | for (int i = 0 ; i < dim ; i++) |
| 844 | { |
| 845 | key_sub.set_d(i,kl2.get(i) - kl1.get(i) ); |
| 846 | } |
| 847 | |
| 848 | int c_id[openfpm::math::pow(2,dim)]; |
| 849 | size_t sz[dim]; |
| 850 | |
| 851 | for (int i = 0 ; i < dim ; i++) |
| 852 | {sz[i] = 3;} |
| 853 | |
| 854 | grid_sm<dim,void> gcnk(gbs.sz_block); |
| 855 | grid_key_dx_iterator<dim> it(gcnk); |
| 856 | while (it.isNext()) |
| 857 | { |
| 858 | auto k = it.get(); |
| 859 | |
| 860 | int off = 0; |
| 861 | int bid = 0; |
| 862 | int stride = 1; |
| 863 | int stride_off = 1; |
| 864 | for (int i = 0 ; i < dim ; i++) |
| 865 | { |
| 866 | if ((long int)k.get(i) + key_sub.get(i) >= (long int)gbs.sz_block[i]) |
| 867 | { |
| 868 | bid += 2*stride; |
| 869 | |
| 870 | } |
| 871 | else if ((long int)k.get(i) + key_sub.get(i) < 0) |
| 872 | { |
| 873 | bid += 0*stride; |
| 874 | |
| 875 | } |
| 876 | else |
| 877 | { |
| 878 | bid += 1*stride; |
| 879 | } |
| 880 | off += (openfpm::math::positive_modulo(key_sub.get(i) + k.get(i),gbs.sz_block[i]))*stride_off; |
| 881 | stride *= 3; |
| 882 | stride_off *= gbs.sz_block[i]; |
| 883 | } |
| 884 | |
| 885 | miss_al_map[gcnk.LinId(k)] = bid; |
| 886 | mp_off[gcnk.LinId(k)] = off; |
| 887 | |
| 888 | ++it; |
| 889 | } |
| 890 | |
| 891 | // Filtering: sometime in particular for ghost copy we have a slice to copy, in this case some of the index in the map |
| 892 | // are never touched so we can eliminate elements in the vk |
| 893 | |
| 894 | Box<dim,long int> slice; |
| 895 | |
| 896 | // calculate slice |
| 897 | for (int i = 0 ; i < dim ; i++) |
| 898 | { |
| 899 | if (kl1.get(i) + (b_src.getHigh(i) - b_src.getLow(i) + 1) > gbs.sz_block[i]) |
| 900 | { |
| 901 | slice.setLow(i,0); |
| 902 | slice.setHigh(i,gbs.sz_block[i]-1); |
| 903 | } |
| 904 | else |
| 905 | { |
| 906 | slice.setLow(i,kl1.get(i)); |
| 907 | slice.setHigh(i,kl1.get(i) + (b_src.getHigh(i) - b_src.getLow(i) + 1)); |
| 908 | } |
| 909 | } |
| 910 | |
| 911 | key_int<dim> l; |
| 912 | l.i = 0; |
| 913 | l.k.zero(); |
| 914 | vk.add(l); |
| 915 | |
| 916 | for (int i = 0 ; i < dim ; i++) |
| 917 | { |
| 918 | if (key_sub.get(i) >= 0) |
| 919 | { |
| 920 | size_t bord = gbs.sz_block[i] - key_sub.get(i); |
| 921 | |
| 922 | if (slice.getLow(i) < bord) |
| 923 | { |
| 924 | // set the component |
| 925 | for (int j = 0 ; j < vk.size() ; j++) |
| 926 | { |
| 927 | vk.get(j).k.set_d(i,0); |
| 928 | } |
| 929 | if (bord <= slice.getHigh(i) ) |
| 930 | { |
| 931 | int n_dup = vk.size(); |
| 932 | |
| 933 | // add the other parts with zero |
| 934 | for (int j = 0 ; j < n_dup ; j++) |
| 935 | { |
| 936 | key_int<dim> tmp; |
| 937 | tmp.k = vk.get(j).k; |
| 938 | |
| 939 | tmp.k.set_d(i,1); |
| 940 | |
| 941 | vk.add(tmp); |
| 942 | } |
| 943 | } |
| 944 | } |
| 945 | else |
| 946 | { |
| 947 | // set the component |
| 948 | for (int j = 0 ; j < vk.size() ; j++) |
| 949 | { |
| 950 | vk.get(j).k.set_d(i,0); |
| 951 | } |
| 952 | } |
| 953 | } |
| 954 | else |
| 955 | { |
| 956 | size_t bord = -key_sub.get(i); |
| 957 | |
| 958 | if (slice.getLow(i) < bord) |
| 959 | { |
| 960 | // set the component |
| 961 | for (int j = 0 ; j < vk.size() ; j++) |
| 962 | { |
| 963 | vk.get(j).k.set_d(i,-1); |
| 964 | } |
| 965 | if (bord <= slice.getHigh(i) ) |
| 966 | { |
| 967 | int n_dup = vk.size(); |
| 968 | |
| 969 | // add the other parts with zero |
| 970 | for (int j = 0 ; j < n_dup ; j++) |
| 971 | { |
| 972 | key_int<dim> tmp; |
| 973 | tmp.k = vk.get(j).k; |
| 974 | |
| 975 | tmp.k.set_d(i,0); |
| 976 | |
| 977 | vk.add(tmp); |
| 978 | } |
| 979 | } |
| 980 | } |
| 981 | else |
| 982 | { |
| 983 | // set the component |
| 984 | for (int j = 0 ; j < vk.size() ; j++) |
| 985 | { |
| 986 | vk.get(j).k.set_d(i,0); |
| 987 | } |
| 988 | } |
| 989 | } |
| 990 | |
| 991 | /* size_t bord = (gbs.sz_block[i] - key_sub.get(i)); |
| 992 | |
| 993 | if (slice.getLow(i) < (gbs.sz_block[i] - key_sub.get(i))) |
| 994 | { |
| 995 | // set the component |
| 996 | for (int j = 0 ; j < vk.size() ; j++) |
| 997 | { |
| 998 | vk.get(j).k.set_d(i,0); |
| 999 | } |
| 1000 | if ((gbs.sz_block[i] - key_sub.get(i)) <= slice.getHigh(i) ) |
| 1001 | { |
| 1002 | int n_dup = vk.size(); |
| 1003 | |
| 1004 | // add the other parts with zero |
| 1005 | for (int j = 0 ; j < n_dup ; j++) |
| 1006 | { |
| 1007 | key_int<dim> tmp; |
| 1008 | tmp.k = vk.get(j).k; |
| 1009 | |
| 1010 | tmp.k.set_d(i,0); |
| 1011 | |
| 1012 | vk.add(tmp); |
| 1013 | } |
| 1014 | } |
| 1015 | } |
| 1016 | else |
| 1017 | { |
| 1018 | // set the component |
| 1019 | for (int j = 0 ; j < vk.size() ; j++) |
| 1020 | { |
| 1021 | vk.get(j).k.set_d(i,0); |
| 1022 | } |
| 1023 | }*/ |
| 1024 | } |
| 1025 | } |
| 1026 | |
| 1027 | |
| 1028 | template<typename SparseGridType> |
| 1029 | void copy_remove_to_impl(const SparseGridType & grid_src, |
| 1030 | SparseGridType & grid_dst, |
| 1031 | const Box<SparseGridType::dims,long int> & b_src, |
| 1032 | const Box<SparseGridType::dims,long int> & b_dst) |
| 1033 | { |
| 1034 | typedef typename vmpl_create_constant<SparseGridType::dims,1>::type one_vmpl; |
| 1035 | |
| 1036 | get_block_sizes<SparseGridType::dims,0,typename SparseGridType::chunking_type::type,one_vmpl> gbs; |
| 1037 | boost::mpl::for_each_ref< boost::mpl::range_c<int,0,SparseGridType::dims> >(gbs); |
| 1038 | |
| 1039 | typedef typename vmpl_reduce_prod<typename SparseGridType::chunking_type::type>::type sizeBlock; |
| 1040 | |
| 1041 | unsigned char miss_al_map[sizeBlock::value]; |
| 1042 | short int mp_off[sizeBlock::value]; |
| 1043 | |
| 1044 | openfpm::vector<key_int<SparseGridType::dims>> vk; |
| 1045 | |
| 1046 | construct_chunk_missalign_map<SparseGridType::dims, |
| 1047 | sizeBlock::value, |
| 1048 | typename SparseGridType::chunking_type> |
| 1049 | (miss_al_map,mp_off, |
| 1050 | b_src,b_dst,vk); |
| 1051 | |
| 1052 | // Now we intersect every chunk source |
| 1053 | |
| 1054 | Box<SparseGridType::dims,long int> b_inte; |
| 1055 | Box<SparseGridType::dims,long int> b_c; |
| 1056 | |
| 1057 | auto & data_src = grid_src.private_get_data(); |
| 1058 | auto & = grid_src.private_get_header(); |
| 1059 | |
| 1060 | auto & data_dst = grid_src.private_get_data(); |
| 1061 | auto & = grid_src.private_get_header(); |
| 1062 | |
| 1063 | grid_sm<SparseGridType::dims,void> gb; |
| 1064 | |
| 1065 | int chunk_pos[openfpm::math::pow(2,SparseGridType::dims)]; |
| 1066 | |
| 1067 | for (int i = 0 ; i < header_src.size() ; i++) |
| 1068 | { |
| 1069 | for (int j = 0 ; j < SparseGridType::dims ; j++) |
| 1070 | { |
| 1071 | b_c.setLow(j,header_src.get(i).pos.get(j)); |
| 1072 | b_c.setHigh(j,header_src.get(i).pos.get(j) + gbs.sz_block[j] - 1); |
| 1073 | } |
| 1074 | |
| 1075 | bool inte = b_src.Intersect(b_c,b_inte); |
| 1076 | |
| 1077 | if (inte == true) |
| 1078 | { |
| 1079 | // Prepare destination chunks |
| 1080 | |
| 1081 | for (int s = 0 ; s < vk.size() ; s++) |
| 1082 | { |
| 1083 | chunk_pos[vk.get(s).i] = grid_dst.getChunkCreate(); |
| 1084 | } |
| 1085 | |
| 1086 | grid_key_dx_iterator_sub<SparseGridType::dims> it(gb,b_inte.getKP1(),b_inte.getKP2()); |
| 1087 | |
| 1088 | auto & block_src = data_src.get(i); |
| 1089 | |
| 1090 | while (it.isNext()) |
| 1091 | { |
| 1092 | auto id = gb.LinId(it.get()); |
| 1093 | |
| 1094 | int dest_bid = chunk_pos[miss_al_map[id]]; |
| 1095 | |
| 1096 | data_dst.get(dest_bid)[mp_off[id]] = block_src[i]; |
| 1097 | |
| 1098 | ++it; |
| 1099 | } |
| 1100 | } |
| 1101 | } |
| 1102 | } |
| 1103 | |
| 1104 | #endif /* SPARSEGRID_CHUNK_COPY_HPP_ */ |
| 1105 | |