00001
00002
00003
00004
00005
00006
00007
00008 #include <stdlib.h>
00009 #include <limits.h>
00010
00011 #include "./dataloop.h"
00012
00013 static void DLOOP_Dataloop_create_named(MPI_Datatype type,
00014 DLOOP_Dataloop **dlp_p,
00015 int *dlsz_p,
00016 int *dldepth_p,
00017 int flag);
00018
00019 void PREPEND_PREFIX(Dataloop_create)(MPI_Datatype type,
00020 DLOOP_Dataloop **dlp_p,
00021 int *dlsz_p,
00022 int *dldepth_p,
00023 int flag)
00024 {
00025 int i;
00026
00027 int nr_ints, nr_aints, nr_types, combiner;
00028 MPI_Datatype *types;
00029 int *ints;
00030 MPI_Aint *aints;
00031
00032 DLOOP_Dataloop *old_dlp;
00033 int old_dlsz, old_dldepth;
00034
00035 int dummy1, dummy2, dummy3, type0_combiner, ndims;
00036 MPI_Datatype tmptype;
00037
00038 MPI_Aint stride;
00039 MPI_Aint *disps;
00040
00041 MPI_Type_get_envelope(type, &nr_ints, &nr_aints, &nr_types, &combiner);
00042
00043
00044 if (combiner == MPI_COMBINER_NAMED) {
00045 DLOOP_Dataloop_create_named(type, dlp_p, dlsz_p, dldepth_p, flag);
00046 return;
00047 }
00048
00049
00050
00051
00052
00053 DLOOP_Handle_get_loopptr_macro(type, old_dlp, flag);
00054 if (old_dlp != NULL) {
00055
00056 *dlp_p = old_dlp;
00057 DLOOP_Handle_get_loopsize_macro(type, *dlsz_p, flag);
00058 DLOOP_Handle_get_loopdepth_macro(type, *dldepth_p, flag);
00059 return;
00060 }
00061
00062 PREPEND_PREFIX(Type_access_contents)(type, &ints, &aints, &types);
00063
00064
00065 switch(combiner) {
00066 case MPI_COMBINER_CONTIGUOUS:
00067 case MPI_COMBINER_VECTOR:
00068 case MPI_COMBINER_HVECTOR_INTEGER:
00069 case MPI_COMBINER_HVECTOR:
00070 case MPI_COMBINER_INDEXED_BLOCK:
00071 case MPI_COMBINER_INDEXED:
00072 case MPI_COMBINER_HINDEXED_INTEGER:
00073 case MPI_COMBINER_HINDEXED:
00074 case MPI_COMBINER_STRUCT_INTEGER:
00075 case MPI_COMBINER_STRUCT:
00076 if (ints[0] == 0) {
00077 PREPEND_PREFIX(Dataloop_create_contiguous)(0,
00078 MPI_INT,
00079 dlp_p,
00080 dlsz_p,
00081 dldepth_p,
00082 flag);
00083 goto clean_exit;
00084 }
00085 break;
00086 default:
00087 break;
00088 }
00089
00090
00091
00092
00093
00094
00095
00096 MPI_Type_get_envelope(types[0], &dummy1, &dummy2, &dummy3,
00097 &type0_combiner);
00098 if (type0_combiner != MPI_COMBINER_NAMED)
00099 {
00100 DLOOP_Handle_get_loopptr_macro(types[0], old_dlp, flag);
00101 if (old_dlp == NULL)
00102 {
00103
00104 PREPEND_PREFIX(Dataloop_create)(types[0],
00105 &old_dlp,
00106 &old_dlsz,
00107 &old_dldepth,
00108 flag);
00109
00110 DLOOP_Handle_set_loopptr_macro(types[0], old_dlp, flag);
00111 DLOOP_Handle_set_loopsize_macro(types[0], old_dlsz, flag);
00112 DLOOP_Handle_set_loopdepth_macro(types[0], old_dldepth, flag);
00113 }
00114 }
00115
00116 switch(combiner)
00117 {
00118 case MPI_COMBINER_DUP:
00119 if (type0_combiner != MPI_COMBINER_NAMED) {
00120 PREPEND_PREFIX(Dataloop_dup)(old_dlp, old_dlsz, dlp_p);
00121 *dlsz_p = old_dlsz;
00122 *dldepth_p = old_dldepth;
00123 }
00124 else {
00125 PREPEND_PREFIX(Dataloop_create_contiguous)(1,
00126 types[0],
00127 dlp_p, dlsz_p,
00128 dldepth_p,
00129 flag);
00130 }
00131 break;
00132 case MPI_COMBINER_RESIZED:
00133 if (type0_combiner != MPI_COMBINER_NAMED) {
00134 PREPEND_PREFIX(Dataloop_dup)(old_dlp, old_dlsz, dlp_p);
00135 *dlsz_p = old_dlsz;
00136 *dldepth_p = old_dldepth;
00137 }
00138 else {
00139 PREPEND_PREFIX(Dataloop_create_contiguous)(1,
00140 types[0],
00141 dlp_p, dlsz_p,
00142 dldepth_p,
00143 flag);
00144
00145 (*dlp_p)->el_extent = aints[1];
00146 }
00147 break;
00148 case MPI_COMBINER_CONTIGUOUS:
00149 PREPEND_PREFIX(Dataloop_create_contiguous)(ints[0] ,
00150 types[0] ,
00151 dlp_p, dlsz_p,
00152 dldepth_p,
00153 flag);
00154 break;
00155 case MPI_COMBINER_VECTOR:
00156 PREPEND_PREFIX(Dataloop_create_vector)(ints[0] ,
00157 ints[1] ,
00158 ints[2] ,
00159 0 ,
00160 types[0] ,
00161 dlp_p, dlsz_p, dldepth_p,
00162 flag);
00163 break;
00164 case MPI_COMBINER_HVECTOR_INTEGER:
00165 case MPI_COMBINER_HVECTOR:
00166
00167 if (combiner == MPI_COMBINER_HVECTOR_INTEGER) {
00168 stride = (MPI_Aint) ints[2];
00169 }
00170 else {
00171 stride = aints[0];
00172 }
00173
00174 PREPEND_PREFIX(Dataloop_create_vector)(ints[0] ,
00175 ints[1] ,
00176 stride,
00177 1 ,
00178 types[0] ,
00179 dlp_p, dlsz_p, dldepth_p,
00180 flag);
00181 break;
00182 case MPI_COMBINER_INDEXED_BLOCK:
00183 PREPEND_PREFIX(Dataloop_create_blockindexed)(ints[0] ,
00184 ints[1] ,
00185 &ints[2] ,
00186 0 ,
00187 types[0] ,
00188 dlp_p, dlsz_p,
00189 dldepth_p,
00190 flag);
00191 break;
00192 case MPI_COMBINER_INDEXED:
00193 PREPEND_PREFIX(Dataloop_create_indexed)(ints[0] ,
00194 &ints[1] ,
00195 &ints[ints[0]+1] ,
00196 0 ,
00197 types[0] ,
00198 dlp_p, dlsz_p, dldepth_p,
00199 flag);
00200 break;
00201 case MPI_COMBINER_HINDEXED_INTEGER:
00202 case MPI_COMBINER_HINDEXED:
00203 if (combiner == MPI_COMBINER_HINDEXED_INTEGER) {
00204 disps = (MPI_Aint *) DLOOP_Malloc(ints[0] * sizeof(MPI_Aint));
00205
00206 for (i=0; i < ints[0]; i++) {
00207 disps[i] = (MPI_Aint) ints[ints[0] + 1 + i];
00208 }
00209 }
00210 else {
00211 disps = aints;
00212 }
00213
00214 PREPEND_PREFIX(Dataloop_create_indexed)(ints[0] ,
00215 &ints[1] ,
00216 disps,
00217 1 ,
00218 types[0] ,
00219 dlp_p, dlsz_p, dldepth_p,
00220 flag);
00221
00222 if (combiner == MPI_COMBINER_HINDEXED_INTEGER) {
00223 DLOOP_Free(disps);
00224 }
00225
00226 break;
00227 case MPI_COMBINER_STRUCT_INTEGER:
00228 case MPI_COMBINER_STRUCT:
00229 for (i = 1; i < ints[0]; i++) {
00230 int type_combiner;
00231 MPI_Type_get_envelope(types[i], &dummy1, &dummy2, &dummy3,
00232 &type_combiner);
00233
00234 if (type_combiner != MPI_COMBINER_NAMED) {
00235 DLOOP_Handle_get_loopptr_macro(types[i], old_dlp, flag);
00236 if (old_dlp == NULL)
00237 {
00238 PREPEND_PREFIX(Dataloop_create)(types[i],
00239 &old_dlp,
00240 &old_dlsz,
00241 &old_dldepth,
00242 flag);
00243
00244 DLOOP_Handle_set_loopptr_macro(types[i], old_dlp,
00245 flag);
00246 DLOOP_Handle_set_loopsize_macro(types[i], old_dlsz,
00247 flag);
00248 DLOOP_Handle_set_loopdepth_macro(types[i], old_dldepth,
00249 flag);
00250 }
00251 }
00252 }
00253 if (combiner == MPI_COMBINER_STRUCT_INTEGER) {
00254 disps = (MPI_Aint *) DLOOP_Malloc(ints[0] * sizeof(MPI_Aint));
00255
00256 for (i=0; i < ints[0]; i++) {
00257 disps[i] = (MPI_Aint) ints[ints[0] + 1 + i];
00258 }
00259 }
00260 else {
00261 disps = aints;
00262 }
00263
00264 PREPEND_PREFIX(Dataloop_create_struct)(ints[0] ,
00265 &ints[1] ,
00266 disps,
00267 types ,
00268 dlp_p, dlsz_p, dldepth_p,
00269 flag);
00270
00271 if (combiner == MPI_COMBINER_STRUCT_INTEGER) {
00272 DLOOP_Free(disps);
00273 }
00274 break;
00275 case MPI_COMBINER_SUBARRAY:
00276 ndims = ints[0];
00277 PREPEND_PREFIX(Type_convert_subarray)(ndims,
00278 &ints[1] ,
00279 &ints[1+ndims] ,
00280 &ints[1+2*ndims] ,
00281 ints[1+3*ndims] ,
00282 types[0],
00283 &tmptype);
00284
00285 PREPEND_PREFIX(Dataloop_create)(tmptype,
00286 dlp_p,
00287 dlsz_p,
00288 dldepth_p,
00289 flag);
00290
00291 MPI_Type_free(&tmptype);
00292 break;
00293 case MPI_COMBINER_DARRAY:
00294 ndims = ints[2];
00295 PREPEND_PREFIX(Type_convert_darray)(ints[0] ,
00296 ints[1] ,
00297 ndims,
00298 &ints[3] ,
00299 &ints[3+ndims] ,
00300 &ints[3+2*ndims] ,
00301 &ints[3+3*ndims] ,
00302 ints[3+4*ndims] ,
00303 types[0],
00304 &tmptype);
00305
00306 PREPEND_PREFIX(Dataloop_create)(tmptype,
00307 dlp_p,
00308 dlsz_p,
00309 dldepth_p,
00310 flag);
00311
00312 MPI_Type_free(&tmptype);
00313 break;
00314 case MPI_COMBINER_F90_REAL:
00315 case MPI_COMBINER_F90_COMPLEX:
00316 case MPI_COMBINER_F90_INTEGER:
00317
00318 default:
00319 DLOOP_Assert(0);
00320 break;
00321 }
00322
00323 clean_exit:
00324
00325 PREPEND_PREFIX(Type_release_contents)(type, &ints, &aints, &types);
00326
00327
00328
00329
00330
00331 return;
00332 }
00333
00334
00335
00336
00337
00338
00339
00340
00341
00342
00343 static void DLOOP_Dataloop_create_named(MPI_Datatype type,
00344 DLOOP_Dataloop **dlp_p,
00345 int *dlsz_p,
00346 int *dldepth_p,
00347 int flag)
00348 {
00349 DLOOP_Dataloop *dlp;
00350
00351
00352
00353
00354
00355
00356
00357
00358
00359
00360 if (type == MPI_FLOAT_INT || type == MPI_DOUBLE_INT ||
00361 type == MPI_LONG_INT || type == MPI_SHORT_INT ||
00362 type == MPI_LONG_DOUBLE_INT)
00363 {
00364 DLOOP_Handle_get_loopptr_macro(type, dlp, flag);
00365 if (dlp != NULL) {
00366
00367 *dlp_p = dlp;
00368 DLOOP_Handle_get_loopsize_macro(type, *dlsz_p, flag);
00369 DLOOP_Handle_get_loopdepth_macro(type, *dldepth_p, flag);
00370 }
00371 else {
00372 PREPEND_PREFIX(Dataloop_create_pairtype)(type,
00373 dlp_p,
00374 dlsz_p,
00375 dldepth_p,
00376 flag);
00377 }
00378 return;
00379 }
00380
00381 else {
00382 *dlp_p = NULL;
00383 *dlsz_p = 0;
00384 *dldepth_p = 0;
00385 return;
00386 }
00387 }