00001 #include "cksparsereducer.h"
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021 CkReduction::reducerType sparse1D_sum_int;
00022 CkReduction::reducerType sparse1D_sum_float;
00023 CkReduction::reducerType sparse1D_sum_double;
00024
00025 CkReduction::reducerType sparse1D_product_int;
00026 CkReduction::reducerType sparse1D_product_float;
00027 CkReduction::reducerType sparse1D_product_double;
00028
00029 CkReduction::reducerType sparse1D_max_int;
00030 CkReduction::reducerType sparse1D_max_float;
00031 CkReduction::reducerType sparse1D_max_double;
00032
00033 CkReduction::reducerType sparse1D_min_int;
00034 CkReduction::reducerType sparse1D_min_float;
00035 CkReduction::reducerType sparse1D_min_double;
00036
00037 CkReduction::reducerType sparse2D_sum_int;
00038 CkReduction::reducerType sparse2D_sum_float;
00039 CkReduction::reducerType sparse2D_sum_double;
00040
00041 CkReduction::reducerType sparse2D_product_int;
00042 CkReduction::reducerType sparse2D_product_float;
00043 CkReduction::reducerType sparse2D_product_double;
00044
00045 CkReduction::reducerType sparse2D_max_int;
00046 CkReduction::reducerType sparse2D_max_float;
00047 CkReduction::reducerType sparse2D_max_double;
00048
00049 CkReduction::reducerType sparse2D_min_int;
00050 CkReduction::reducerType sparse2D_min_float;
00051 CkReduction::reducerType sparse2D_min_double;
00052
00053 CkReduction::reducerType sparse3D_sum_int;
00054 CkReduction::reducerType sparse3D_sum_float;
00055 CkReduction::reducerType sparse3D_sum_double;
00056
00057 CkReduction::reducerType sparse3D_product_int;
00058 CkReduction::reducerType sparse3D_product_float;
00059 CkReduction::reducerType sparse3D_product_double;
00060
00061 CkReduction::reducerType sparse3D_max_int;
00062 CkReduction::reducerType sparse3D_max_float;
00063 CkReduction::reducerType sparse3D_max_double;
00064
00065 CkReduction::reducerType sparse3D_min_int;
00066 CkReduction::reducerType sparse3D_min_float;
00067 CkReduction::reducerType sparse3D_min_double;
00068
00069 #define SIMPLE_SPARSE1D_REDUCTION(name,dataType,typeStr,loop) \
00070 static CkReductionMsg *name(int nMsg,CkReductionMsg **msg)\
00071 {\
00072 int mergedDataSize=0, outDataSize=0;\
00073 int sizeofRec = sizeof(sparseRec1D<dataType>);\
00074 sparseRec1D<dataType> *mergedData, *mergedDataEnd;\
00075 sparseRec1D<dataType> *out, *mergeMsg, *mergeMsgEnd, *buff1, *buff2;\
00076 \
00077 \
00078 for(int i=0; i<nMsg; i++)\
00079 outDataSize += msg[i]->getSize()/sizeofRec;\
00080 \
00081 buff1 = new sparseRec1D<dataType>[outDataSize];\
00082 buff2 = new sparseRec1D<dataType>[outDataSize];\
00083 \
00084 outDataSize = 0;\
00085
00086 \
00087 for(int i=0; i<nMsg; i++)\
00088 {\
00089 \
00090 mergedData = buff2;\
00091 mergedDataEnd = mergedData + outDataSize;\
00092 mergedDataSize = outDataSize;\
00093 \
00094 mergeMsg = (sparseRec1D<dataType> *)(msg[i]->getData());\
00095 mergeMsgEnd = mergeMsg + (msg[i]->getSize()/sizeofRec);\
00096 \
00097 out = buff1;\
00098 outDataSize = 0;\
00099 \
00100 buff1 = mergedData;\
00101 buff2 = out;\
00102 \
00103 \
00104 while((mergedData != mergedDataEnd)&&(mergeMsg != mergeMsgEnd))\
00105 {\
00106 if(mergedData->x < mergeMsg->x)\
00107 *out++ = *mergedData++;\
00108 else\
00109 if(mergedData->x > mergeMsg->x)\
00110 *out++ = *mergeMsg++;\
00111 else\
00112 {\
00113 *out = *mergedData;\
00114 loop\
00115 out++; mergedData++; mergeMsg++;\
00116 }\
00117 }\
00118 \
00119 while(mergedData != mergedDataEnd)\
00120 *out++ = *mergedData++;\
00121 \
00122 while(mergeMsg != mergeMsgEnd)\
00123 *out++ = *mergeMsg++;\
00124 \
00125 outDataSize = out - buff2;\
00126 }\
00127 \
00128 CkReductionMsg* m = CkReductionMsg::buildNew(outDataSize*sizeofRec, \
00129 (void*)buff2);\
00130 \
00131 delete[] buff1;\
00132 delete[] buff2;\
00133 \
00134 return m;\
00135 }
00136
00137 #define SIMPLE_SPARSE2D_REDUCTION(name,dataType,typeStr,loop) \
00138 static CkReductionMsg *name(int nMsg,CkReductionMsg **msg)\
00139 {\
00140 int mergedDataSize=0, outDataSize=0;\
00141 int sizeofRec = sizeof(sparseRec2D<dataType>);\
00142 sparseRec2D<dataType> *mergedData, *mergedDataEnd;\
00143 sparseRec2D<dataType> *out, *mergeMsg, *mergeMsgEnd, *buff1, *buff2;\
00144 \
00145 \
00146 for(int i=0; i<nMsg; i++)\
00147 outDataSize += msg[i]->getSize()/sizeofRec;\
00148 \
00149 buff1 = new sparseRec2D<dataType>[outDataSize];\
00150 buff2 = new sparseRec2D<dataType>[outDataSize];\
00151 \
00152 outDataSize = 0;\
00153
00154 \
00155 for(int i=0; i<nMsg; i++)\
00156 {\
00157 \
00158 mergedData = buff2;\
00159 mergedDataEnd = mergedData + outDataSize;\
00160 mergedDataSize = outDataSize;\
00161 \
00162 mergeMsg = (sparseRec2D<dataType> *)(msg[i]->getData());\
00163 mergeMsgEnd = mergeMsg + (msg[i]->getSize()/sizeofRec);\
00164 \
00165 out = buff1;\
00166 outDataSize = 0;\
00167 \
00168 buff1 = mergedData;\
00169 buff2 = out;\
00170 \
00171 \
00172 while((mergedData != mergedDataEnd)&&(mergeMsg != mergeMsgEnd))\
00173 {\
00174 if((mergedData->y < mergeMsg->y) || ((mergedData->y == mergeMsg->y) &&\
00175 (mergedData->x < mergeMsg->x)))\
00176 *out++ = *mergedData++;\
00177 else\
00178 if((mergedData->y > mergeMsg->y) || ((mergedData->y == mergeMsg->y) &&\
00179 (mergedData->x > mergeMsg->x)))\
00180 *out++ = *mergeMsg++;\
00181 else\
00182 {\
00183 *out = *mergedData;\
00184 loop\
00185 out++; mergedData++; mergeMsg++;\
00186 }\
00187 }\
00188 \
00189 while(mergedData != mergedDataEnd)\
00190 *out++ = *mergedData++;\
00191 \
00192 while(mergeMsg != mergeMsgEnd)\
00193 *out++ = *mergeMsg++;\
00194 \
00195 outDataSize = out - buff2;\
00196 }\
00197 \
00198 CkReductionMsg* m = CkReductionMsg::buildNew(outDataSize*sizeofRec, \
00199 (void*)buff2);\
00200 \
00201 delete[] buff1;\
00202 delete[] buff2;\
00203 \
00204 return m;\
00205 }
00206
00207 #define SIMPLE_SPARSE3D_REDUCTION(name,dataType,typeStr,loop) \
00208 static CkReductionMsg *name(int nMsg,CkReductionMsg **msg)\
00209 {\
00210 int mergedDataSize=0, outDataSize=0;\
00211 int sizeofRec = sizeof(sparseRec3D<dataType>);\
00212 sparseRec3D<dataType> *mergedData, *mergedDataEnd;\
00213 sparseRec3D<dataType> *out, *mergeMsg, *mergeMsgEnd, *buff1, *buff2;\
00214 \
00215 \
00216 for(int i=0; i<nMsg; i++)\
00217 outDataSize += msg[i]->getSize()/sizeofRec;\
00218 \
00219 buff1 = new sparseRec3D<dataType>[outDataSize];\
00220 buff2 = new sparseRec3D<dataType>[outDataSize];\
00221 \
00222 outDataSize = 0;\
00223
00224 \
00225 for(int i=0; i<nMsg; i++)\
00226 {\
00227 \
00228 mergedData = buff2;\
00229 mergedDataEnd = mergedData + outDataSize;\
00230 mergedDataSize = outDataSize;\
00231 \
00232 mergeMsg = (sparseRec3D<dataType> *)(msg[i]->getData());\
00233 mergeMsgEnd = mergeMsg + (msg[i]->getSize()/sizeofRec);\
00234 \
00235 out = buff1;\
00236 outDataSize = 0;\
00237 \
00238 buff1 = mergedData;\
00239 buff2 = out;\
00240 \
00241 \
00242 while((mergedData != mergedDataEnd)&&(mergeMsg != mergeMsgEnd))\
00243 {\
00244 if((mergedData->z < mergeMsg->z) || ((mergedData->z == mergeMsg->z) &&\
00245 (mergedData->y < mergeMsg->y)) || ((mergedData->z == mergeMsg->z) &&\
00246 (mergedData->y == mergeMsg->y) && (mergedData->x < mergeMsg->x)))\
00247 *out++ = *mergedData++;\
00248 else\
00249 if((mergedData->z > mergeMsg->z) || ((mergedData->z == mergeMsg->z) &&\
00250 (mergedData->y > mergeMsg->y)) || ((mergedData->z == mergeMsg->z) &&\
00251 (mergedData->y == mergeMsg->y) && (mergedData->x > mergeMsg->x)))\
00252 *out++ = *mergeMsg++;\
00253 else\
00254 {\
00255 *out = *mergedData;\
00256 loop\
00257 out++; mergedData++; mergeMsg++;\
00258 }\
00259 }\
00260 \
00261 while(mergedData != mergedDataEnd)\
00262 *out++ = *mergedData++;\
00263 \
00264 while(mergeMsg != mergeMsgEnd)\
00265 *out++ = *mergeMsg++;\
00266 \
00267 outDataSize = out - buff2;\
00268 }\
00269 \
00270 CkReductionMsg* m = CkReductionMsg::buildNew(outDataSize*sizeofRec, \
00271 (void*)buff2);\
00272 \
00273 delete[] buff1;\
00274 delete[] buff2;\
00275 \
00276 return m;\
00277 }
00278
00279
00280 #define SIMPLE_POLYMORPH_SPARSE1D_REDUCTION(nameBase,loop) \
00281 SIMPLE_SPARSE1D_REDUCTION(nameBase##_int,int,"%d",loop) \
00282 SIMPLE_SPARSE1D_REDUCTION(nameBase##_float,float,"%f",loop) \
00283 SIMPLE_SPARSE1D_REDUCTION(nameBase##_double,double,"%f",loop)
00284
00285 #define SIMPLE_POLYMORPH_SPARSE2D_REDUCTION(nameBase,loop) \
00286 SIMPLE_SPARSE2D_REDUCTION(nameBase##_int,int,"%d",loop) \
00287 SIMPLE_SPARSE2D_REDUCTION(nameBase##_float,float,"%f",loop) \
00288 SIMPLE_SPARSE2D_REDUCTION(nameBase##_double,double,"%f",loop)
00289
00290 #define SIMPLE_POLYMORPH_SPARSE3D_REDUCTION(nameBase,loop) \
00291 SIMPLE_SPARSE3D_REDUCTION(nameBase##_int,int,"%d",loop) \
00292 SIMPLE_SPARSE3D_REDUCTION(nameBase##_float,float,"%f",loop) \
00293 SIMPLE_SPARSE3D_REDUCTION(nameBase##_double,double,"%f",loop)
00294
00295
00296
00297 SIMPLE_POLYMORPH_SPARSE1D_REDUCTION(_sparse1D_sum, out->data += mergeMsg->data;)
00298
00299
00300
00301 SIMPLE_POLYMORPH_SPARSE1D_REDUCTION(_sparse1D_product, out->data *=
00302 mergeMsg->data;)
00303
00304
00305
00306 SIMPLE_POLYMORPH_SPARSE1D_REDUCTION(_sparse1D_max, if(out->data<mergeMsg->data)
00307 out->data=mergeMsg->data;)
00308
00309
00310
00311 SIMPLE_POLYMORPH_SPARSE1D_REDUCTION(_sparse1D_min,if(out->data>mergeMsg->data)
00312 out->data=mergeMsg->data;)
00313
00314
00315
00316 SIMPLE_POLYMORPH_SPARSE2D_REDUCTION(_sparse2D_sum, out->data += mergeMsg->data;)
00317
00318
00319
00320 SIMPLE_POLYMORPH_SPARSE2D_REDUCTION(_sparse2D_product, out->data *=
00321 mergeMsg->data;)
00322
00323
00324
00325 SIMPLE_POLYMORPH_SPARSE2D_REDUCTION(_sparse2D_max, if(out->data<mergeMsg->data)
00326 out->data=mergeMsg->data;)
00327
00328
00329
00330 SIMPLE_POLYMORPH_SPARSE2D_REDUCTION(_sparse2D_min,if(out->data>mergeMsg->data)
00331 out->data=mergeMsg->data;)
00332
00333
00334
00335 SIMPLE_POLYMORPH_SPARSE3D_REDUCTION(_sparse3D_sum, out->data += mergeMsg->data;)
00336
00337
00338
00339 SIMPLE_POLYMORPH_SPARSE3D_REDUCTION(_sparse3D_product, out->data *=
00340 mergeMsg->data;)
00341
00342
00343
00344 SIMPLE_POLYMORPH_SPARSE3D_REDUCTION(_sparse3D_max, if(out->data<mergeMsg->data)
00345 out->data=mergeMsg->data;)
00346
00347
00348
00349 SIMPLE_POLYMORPH_SPARSE3D_REDUCTION(_sparse3D_min,if(out->data>mergeMsg->data)
00350 out->data=mergeMsg->data;)
00351
00352
00353 void registerReducers(void)
00354 {
00355 sparse1D_sum_int = CkReduction::addReducer(_sparse1D_sum_int);
00356 sparse1D_sum_float = CkReduction::addReducer(_sparse1D_sum_float);
00357 sparse1D_sum_double = CkReduction::addReducer(_sparse1D_sum_double);
00358
00359 sparse1D_product_int = CkReduction::addReducer(_sparse1D_product_int);
00360 sparse1D_product_float = CkReduction::addReducer(_sparse1D_product_float);
00361 sparse1D_product_double = CkReduction::addReducer(_sparse1D_product_double);
00362
00363 sparse1D_max_int = CkReduction::addReducer(_sparse1D_max_int);
00364 sparse1D_max_float = CkReduction::addReducer(_sparse1D_max_float);
00365 sparse1D_max_double = CkReduction::addReducer(_sparse1D_max_double);
00366
00367 sparse1D_min_int = CkReduction::addReducer(_sparse1D_min_int);
00368 sparse1D_min_float = CkReduction::addReducer(_sparse1D_min_float);
00369 sparse1D_min_double = CkReduction::addReducer(_sparse1D_min_double);
00370
00371 sparse2D_sum_int = CkReduction::addReducer(_sparse2D_sum_int);
00372 sparse2D_sum_float = CkReduction::addReducer(_sparse2D_sum_float);
00373 sparse2D_sum_double = CkReduction::addReducer(_sparse2D_sum_double);
00374
00375 sparse2D_product_int = CkReduction::addReducer(_sparse2D_product_int);
00376 sparse2D_product_float = CkReduction::addReducer(_sparse2D_product_float);
00377 sparse2D_product_double = CkReduction::addReducer(_sparse2D_product_double);
00378
00379 sparse2D_max_int = CkReduction::addReducer(_sparse2D_max_int);
00380 sparse2D_max_float = CkReduction::addReducer(_sparse2D_max_float);
00381 sparse2D_max_double = CkReduction::addReducer(_sparse2D_max_double);
00382
00383 sparse2D_min_int = CkReduction::addReducer(_sparse2D_min_int);
00384 sparse2D_min_float = CkReduction::addReducer(_sparse2D_min_float);
00385 sparse2D_min_double = CkReduction::addReducer(_sparse2D_min_double);
00386
00387 sparse3D_sum_int = CkReduction::addReducer(_sparse3D_sum_int);
00388 sparse3D_sum_float = CkReduction::addReducer(_sparse3D_sum_float);
00389 sparse3D_sum_double = CkReduction::addReducer(_sparse3D_sum_double);
00390
00391 sparse3D_product_int = CkReduction::addReducer(_sparse3D_product_int);
00392 sparse3D_product_float = CkReduction::addReducer(_sparse3D_product_float);
00393 sparse3D_product_double = CkReduction::addReducer(_sparse3D_product_double);
00394
00395 sparse3D_max_int = CkReduction::addReducer(_sparse3D_max_int);
00396 sparse3D_max_float = CkReduction::addReducer(_sparse3D_max_float);
00397 sparse3D_max_double = CkReduction::addReducer(_sparse3D_max_double);
00398
00399 sparse3D_min_int = CkReduction::addReducer(_sparse3D_min_int);
00400 sparse3D_min_float = CkReduction::addReducer(_sparse3D_min_float);
00401 sparse3D_min_double = CkReduction::addReducer(_sparse3D_min_double);
00402 }
00403
00404 #include "CkSparseReducer.def.h"