00001 #ifndef _CKSPARSEREDUCER_H
00002 #define _CKSPARSEREDUCER_H
00003
00004 #include "CkSparseReducer.decl.h"
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034
00035 template <class T>
00036 struct sparseRec1D
00037 {
00038 sparseRec1D(int _x, T _data)
00039 {
00040 x = _x;
00041 data = _data;
00042 }
00043
00044 sparseRec1D()
00045 {
00046 }
00047
00048 int x;
00049 T data;
00050 };
00051
00052 template <class T>
00053 struct sparseRec2D
00054 {
00055 sparseRec2D(int _x, int _y, T _data)
00056 {
00057 x = _x;
00058 y = _y;
00059 data = _data;
00060 }
00061
00062 sparseRec2D()
00063 {
00064 }
00065
00066 int x,y;
00067 T data;
00068 };
00069
00070 template <class T>
00071 struct sparseRec3D
00072 {
00073 sparseRec3D(int _x, int _y, int _z, T _data)
00074 {
00075 x = _x;
00076 y = _y;
00077 z = _z;
00078 data = _data;
00079 }
00080
00081 sparseRec3D()
00082 {
00083 }
00084
00085 int x,y,z;
00086 T data;
00087 };
00088
00089
00090 extern CkReduction::reducerType sparse1D_sum_int;
00091 extern CkReduction::reducerType sparse1D_sum_float;
00092 extern CkReduction::reducerType sparse1D_sum_double;
00093
00094 extern CkReduction::reducerType sparse1D_product_int;
00095 extern CkReduction::reducerType sparse1D_product_float;
00096 extern CkReduction::reducerType sparse1D_product_double;
00097
00098 extern CkReduction::reducerType sparse1D_max_int;
00099 extern CkReduction::reducerType sparse1D_max_float;
00100 extern CkReduction::reducerType sparse1D_max_double;
00101
00102 extern CkReduction::reducerType sparse1D_min_int;
00103 extern CkReduction::reducerType sparse1D_min_float;
00104 extern CkReduction::reducerType sparse1D_min_double;
00105
00106 extern CkReduction::reducerType sparse2D_sum_int;
00107 extern CkReduction::reducerType sparse2D_sum_float;
00108 extern CkReduction::reducerType sparse2D_sum_double;
00109
00110 extern CkReduction::reducerType sparse2D_product_int;
00111 extern CkReduction::reducerType sparse2D_product_float;
00112 extern CkReduction::reducerType sparse2D_product_double;
00113
00114 extern CkReduction::reducerType sparse2D_max_int;
00115 extern CkReduction::reducerType sparse2D_max_float;
00116 extern CkReduction::reducerType sparse2D_max_double;
00117
00118 extern CkReduction::reducerType sparse2D_min_int;
00119 extern CkReduction::reducerType sparse2D_min_float;
00120 extern CkReduction::reducerType sparse2D_min_double;
00121
00122 extern CkReduction::reducerType sparse3D_sum_int;
00123 extern CkReduction::reducerType sparse3D_sum_float;
00124 extern CkReduction::reducerType sparse3D_sum_double;
00125
00126 extern CkReduction::reducerType sparse3D_product_int;
00127 extern CkReduction::reducerType sparse3D_product_float;
00128 extern CkReduction::reducerType sparse3D_product_double;
00129
00130 extern CkReduction::reducerType sparse3D_max_int;
00131 extern CkReduction::reducerType sparse3D_max_float;
00132 extern CkReduction::reducerType sparse3D_max_double;
00133
00134 extern CkReduction::reducerType sparse3D_min_int;
00135 extern CkReduction::reducerType sparse3D_min_float;
00136 extern CkReduction::reducerType sparse3D_min_double;
00137
00138 template <class T>
00139 class CkSparseReducer1D
00140 {
00141 public:
00142
00143 CkSparseReducer1D(int numOfElements)
00144 {
00145 size = numOfElements;
00146 index = 0;
00147 if(size != 0)
00148 records = new rec[size];
00149 else
00150 records = NULL;
00151 }
00152
00153 ~CkSparseReducer1D()
00154 {
00155 if(records != NULL)
00156 delete[] records;
00157 }
00158
00159 void add(int x, T data)
00160 {
00161 int ind = index;
00162
00163 while((ind != 0)&&(records[ind-1].x > x))
00164 {
00165 records[ind] = records[ind-1];
00166 ind--;
00167 }
00168 records[ind].x = x;
00169 records[ind].data = data;
00170 index++;
00171 }
00172
00173
00174 void contributeSum(ArrayElement *elem, const CkCallback &cb)
00175 {
00176 T dummy;
00177 contributeSum(elem, cb, dummy);
00178 }
00179
00180 void contributeSum(ArrayElement *elem, const CkCallback &cb, int dummy)
00181 {
00182 elem->contribute(size*sizeof(rec), records, sparse1D_sum_int, cb);
00183 }
00184
00185 void contributeSum(ArrayElement *elem, const CkCallback &cb, float dummy)
00186 {
00187 elem->contribute(size*sizeof(rec), records, sparse1D_sum_float, cb);
00188 }
00189
00190 void contributeSum(ArrayElement *elem, const CkCallback &cb, double dummy)
00191 {
00192 elem->contribute(size*sizeof(rec), records, sparse1D_sum_double, cb);
00193 }
00194
00195
00196 void contributeProduct(ArrayElement *elem, const CkCallback &cb)
00197 {
00198 T dummy;
00199 contributeProduct(elem, cb, dummy);
00200 }
00201
00202 void contributeProduct(ArrayElement *elem, const CkCallback &cb, int dummy)
00203 {
00204 elem->contribute(size*sizeof(rec), records, sparse1D_product_int, cb);
00205 }
00206
00207 void contributeProduct(ArrayElement *elem, const CkCallback &cb, float
00208 dummy)
00209 {
00210 elem->contribute(size*sizeof(rec), records, sparse1D_product_float, cb);
00211 }
00212
00213 void contributeProduct(ArrayElement *elem, const CkCallback &cb, double
00214 dummy)
00215 {
00216 elem->contribute(size*sizeof(rec), records, sparse1D_product_double, cb);
00217 }
00218
00219
00220 void contributeMax(ArrayElement *elem, const CkCallback &cb)
00221 {
00222 T dummy;
00223 contributeMax(elem, cb, dummy);
00224 }
00225
00226 void contributeMax(ArrayElement *elem, const CkCallback &cb, int dummy)
00227 {
00228 elem->contribute(size*sizeof(rec), records, sparse1D_max_int, cb);
00229 }
00230
00231 void contributeMax(ArrayElement *elem, const CkCallback &cb, float dummy)
00232 {
00233 elem->contribute(size*sizeof(rec), records, sparse1D_max_float, cb);
00234 }
00235
00236 void contributeMax(ArrayElement *elem, const CkCallback &cb, double dummy)
00237 {
00238 elem->contribute(size*sizeof(rec), records, sparse1D_max_double, cb);
00239 }
00240
00241
00242 void contributeMin(ArrayElement *elem, const CkCallback &cb)
00243 {
00244 T dummy;
00245 contributeMin(elem, cb, dummy);
00246 }
00247
00248 void contributeMin(ArrayElement *elem, const CkCallback &cb, int dummy)
00249 {
00250 elem->contribute(size*sizeof(rec), records, sparse1D_min_int, cb);
00251 }
00252
00253 void contributeMin(ArrayElement *elem, const CkCallback &cb, float dummy)
00254 {
00255 elem->contribute(size*sizeof(rec), records, sparse1D_min_float, cb);
00256 }
00257
00258 void contributeMin(ArrayElement *elem, const CkCallback &cb, double dummy)
00259 {
00260 elem->contribute(size*sizeof(rec), records, sparse1D_min_double, cb);
00261 }
00262
00263 protected:
00264
00265 typedef sparseRec1D<T> rec;
00266 rec *records;
00267 int size;
00268 int index;
00269
00270 private:
00271 CkSparseReducer1D(){}
00272 };
00273
00274 template <class T>
00275 class CkSparseReducer2D
00276 {
00277 public:
00278
00279 CkSparseReducer2D(int numOfElements)
00280 {
00281 size = numOfElements;
00282 index = 0;
00283 if(size != 0)
00284 records = new rec[size];
00285 else
00286 records = NULL;
00287 }
00288
00289 ~CkSparseReducer2D()
00290 {
00291 if(records != NULL)
00292 delete[] records;
00293 }
00294
00295 void add(int x, int y, T data)
00296 {
00297 int ind = index;
00298
00299 while((ind != 0)&&((records[ind-1].y > y) || ((records[ind-1].y == y) &&
00300 (records[ind-1].x > x))))
00301 {
00302 records[ind] = records[ind-1];
00303 ind--;
00304 }
00305 records[ind].x = x;
00306 records[ind].y = y;
00307 records[ind].data = data;
00308 index++;
00309 }
00310
00311
00312 void contributeSum(ArrayElement *elem, const CkCallback &cb)
00313 {
00314 T dummy;
00315 contributeSum(elem, cb, dummy);
00316 }
00317
00318 void contributeSum(ArrayElement *elem, const CkCallback &cb, int dummy)
00319 {
00320 elem->contribute(size*sizeof(rec), records, sparse2D_sum_int, cb);
00321 }
00322
00323 void contributeSum(ArrayElement *elem, const CkCallback &cb, float dummy)
00324 {
00325 elem->contribute(size*sizeof(rec), records, sparse2D_sum_float, cb);
00326 }
00327
00328 void contributeSum(ArrayElement *elem, const CkCallback &cb, double dummy)
00329 {
00330 elem->contribute(size*sizeof(rec), records, sparse2D_sum_double, cb);
00331 }
00332
00333
00334 void contributeProduct(ArrayElement *elem, const CkCallback &cb)
00335 {
00336 T dummy;
00337 contributeProduct(elem, cb, dummy);
00338 }
00339
00340 void contributeProduct(ArrayElement *elem, const CkCallback &cb, int dummy)
00341 {
00342 elem->contribute(size*sizeof(rec), records, sparse2D_product_int, cb);
00343 }
00344
00345 void contributeProduct(ArrayElement *elem, const CkCallback &cb, float
00346 dummy)
00347 {
00348 elem->contribute(size*sizeof(rec), records, sparse2D_product_float, cb);
00349 }
00350
00351 void contributeProduct(ArrayElement *elem, const CkCallback &cb, double
00352 dummy)
00353 {
00354 elem->contribute(size*sizeof(rec), records, sparse2D_product_double, cb);
00355 }
00356
00357
00358 void contributeMax(ArrayElement *elem, const CkCallback &cb)
00359 {
00360 T dummy;
00361 contributeMax(elem, cb, dummy);
00362 }
00363
00364 void contributeMax(ArrayElement *elem, const CkCallback &cb, int dummy)
00365 {
00366 elem->contribute(size*sizeof(rec), records, sparse2D_max_int, cb);
00367 }
00368
00369 void contributeMax(ArrayElement *elem, const CkCallback &cb, float dummy)
00370 {
00371 elem->contribute(size*sizeof(rec), records, sparse2D_max_float, cb);
00372 }
00373
00374 void contributeMax(ArrayElement *elem, const CkCallback &cb, double dummy)
00375 {
00376 elem->contribute(size*sizeof(rec), records, sparse2D_max_double, cb);
00377 }
00378
00379
00380 void contributeMin(ArrayElement *elem, const CkCallback &cb)
00381 {
00382 T dummy;
00383 contributeMin(elem, cb, dummy);
00384 }
00385
00386 void contributeMin(ArrayElement *elem, const CkCallback &cb, int dummy)
00387 {
00388 elem->contribute(size*sizeof(rec), records, sparse2D_min_int, cb);
00389 }
00390
00391 void contributeMin(ArrayElement *elem, const CkCallback &cb, float dummy)
00392 {
00393 elem->contribute(size*sizeof(rec), records, sparse2D_min_float, cb);
00394 }
00395
00396 void contributeMin(ArrayElement *elem, const CkCallback &cb, double dummy)
00397 {
00398 elem->contribute(size*sizeof(rec), records, sparse2D_min_double, cb);
00399 }
00400
00401 protected:
00402
00403 typedef sparseRec2D<T> rec;
00404 rec *records;
00405 int size;
00406 int index;
00407
00408 private:
00409 CkSparseReducer2D(){}
00410 };
00411
00412 template <class T>
00413 class CkSparseReducer3D
00414 {
00415 public:
00416
00417 CkSparseReducer3D(int numOfElements)
00418 {
00419 size = numOfElements;
00420 index = 0;
00421 if(size != 0)
00422 records = new rec[size];
00423 else
00424 records = NULL;
00425 }
00426
00427 ~CkSparseReducer3D()
00428 {
00429 if(records != NULL)
00430 delete[] records;
00431 }
00432
00433 void add(int x, int y, int z, T data)
00434 {
00435 int ind = index;
00436
00437 while((ind != 0) && ((records[ind-1].z > z) || ((records[ind-1].z == z) &&
00438 (records[ind-1].y > y)) || ((records[ind-1].z == z) &&
00439 (records[ind-1].y == y) && (records[ind-1].x > x))))
00440 {
00441 records[ind] = records[ind-1];
00442 ind--;
00443 }
00444 records[ind].x = x;
00445 records[ind].y = y;
00446 records[ind].z = z;
00447 records[ind].data = data;
00448 index++;
00449 }
00450
00451
00452 void contributeSum(ArrayElement *elem, const CkCallback &cb)
00453 {
00454 T dummy;
00455 contributeSum(elem, cb, dummy);
00456 }
00457
00458 void contributeSum(ArrayElement *elem, const CkCallback &cb, int dummy)
00459 {
00460 elem->contribute(size*sizeof(rec), records, sparse3D_sum_int, cb);
00461 }
00462
00463 void contributeSum(ArrayElement *elem, const CkCallback &cb, float dummy)
00464 {
00465 elem->contribute(size*sizeof(rec), records, sparse3D_sum_float, cb);
00466 }
00467
00468 void contributeSum(ArrayElement *elem, const CkCallback &cb, double dummy)
00469 {
00470 elem->contribute(size*sizeof(rec), records, sparse3D_sum_double, cb);
00471 }
00472
00473
00474 void contributeProduct(ArrayElement *elem, const CkCallback &cb)
00475 {
00476 T dummy;
00477 contributeProduct(elem, cb, dummy);
00478 }
00479
00480 void contributeProduct(ArrayElement *elem, const CkCallback &cb, int dummy)
00481 {
00482 elem->contribute(size*sizeof(rec), records, sparse3D_product_int, cb);
00483 }
00484
00485 void contributeProduct(ArrayElement *elem, const CkCallback &cb, float
00486 dummy)
00487 {
00488 elem->contribute(size*sizeof(rec), records, sparse3D_product_float, cb);
00489 }
00490
00491 void contributeProduct(ArrayElement *elem, const CkCallback &cb, double
00492 dummy)
00493 {
00494 elem->contribute(size*sizeof(rec), records, sparse3D_product_double, cb);
00495 }
00496
00497
00498 void contributeMax(ArrayElement *elem, const CkCallback &cb)
00499 {
00500 T dummy;
00501 contributeMax(elem, cb, dummy);
00502 }
00503
00504 void contributeMax(ArrayElement *elem, const CkCallback &cb, int dummy)
00505 {
00506 elem->contribute(size*sizeof(rec), records, sparse3D_max_int, cb);
00507 }
00508
00509 void contributeMax(ArrayElement *elem, const CkCallback &cb, float dummy)
00510 {
00511 elem->contribute(size*sizeof(rec), records, sparse3D_max_float, cb);
00512 }
00513
00514 void contributeMax(ArrayElement *elem, const CkCallback &cb, double dummy)
00515 {
00516 elem->contribute(size*sizeof(rec), records, sparse3D_max_double, cb);
00517 }
00518
00519
00520 void contributeMin(ArrayElement *elem, const CkCallback &cb)
00521 {
00522 T dummy;
00523 contributeMin(elem, cb, dummy);
00524 }
00525
00526 void contributeMin(ArrayElement *elem, const CkCallback &cb, int dummy)
00527 {
00528 elem->contribute(size*sizeof(rec), records, sparse3D_min_int, cb);
00529 }
00530
00531 void contributeMin(ArrayElement *elem, const CkCallback &cb, float dummy)
00532 {
00533 elem->contribute(size*sizeof(rec), records, sparse3D_min_float, cb);
00534 }
00535
00536 void contributeMin(ArrayElement *elem, const CkCallback &cb, double dummy)
00537 {
00538 elem->contribute(size*sizeof(rec), records, sparse3D_min_double, cb);
00539 }
00540
00541 protected:
00542
00543 typedef sparseRec3D<T> rec;
00544 rec *records;
00545 int size;
00546 int index;
00547
00548 private:
00549 CkSparseReducer3D(){}
00550 };
00551
00552 #endif