Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
Upgrade coll mpich testlist to new mpich
[simgrid.git] / teshsuite / smpi / mpich3-test / coll / exscan.c
index 64ab9d5..4667a70 100644 (file)
 static char MTEST_Descrip[] = "Test MPI_Exscan";
 */
 
-int main( int argc, char *argv[] )
+int main(int argc, char *argv[])
 {
     int errs = 0;
     int rank, size;
-    int minsize = 2, count; 
+    int minsize = 2, count;
     int *sendbuf, *recvbuf, i;
-    MPI_Comm      comm;
+    MPI_Comm comm;
 
-    MTest_Init( &argc, &argv );
+    MTest_Init(&argc, &argv);
 
-    /* The following illustrates the use of the routines to 
-       run through a selection of communicators and datatypes.
-       Use subsets of these for tests that do not involve combinations 
-       of communicators, datatypes, and counts of datatypes */
-    while (MTestGetIntracommGeneral( &comm, minsize, 1 )) {
-       if (comm == MPI_COMM_NULL) continue;
+    /* The following illustrates the use of the routines to
+     * run through a selection of communicators and datatypes.
+     * Use subsets of these for tests that do not involve combinations
+     * of communicators, datatypes, and counts of datatypes */
+    while (MTestGetIntracommGeneral(&comm, minsize, 1)) {
+        if (comm == MPI_COMM_NULL)
+            continue;
 
-       MPI_Comm_rank( comm, &rank );
-       MPI_Comm_size( comm, &size );
-       
-       for (count = 1; count < 65000; count = count * 2) {
+        MPI_Comm_rank(comm, &rank);
+        MPI_Comm_size(comm, &size);
 
-           sendbuf = (int *)malloc( count * sizeof(int) );
-           recvbuf = (int *)malloc( count * sizeof(int) );
+        for (count = 1; count < 65000; count = count * 2) {
 
-           for (i=0; i<count; i++) {
-               sendbuf[i] = rank + i * size;
-               recvbuf[i] = -1;
-           }
-           
-           MPI_Exscan( sendbuf, recvbuf, count, MPI_INT, MPI_SUM, comm );
+            sendbuf = (int *) malloc(count * sizeof(int));
+            recvbuf = (int *) malloc(count * sizeof(int));
 
-           /* Check the results.  rank 0 has no data */
-           if (rank > 0) {
-               int result;
-               for (i=0; i<count; i++) {
-                   result = rank * i * size + ((rank) * (rank-1))/2;
-                   if (recvbuf[i] != result) {
-                       errs++;
-                       if (errs < 10) {
-                           fprintf( stderr, "Error in recvbuf[%d] = %d on %d, expected %d\n",
-                                    i, recvbuf[i], rank, result );
-                       }
-                   }
-               }
-           }
+            for (i = 0; i < count; i++) {
+                sendbuf[i] = rank + i * size;
+                recvbuf[i] = -1;
+            }
+
+            MPI_Exscan(sendbuf, recvbuf, count, MPI_INT, MPI_SUM, comm);
+
+            /* Check the results.  rank 0 has no data */
+            if (rank > 0) {
+                int result;
+                for (i = 0; i < count; i++) {
+                    result = rank * i * size + ((rank) * (rank - 1)) / 2;
+                    if (recvbuf[i] != result) {
+                        errs++;
+                        if (errs < 10) {
+                            fprintf(stderr, "Error in recvbuf[%d] = %d on %d, expected %d\n",
+                                    i, recvbuf[i], rank, result);
+                        }
+                    }
+                }
+            }
 
 #if MTEST_HAVE_MIN_MPI_VERSION(2,2)
             /* now try the MPI_IN_PLACE flavor */
-            for (i=0; i<count; i++) {
-                sendbuf[i] = -1; /* unused */
+            for (i = 0; i < count; i++) {
+                sendbuf[i] = -1;        /* unused */
                 recvbuf[i] = rank + i * size;
             }
 
-            MPI_Exscan( MPI_IN_PLACE, recvbuf, count, MPI_INT, MPI_SUM, comm );
+            MPI_Exscan(MPI_IN_PLACE, recvbuf, count, MPI_INT, MPI_SUM, comm);
 
             /* Check the results.  rank 0's data must remain unchanged */
-            for (i=0; i<count; i++) {
+            for (i = 0; i < count; i++) {
                 int result;
                 if (rank == 0)
                     result = rank + i * size;
                 else
-                    result = rank * i * size + ((rank) * (rank-1))/2;
+                    result = rank * i * size + ((rank) * (rank - 1)) / 2;
                 if (recvbuf[i] != result) {
                     errs++;
                     if (errs < 10) {
-                        fprintf( stderr, "Error in recvbuf[%d] = %d on %d, expected %d\n",
-                                 i, recvbuf[i], rank, result );
+                        fprintf(stderr, "Error in recvbuf[%d] = %d on %d, expected %d\n",
+                                i, recvbuf[i], rank, result);
                     }
                 }
             }
-
-            MPI_Comm_set_errhandler(MPI_COMM_WORLD, MPI_ERRORS_RETURN);
-            /* Make sure that we check for buffer aliasing properly */
-            if (MPI_SUCCESS == MPI_Exscan( recvbuf, recvbuf, count, MPI_INT, MPI_SUM, comm ))
-                errs++;
 #endif
 
-           free( sendbuf );
-           free( recvbuf );
-       }
-       MTestFreeComm( &comm );
+            free(sendbuf);
+            free(recvbuf);
+        }
+        MTestFreeComm(&comm);
     }
 
-    MTest_Finalize( errs );
+    MTest_Finalize(errs);
     MPI_Finalize();
     return 0;
 }