Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
manually privatize allred test, to have it work on non-mmap systems also
authorAugustin Degomme <augustin.degomme@imag.fr>
Thu, 24 Jul 2014 08:41:00 +0000 (10:41 +0200)
committerAugustin Degomme <augustin.degomme@imag.fr>
Thu, 24 Jul 2014 13:23:03 +0000 (15:23 +0200)
teshsuite/smpi/mpich3-test/coll/allred.c

index e9becde..bf13e8a 100644 (file)
@@ -10,6 +10,7 @@
 
 #include "mpi.h"
 #include "mpitest.h"
 
 #include "mpi.h"
 #include "mpitest.h"
+#include "smpi_cocci.h"
 #include <stdio.h>
 #include <stdlib.h>
 #include <string.h>
 #include <stdio.h>
 #include <stdlib.h>
 #include <string.h>
 #include <stdint.h>
 #endif
 
 #include <stdint.h>
 #endif
 
-int count, size, rank;
-int cerrcnt;
+SMPI_VARINIT_GLOBAL(count, int);
+SMPI_VARINIT_GLOBAL(size, int);
+SMPI_VARINIT_GLOBAL(rank, int);
+SMPI_VARINIT_GLOBAL(cerrcnt, int);
 
 struct int_test { int a; int b; };
 struct long_test { long a; int b; };
 
 struct int_test { int a; int b; };
 struct long_test { long a; int b; };
@@ -44,35 +47,35 @@ struct double_test { double a; int b; };
 /* calloc to avoid spurious valgrind warnings when "type" has padding bytes */
 #define DECL_MALLOC_IN_OUT_SOL(type)                 \
     type *in, *out, *sol;                            \
 /* calloc to avoid spurious valgrind warnings when "type" has padding bytes */
 #define DECL_MALLOC_IN_OUT_SOL(type)                 \
     type *in, *out, *sol;                            \
