Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
Fix dist
[simgrid.git] / teshsuite / smpi / mpich3-test / coll / icalltoallw.c
index 2b8252e..7bf1544 100644 (file)
@@ -7,6 +7,7 @@
 #include "mpitest.h"
 #include <stdlib.h>
 #include <stdio.h>
 #include "mpitest.h"
 #include <stdlib.h>
 #include <stdio.h>
+#include "mpicolltest.h"
 
 /*
   This program tests MPI_Alltoallw by having processor i send different
 
 /*
   This program tests MPI_Alltoallw by having processor i send different
 
   Because there are separate send and receive types to alltoallw,
   there need to be tests to rearrange data on the fly.  Not done yet.
 
   Because there are separate send and receive types to alltoallw,
   there need to be tests to rearrange data on the fly.  Not done yet.
-  
+
   The first test sends i items to processor i from all processors.
 
   Currently, the test uses only MPI_INT; this is adequate for testing systems
   that use point-to-point operations
  */
 
   The first test sends i items to processor i from all processors.
 
   Currently, the test uses only MPI_INT; this is adequate for testing systems
   that use point-to-point operations
  */
 
-int main( int argc, char **argv )
+int main(int argc, char **argv)
 {
 
     MPI_Comm comm;
 {
 
     MPI_Comm comm;
-    int      *sbuf, *rbuf;
-    int      rank, size, lsize, asize;
-    int      *sendcounts, *recvcounts, *rdispls, *sdispls;
-    int      i, j, *p, err;
+    int *sbuf, *rbuf;
+    int rank, size, lsize, asize;
+    int *sendcounts, *recvcounts, *rdispls, *sdispls;
+    int i, j, *p, err;
     MPI_Datatype *sendtypes, *recvtypes;
     MPI_Datatype *sendtypes, *recvtypes;
-    int      leftGroup;
+    int leftGroup;
 
 
-    MTest_Init( &argc, &argv );
+    MTest_Init(&argc, &argv);
     err = 0;
 
     err = 0;
 
-    while (MTestGetIntercomm( &comm, &leftGroup, 4 )) {
-      if (comm == MPI_COMM_NULL) continue;
+    while (MTestGetIntercomm(&comm, &leftGroup, 4)) {
+        if (comm == MPI_COMM_NULL)
+            continue;
+
+        /* Create the buffer */
+        MPI_Comm_size(comm, &lsize);
+        MPI_Comm_remote_size(comm, &size);
+        asize = (lsize > size) ? lsize : size;
+        MPI_Comm_rank(comm, &rank);
+        sbuf = (int *) malloc(size * size * sizeof(int));
+        rbuf = (int *) malloc(asize * asize * sizeof(int));
+        if (!sbuf || !rbuf) {
+            fprintf(stderr, "Could not allocated buffers!\n");
+            MPI_Abort(comm, 1);
+        }
+
+        /* Load up the buffers */
+        for (i = 0; i < size * size; i++) {
+            sbuf[i] = i + 100 * rank;
+            rbuf[i] = -i;
+        }
 
 
-      /* Create the buffer */
-      MPI_Comm_size( comm, &lsize );
-      MPI_Comm_remote_size( comm, &size );
-      asize = (lsize > size) ? lsize : size;
-      MPI_Comm_rank( comm, &rank );
-      sbuf = (int *)malloc( size * size * sizeof(int) );
-      rbuf = (int *)malloc( asize * asize * sizeof(int) );
-      if (!sbuf || !rbuf) {
-       fprintf( stderr, "Could not allocated buffers!\n" );
-       MPI_Abort( comm, 1 );
-      }
-      
-      /* Load up the buffers */
-      for (i=0; i<size*size; i++) {
-       sbuf[i] = i + 100*rank;
-       rbuf[i] = -i;
-      }
+        /* Create and load the arguments to alltoallv */
+        sendcounts = (int *) malloc(size * sizeof(int));
+        recvcounts = (int *) malloc(size * sizeof(int));
+        rdispls = (int *) malloc(size * sizeof(int));
+        sdispls = (int *) malloc(size * sizeof(int));
+        sendtypes = (MPI_Datatype *) malloc(size * sizeof(MPI_Datatype));
+        recvtypes = (MPI_Datatype *) malloc(size * sizeof(MPI_Datatype));
+        if (!sendcounts || !recvcounts || !rdispls || !sdispls || !sendtypes || !recvtypes) {
+            fprintf(stderr, "Could not allocate arg items!\n");
+            MPI_Abort(comm, 1);
+        }
+        /* Note that process 0 sends no data (sendcounts[0] = 0) */
+        for (i = 0; i < size; i++) {
+            sendcounts[i] = i;
+            sdispls[i] = (((i + 1) * (i)) / 2) * sizeof(int);
+            sendtypes[i] = MPI_INT;
+            recvcounts[i] = rank;
+            rdispls[i] = i * rank * sizeof(int);
+            recvtypes[i] = MPI_INT;
+        }
+        MTest_Alltoallw(sbuf, sendcounts, sdispls, sendtypes,
+                        rbuf, recvcounts, rdispls, recvtypes, comm);
 
 
-      /* Create and load the arguments to alltoallv */
-      sendcounts = (int *)malloc( size * sizeof(int) );
-      recvcounts = (int *)malloc( size * sizeof(int) );
-      rdispls    = (int *)malloc( size * sizeof(int) );
-      sdispls    = (int *)malloc( size * sizeof(int) );
-      sendtypes  = (MPI_Datatype *)malloc( size * sizeof(MPI_Datatype) );
-      recvtypes  = (MPI_Datatype *)malloc( size * sizeof(MPI_Datatype) );
-      if (!sendcounts || !recvcounts || !rdispls || !sdispls || !sendtypes || !recvtypes) {
-       fprintf( stderr, "Could not allocate arg items!\n" );
-       MPI_Abort( comm, 1 );
-      }
-      /* Note that process 0 sends no data (sendcounts[0] = 0) */
-      for (i=0; i<size; i++) {
-       sendcounts[i] = i;
-       sdispls[i]    = (((i+1) * (i))/2) * sizeof(int);
-        sendtypes[i]  = MPI_INT;
-       recvcounts[i] = rank;
-       rdispls[i]    = i * rank * sizeof(int);
-       recvtypes[i]  = MPI_INT;
-      }
-      MPI_Alltoallw( sbuf, sendcounts, sdispls, sendtypes,
-                    rbuf, recvcounts, rdispls, recvtypes, comm );
-      
-      /* Check rbuf */
-      for (i=0; i<size; i++) {
-       p = rbuf + rdispls[i]/sizeof(int);
-       for (j=0; j<rank; j++) {
-         if (p[j] != i * 100 + (rank*(rank+1))/2 + j) {
-           fprintf( stderr, "[%d] got %d expected %d for %dth\n",
-                    rank, p[j],(i*(i+1))/2 + j, j );
-           err++;
-         }
-       }
-      }
+        /* Check rbuf */
+        for (i = 0; i < size; i++) {
+            p = rbuf + rdispls[i] / sizeof(int);
+            for (j = 0; j < rank; j++) {
+                if (p[j] != i * 100 + (rank * (rank + 1)) / 2 + j) {
+                    fprintf(stderr, "[%d] got %d expected %d for %dth\n",
+                            rank, p[j], (i * (i + 1)) / 2 + j, j);
+                    err++;
+                }
+            }
+        }
 
 
-      free(sendtypes);
-      free(recvtypes);
-      free( sdispls );
-      free( rdispls );
-      free( recvcounts );
-      free( sendcounts );
-      free( rbuf );
-      free( sbuf );
-      MTestFreeComm( &comm );
+        free(sendtypes);
+        free(recvtypes);
+        free(sdispls);
+        free(rdispls);
+        free(recvcounts);
+        free(sendcounts);
+        free(rbuf);
+        free(sbuf);
+        MTestFreeComm(&comm);
     }
 
     }
 
-    MTest_Finalize( err );
+    MTest_Finalize(err);
     MPI_Finalize();
     return 0;
 }
     MPI_Finalize();
     return 0;
 }