X-Git-Url: http://bilbo.iut-bm.univ-fcomte.fr/pub/gitweb/simgrid.git/blobdiff_plain/d0ffc37686edcc803601f76ab51fdfed5fc2f241..8bd25d18b5b13783fe7fa8e1c7b3961f2bf5e0dc:/teshsuite/smpi/mpich3-test/datatype/slice-pack-external.c diff --git a/teshsuite/smpi/mpich3-test/datatype/slice-pack-external.c b/teshsuite/smpi/mpich3-test/datatype/slice-pack-external.c index 25038fc192..87816193f9 100644 --- a/teshsuite/smpi/mpich3-test/datatype/slice-pack-external.c +++ b/teshsuite/smpi/mpich3-test/datatype/slice-pack-external.c @@ -12,6 +12,7 @@ static int verbose = 0; int a[100][100][100], e[9][9][9]; +int main(int argc, char *argv[]); /* helper functions */ static int parse_args(int argc, char **argv); @@ -23,22 +24,22 @@ int main(int argc, char *argv[]) int errs = 0; MPI_Aint sizeofint, bufsize, position; void *buffer; - + int i, j, k; - + /* Initialize a to some known values. */ for (i = 0; i < 100; i++) { - for (j = 0; j < 100; j++) { - for (k = 0; k < 100; k++) { - a[i][j][k] = i*1000000+j*1000+k; - } - } + for (j = 0; j < 100; j++) { + for (k = 0; k < 100; k++) { + a[i][j][k] = i * 1000000 + j * 1000 + k; + } + } } - + /* Initialize MPI */ MPI_Init(&argc, &argv); MPI_Type_extent(MPI_INT, &sizeofint); - + parse_args(argc, argv); /* Create data types. */ @@ -46,62 +47,52 @@ int main(int argc, char *argv[]) /* On the sheet, the slice is a[0, 2, 4, ..., 16][2-10][1-9]. */ /* Below, the slice is a[0-8][2-10][1, 3, 5, ..., 17]. */ MPI_Type_vector(9, 1, 2, MPI_INT, &oneslice); - MPI_Type_hvector(9, 1, 100*sizeofint, oneslice, &twoslice); - MPI_Type_hvector(9, 1, 100*100*sizeofint, twoslice, &threeslice); - + MPI_Type_hvector(9, 1, 100 * sizeofint, oneslice, &twoslice); + MPI_Type_hvector(9, 1, 100 * 100 * sizeofint, twoslice, &threeslice); + MPI_Type_commit(&threeslice); - + /* Pack it into a buffer. */ position = 0; /* MPI_Pack_size(1, threeslice, MPI_COMM_WORLD, &bufsize); */ - MPI_Pack_external_size((char*)"external32", 1, threeslice, &bufsize); - if (bufsize != 2916) - { - fprintf(stderr," Error on pack size! Got %d; expecting %d\n", (int) bufsize, 2916); + MPI_Pack_external_size((char *) "external32", 1, threeslice, &bufsize); + if (bufsize != 2916) { + fprintf(stderr, " Error on pack size! Got %d; expecting %d\n", (int) bufsize, 2916); } buffer = (void *) malloc((unsigned) bufsize); /* -1 to indices on sheet to compensate for Fortran --> C */ - MPI_Pack_external((char*)"external32", - &(a[0][2][1]), - 1, threeslice, - buffer, - bufsize, - &position); + MPI_Pack_external((char *) "external32", + &(a[0][2][1]), 1, threeslice, buffer, bufsize, &position); /* Unpack the buffer into e. */ position = 0; - MPI_Unpack_external((char*)"external32", - buffer, - bufsize, - &position, - e, 9*9*9, - MPI_INT); - + MPI_Unpack_external((char *) "external32", buffer, bufsize, &position, e, 9 * 9 * 9, MPI_INT); + /* Display errors, if any. */ for (i = 0; i < 9; i++) { - for (j = 0; j < 9; j++) { - for (k = 0; k < 9; k++) { - /* The truncation in integer division makes this safe. */ - if (e[i][j][k] != a[i][j+2][k*2+1]) { - errs++; - if (verbose) { - printf("Error in location %d x %d x %d: %d, should be %d.\n", - i, j, k, e[i][j][k], a[i][j+2][k*2+1]); - } - } - } - } - } - + for (j = 0; j < 9; j++) { + for (k = 0; k < 9; k++) { + /* The truncation in integer division makes this safe. */ + if (e[i][j][k] != a[i][j + 2][k * 2 + 1]) { + errs++; + if (verbose) { + printf("Error in location %d x %d x %d: %d, should be %d.\n", + i, j, k, e[i][j][k], a[i][j + 2][k * 2 + 1]); + } + } + } + } + } + /* Release memory. */ free(buffer); 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_Type_free(&oneslice); @@ -118,13 +109,12 @@ static int parse_args(int argc, char **argv) { int ret; - while ((ret = getopt(argc, argv, "v")) >= 0) - { - switch (ret) { - case 'v': - verbose = 1; - break; - } + while ((ret = getopt(argc, argv, "v")) >= 0) { + switch (ret) { + case 'v': + verbose = 1; + break; + } } return 0; }