X-Git-Url: http://info.iut-bm.univ-fcomte.fr/pub/gitweb/simgrid.git/blobdiff_plain/8006a03b1ef66a0ddd4a4983ef170781a87a7225..61427a88a76a2c2ef25d0d5b8132995c6f550e5c:/teshsuite/smpi/mpich3-test/datatype/struct-pack.c diff --git a/teshsuite/smpi/mpich3-test/datatype/struct-pack.c b/teshsuite/smpi/mpich3-test/datatype/struct-pack.c index d7b5719a44..04c08073c6 100644 --- a/teshsuite/smpi/mpich3-test/datatype/struct-pack.c +++ b/teshsuite/smpi/mpich3-test/datatype/struct-pack.c @@ -18,8 +18,8 @@ int array_of_structs_test(void); int struct_of_structs_test(void); struct test_struct_1 { - int a,b; - char c,d; + int a, b; + char c, d; int e; }; @@ -32,27 +32,30 @@ int main(int argc, char *argv[]) parse_args(argc, argv); /* To improve reporting of problems about operations, we - change the error handler to errors return */ - MPI_Comm_set_errhandler( MPI_COMM_WORLD, MPI_ERRORS_RETURN ); + * change the error handler to errors return */ + MPI_Comm_set_errhandler(MPI_COMM_WORLD, MPI_ERRORS_RETURN); err = single_struct_test(); - if (verbose && err) fprintf(stderr, "error in single_struct_test\n"); + if (verbose && err) + fprintf(stderr, "error in single_struct_test\n"); errs += err; err = array_of_structs_test(); - if (verbose && err) fprintf(stderr, "error in array_of_structs_test\n"); + if (verbose && err) + fprintf(stderr, "error in array_of_structs_test\n"); errs += err; err = struct_of_structs_test(); - if (verbose && err) fprintf(stderr, "error in struct_of_structs_test\n"); + if (verbose && err) + fprintf(stderr, "error in struct_of_structs_test\n"); errs += err; /* print message and exit */ if (errs) { - fprintf(stderr, "Found %d errors\n", errs); + fprintf(stderr, "Found %d errors\n", errs); } else { - printf(" No Errors\n"); + printf(" No Errors\n"); } MPI_Finalize(); return 0; @@ -66,7 +69,7 @@ int single_struct_test(void) MPI_Datatype mystruct; char *buffer; - MPI_Aint disps[3] = {0, 2*sizeof(int), 3*sizeof(int)}; /* guessing... */ + MPI_Aint disps[3] = { 0, 2 * sizeof(int), 3 * sizeof(int) }; /* guessing... */ int blks[3] = { 2, 2, 1 }; MPI_Datatype types[3] = { MPI_INT, MPI_CHAR, MPI_INT }; @@ -78,10 +81,10 @@ int single_struct_test(void) err = MPI_Type_struct(3, blks, disps, types, &mystruct); if (err != MPI_SUCCESS) { - errs++; - if (verbose) { - fprintf(stderr, "MPI_Type_struct returned error\n"); - } + errs++; + if (verbose) { + fprintf(stderr, "MPI_Type_struct returned error\n"); + } } MPI_Type_commit(&mystruct); @@ -89,69 +92,55 @@ int single_struct_test(void) MPI_Pack_size(1, mystruct, MPI_COMM_WORLD, &bufsize); buffer = (char *) malloc(bufsize); - err = MPI_Pack(&ts1, - 1, - mystruct, - buffer, - bufsize, - &position, - MPI_COMM_WORLD); + err = MPI_Pack(&ts1, 1, mystruct, buffer, bufsize, &position, MPI_COMM_WORLD); if (err != MPI_SUCCESS) { - errs++; - if (verbose) { - fprintf(stderr, "MPI_Pack returned error\n"); - } + errs++; + if (verbose) { + fprintf(stderr, "MPI_Pack returned error\n"); + } } position = 0; - err = MPI_Unpack(buffer, - bufsize, - &position, - &ts2, - 1, - mystruct, - MPI_COMM_WORLD); + err = MPI_Unpack(buffer, bufsize, &position, &ts2, 1, mystruct, MPI_COMM_WORLD); if (err != MPI_SUCCESS) { - errs++; - if (verbose) { - fprintf(stderr, "MPI_Unpack returned error\n"); - } + errs++; + if (verbose) { + fprintf(stderr, "MPI_Unpack returned error\n"); + } } MPI_Type_free(&mystruct); free(buffer); if (ts1.a != ts2.a) { - errs++; - if (verbose) { - fprintf(stderr, "ts2.a = %d; should be %d\n", ts2.a, ts1.a); - } + errs++; + if (verbose) { + fprintf(stderr, "ts2.a = %d; should be %d\n", ts2.a, ts1.a); + } } if (ts1.b != ts2.b) { - errs++; - if (verbose) { - fprintf(stderr, "ts2.b = %d; should be %d\n", ts2.b, ts1.b); - } + errs++; + if (verbose) { + fprintf(stderr, "ts2.b = %d; should be %d\n", ts2.b, ts1.b); + } } if (ts1.c != ts2.c) { - errs++; - if (verbose) { - fprintf(stderr, "ts2.c = %d; should be %d\n", - (int) ts2.c, (int) ts1.c); - } + errs++; + if (verbose) { + fprintf(stderr, "ts2.c = %d; should be %d\n", (int) ts2.c, (int) ts1.c); + } } if (ts1.d != ts2.d) { - errs++; - if (verbose) { - fprintf(stderr, "ts2.d = %d; should be %d\n", - (int) ts2.d, (int) ts1.d); - } + errs++; + if (verbose) { + fprintf(stderr, "ts2.d = %d; should be %d\n", (int) ts2.d, (int) ts1.d); + } } if (ts1.e != ts2.e) { - errs++; - if (verbose) { - fprintf(stderr, "ts2.e = %d; should be %d\n", ts2.e, ts1.e); - } + errs++; + if (verbose) { + fprintf(stderr, "ts2.e = %d; should be %d\n", ts2.e, ts1.e); + } } return errs; @@ -165,30 +154,30 @@ int array_of_structs_test(void) MPI_Datatype mystruct; char *buffer; - MPI_Aint disps[3] = {0, 2*sizeof(int), 3*sizeof(int)}; /* guessing... */ + MPI_Aint disps[3] = { 0, 2 * sizeof(int), 3 * sizeof(int) }; /* guessing... */ int blks[3] = { 2, 2, 1 }; MPI_Datatype types[3] = { MPI_INT, MPI_CHAR, MPI_INT }; - for (i=0; i < 10; i++) { - ts1[i].a = 10*i + 1; - ts1[i].b = 10*i + 2; - ts1[i].c = 10*i + 3; - ts1[i].d = 10*i + 4; - ts1[i].e = 10*i + 5; - - ts2[i].a = -13; - ts2[i].b = -13; - ts2[i].c = -13; - ts2[i].d = -13; - ts2[i].e = -13; + for (i = 0; i < 10; i++) { + ts1[i].a = 10 * i + 1; + ts1[i].b = 10 * i + 2; + ts1[i].c = 10 * i + 3; + ts1[i].d = 10 * i + 4; + ts1[i].e = 10 * i + 5; + + ts2[i].a = -13; + ts2[i].b = -13; + ts2[i].c = -13; + ts2[i].d = -13; + ts2[i].e = -13; } err = MPI_Type_struct(3, blks, disps, types, &mystruct); if (err != MPI_SUCCESS) { - errs++; - if (verbose) { - fprintf(stderr, "MPI_Type_struct returned error\n"); - } + errs++; + if (verbose) { + fprintf(stderr, "MPI_Type_struct returned error\n"); + } } MPI_Type_commit(&mystruct); @@ -196,74 +185,59 @@ int array_of_structs_test(void) MPI_Pack_size(10, mystruct, MPI_COMM_WORLD, &bufsize); buffer = (char *) malloc(bufsize); - err = MPI_Pack(ts1, - 10, - mystruct, - buffer, - bufsize, - &position, - MPI_COMM_WORLD); + err = MPI_Pack(ts1, 10, mystruct, buffer, bufsize, &position, MPI_COMM_WORLD); if (err != MPI_SUCCESS) { - errs++; - if (verbose) { - fprintf(stderr, "MPI_Pack returned error\n"); - } + errs++; + if (verbose) { + fprintf(stderr, "MPI_Pack returned error\n"); + } } position = 0; - err = MPI_Unpack(buffer, - bufsize, - &position, - ts2, - 10, - mystruct, - MPI_COMM_WORLD); + err = MPI_Unpack(buffer, bufsize, &position, ts2, 10, mystruct, MPI_COMM_WORLD); if (err != MPI_SUCCESS) { - errs++; - if (verbose) { - fprintf(stderr, "MPI_Unpack returned error\n"); - } + errs++; + if (verbose) { + fprintf(stderr, "MPI_Unpack returned error\n"); + } } MPI_Type_free(&mystruct); free(buffer); - for (i=0; i < 10; i++) { - if (ts1[i].a != ts2[i].a) { - errs++; - if (verbose) { - fprintf(stderr, "ts2[%d].a = %d; should be %d\n", - i, ts2[i].a, ts1[i].a); - } - } - if (ts1[i].b != ts2[i].b) { - errs++; - if (verbose) { - fprintf(stderr, "ts2[%d].b = %d; should be %d\n", - i, ts2[i].b, ts1[i].b); - } - } - if (ts1[i].c != ts2[i].c) { - errs++; - if (verbose) { - fprintf(stderr, "ts2[%d].c = %d; should be %d\n", - i, (int) ts2[i].c, (int) ts1[i].c); - } - } - if (ts1[i].d != ts2[i].d) { - errs++; - if (verbose) { - fprintf(stderr, "ts2[%d].d = %d; should be %d\n", - i, (int) ts2[i].d, (int) ts1[i].d); - } - } - if (ts1[i].e != ts2[i].e) { - errs++; - if (verbose) { - fprintf(stderr, "ts2[%d].e = %d; should be %d\n", - i, ts2[i].e, ts1[i].e); - } - } + for (i = 0; i < 10; i++) { + if (ts1[i].a != ts2[i].a) { + errs++; + if (verbose) { + fprintf(stderr, "ts2[%d].a = %d; should be %d\n", i, ts2[i].a, ts1[i].a); + } + } + if (ts1[i].b != ts2[i].b) { + errs++; + if (verbose) { + fprintf(stderr, "ts2[%d].b = %d; should be %d\n", i, ts2[i].b, ts1[i].b); + } + } + if (ts1[i].c != ts2[i].c) { + errs++; + if (verbose) { + fprintf(stderr, "ts2[%d].c = %d; should be %d\n", + i, (int) ts2[i].c, (int) ts1[i].c); + } + } + if (ts1[i].d != ts2[i].d) { + errs++; + if (verbose) { + fprintf(stderr, "ts2[%d].d = %d; should be %d\n", + i, (int) ts2[i].d, (int) ts1[i].d); + } + } + if (ts1[i].e != ts2[i].e) { + errs++; + if (verbose) { + fprintf(stderr, "ts2[%d].e = %d; should be %d\n", i, ts2[i].e, ts1[i].e); + } + } } return errs; @@ -275,8 +249,8 @@ int struct_of_structs_test(void) char buf[50], buf2[50], *packbuf; - MPI_Aint disps[3] = {0, 3, 0}; - int blks[3] = {2, 1, 0}; + MPI_Aint disps[3] = { 0, 3, 0 }; + int blks[3] = { 2, 1, 0 }; MPI_Datatype types[3], chartype, tiletype1, tiletype2, finaltype; /* build a contig of one char to try to keep optimizations @@ -284,11 +258,11 @@ int struct_of_structs_test(void) */ err = MPI_Type_contiguous(1, MPI_CHAR, &chartype); if (err != MPI_SUCCESS) { - errs++; - if (verbose) { - fprintf(stderr, "chartype create failed\n"); - } - return errs; + errs++; + if (verbose) { + fprintf(stderr, "chartype create failed\n"); + } + return errs; } /* build a type that we can tile a few times */ @@ -297,40 +271,40 @@ int struct_of_structs_test(void) err = MPI_Type_struct(2, blks, disps, types, &tiletype1); if (err != MPI_SUCCESS) { - errs++; - if (verbose) { - fprintf(stderr, "tiletype1 create failed\n"); - } - return errs; + errs++; + if (verbose) { + fprintf(stderr, "tiletype1 create failed\n"); + } + return errs; } /* build the same type again, again to avoid optimizations */ err = MPI_Type_struct(2, blks, disps, types, &tiletype2); if (err != MPI_SUCCESS) { - errs++; - if (verbose) { - fprintf(stderr, "tiletype2 create failed\n"); - } - return errs; + errs++; + if (verbose) { + fprintf(stderr, "tiletype2 create failed\n"); + } + return errs; } /* build a combination of those two tiletypes */ disps[0] = 0; disps[1] = 5; disps[2] = 10; - blks[0] = 1; - blks[1] = 1; - blks[2] = 1; + blks[0] = 1; + blks[1] = 1; + blks[2] = 1; types[0] = tiletype1; types[1] = tiletype2; types[2] = MPI_UB; err = MPI_Type_struct(3, blks, disps, types, &finaltype); if (err != MPI_SUCCESS) { - errs++; - if (verbose) { - fprintf(stderr, "finaltype create failed\n"); - } - return errs; + errs++; + if (verbose) { + fprintf(stderr, "finaltype create failed\n"); + } + return errs; } MPI_Type_commit(&finaltype); @@ -342,54 +316,54 @@ int struct_of_structs_test(void) packbuf = malloc(bufsize); if (packbuf == NULL) { - errs++; - if (verbose) { - fprintf(stderr, "pack buffer allocation (%d bytes) failed\n", bufsize); - } - return errs; + errs++; + if (verbose) { + fprintf(stderr, "pack buffer allocation (%d bytes) failed\n", bufsize); + } + return errs; } - for (j=0; j < 10; j++) { - for (i=0; i < 5; i++) { - if (i == 2 || i == 4) buf[5*j + i] = 0; - else buf[5*j + i] = i; - } + for (j = 0; j < 10; j++) { + for (i = 0; i < 5; i++) { + if (i == 2 || i == 4) + buf[5 * j + i] = 0; + else + buf[5 * j + i] = i; + } } position = 0; err = MPI_Pack(buf, 5, finaltype, packbuf, bufsize, &position, MPI_COMM_WORLD); if (err != MPI_SUCCESS) { - errs++; - if (verbose) { - fprintf(stderr, "pack failed\n"); - } - return errs; + errs++; + if (verbose) { + fprintf(stderr, "pack failed\n"); + } + return errs; } memset(buf2, 0, 50); position = 0; err = MPI_Unpack(packbuf, bufsize, &position, buf2, 5, finaltype, MPI_COMM_WORLD); if (err != MPI_SUCCESS) { - errs++; - if (verbose) { - fprintf(stderr, "unpack failed\n"); - } - return errs; + errs++; + if (verbose) { + fprintf(stderr, "unpack failed\n"); + } + return errs; } - for (j=0; j < 10; j++) { - for (i=0; i < 5; i++) { - if (buf[5*j + i] != buf2[5*j + i]) { - errs++; - if (verbose) { - fprintf(stderr, - "buf2[%d] = %d; should be %d\n", - 5*j + i, - (int) buf2[5*j+i], - (int) buf[5*j+i]); - } - } - } + for (j = 0; j < 10; j++) { + for (i = 0; i < 5; i++) { + if (buf[5 * j + i] != buf2[5 * j + i]) { + errs++; + if (verbose) { + fprintf(stderr, + "buf2[%d] = %d; should be %d\n", + 5 * j + i, (int) buf2[5 * j + i], (int) buf[5 * j + i]); + } + } + } } free(packbuf); @@ -400,18 +374,18 @@ int struct_of_structs_test(void) int parse_args(int argc, char **argv) { /* - int ret; - - while ((ret = getopt(argc, argv, "v")) >= 0) - { - switch (ret) { - case 'v': - verbose = 1; - break; - } - } - */ + * int ret; + * + * while ((ret = getopt(argc, argv, "v")) >= 0) + * { + * switch (ret) { + * case 'v': + * verbose = 1; + * break; + * } + * } + */ if (argc > 1 && strcmp(argv[1], "-v") == 0) - verbose = 1; + verbose = 1; return 0; }