Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
MPI_Ireduce_scatter, MPI_Ireduce_scatter_block
[simgrid.git] / teshsuite / smpi / mpich3-test / coll / nonblocking2.c
index bc8a2c2..187b288 100644 (file)
@@ -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 <stdlib.h>
 #include <stdio.h>
-/* USE_STRICT_MPI may be defined in mpitestconf.h */
-#include "mpitestconf.h"
 
 #define COUNT (10)
 #define PRIME (17)
         }                                                                 \
     } 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;
@@ -57,27 +47,23 @@ int main(int argc, char **argv)
     int *recvcounts = NULL;
     int *sdispls = NULL;
     int *rdispls = NULL;
-    int *sendtypes = NULL;
-    int *recvtypes = NULL;
-#if defined(TEST_NBC_ROUTINES)
-    int i, j;
-    char *buf_alias = NULL;
+    MPI_Datatype *sendtypes = NULL;
+    MPI_Datatype *recvtypes = 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,17 +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, 1, &op);
         for (i = 0; i < COUNT; ++i) {
             buf[i] = rank + i;
             recvbuf[i] = 0xdeadbeef;
@@ -150,9 +136,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 +152,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 +165,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 +189,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 +204,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 +230,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 +242,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 +255,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 +276,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 +284,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);
@@ -305,16 +295,16 @@ 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);
+/*             check we didn't corrupt the rest of the recvbuf */
+            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 +315,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 +331,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 +350,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 +372,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 +403,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 +417,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 +429,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 +458,3 @@ int main(int argc, char **argv)
     free(sendtypes);
     return 0;
 }
-