X-Git-Url: http://info.iut-bm.univ-fcomte.fr/pub/gitweb/simgrid.git/blobdiff_plain/50bc81a8526eb95a52e6a4b4a2ae1be94dfb24c1..239db2df2d2884b52782ad2c7cf141179bf9c352:/teshsuite/smpi/mpich3-test/datatype/large_type.c diff --git a/teshsuite/smpi/mpich3-test/datatype/large_type.c b/teshsuite/smpi/mpich3-test/datatype/large_type.c index 4688e1b158..48a256d532 100644 --- a/teshsuite/smpi/mpich3-test/datatype/large_type.c +++ b/teshsuite/smpi/mpich3-test/datatype/large_type.c @@ -11,34 +11,35 @@ static MPI_Datatype make_largexfer_type_struct(MPI_Offset nbytes) { - int typechunk_size = 1024*1024; /* in bytes: TODO: figure out how big a - chunk is really needed */ + int typechunk_size = 1024 * 1024; /* in bytes: TODO: figure out how big a + * chunk is really needed */ int chunk_count; - int remainder=0; + int remainder = 0; MPI_Datatype memtype, chunktype; /* need to cook up a new datatype to accomodate large datatypes */ /* first pass: chunks of 1 MiB plus an additional remainder. Does require * 8 byte MPI_Aint, which should have been checked for earlier */ - chunk_count = nbytes/typechunk_size; + chunk_count = nbytes / typechunk_size; remainder = nbytes % typechunk_size; MPI_Type_contiguous(typechunk_size, MPI_BYTE, &chunktype); MPI_Type_commit(&chunktype); /* a zero remainder means we can just count contigs */ if (remainder == 0) { - MPI_Type_contiguous(chunk_count, chunktype, &memtype); - MPI_Type_free(&chunktype); - } else { - if (sizeof(MPI_Aint) <= sizeof(int)) { - return MPI_DATATYPE_NULL; - } - /* struct type: some number of chunks plus remaining bytes tacked + MPI_Type_contiguous(chunk_count, chunktype, &memtype); + MPI_Type_free(&chunktype); + } + else { + if (sizeof(MPI_Aint) <= sizeof(int)) { + return MPI_DATATYPE_NULL; + } + /* struct type: some number of chunks plus remaining bytes tacked * on at end */ - int lens[] = {chunk_count, remainder}; - MPI_Aint disp[] = {0, (MPI_Aint) typechunk_size * (MPI_Aint)chunk_count}; - MPI_Datatype types[] = {chunktype, MPI_BYTE}; + int lens[] = { chunk_count, remainder }; + MPI_Aint disp[] = { 0, (MPI_Aint) typechunk_size * (MPI_Aint) chunk_count }; + MPI_Datatype types[] = { chunktype, MPI_BYTE }; MPI_Type_struct(2, lens, disp, types, &memtype); MPI_Type_free(&chunktype); @@ -46,10 +47,11 @@ static MPI_Datatype make_largexfer_type_struct(MPI_Offset nbytes) MPI_Type_commit(&memtype); return memtype; } + static MPI_Datatype make_largexfer_type_hindexed(MPI_Offset nbytes) { int i, count; - int chunk_size = 1024*1024; + int chunk_size = 1024 * 1024; int *blocklens; MPI_Aint *disp; MPI_Datatype memtype; @@ -61,53 +63,55 @@ static MPI_Datatype make_largexfer_type_hindexed(MPI_Offset nbytes) if (sizeof(MPI_Aint) <= sizeof(int)) { return MPI_DATATYPE_NULL; } - + /* ceiling division */ - count = 1 + ((nbytes -1) / chunk_size ); + count = 1 + ((nbytes - 1) / chunk_size); blocklens = calloc(count, sizeof(int)); disp = calloc(count, sizeof(MPI_Aint)); - for (i=0; i<(count-1); i++) { - blocklens[i] = chunk_size; - disp[i] = (MPI_Aint)chunk_size*i; + for (i = 0; i < (count - 1); i++) { + blocklens[i] = chunk_size; + disp[i] = (MPI_Aint) chunk_size *i; } - blocklens[count-1] = nbytes-((MPI_Aint)chunk_size*i); - disp[count-1] = (MPI_Aint)chunk_size*(count-1); + blocklens[count - 1] = nbytes - ((MPI_Aint) chunk_size * i); + disp[count - 1] = (MPI_Aint) chunk_size *(count - 1); MPI_Type_create_hindexed(count, blocklens, disp, MPI_BYTE, &memtype); MPI_Type_commit(&memtype); + free(blocklens); + free(disp); return memtype; } -int testtype(MPI_Datatype type, MPI_Offset expected) { +int testtype(MPI_Datatype type, MPI_Offset expected) +{ MPI_Count size, lb, extent; - int nerrors=0; + int nerrors = 0; MPI_Type_size_x(type, &size); - if (size < 0) { - printf("ERROR: type size apparently overflowed integer\n"); - nerrors++; + if (size < 0) { + printf("ERROR: type size apparently overflowed integer\n"); + nerrors++; } if (size != expected) { - printf("reported type size %lld does not match expected %lld\n", - size, expected); - nerrors++; + printf("reported type size %lld does not match expected %lld\n", size, expected); + nerrors++; } MPI_Type_get_true_extent_x(type, &lb, &extent); if (lb != 0) { - printf("ERROR: type should have lb of 0, reported %lld\n", lb); - nerrors ++; + printf("ERROR: type should have lb of 0, reported %lld\n", lb); + nerrors++; } - if (extent != size) { - printf("ERROR: extent should match size, not %lld\n", extent); - nerrors ++; + if (extent != size) { + printf("ERROR: extent should match size, not %lld\n", extent); + nerrors++; } return nerrors; } @@ -116,16 +120,17 @@ int testtype(MPI_Datatype type, MPI_Offset expected) { int main(int argc, char **argv) { - int nerrors=0, i; + int nerrors = 0, i; int rank, size; MPI_Init(&argc, &argv); MPI_Comm_rank(MPI_COMM_WORLD, &rank); MPI_Comm_size(MPI_COMM_WORLD, &size); #define NR_TYPES 3 - MPI_Offset expected_sizes[NR_TYPES] = {1024UL*1024UL*2400UL, - 2346319872, - 2346319872}; + MPI_Offset expected_sizes[NR_TYPES] = { 1024UL * 1024UL * 2400UL, + 2346319872, + 2346319872 + }; MPI_Datatype types[NR_TYPES]; /* a contig type, itself large, but does not need 8 byte aints */ @@ -135,20 +140,21 @@ int main(int argc, char **argv) /* similar, but with hindexed type */ types[2] = make_largexfer_type_hindexed(expected_sizes[2]); - for (i=0; i