1 #include "colls_private.h"
4 * created by Pitch Patarasuk
7 * realize a subset of MPI predefine operators:
8 * MPI_LAND, MPI_BAND: C integer, Fortran integer, Byte
9 * MPI_LOR, MPI_BOR: C integer, Fortran integer, Byte
10 * MPI_LXOR, MPI_BXOR: C integer, Fortran integer, Byte
11 * MPI_SUM, MPI_PROD: C integer, Fortran integer, Floating point
12 * MPI_MIN, MPI_MAX: C integer, Fortran integer, Floating point, Byte
14 * Types not implemented: MPI_LONG_DOUBLE, MPI_LOGICAL, MPI_COMPLEX
17 #ifndef STAR_REDUCTION
18 #define STAR_REDUCTION
21 #ifdef MPICH2_REDUCTION
22 extern MPI_User_function * MPIR_Op_table[];
23 #elif defined MVAPICH_REDUCETION
24 extern void *MPIR_ToPointer();
27 MPI_User_function *op;
33 static void star_generic_reduction(MPI_Op op, void *src, void *target, int *count, MPI_Datatype *dtype){
35 if ((op == MPI_BOR) || (op == MPI_LOR)) {
36 if ((*dtype == MPI_BYTE) || (*dtype == MPI_CHAR)) {
37 for (i=0;i<*count;i++) {
38 ((char *)target)[i] |= ((char *)src)[i];
41 else if ((*dtype == MPI_INT)
42 || (*dtype == MPI_LONG)
43 || (*dtype == MPI_INT)
44 || (*dtype == MPI_UNSIGNED)
45 || (*dtype == MPI_UNSIGNED_LONG)) {
46 for (i=0;i<*count;i++) {
47 ((int *)target)[i] |= ((int *)src)[i];
50 else if ((*dtype == MPI_SHORT)
51 || (*dtype == MPI_UNSIGNED_SHORT)) {
52 for (i=0;i<*count;i++) {
53 ((short *)target)[i] |= ((short *)src)[i];
57 printf("reduction operation not supported\n");
61 else if ((op == MPI_BAND) || (op == MPI_LAND)) {
62 if ((*dtype == MPI_BYTE) || (*dtype == MPI_CHAR)) {
63 for (i=0;i<*count;i++) {
64 ((char *)target)[i] &= ((char *)src)[i];
67 else if ((*dtype == MPI_INT)
68 || (*dtype == MPI_LONG)
69 || (*dtype == MPI_UNSIGNED)
70 || (*dtype == MPI_UNSIGNED_LONG)) {
71 for (i=0;i<*count;i++) {
72 ((int *)target)[i] &= ((int *)src)[i];
75 else if ((*dtype == MPI_SHORT)
76 || (*dtype == MPI_UNSIGNED_SHORT)) {
77 for (i=0;i<*count;i++) {
78 ((short *)target)[i] &= ((short *)src)[i];
82 printf("reduction operation not supported\n");
87 else if ((op == MPI_BXOR) || (op == MPI_LXOR)) {
88 if ((*dtype == MPI_BYTE) || (*dtype == MPI_CHAR)) {
89 for (i=0;i<*count;i++) {
90 ((char *)target)[i] ^= ((char *)src)[i];
93 else if ((*dtype == MPI_INT)
94 || (*dtype == MPI_LONG)
95 || (*dtype == MPI_UNSIGNED)
96 || (*dtype == MPI_UNSIGNED_LONG)) {
97 for (i=0;i<*count;i++) {
98 ((int *)target)[i] ^= ((int *)src)[i];
101 else if ((*dtype == MPI_SHORT)
102 || (*dtype == MPI_UNSIGNED_SHORT)) {
103 for (i=0;i<*count;i++) {
104 ((short *)target)[i] ^= ((short *)src)[i];
108 printf("reduction operation not supported\n");
112 else if (op == MPI_MAX) {
113 if ((*dtype == MPI_INT)
114 || (*dtype == MPI_LONG)) {
115 for (i=0;i<*count;i++) {
116 if (((int *)src)[i] > ((int *)target)[i]) {
117 ((int *)target)[i] = ((int *)src)[i];
121 else if ((*dtype == MPI_UNSIGNED)
122 || (*dtype == MPI_UNSIGNED_LONG)) {
123 for (i=0;i<*count;i++) {
124 if (((unsigned int *)src)[i] > ((unsigned int *)target)[i]) {
125 ((unsigned int *)target)[i] = ((unsigned int *)src)[i];
129 else if (*dtype == MPI_SHORT) {
130 for (i=0;i<*count;i++) {
131 if (((short *)src)[i] > ((short *)target)[i]) {
132 ((short *)target)[i] = ((short *)src)[i];
136 else if (*dtype == MPI_UNSIGNED_SHORT) {
137 for (i=0;i<*count;i++) {
138 if (((unsigned short *)src)[i] > ((unsigned short *)target)[i]) {
139 ((unsigned short *)target)[i] = ((unsigned short *)src)[i];
144 else if (*dtype == MPI_DOUBLE) {
145 for (i=0;i<*count;i++) {
146 if (((double *)src)[i] > ((double *)target)[i]) {
147 ((double *)target)[i] = ((double *)src)[i];
151 else if (*dtype == MPI_FLOAT) {
152 for (i=0;i<*count;i++) {
153 if (((float *)src)[i] > ((float *)target)[i]) {
154 ((float *)target)[i] = ((float *)src)[i];
158 else if ((*dtype == MPI_CHAR) || (*dtype == MPI_BYTE)) {
159 for (i=0;i<*count;i++) {
160 if (((char *)src)[i] > ((char *)target)[i]) {
161 ((char *)target)[i] = ((char *)src)[i];
166 printf("reduction operation not supported\n");
172 else if (op == MPI_MIN) {
173 if ((*dtype == MPI_INT)
174 || (*dtype == MPI_LONG)) {
175 for (i=0;i<*count;i++) {
176 if (((int *)src)[i] < ((int *)target)[i]) {
177 ((int *)target)[i] = ((int *)src)[i];
181 else if ((*dtype == MPI_UNSIGNED)
182 || (*dtype == MPI_UNSIGNED_LONG)) {
183 for (i=0;i<*count;i++) {
184 if (((unsigned int *)src)[i] < ((unsigned int *)target)[i]) {
185 ((unsigned int *)target)[i] = ((unsigned int *)src)[i];
189 else if (*dtype == MPI_SHORT) {
190 for (i=0;i<*count;i++) {
191 if (((short *)src)[i] < ((short *)target)[i]) {
192 ((short *)target)[i] = ((short *)src)[i];
196 else if (*dtype == MPI_UNSIGNED_SHORT) {
197 for (i=0;i<*count;i++) {
198 if (((unsigned short *)src)[i] < ((unsigned short *)target)[i]) {
199 ((unsigned short *)target)[i] = ((unsigned short *)src)[i];
204 else if (*dtype == MPI_DOUBLE) {
205 for (i=0;i<*count;i++) {
206 if (((double *)src)[i] < ((double *)target)[i]) {
207 ((double *)target)[i] = ((double *)src)[i];
211 else if (*dtype == MPI_FLOAT) {
212 for (i=0;i<*count;i++) {
213 if (((float *)src)[i] < ((float *)target)[i]) {
214 ((float *)target)[i] = ((float *)src)[i];
218 else if ((*dtype == MPI_CHAR) || (*dtype == MPI_BYTE)) {
219 for (i=0;i<*count;i++) {
220 if (((char *)src)[i] < ((char *)target)[i]) {
221 ((char *)target)[i] = ((char *)src)[i];
226 printf("reduction operation not supported\n");
231 else if (op == MPI_SUM) {
232 if ((*dtype == MPI_INT)
233 || (*dtype == MPI_LONG)) {
234 for (i=0;i<*count;i++) {
235 ((int *)target)[i] += ((int *)src)[i];
238 else if ((*dtype == MPI_UNSIGNED)
239 || (*dtype == MPI_UNSIGNED_LONG)) {
240 for (i=0;i<*count;i++) {
241 ((unsigned int *)target)[i] += ((unsigned int *)src)[i];
244 else if (*dtype == MPI_SHORT) {
245 for (i=0;i<*count;i++) {
246 ((short *)target)[i] += ((short *)src)[i];
249 else if (*dtype == MPI_UNSIGNED_SHORT) {
250 for (i=0;i<*count;i++) {
251 ((unsigned short *)target)[i] += ((unsigned short *)src)[i];
255 else if (*dtype == MPI_DOUBLE) {
256 for (i=0;i<*count;i++) {
257 ((double *)target)[i] += ((double *)src)[i];
260 else if (*dtype == MPI_FLOAT) {
261 for (i=0;i<*count;i++) {
262 ((float *)target)[i] += ((float *)src)[i];
266 printf("reduction operation not supported\n");
270 else if (op == MPI_PROD) {
271 if ((*dtype == MPI_INT)
272 || (*dtype == MPI_LONG)) {
273 for (i=0;i<*count;i++) {
274 ((int *)target)[i] *= ((int *)src)[i];
277 else if ((*dtype == MPI_UNSIGNED)
278 || (*dtype == MPI_UNSIGNED_LONG)) {
279 for (i=0;i<*count;i++) {
280 ((unsigned int *)target)[i] *= ((unsigned int *)src)[i];
283 else if (*dtype == MPI_SHORT) {
284 for (i=0;i<*count;i++) {
285 ((short *)target)[i] *= ((short *)src)[i];
288 else if (*dtype == MPI_UNSIGNED_SHORT) {
289 for (i=0;i<*count;i++) {
290 ((unsigned short *)target)[i] *= ((unsigned short *)src)[i];
294 else if (*dtype == MPI_DOUBLE) {
295 for (i=0;i<*count;i++) {
296 ((double *)target)[i] *= ((double *)src)[i];
299 else if (*dtype == MPI_FLOAT) {
300 for (i=0;i<*count;i++) {
301 ((float *)target)[i] *= ((float *)src)[i];
305 printf("reduction operation not supported\n");
310 printf("reduction operation not supported\n");
314 void star_reduction(MPI_Op op, void *src, void *target, int *count, MPI_Datatype *dtype){
316 #ifdef MPICH2_REDUCTION
317 MPI_User_function * uop = MPIR_Op_table[op % 16 - 1];
318 return (*uop) (src,target,count,dtype);
319 #elif defined MVAPICH_REDUCTION
320 MPI_User_function *uop;
321 struct MPIR_OP *op_ptr;
322 op_ptr = MPIR_ToPointer(op);
324 return (*uop) (src,target,count,dtype);
326 return star_generic_reduction(op,src,target,count,dtype);