-    in  = (type *) calloc(count, sizeof(type));      \
-    out = (type *) calloc(count, sizeof(type));      \
-    sol = (type *) calloc(count, sizeof(type));
+    in  = (type *) calloc(SMPI_VARGET_GLOBAL(count), sizeof(type));      \
+    out = (type *) calloc(SMPI_VARGET_GLOBAL(count), sizeof(type));      \
+    sol = (type *) calloc(SMPI_VARGET_GLOBAL(count), sizeof(type));
 
 #define SET_INDEX_CONST(arr, val)               \
     {                                           \
         int i;                                  \
 
 #define SET_INDEX_CONST(arr, val)               \
     {                                           \
         int i;                                  \
-        for (i = 0; i < count; i++)             \
+        for (i = 0; i < SMPI_VARGET_GLOBAL(count); i++)             \
             arr[i] = val;                       \
     }
 
 #define SET_INDEX_SUM(arr, val)                 \
     {                                           \
         int i;                                  \
             arr[i] = val;                       \
     }
 
 #define SET_INDEX_SUM(arr, val)                 \
     {                                           \
         int i;                                  \
-        for (i = 0; i < count; i++)             \
+        for (i = 0; i < SMPI_VARGET_GLOBAL(count); i++)             \
             arr[i] = i + val;                   \
     }
 
 #define SET_INDEX_FACTOR(arr, val)              \
     {                                           \
         int i;                                  \
             arr[i] = i + val;                   \
     }
 
 #define SET_INDEX_FACTOR(arr, val)              \
     {                                           \
         int i;                                  \
-        for (i = 0; i < count; i++)             \
+        for (i = 0; i < SMPI_VARGET_GLOBAL(count); i++)             \
             arr[i] = i * (val);                 \
     }
 
 #define SET_INDEX_POWER(arr, val)               \
     {                                           \
         int i, j;                               \
             arr[i] = i * (val);                 \
     }
 
 #define SET_INDEX_POWER(arr, val)               \
     {                                           \
         int i, j;                               \
-        for (i = 0; i < count; i++) {           \
+        for (i = 0; i < SMPI_VARGET_GLOBAL(count); i++) {           \
             (arr)[i] = 1;                       \
             for (j = 0; j < (val); j++)         \
                 arr[i] *= i;                    \
             (arr)[i] = 1;                       \
             for (j = 0; j < (val); j++)         \
                 arr[i] *= i;                    \
@@ -86,7 +89,7 @@ struct double_test { double a; int b; };
         if (lerrcnt) {                                                  \
             MPI_Type_get_name(mpi_type, name, &len);                    \
             fprintf(stderr, "(%d) Error for type %s and op %s\n",       \
         if (lerrcnt) {                                                  \
             MPI_Type_get_name(mpi_type, name, &len);                    \
             fprintf(stderr, "(%d) Error for type %s and op %s\n",       \
-                    rank, name, mpi_op2str(mpi_op));                    \
+                    SMPI_VARGET_GLOBAL(rank), name, mpi_op2str(mpi_op));                    \
         }                                                               \
         free(in); free(out); free(sol);                                 \
     } while(0)
         }                                                               \
         free(in); free(out); free(sol);                                 \
     } while(0)
@@ -100,12 +103,12 @@ struct double_test { double a; int b; };
 #define ALLREDUCE_AND_FREE(mpi_type, mpi_op, in, out, sol)              \
     {                                                                   \
         int i, rc, lerrcnt = 0;                                                \
 #define ALLREDUCE_AND_FREE(mpi_type, mpi_op, in, out, sol)              \
     {                                                                   \
         int i, rc, lerrcnt = 0;                                                \
-        rc = MPI_Allreduce(in, out, count, mpi_type, mpi_op, MPI_COMM_WORLD); \
-       if (rc) { lerrcnt++; cerrcnt++; MTestPrintError( rc ); }        \
+        rc = MPI_Allreduce(in, out, SMPI_VARGET_GLOBAL(count), mpi_type, mpi_op, MPI_COMM_WORLD); \
+       if (rc) { lerrcnt++; SMPI_VARGET_GLOBAL(cerrcnt)++; MTestPrintError( rc ); }        \
        else {                                                          \
        else {                                                          \
-          for (i = 0; i < count; i++) {                                   \
+          for (i = 0; i < SMPI_VARGET_GLOBAL(count); i++) {                                   \
               if (out[i] != sol[i]) {                                     \
               if (out[i] != sol[i]) {                                     \
-                  cerrcnt++;                                              \
+                  SMPI_VARGET_GLOBAL(cerrcnt)++;                                              \
                   lerrcnt++;                                              \
               }                                                           \
           }                                                              \
                   lerrcnt++;                                              \
               }                                                           \
           }                                                              \
@@ -116,12 +119,12 @@ struct double_test { double a; int b; };
 #define STRUCT_ALLREDUCE_AND_FREE(mpi_type, mpi_op, in, out, sol)       \
     {                                                                   \
         int i, rc, lerrcnt = 0;                                                \
 #define STRUCT_ALLREDUCE_AND_FREE(mpi_type, mpi_op, in, out, sol)       \
     {                                                                   \
         int i, rc, lerrcnt = 0;                                                \
-        rc = MPI_Allreduce(in, out, count, mpi_type, mpi_op, MPI_COMM_WORLD); \
-       if (rc) { lerrcnt++; cerrcnt++; MTestPrintError( rc ); }        \
+        rc = MPI_Allreduce(in, out, SMPI_VARGET_GLOBAL(count), mpi_type, mpi_op, MPI_COMM_WORLD); \
+       if (rc) { lerrcnt++; SMPI_VARGET_GLOBAL(cerrcnt)++; MTestPrintError( rc ); }        \
         else {                                                            \
         else {                                                            \
-          for (i = 0; i < count; i++) {                                   \
+          for (i = 0; i < SMPI_VARGET_GLOBAL(count); i++) {                                   \
               if ((out[i].a != sol[i].a) || (out[i].b != sol[i].b)) {     \
               if ((out[i].a != sol[i].a) || (out[i].b != sol[i].b)) {     \
-                  cerrcnt++;                                              \
+                  SMPI_VARGET_GLOBAL(cerrcnt)++;                                              \
                   lerrcnt++;                                              \
               }                                                           \
             }                                                             \
                   lerrcnt++;                                              \
               }                                                           \
             }                                                             \
@@ -132,14 +135,14 @@ struct double_test { double a; int b; };
 #define SET_INDEX_STRUCT_CONST(arr, val, el)                    \
     {                                                           \
         int i;                                                  \
 #define SET_INDEX_STRUCT_CONST(arr, val, el)                    \
     {                                                           \
         int i;                                                  \
-        for (i = 0; i < count; i++)                             \
+        for (i = 0; i < SMPI_VARGET_GLOBAL(count); i++)                             \
             arr[i].el = val;                                    \
     }
 
 #define SET_INDEX_STRUCT_SUM(arr, val, el)                      \
     {                                                           \
         int i;                                                  \
             arr[i].el = val;                                    \
     }
 
 #define SET_INDEX_STRUCT_SUM(arr, val, el)                      \
     {                                                           \
         int i;                                                  \
-        for (i = 0; i < count; i++)                             \
+        for (i = 0; i < SMPI_VARGET_GLOBAL(count); i++)                             \
             arr[i].el = i + (val);                              \
     }
 
             arr[i].el = i + (val);                              \
     }
 
@@ -147,7 +150,7 @@ struct double_test { double a; int b; };
     {                                                                   \
         DECL_MALLOC_IN_OUT_SOL(type);                                   \
         SET_INDEX_SUM(in, 0);                                           \
     {                                                                   \
         DECL_MALLOC_IN_OUT_SOL(type);                                   \
         SET_INDEX_SUM(in, 0);                                           \
-        SET_INDEX_FACTOR(sol, size);                                    \
+        SET_INDEX_FACTOR(sol, SMPI_VARGET_GLOBAL(size));                                    \
         SET_INDEX_CONST(out, 0);                                        \
         ALLREDUCE_AND_FREE(mpi_type, MPI_SUM, in, out, sol);            \
     }
         SET_INDEX_CONST(out, 0);                                        \
         ALLREDUCE_AND_FREE(mpi_type, MPI_SUM, in, out, sol);            \
     }
@@ -156,7 +159,7 @@ struct double_test { double a; int b; };
     {                                                                   \
         DECL_MALLOC_IN_OUT_SOL(type);                                   \
         SET_INDEX_SUM(in, 0);                                           \
     {                                                                   \
         DECL_MALLOC_IN_OUT_SOL(type);                                   \
         SET_INDEX_SUM(in, 0);                                           \
-        SET_INDEX_POWER(sol, size);                                     \
+        SET_INDEX_POWER(sol, SMPI_VARGET_GLOBAL(size));                                     \
         SET_INDEX_CONST(out, 0);                                        \
         ALLREDUCE_AND_FREE(mpi_type, MPI_PROD, in, out, sol);           \
     }
         SET_INDEX_CONST(out, 0);                                        \
         ALLREDUCE_AND_FREE(mpi_type, MPI_PROD, in, out, sol);           \
     }
@@ -164,8 +167,8 @@ struct double_test { double a; int b; };
 #define max_test1(type, mpi_type)                                       \
     {                                                                   \
         DECL_MALLOC_IN_OUT_SOL(type);                                   \
 #define max_test1(type, mpi_type)                                       \
     {                                                                   \
         DECL_MALLOC_IN_OUT_SOL(type);                                   \
-        SET_INDEX_SUM(in, rank);                                        \
-        SET_INDEX_SUM(sol, size - 1);                                   \
+        SET_INDEX_SUM(in, SMPI_VARGET_GLOBAL(rank));                                        \
+        SET_INDEX_SUM(sol, SMPI_VARGET_GLOBAL(size) - 1);                                   \
         SET_INDEX_CONST(out, 0);                                        \
         ALLREDUCE_AND_FREE(mpi_type, MPI_MAX, in, out, sol);            \
     }
         SET_INDEX_CONST(out, 0);                                        \
         ALLREDUCE_AND_FREE(mpi_type, MPI_MAX, in, out, sol);            \
     }
@@ -173,7 +176,7 @@ struct double_test { double a; int b; };
 #define min_test1(type, mpi_type)                                       \
     {                                                                   \
         DECL_MALLOC_IN_OUT_SOL(type);                                   \
 #define min_test1(type, mpi_type)                                       \
     {                                                                   \
         DECL_MALLOC_IN_OUT_SOL(type);                                   \
-        SET_INDEX_SUM(in, rank);                                        \
+        SET_INDEX_SUM(in, SMPI_VARGET_GLOBAL(rank));                                        \
         SET_INDEX_SUM(sol, 0);                                          \
         SET_INDEX_CONST(out, 0);                                        \
         ALLREDUCE_AND_FREE(mpi_type, MPI_MIN, in, out, sol);            \
         SET_INDEX_SUM(sol, 0);                                          \
         SET_INDEX_CONST(out, 0);                                        \
         ALLREDUCE_AND_FREE(mpi_type, MPI_MIN, in, out, sol);            \
@@ -189,32 +192,32 @@ struct double_test { double a; int b; };
     }
 
 #define lor_test1(type, mpi_type)                                       \
     }
 
 #define lor_test1(type, mpi_type)                                       \
-    const_test(type, mpi_type, MPI_LOR, (rank & 0x1), (size > 1), 0)
+    const_test(type, mpi_type, MPI_LOR, (SMPI_VARGET_GLOBAL(rank) & 0x1), (SMPI_VARGET_GLOBAL(size) > 1), 0)
 #define lor_test2(type, mpi_type)                       \
     const_test(type, mpi_type, MPI_LOR, 0, 0, 0)
 #define lxor_test1(type, mpi_type)                                      \
 #define lor_test2(type, mpi_type)                       \
     const_test(type, mpi_type, MPI_LOR, 0, 0, 0)
 #define lxor_test1(type, mpi_type)                                      \
-    const_test(type, mpi_type, MPI_LXOR, (rank == 1), (size > 1), 0)
+    const_test(type, mpi_type, MPI_LXOR, (SMPI_VARGET_GLOBAL(rank) == 1), (SMPI_VARGET_GLOBAL(size) > 1), 0)
 #define lxor_test2(type, mpi_type)                      \
     const_test(type, mpi_type, MPI_LXOR, 0, 0, 0)
 #define lxor_test3(type, mpi_type)                      \
 #define lxor_test2(type, mpi_type)                      \
     const_test(type, mpi_type, MPI_LXOR, 0, 0, 0)
 #define lxor_test3(type, mpi_type)                      \
-    const_test(type, mpi_type, MPI_LXOR, 1, (size & 0x1), 0)
+    const_test(type, mpi_type, MPI_LXOR, 1, (SMPI_VARGET_GLOBAL(size) & 0x1), 0)
 #define land_test1(type, mpi_type)                              \
 #define land_test1(type, mpi_type)                              \
-    const_test(type, mpi_type, MPI_LAND, (rank & 0x1), 0, 0)
+    const_test(type, mpi_type, MPI_LAND, (SMPI_VARGET_GLOBAL(rank) & 0x1), 0, 0)
 #define land_test2(type, mpi_type)                      \
     const_test(type, mpi_type, MPI_LAND, 1, 1, 0)
 #define bor_test1(type, mpi_type)                                       \
 #define land_test2(type, mpi_type)                      \
     const_test(type, mpi_type, MPI_LAND, 1, 1, 0)
 #define bor_test1(type, mpi_type)                                       \
-    const_test(type, mpi_type, MPI_BOR, (rank & 0x3), ((size < 3) ? size - 1 : 0x3), 0)
+    const_test(type, mpi_type, MPI_BOR, (SMPI_VARGET_GLOBAL(rank) & 0x3), ((SMPI_VARGET_GLOBAL(size) < 3) ? SMPI_VARGET_GLOBAL(size) - 1 : 0x3), 0)
 #define bxor_test1(type, mpi_type)                                      \
 #define bxor_test1(type, mpi_type)                                      \
-    const_test(type, mpi_type, MPI_BXOR, (rank == 1) * 0xf0, (size > 1) * 0xf0, 0)
+    const_test(type, mpi_type, MPI_BXOR, (SMPI_VARGET_GLOBAL(rank) == 1) * 0xf0, (SMPI_VARGET_GLOBAL(size) > 1) * 0xf0, 0)
 #define bxor_test2(type, mpi_type)                      \
     const_test(type, mpi_type, MPI_BXOR, 0, 0, 0)
 #define bxor_test3(type, mpi_type)                      \
 #define bxor_test2(type, mpi_type)                      \
     const_test(type, mpi_type, MPI_BXOR, 0, 0, 0)
 #define bxor_test3(type, mpi_type)                      \
-    const_test(type, mpi_type, MPI_BXOR, ~0, (size &0x1) ? ~0 : 0, 0)
+    const_test(type, mpi_type, MPI_BXOR, ~0, (SMPI_VARGET_GLOBAL(size) &0x1) ? ~0 : 0, 0)
 
 #define band_test1(type, mpi_type)                                      \
     {                                                                   \
         DECL_MALLOC_IN_OUT_SOL(type);                                   \
 
 #define band_test1(type, mpi_type)                                      \
     {                                                                   \
         DECL_MALLOC_IN_OUT_SOL(type);                                   \
-        if (rank == size-1) {                                           \
+        if (SMPI_VARGET_GLOBAL(rank) == SMPI_VARGET_GLOBAL(size)-1) {                                           \
             SET_INDEX_SUM(in, 0);                                       \
         }                                                               \
         else {                                                          \
             SET_INDEX_SUM(in, 0);                                       \
         }                                                               \
         else {                                                          \
@@ -228,7 +231,7 @@ struct double_test { double a; int b; };
 #define band_test2(type, mpi_type)                                      \
     {                                                                   \
         DECL_MALLOC_IN_OUT_SOL(type);                                   \
 #define band_test2(type, mpi_type)                                      \
     {                                                                   \
         DECL_MALLOC_IN_OUT_SOL(type);                                   \
-        if (rank == size-1) {                                           \
+        if (SMPI_VARGET_GLOBAL(rank) == SMPI_VARGET_GLOBAL(size)-1) {                                           \
             SET_INDEX_SUM(in, 0);                                       \
         }                                                               \
         else {                                                          \
             SET_INDEX_SUM(in, 0);                                       \
         }                                                               \
         else {                                                          \
@@ -242,10 +245,10 @@ struct double_test { double a; int b; };
 #define maxloc_test(type, mpi_type)                                     \
     {                                                                   \
         DECL_MALLOC_IN_OUT_SOL(type);                                   \
 #define maxloc_test(type, mpi_type)                                     \
     {                                                                   \
         DECL_MALLOC_IN_OUT_SOL(type);                                   \
-        SET_INDEX_STRUCT_SUM(in, rank, a);                              \
-        SET_INDEX_STRUCT_CONST(in, rank, b);                            \
-        SET_INDEX_STRUCT_SUM(sol, size - 1, a);                         \
-        SET_INDEX_STRUCT_CONST(sol, size - 1, b);                       \
+        SET_INDEX_STRUCT_SUM(in, SMPI_VARGET_GLOBAL(rank), a);                              \
+        SET_INDEX_STRUCT_CONST(in, SMPI_VARGET_GLOBAL(rank), b);                            \
+        SET_INDEX_STRUCT_SUM(sol, SMPI_VARGET_GLOBAL(size) - 1, a);                         \
+        SET_INDEX_STRUCT_CONST(sol, SMPI_VARGET_GLOBAL(size) - 1, b);                       \
         SET_INDEX_STRUCT_CONST(out, 0, a);                              \
         SET_INDEX_STRUCT_CONST(out, -1, b);                             \
         STRUCT_ALLREDUCE_AND_FREE(mpi_type, MPI_MAXLOC, in, out, sol);   \
         SET_INDEX_STRUCT_CONST(out, 0, a);                              \
         SET_INDEX_STRUCT_CONST(out, -1, b);                             \
         STRUCT_ALLREDUCE_AND_FREE(mpi_type, MPI_MAXLOC, in, out, sol);   \
@@ -254,8 +257,8 @@ struct double_test { double a; int b; };
 #define minloc_test(type, mpi_type)                                     \
     {                                                                   \
         DECL_MALLOC_IN_OUT_SOL(type);                                   \
 #define minloc_test(type, mpi_type)                                     \
     {                                                                   \
         DECL_MALLOC_IN_OUT_SOL(type);                                   \
-        SET_INDEX_STRUCT_SUM(in, rank, a);                              \
-        SET_INDEX_STRUCT_CONST(in, rank, b);                            \
+        SET_INDEX_STRUCT_SUM(in, SMPI_VARGET_GLOBAL(rank), a);                              \
+        SET_INDEX_STRUCT_CONST(in, SMPI_VARGET_GLOBAL(rank), b);                            \
         SET_INDEX_STRUCT_SUM(sol, 0, a);                                \
         SET_INDEX_STRUCT_CONST(sol, 0, b);                              \
         SET_INDEX_STRUCT_CONST(out, 0, a);                              \
         SET_INDEX_STRUCT_SUM(sol, 0, a);                                \
         SET_INDEX_STRUCT_CONST(sol, 0, b);                              \
         SET_INDEX_STRUCT_CONST(out, 0, a);                              \
@@ -282,7 +285,7 @@ struct double_test { double a; int b; };
 
 #if MTEST_HAVE_MIN_MPI_VERSION(3,0)
 #define test_types_set_mpi_3_0_integer(op,post) do {                \
 
 #if MTEST_HAVE_MIN_MPI_VERSION(3,0)
 #define test_types_set_mpi_3_0_integer(op,post) do {                \
-        op##_test##post(MPI_Count, MPI_COUNT);                      \
+        op##_test##post(MPI_SMPI_VARGET_GLOBAL(count), MPI_SMPI_VARGET_GLOBAL(count));                      \
     } while (0)
 #else
 #define test_types_set_mpi_3_0_integer(op,post) do { } while (0)
     } while (0)
 #else
 #define test_types_set_mpi_3_0_integer(op,post) do { } while (0)
@@ -362,10 +365,10 @@ int main( int argc, char **argv )
 {
     MTest_Init( &argc, &argv );
 
 {
     MTest_Init( &argc, &argv );
 
-    MPI_Comm_size(MPI_COMM_WORLD, &size);
-    MPI_Comm_rank(MPI_COMM_WORLD, &rank);
+    MPI_Comm_size(MPI_COMM_WORLD, &SMPI_VARGET_GLOBAL(size));
+    MPI_Comm_rank(MPI_COMM_WORLD, &SMPI_VARGET_GLOBAL(rank));
 
 
-    if (size < 2) {
+    if (SMPI_VARGET_GLOBAL(size) < 2) {
        fprintf( stderr, "At least 2 processes required\n" );
        MPI_Abort( MPI_COMM_WORLD, 1 );
         exit(1);
        fprintf( stderr, "At least 2 processes required\n" );
        MPI_Abort( MPI_COMM_WORLD, 1 );
         exit(1);
@@ -375,13 +378,13 @@ int main( int argc, char **argv )
        should a routine reject one of the operand/datatype pairs */
     MPI_Errhandler_set( MPI_COMM_WORLD, MPI_ERRORS_RETURN );
 
        should a routine reject one of the operand/datatype pairs */
     MPI_Errhandler_set( MPI_COMM_WORLD, MPI_ERRORS_RETURN );
 
-    count = 10;
+    SMPI_VARGET_GLOBAL(count) = 10;
     /* Allow an argument to override the count.
        Note that the product tests may fail if the count is very large.
      */
     if (argc >= 2) {
     /* Allow an argument to override the count.
        Note that the product tests may fail if the count is very large.
      */
     if (argc >= 2) {
-       count = atoi( argv[1] );
-       if  (count <= 0) {
+       SMPI_VARGET_GLOBAL(count) = atoi( argv[1] );
+       if  (SMPI_VARGET_GLOBAL(count) <= 0) {
            fprintf( stderr, "Invalid count argument %s\n", argv[1] );
            MPI_Abort( MPI_COMM_WORLD, 1 );
             exit(1);
            fprintf( stderr, "Invalid count argument %s\n", argv[1] );
            MPI_Abort( MPI_COMM_WORLD, 1 );
             exit(1);
@@ -443,7 +446,7 @@ int main( int argc, char **argv )
     minloc_test(struct double_test, MPI_DOUBLE_INT);
 
     MPI_Errhandler_set( MPI_COMM_WORLD, MPI_ERRORS_ARE_FATAL );
     minloc_test(struct double_test, MPI_DOUBLE_INT);
 
     MPI_Errhandler_set( MPI_COMM_WORLD, MPI_ERRORS_ARE_FATAL );
-    MTest_Finalize( cerrcnt );
+    MTest_Finalize( SMPI_VARGET_GLOBAL(cerrcnt) );
     MPI_Finalize();
     return 0;
 }
     MPI_Finalize();
     return 0;
 }