X-Git-Url: http://info.iut-bm.univ-fcomte.fr/pub/gitweb/simgrid.git/blobdiff_plain/d0ffc37686edcc803601f76ab51fdfed5fc2f241..a9c9083479c7a98cb890faad9d2f40e9a64ccd83:/teshsuite/smpi/mpich3-test/coll/nonblocking2.c diff --git a/teshsuite/smpi/mpich3-test/coll/nonblocking2.c b/teshsuite/smpi/mpich3-test/coll/nonblocking2.c index bc8a2c270a..634077bdd7 100644 --- a/teshsuite/smpi/mpich3-test/coll/nonblocking2.c +++ b/teshsuite/smpi/mpich3-test/coll/nonblocking2.c @@ -5,7 +5,7 @@ */ /* A basic test of all 17 nonblocking collective operations specified by the - * draft MPI-3 standard. It only exercises the intracommunicator functionality, + * MPI-3 standard. It only exercises the intracommunicator functionality, * does not use MPI_IN_PLACE, and only transmits/receives simple integer types * with relatively small counts. It does check a few fancier issues, such as * ensuring that "premature user releases" of MPI_Op and MPI_Datatype objects @@ -14,8 +14,6 @@ #include "mpi.h" #include #include -/* USE_STRICT_MPI may be defined in mpitestconf.h */ -#include "mpitestconf.h" #define COUNT (10) #define PRIME (17) @@ -28,16 +26,7 @@ } \ } while (0) -/* Since MPICH is currently the only NBC implementation in existence, just use - * this quick-and-dirty #ifdef to decide whether to test the nonblocking - * collectives. Eventually we can add a configure option or configure test, or - * the MPI-3 standard will be released and these can be gated on a MPI_VERSION - * check */ -#if !defined(USE_STRICT_MPI) && defined(MPICH) -#define TEST_NBC_ROUTINES 1 -#endif - -static void sum_fn(void *invec, void *inoutvec, int *len, MPI_Datatype *datatype) +static void sum_fn(void *invec, void *inoutvec, int *len, MPI_Datatype * datatype) { int i; int *in = invec; @@ -50,6 +39,7 @@ static void sum_fn(void *invec, void *inoutvec, int *len, MPI_Datatype *datatype int main(int argc, char **argv) { + int i, j; int rank, size; int *buf = NULL; int *recvbuf = NULL; @@ -59,25 +49,21 @@ int main(int argc, char **argv) int *rdispls = NULL; int *sendtypes = NULL; int *recvtypes = NULL; -#if defined(TEST_NBC_ROUTINES) - int i, j; - char *buf_alias = NULL; + signed char *buf_alias = NULL; MPI_Request req; -#endif MPI_Init(&argc, &argv); MPI_Comm_rank(MPI_COMM_WORLD, &rank); MPI_Comm_size(MPI_COMM_WORLD, &size); -#if defined(TEST_NBC_ROUTINES) - buf = malloc(COUNT*size*sizeof(int)); - recvbuf = malloc(COUNT*size*sizeof(int)); - sendcounts = malloc(size*sizeof(int)); - recvcounts = malloc(size*sizeof(int)); - sdispls = malloc(size*sizeof(int)); - rdispls = malloc(size*sizeof(int)); - sendtypes = malloc(size*sizeof(MPI_Datatype)); - recvtypes = malloc(size*sizeof(MPI_Datatype)); + buf = malloc(COUNT * size * sizeof(int)); + recvbuf = malloc(COUNT * size * sizeof(int)); + sendcounts = malloc(size * sizeof(int)); + recvcounts = malloc(size * sizeof(int)); + sdispls = malloc(size * sizeof(int)); + rdispls = malloc(size * sizeof(int)); + sendtypes = malloc(size * sizeof(MPI_Datatype)); + recvtypes = malloc(size * sizeof(MPI_Datatype)); /* MPI_Ibcast */ for (i = 0; i < COUNT; ++i) { @@ -98,8 +84,8 @@ int main(int argc, char **argv) } /* MPI_Ibcast (again, but designed to stress scatter/allgather impls) */ - buf_alias = (char *)buf; - my_assert(COUNT*size*sizeof(int) > PRIME); /* sanity */ + buf_alias = (signed char *) buf; + my_assert(COUNT * size * sizeof(int) > PRIME); /* sanity */ for (i = 0; i < PRIME; ++i) { if (rank == 0) buf_alias[i] = i; @@ -109,7 +95,7 @@ int main(int argc, char **argv) for (i = PRIME; i < COUNT * size * sizeof(int); ++i) { buf_alias[i] = 0xbf; } - MPI_Ibcast(buf, PRIME, MPI_SIGNED_CHAR, 0, MPI_COMM_WORLD, &req); + MPI_Ibcast(buf_alias, PRIME, MPI_SIGNED_CHAR, 0, MPI_COMM_WORLD, &req); MPI_Wait(&req, MPI_STATUS_IGNORE); for (i = 0; i < PRIME; ++i) { if (buf_alias[i] != i) @@ -130,16 +116,17 @@ int main(int argc, char **argv) MPI_Wait(&req, MPI_STATUS_IGNORE); if (rank == 0) { for (i = 0; i < COUNT; ++i) { - if (recvbuf[i] != ((size * (size-1) / 2) + (i * size))) - printf("got recvbuf[%d]=%d, expected %d\n", i, recvbuf[i], ((size * (size-1) / 2) + (i * size))); - my_assert(recvbuf[i] == ((size * (size-1) / 2) + (i * size))); + if (recvbuf[i] != ((size * (size - 1) / 2) + (i * size))) + printf("got recvbuf[%d]=%d, expected %d\n", i, recvbuf[i], + ((size * (size - 1) / 2) + (i * size))); + my_assert(recvbuf[i] == ((size * (size - 1) / 2) + (i * size))); } } /* same again, use a user op and free it before the wait */ { MPI_Op op = MPI_OP_NULL; - MPI_Op_create(sum_fn, /*commute=*/1, &op); + MPI_Op_create(sum_fn, /*commute= */ 1, &op); for (i = 0; i < COUNT; ++i) { buf[i] = rank + i; @@ -150,9 +137,10 @@ int main(int argc, char **argv) MPI_Wait(&req, MPI_STATUS_IGNORE); if (rank == 0) { for (i = 0; i < COUNT; ++i) { - if (recvbuf[i] != ((size * (size-1) / 2) + (i * size))) - printf("got recvbuf[%d]=%d, expected %d\n", i, recvbuf[i], ((size * (size-1) / 2) + (i * size))); - my_assert(recvbuf[i] == ((size * (size-1) / 2) + (i * size))); + if (recvbuf[i] != ((size * (size - 1) / 2) + (i * size))) + printf("got recvbuf[%d]=%d, expected %d\n", i, recvbuf[i], + ((size * (size - 1) / 2) + (i * size))); + my_assert(recvbuf[i] == ((size * (size - 1) / 2) + (i * size))); } } } @@ -165,9 +153,10 @@ int main(int argc, char **argv) MPI_Iallreduce(buf, recvbuf, COUNT, MPI_INT, MPI_SUM, MPI_COMM_WORLD, &req); MPI_Wait(&req, MPI_STATUS_IGNORE); for (i = 0; i < COUNT; ++i) { - if (recvbuf[i] != ((size * (size-1) / 2) + (i * size))) - printf("got recvbuf[%d]=%d, expected %d\n", i, recvbuf[i], ((size * (size-1) / 2) + (i * size))); - my_assert(recvbuf[i] == ((size * (size-1) / 2) + (i * size))); + if (recvbuf[i] != ((size * (size - 1) / 2) + (i * size))) + printf("got recvbuf[%d]=%d, expected %d\n", i, recvbuf[i], + ((size * (size - 1) / 2) + (i * size))); + my_assert(recvbuf[i] == ((size * (size - 1) / 2) + (i * size))); } /* MPI_Ialltoallv (a weak test, neither irregular nor sparse) */ @@ -177,21 +166,22 @@ int main(int argc, char **argv) sdispls[i] = COUNT * i; rdispls[i] = COUNT * i; for (j = 0; j < COUNT; ++j) { - buf[i*COUNT+j] = rank + (i * j); - recvbuf[i*COUNT+j] = 0xdeadbeef; + buf[i * COUNT + j] = rank + (i * j); + recvbuf[i * COUNT + j] = 0xdeadbeef; } } - MPI_Ialltoallv(buf, sendcounts, sdispls, MPI_INT, recvbuf, recvcounts, rdispls, MPI_INT, MPI_COMM_WORLD, &req); + MPI_Ialltoallv(buf, sendcounts, sdispls, MPI_INT, recvbuf, recvcounts, rdispls, MPI_INT, + MPI_COMM_WORLD, &req); MPI_Wait(&req, MPI_STATUS_IGNORE); for (i = 0; i < size; ++i) { for (j = 0; j < COUNT; ++j) { - /*printf("recvbuf[%d*COUNT+%d]=%d, expecting %d\n", i, j, recvbuf[i*COUNT+j], (i + (rank * j)));*/ - my_assert(recvbuf[i*COUNT+j] == (i + (rank * j))); + /*printf("recvbuf[%d*COUNT+%d]=%d, expecting %d\n", i, j, recvbuf[i*COUNT+j], (i + (rank * j))); */ + my_assert(recvbuf[i * COUNT + j] == (i + (rank * j))); } } /* MPI_Igather */ - for (i = 0; i < size*COUNT; ++i) { + for (i = 0; i < size * COUNT; ++i) { buf[i] = rank + i; recvbuf[i] = 0xdeadbeef; } @@ -200,12 +190,12 @@ int main(int argc, char **argv) if (rank == 0) { for (i = 0; i < size; ++i) { for (j = 0; j < COUNT; ++j) { - my_assert(recvbuf[i*COUNT+j] == i + j); + my_assert(recvbuf[i * COUNT + j] == i + j); } } } else { - for (i = 0; i < size*COUNT; ++i) { + for (i = 0; i < size * COUNT; ++i) { my_assert(recvbuf[i] == 0xdeadbeef); } } @@ -215,23 +205,23 @@ int main(int argc, char **argv) MPI_Datatype type = MPI_DATATYPE_NULL; MPI_Type_dup(MPI_INT, &type); - for (i = 0; i < size*COUNT; ++i) { + for (i = 0; i < size * COUNT; ++i) { buf[i] = rank + i; recvbuf[i] = 0xdeadbeef; } MPI_Igather(buf, COUNT, MPI_INT, recvbuf, COUNT, type, 0, MPI_COMM_WORLD, &req); - MPI_Type_free(&type); /* should cause implementations that don't refcount - correctly to blow up or hang in the wait */ + MPI_Type_free(&type); /* should cause implementations that don't refcount + * correctly to blow up or hang in the wait */ MPI_Wait(&req, MPI_STATUS_IGNORE); if (rank == 0) { for (i = 0; i < size; ++i) { for (j = 0; j < COUNT; ++j) { - my_assert(recvbuf[i*COUNT+j] == i + j); + my_assert(recvbuf[i * COUNT + j] == i + j); } } } else { - for (i = 0; i < size*COUNT; ++i) { + for (i = 0; i < size * COUNT; ++i) { my_assert(recvbuf[i] == 0xdeadbeef); } } @@ -241,10 +231,10 @@ int main(int argc, char **argv) for (i = 0; i < size; ++i) { for (j = 0; j < COUNT; ++j) { if (rank == 0) - buf[i*COUNT+j] = i + j; + buf[i * COUNT + j] = i + j; else - buf[i*COUNT+j] = 0xdeadbeef; - recvbuf[i*COUNT+j] = 0xdeadbeef; + buf[i * COUNT + j] = 0xdeadbeef; + recvbuf[i * COUNT + j] = 0xdeadbeef; } } MPI_Iscatter(buf, COUNT, MPI_INT, recvbuf, COUNT, MPI_INT, 0, MPI_COMM_WORLD, &req); @@ -253,7 +243,7 @@ int main(int argc, char **argv) my_assert(recvbuf[j] == rank + j); } if (rank != 0) { - for (i = 0; i < size*COUNT; ++i) { + for (i = 0; i < size * COUNT; ++i) { /* check we didn't corrupt the sendbuf somehow */ my_assert(buf[i] == 0xdeadbeef); } @@ -266,19 +256,20 @@ int main(int argc, char **argv) sdispls[i] = i * COUNT; for (j = 0; j < COUNT; ++j) { if (rank == 0) - buf[i*COUNT+j] = i + j; + buf[i * COUNT + j] = i + j; else - buf[i*COUNT+j] = 0xdeadbeef; - recvbuf[i*COUNT+j] = 0xdeadbeef; + buf[i * COUNT + j] = 0xdeadbeef; + recvbuf[i * COUNT + j] = 0xdeadbeef; } } - MPI_Iscatterv(buf, sendcounts, sdispls, MPI_INT, recvbuf, COUNT, MPI_INT, 0, MPI_COMM_WORLD, &req); + MPI_Iscatterv(buf, sendcounts, sdispls, MPI_INT, recvbuf, COUNT, MPI_INT, 0, MPI_COMM_WORLD, + &req); MPI_Wait(&req, MPI_STATUS_IGNORE); for (j = 0; j < COUNT; ++j) { my_assert(recvbuf[j] == rank + j); } if (rank != 0) { - for (i = 0; i < size*COUNT; ++i) { + for (i = 0; i < size * COUNT; ++i) { /* check we didn't corrupt the sendbuf somehow */ my_assert(buf[i] == 0xdeadbeef); } @@ -286,7 +277,7 @@ int main(int argc, char **argv) for (i = 1; i < size; ++i) { for (j = 0; j < COUNT; ++j) { /* check we didn't corrupt the rest of the recvbuf */ - my_assert(recvbuf[i*COUNT+j] == 0xdeadbeef); + my_assert(recvbuf[i * COUNT + j] == 0xdeadbeef); } } @@ -294,8 +285,8 @@ int main(int argc, char **argv) for (i = 0; i < size; ++i) { recvcounts[i] = COUNT; for (j = 0; j < COUNT; ++j) { - buf[i*COUNT+j] = rank + i; - recvbuf[i*COUNT+j] = 0xdeadbeef; + buf[i * COUNT + j] = rank + i; + recvbuf[i * COUNT + j] = 0xdeadbeef; } } MPI_Ireduce_scatter(buf, recvbuf, recvcounts, MPI_INT, MPI_SUM, MPI_COMM_WORLD, &req); @@ -306,15 +297,15 @@ int main(int argc, char **argv) for (i = 1; i < size; ++i) { for (j = 0; j < COUNT; ++j) { /* check we didn't corrupt the rest of the recvbuf */ - my_assert(recvbuf[i*COUNT+j] == 0xdeadbeef); + my_assert(recvbuf[i * COUNT + j] == 0xdeadbeef); } } /* MPI_Ireduce_scatter_block */ for (i = 0; i < size; ++i) { for (j = 0; j < COUNT; ++j) { - buf[i*COUNT+j] = rank + i; - recvbuf[i*COUNT+j] = 0xdeadbeef; + buf[i * COUNT + j] = rank + i; + recvbuf[i * COUNT + j] = 0xdeadbeef; } } MPI_Ireduce_scatter_block(buf, recvbuf, COUNT, MPI_INT, MPI_SUM, MPI_COMM_WORLD, &req); @@ -325,12 +316,12 @@ int main(int argc, char **argv) for (i = 1; i < size; ++i) { for (j = 0; j < COUNT; ++j) { /* check we didn't corrupt the rest of the recvbuf */ - my_assert(recvbuf[i*COUNT+j] == 0xdeadbeef); + my_assert(recvbuf[i * COUNT + j] == 0xdeadbeef); } } /* MPI_Igatherv */ - for (i = 0; i < size*COUNT; ++i) { + for (i = 0; i < size * COUNT; ++i) { buf[i] = 0xdeadbeef; recvbuf[i] = 0xdeadbeef; } @@ -341,17 +332,18 @@ int main(int argc, char **argv) recvcounts[i] = COUNT; rdispls[i] = i * COUNT; } - MPI_Igatherv(buf, COUNT, MPI_INT, recvbuf, recvcounts, rdispls, MPI_INT, 0, MPI_COMM_WORLD, &req); + MPI_Igatherv(buf, COUNT, MPI_INT, recvbuf, recvcounts, rdispls, MPI_INT, 0, MPI_COMM_WORLD, + &req); MPI_Wait(&req, MPI_STATUS_IGNORE); if (rank == 0) { for (i = 0; i < size; ++i) { for (j = 0; j < COUNT; ++j) { - my_assert(recvbuf[i*COUNT+j] == i + j); + my_assert(recvbuf[i * COUNT + j] == i + j); } } } else { - for (i = 0; i < size*COUNT; ++i) { + for (i = 0; i < size * COUNT; ++i) { my_assert(recvbuf[i] == 0xdeadbeef); } } @@ -359,21 +351,21 @@ int main(int argc, char **argv) /* MPI_Ialltoall */ for (i = 0; i < size; ++i) { for (j = 0; j < COUNT; ++j) { - buf[i*COUNT+j] = rank + (i * j); - recvbuf[i*COUNT+j] = 0xdeadbeef; + buf[i * COUNT + j] = rank + (i * j); + recvbuf[i * COUNT + j] = 0xdeadbeef; } } MPI_Ialltoall(buf, COUNT, MPI_INT, recvbuf, COUNT, MPI_INT, MPI_COMM_WORLD, &req); MPI_Wait(&req, MPI_STATUS_IGNORE); for (i = 0; i < size; ++i) { for (j = 0; j < COUNT; ++j) { - /*printf("recvbuf[%d*COUNT+%d]=%d, expecting %d\n", i, j, recvbuf[i*COUNT+j], (i + (i * j)));*/ - my_assert(recvbuf[i*COUNT+j] == (i + (rank * j))); + /*printf("recvbuf[%d*COUNT+%d]=%d, expecting %d\n", i, j, recvbuf[i*COUNT+j], (i + (i * j))); */ + my_assert(recvbuf[i * COUNT + j] == (i + (rank * j))); } } /* MPI_Iallgather */ - for (i = 0; i < size*COUNT; ++i) { + for (i = 0; i < size * COUNT; ++i) { buf[i] = rank + i; recvbuf[i] = 0xdeadbeef; } @@ -381,25 +373,26 @@ int main(int argc, char **argv) MPI_Wait(&req, MPI_STATUS_IGNORE); for (i = 0; i < size; ++i) { for (j = 0; j < COUNT; ++j) { - my_assert(recvbuf[i*COUNT+j] == i + j); + my_assert(recvbuf[i * COUNT + j] == i + j); } } /* MPI_Iallgatherv */ for (i = 0; i < size; ++i) { for (j = 0; j < COUNT; ++j) { - recvbuf[i*COUNT+j] = 0xdeadbeef; + recvbuf[i * COUNT + j] = 0xdeadbeef; } recvcounts[i] = COUNT; rdispls[i] = i * COUNT; } for (i = 0; i < COUNT; ++i) buf[i] = rank + i; - MPI_Iallgatherv(buf, COUNT, MPI_INT, recvbuf, recvcounts, rdispls, MPI_INT, MPI_COMM_WORLD, &req); + MPI_Iallgatherv(buf, COUNT, MPI_INT, recvbuf, recvcounts, rdispls, MPI_INT, MPI_COMM_WORLD, + &req); MPI_Wait(&req, MPI_STATUS_IGNORE); for (i = 0; i < size; ++i) { for (j = 0; j < COUNT; ++j) { - my_assert(recvbuf[i*COUNT+j] == i + j); + my_assert(recvbuf[i * COUNT + j] == i + j); } } @@ -411,7 +404,7 @@ int main(int argc, char **argv) MPI_Iscan(buf, recvbuf, COUNT, MPI_INT, MPI_SUM, MPI_COMM_WORLD, &req); MPI_Wait(&req, MPI_STATUS_IGNORE); for (i = 0; i < COUNT; ++i) { - my_assert(recvbuf[i] == ((rank * (rank+1) / 2) + (i * (rank + 1)))); + my_assert(recvbuf[i] == ((rank * (rank + 1) / 2) + (i * (rank + 1)))); } /* MPI_Iexscan */ @@ -425,7 +418,7 @@ int main(int argc, char **argv) if (rank == 0) my_assert(recvbuf[i] == 0xdeadbeef); else - my_assert(recvbuf[i] == ((rank * (rank+1) / 2) + (i * (rank + 1)) - (rank + i))); + my_assert(recvbuf[i] == ((rank * (rank + 1) / 2) + (i * (rank + 1)) - (rank + i))); } /* MPI_Ialltoallw (a weak test, neither irregular nor sparse) */ @@ -437,21 +430,20 @@ int main(int argc, char **argv) sendtypes[i] = MPI_INT; recvtypes[i] = MPI_INT; for (j = 0; j < COUNT; ++j) { - buf[i*COUNT+j] = rank + (i * j); - recvbuf[i*COUNT+j] = 0xdeadbeef; + buf[i * COUNT + j] = rank + (i * j); + recvbuf[i * COUNT + j] = 0xdeadbeef; } } - MPI_Ialltoallw(buf, sendcounts, sdispls, sendtypes, recvbuf, recvcounts, rdispls, recvtypes, MPI_COMM_WORLD, &req); + MPI_Ialltoallw(buf, sendcounts, sdispls, sendtypes, recvbuf, recvcounts, rdispls, recvtypes, + MPI_COMM_WORLD, &req); MPI_Wait(&req, MPI_STATUS_IGNORE); for (i = 0; i < size; ++i) { for (j = 0; j < COUNT; ++j) { - /*printf("recvbuf[%d*COUNT+%d]=%d, expecting %d\n", i, j, recvbuf[i*COUNT+j], (i + (rank * j)));*/ - my_assert(recvbuf[i*COUNT+j] == (i + (rank * j))); + /*printf("recvbuf[%d*COUNT+%d]=%d, expecting %d\n", i, j, recvbuf[i*COUNT+j], (i + (rank * j))); */ + my_assert(recvbuf[i * COUNT + j] == (i + (rank * j))); } } -#endif /* defined(TEST_NBC_ROUTINES) */ - if (rank == 0) printf(" No Errors\n"); @@ -467,4 +459,3 @@ int main(int argc, char **argv) free(sendtypes); return 0; } -