Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
Update RMA tests
authordegomme <augustin.degomme@unibas.ch>
Sun, 12 Feb 2017 00:20:37 +0000 (01:20 +0100)
committerdegomme <augustin.degomme@unibas.ch>
Sun, 12 Feb 2017 01:08:28 +0000 (02:08 +0100)
125 files changed:
teshsuite/smpi/mpich3-test/rma/CMakeLists.txt
teshsuite/smpi/mpich3-test/rma/acc-loc.c
teshsuite/smpi/mpich3-test/rma/acc-pairtype.c [new file with mode: 0644]
teshsuite/smpi/mpich3-test/rma/accfence1.c
teshsuite/smpi/mpich3-test/rma/accfence2.c
teshsuite/smpi/mpich3-test/rma/accfence2_am.c
teshsuite/smpi/mpich3-test/rma/accpscw1.c
teshsuite/smpi/mpich3-test/rma/adlb_mimic1.c
teshsuite/smpi/mpich3-test/rma/aint.c [new file with mode: 0644]
teshsuite/smpi/mpich3-test/rma/allocmem.c
teshsuite/smpi/mpich3-test/rma/at_complete.c [new file with mode: 0644]
teshsuite/smpi/mpich3-test/rma/atomic_get.c [new file with mode: 0644]
teshsuite/smpi/mpich3-test/rma/atomic_rmw_cas.c [new file with mode: 0644]
teshsuite/smpi/mpich3-test/rma/atomic_rmw_fop.c [new file with mode: 0644]
teshsuite/smpi/mpich3-test/rma/atomic_rmw_gacc.c [new file with mode: 0644]
teshsuite/smpi/mpich3-test/rma/attrorderwin.c
teshsuite/smpi/mpich3-test/rma/baseattrwin.c
teshsuite/smpi/mpich3-test/rma/compare_and_swap.c
teshsuite/smpi/mpich3-test/rma/contention_put.c
teshsuite/smpi/mpich3-test/rma/contention_putget.c
teshsuite/smpi/mpich3-test/rma/contig_displ.c
teshsuite/smpi/mpich3-test/rma/derived-acc-flush_local.c [new file with mode: 0644]
teshsuite/smpi/mpich3-test/rma/epochtest.c
teshsuite/smpi/mpich3-test/rma/fence_shm.c
teshsuite/smpi/mpich3-test/rma/fetch_and_op.c
teshsuite/smpi/mpich3-test/rma/fetchandadd.c
teshsuite/smpi/mpich3-test/rma/fetchandadd_am.c
teshsuite/smpi/mpich3-test/rma/fetchandadd_tree.c
teshsuite/smpi/mpich3-test/rma/fetchandadd_tree_am.c
teshsuite/smpi/mpich3-test/rma/fkeyvalwin.c
teshsuite/smpi/mpich3-test/rma/flush.c
teshsuite/smpi/mpich3-test/rma/get-struct.c [new file with mode: 0644]
teshsuite/smpi/mpich3-test/rma/get_acc_local.c
teshsuite/smpi/mpich3-test/rma/get_accumulate.c
teshsuite/smpi/mpich3-test/rma/getfence1.c
teshsuite/smpi/mpich3-test/rma/getgroup.c
teshsuite/smpi/mpich3-test/rma/ircpi.c [deleted file]
teshsuite/smpi/mpich3-test/rma/large-acc-flush_local.c [new file with mode: 0644]
teshsuite/smpi/mpich3-test/rma/large-small-acc.c [new file with mode: 0644]
teshsuite/smpi/mpich3-test/rma/linked_list.c
teshsuite/smpi/mpich3-test/rma/linked_list_bench_lock_all.c
teshsuite/smpi/mpich3-test/rma/linked_list_bench_lock_excl.c
teshsuite/smpi/mpich3-test/rma/linked_list_bench_lock_shr.c
teshsuite/smpi/mpich3-test/rma/linked_list_fop.c
teshsuite/smpi/mpich3-test/rma/linked_list_lockall.c
teshsuite/smpi/mpich3-test/rma/lock_contention_dt.c [new file with mode: 0644]
teshsuite/smpi/mpich3-test/rma/lock_dt.c [new file with mode: 0644]
teshsuite/smpi/mpich3-test/rma/lock_dt_flush.c [new file with mode: 0644]
teshsuite/smpi/mpich3-test/rma/lock_dt_flushlocal.c [new file with mode: 0644]
teshsuite/smpi/mpich3-test/rma/lock_nested.c [new file with mode: 0644]
teshsuite/smpi/mpich3-test/rma/lockall_dt.c [new file with mode: 0644]
teshsuite/smpi/mpich3-test/rma/lockall_dt_flush.c [new file with mode: 0644]
teshsuite/smpi/mpich3-test/rma/lockall_dt_flushall.c [new file with mode: 0644]
teshsuite/smpi/mpich3-test/rma/lockall_dt_flushlocal.c [new file with mode: 0644]
teshsuite/smpi/mpich3-test/rma/lockall_dt_flushlocalall.c [new file with mode: 0644]
teshsuite/smpi/mpich3-test/rma/lockcontention.c
teshsuite/smpi/mpich3-test/rma/lockcontention2.c
teshsuite/smpi/mpich3-test/rma/lockcontention3.c
teshsuite/smpi/mpich3-test/rma/locknull.c
teshsuite/smpi/mpich3-test/rma/lockopts.c
teshsuite/smpi/mpich3-test/rma/manyget.c [new file with mode: 0644]
teshsuite/smpi/mpich3-test/rma/manyrma2.c
teshsuite/smpi/mpich3-test/rma/mcs-mutex.c
teshsuite/smpi/mpich3-test/rma/mixedsync.c
teshsuite/smpi/mpich3-test/rma/mutex_bench.c
teshsuite/smpi/mpich3-test/rma/nb_test.c [new file with mode: 0644]
teshsuite/smpi/mpich3-test/rma/nullpscw.c
teshsuite/smpi/mpich3-test/rma/overlap_wins_rma.c [new file with mode: 0644]
teshsuite/smpi/mpich3-test/rma/pscw_ordering.c
teshsuite/smpi/mpich3-test/rma/put_base.c
teshsuite/smpi/mpich3-test/rma/put_bottom.c
teshsuite/smpi/mpich3-test/rma/putfence1.c
teshsuite/smpi/mpich3-test/rma/putfidx.c
teshsuite/smpi/mpich3-test/rma/putpscw1.c
teshsuite/smpi/mpich3-test/rma/racc_local_comp.c [new file with mode: 0644]
teshsuite/smpi/mpich3-test/rma/req_example.c
teshsuite/smpi/mpich3-test/rma/reqops.c
teshsuite/smpi/mpich3-test/rma/rget-unlock.c [new file with mode: 0644]
teshsuite/smpi/mpich3-test/rma/rmanull.c
teshsuite/smpi/mpich3-test/rma/rmazero.c
teshsuite/smpi/mpich3-test/rma/rput_local_comp.c [new file with mode: 0644]
teshsuite/smpi/mpich3-test/rma/selfrma.c
teshsuite/smpi/mpich3-test/rma/strided_acc_indexed.c
teshsuite/smpi/mpich3-test/rma/strided_acc_onelock.c
teshsuite/smpi/mpich3-test/rma/strided_acc_subarray.c
teshsuite/smpi/mpich3-test/rma/strided_get_indexed.c
teshsuite/smpi/mpich3-test/rma/strided_getacc_indexed.c
teshsuite/smpi/mpich3-test/rma/strided_getacc_indexed_shared.c
teshsuite/smpi/mpich3-test/rma/strided_putget_indexed.c
teshsuite/smpi/mpich3-test/rma/strided_putget_indexed_shared.c
teshsuite/smpi/mpich3-test/rma/test1.c
teshsuite/smpi/mpich3-test/rma/test1_am.c
teshsuite/smpi/mpich3-test/rma/test1_dt.c
teshsuite/smpi/mpich3-test/rma/test2.c
teshsuite/smpi/mpich3-test/rma/test2_am.c
teshsuite/smpi/mpich3-test/rma/test3.c
teshsuite/smpi/mpich3-test/rma/test3_am.c
teshsuite/smpi/mpich3-test/rma/test4.c
teshsuite/smpi/mpich3-test/rma/test4_am.c
teshsuite/smpi/mpich3-test/rma/test5.c
teshsuite/smpi/mpich3-test/rma/test5_am.c
teshsuite/smpi/mpich3-test/rma/testlist
teshsuite/smpi/mpich3-test/rma/transpose1.c
teshsuite/smpi/mpich3-test/rma/transpose2.c
teshsuite/smpi/mpich3-test/rma/transpose3.c
teshsuite/smpi/mpich3-test/rma/transpose4.c
teshsuite/smpi/mpich3-test/rma/transpose5.c
teshsuite/smpi/mpich3-test/rma/transpose6.c
teshsuite/smpi/mpich3-test/rma/transpose7.c
teshsuite/smpi/mpich3-test/rma/win_dynamic_acc.c
teshsuite/smpi/mpich3-test/rma/win_flavors.c
teshsuite/smpi/mpich3-test/rma/win_info.c
teshsuite/smpi/mpich3-test/rma/win_large_shm.c
teshsuite/smpi/mpich3-test/rma/win_shared.c
teshsuite/smpi/mpich3-test/rma/win_shared_create.c [new file with mode: 0644]
teshsuite/smpi/mpich3-test/rma/win_shared_noncontig.c
teshsuite/smpi/mpich3-test/rma/win_shared_noncontig_put.c
teshsuite/smpi/mpich3-test/rma/win_shared_put_flush_get.c [new file with mode: 0644]
teshsuite/smpi/mpich3-test/rma/win_shared_rma_flush_load.c [new file with mode: 0644]
teshsuite/smpi/mpich3-test/rma/win_shared_zerobyte.c [new file with mode: 0644]
teshsuite/smpi/mpich3-test/rma/wincall.c
teshsuite/smpi/mpich3-test/rma/window_creation.c
teshsuite/smpi/mpich3-test/rma/winname.c
teshsuite/smpi/mpich3-test/rma/wintest.c
teshsuite/smpi/mpich3-test/rma/wrma_flush_get.c [new file with mode: 0644]

index adf5e2f..4bedbee 100644 (file)
@@ -12,7 +12,9 @@ if(enable_smpi AND enable_smpi_MPICH3_testsuite)
 
   foreach(file accfence1 accfence2_am accfence2 accpscw1 allocmem epochtest getfence1 getgroup manyrma3 nullpscw
           putfence1 putfidx putpscw1 test1_am test1 test1_dt test2_am test2 test3 test5_am test5 transpose1 transpose2
-          transpose3 transpose6 transpose7 window_creation)
+          transpose3 transpose6 transpose7 window_creation  
+          at_complete  acc-pairtype manyget large-small-acc 
+          lock_nested)
     # not compiled files: acc-loc adlb_mimic1 attrorderwin badrma baseattrwin compare_and_swap contention_put
     # contention_putget contig_displ fence_shm fetchandadd_am fetchandadd fetchandadd_tree_am fetchandadd_tree 
     # fetch_and_op fkeyvalwin flush get_acc_local get_accumulate ircpi linked_list_bench_lock_all 
@@ -22,7 +24,8 @@ if(enable_smpi AND enable_smpi_MPICH3_testsuite)
     # strided_acc_onelock strided_acc_subarray strided_getacc_indexed strided_getacc_indexed_shared strided_get_indexed
     # strided_putget_indexed strided_putget_indexed_shared test3_am test4_am test4 transpose4 transpose5 wincall 
     # win_dynamic_acc win_flavors win_info winname win_shared win_shared_noncontig win_shared_noncontig_put 
-    # win_large_shm win_zero wintest
+    # win_large_shm win_zero wintest get-struct atomic_rmw_fop atomic_rmw_gacc rget-unlock atomic_get atomic_rmw_cas
+    # win_shared_zerobyte aint
     add_executable(${file} ${file}.c)
     target_link_libraries(${file} simgrid mtest_c)
     set_target_properties(${file} PROPERTIES COMPILE_FLAGS "${MPICH_FLAGS}")
@@ -46,7 +49,9 @@ foreach(file accfence1 accfence2_am accfence2 accpscw1 allocmem epochtest getfen
           strided_acc_subarray strided_getacc_indexed strided_getacc_indexed_shared strided_get_indexed 
           strided_putget_indexed strided_putget_indexed_shared test3_am test4_am test4 transpose4 transpose5 wincall 
           win_dynamic_acc win_flavors win_info winname win_shared win_shared_noncontig win_shared_noncontig_put 
-          win_large_shm win_zero wintest)
+          win_large_shm win_zero wintest win_shared_zerobyte get-struct
+          at_complete atomic_rmw_fop atomic_rmw_cas atomic_rmw_gacc atomic_get aint acc-pairtype manyget large-small-acc  
+          rget-unlock overlap_wins_rma lock_nested)
   set(examples_src  ${examples_src} ${CMAKE_CURRENT_SOURCE_DIR}/${file}.c)
 endforeach()
 
index 18c3e3a..6e76970 100644 (file)
@@ -20,7 +20,8 @@ typedef struct {
 
 static int errors = 0;
 
-int main(int argc, char **argv) {
+int main(int argc, char **argv)
+{
     int me, nproc;
     twoint_t *data = NULL;
     twoint_t mine;
@@ -76,10 +77,10 @@ int main(int argc, char **argv) {
     MPI_Accumulate(&mine, 1, MPI_2INT, 0, 0, 1, MPI_2INT, MPI_MINLOC, win);
     MPI_Win_fence(0, win);
 
-    if (me == 0 && (data->loc != nproc-1 || data->val != 1)) {
+    if (me == 0 && (data->loc != nproc - 1 || data->val != 1)) {
         errors++;
         printf("Expected: { loc = %d, val = %d }  Actual: { loc = %d, val = %d }\n",
-               nproc-1, 1, data->loc, data->val);
+               nproc - 1, 1, data->loc, data->val);
     }
 
     /* All processes perform MAXLOC and MINLOC operations on a 2INT on rank 0.
diff --git a/teshsuite/smpi/mpich3-test/rma/acc-pairtype.c b/teshsuite/smpi/mpich3-test/rma/acc-pairtype.c
new file mode 100644 (file)
index 0000000..5c23435
--- /dev/null
@@ -0,0 +1,87 @@
+/* -*- Mode: C; c-basic-offset:4 ; indent-tabs-mode:nil ; -*- */
+/*
+ *
+ *  (C) 2015 by Argonne National Laboratory.
+ *      See COPYRIGHT in top-level directory.
+ */
+
+/* This test is going to test when Accumulate operation is working
+ * with pair types. */
+
+#include "mpi.h"
+#include <stdio.h>
+
+#define DATA_SIZE 25
+
+typedef struct long_double_int {
+    long double a;
+    int b;
+} long_double_int_t;
+
+int main(int argc, char *argv[])
+{
+    MPI_Win win;
+    int errors = 0;
+    int rank, nproc, i;
+    long_double_int_t *orig_buf;
+    long_double_int_t *tar_buf;
+    MPI_Datatype vector_dtp;
+
+    MPI_Init(&argc, &argv);
+
+    MPI_Comm_size(MPI_COMM_WORLD, &nproc);
+    MPI_Comm_rank(MPI_COMM_WORLD, &rank);
+
+    MPI_Alloc_mem(sizeof(long_double_int_t) * DATA_SIZE, MPI_INFO_NULL, &orig_buf);
+    MPI_Alloc_mem(sizeof(long_double_int_t) * DATA_SIZE, MPI_INFO_NULL, &tar_buf);
+
+    for (i = 0; i < DATA_SIZE; i++) {
+        orig_buf[i].a = 1.0;
+        orig_buf[i].b = 1;
+        tar_buf[i].a = 0;
+        tar_buf[i].b = 0;
+    }
+
+    MPI_Type_vector(5 /* count */ , 3 /* blocklength */ , 5 /* stride */ , MPI_LONG_DOUBLE_INT,
+                    &vector_dtp);
+    MPI_Type_commit(&vector_dtp);
+
+    MPI_Win_create(tar_buf, sizeof(long_double_int_t) * DATA_SIZE, sizeof(long_double_int_t),
+                   MPI_INFO_NULL, MPI_COMM_WORLD, &win);
+
+    if (rank == 0) {
+        MPI_Win_lock(MPI_LOCK_SHARED, 1, 0, win);
+        MPI_Accumulate(orig_buf, 1, vector_dtp, 1, 0, 1, vector_dtp, MPI_MAXLOC, win);
+        MPI_Win_unlock(1, win);
+    }
+
+    MPI_Win_free(&win);
+
+    if (rank == 1) {
+        for (i = 0; i < DATA_SIZE; i++) {
+            if (i % 5 < 3) {
+                if (tar_buf[i].a != 1.0 || tar_buf[i].b != 1) {
+                    errors++;
+                }
+            }
+            else {
+                if (tar_buf[i].a != 0.0 || tar_buf[i].b != 0) {
+                    errors++;
+                }
+            }
+        }
+    }
+
+    MPI_Type_free(&vector_dtp);
+
+    MPI_Free_mem(orig_buf);
+    MPI_Free_mem(tar_buf);
+
+    if (rank == 1) {
+        if (errors == 0)
+            printf(" No Errors\n");
+    }
+
+    MPI_Finalize();
+    return 0;
+}
index 91d9f43..f4b8930 100644 (file)
 static char MTEST_Descrip[] = "Accumulate/Replace with Fence";
 */
 
-int main( int argc, char *argv[] )
+int main(int argc, char *argv[])
 {
     int errs = 0, err;
     int rank, size, source, dest;
-    int minsize = 2, count; 
-    MPI_Comm      comm;
-    MPI_Win       win;
-    MPI_Aint      extent;
+    int minsize = 2, count;
+    MPI_Comm comm;
+    MPI_Win win;
+    MPI_Aint extent, lb;
     MTestDatatype sendtype, recvtype;
 
-    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;
-       /* Determine the sender and receiver */
-       MPI_Comm_rank( comm, &rank );
-       MPI_Comm_size( comm, &size );
-       source = 0;
-       dest   = size - 1;
-       
-       for (count = 1; count < 65000; count = count * 2) {
-           while (MTestGetDatatypes( &sendtype, &recvtype, count )) {
-               /* Make sure that everyone has a recv buffer */
-               recvtype.InitBuf( &recvtype );
+    /* 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;
+        /* Determine the sender and receiver */
+        MPI_Comm_rank(comm, &rank);
+        MPI_Comm_size(comm, &size);
+        source = 0;
+        dest = size - 1;
 
-               MPI_Type_extent( recvtype.datatype, &extent );
-               MPI_Win_create( recvtype.buf, recvtype.count * extent, 
-                               (int)extent, MPI_INFO_NULL, comm, &win );
-               MPI_Win_fence( 0, win );
-               if (rank == source) {
-                   sendtype.InitBuf( &sendtype );
+        MTEST_DATATYPE_FOR_EACH_COUNT(count) {
+            while (MTestGetDatatypes(&sendtype, &recvtype, count)) {
+                /* Make sure that everyone has a recv buffer */
+                recvtype.InitBuf(&recvtype);
 
-                   /* To improve reporting of problems about operations, we
-                      change the error handler to errors return */
-                   MPI_Win_set_errhandler( win, MPI_ERRORS_RETURN );
-                   
-                   /* MPI_REPLACE on accumulate is almost the same 
-                      as MPI_Put; the only difference is in the
-                      handling of overlapping accumulate operations,
-                      which are not tested here */
-                   err = MPI_Accumulate( sendtype.buf, sendtype.count, 
-                                         sendtype.datatype, dest, 0, 
-                                         recvtype.count, recvtype.datatype, 
-                                         MPI_REPLACE, win );
-                   if (err) {
-                       errs++;
-                       if (errs < 10) {
-                           printf( "Accumulate types: send %s, recv %s\n",
-                                   MTestGetDatatypeName( &sendtype ),
-                                   MTestGetDatatypeName( &recvtype ) );
-                           MTestPrintError( err );
-                       }
-                   }
-                   err = MPI_Win_fence( 0, win );
-                   if (err) {
-                       errs++;
-                       if (errs < 10) {
-                           MTestPrintError( err );
-                       }
-                   }
-               }
-               else if (rank == dest) {
-                   MPI_Win_fence( 0, win );
-                   /* This should have the same effect, in terms of
-                      transfering data, as a send/recv pair */
-                   err = MTestCheckRecv( 0, &recvtype );
-                   if (err) {
-                       errs += err;
-                   }
-               }
-               else {
-                   MPI_Win_fence( 0, win );
-               }
-               MPI_Win_free( &win );
-               MTestFreeDatatype( &sendtype );
-               MTestFreeDatatype( &recvtype );
-           }
-       }
+                MPI_Type_extent(recvtype.datatype, &extent);
+                MPI_Type_lb(recvtype.datatype, &lb);
+                MPI_Win_create(recvtype.buf, recvtype.count * extent + lb,
+                               (int) extent, MPI_INFO_NULL, comm, &win);
+                MPI_Win_fence(0, win);
+                if (rank == source) {
+                    sendtype.InitBuf(&sendtype);
+
+                    /* To improve reporting of problems about operations, we
+                     * change the error handler to errors return */
+                    MPI_Win_set_errhandler(win, MPI_ERRORS_RETURN);
+
+                    /* MPI_REPLACE on accumulate is almost the same
+                     * as MPI_Put; the only difference is in the
+                     * handling of overlapping accumulate operations,
+                     * which are not tested here */
+                    err = MPI_Accumulate(sendtype.buf, sendtype.count,
+                                         sendtype.datatype, dest, 0,
+                                         recvtype.count, recvtype.datatype, MPI_REPLACE, win);
+                    if (err) {
+                        errs++;
+                        if (errs < 10) {
+                            printf("Accumulate types: send %s, recv %s\n",
+                                   MTestGetDatatypeName(&sendtype),
+                                   MTestGetDatatypeName(&recvtype));
+                            MTestPrintError(err);
+                        }
+                    }
+                    err = MPI_Win_fence(0, win);
+                    if (err) {
+                        errs++;
+                        if (errs < 10) {
+                            MTestPrintError(err);
+                        }
+                    }
+                }
+                else if (rank == dest) {
+                    MPI_Win_fence(0, win);
+                    /* This should have the same effect, in terms of
+                     * transfering data, as a send/recv pair */
+                    err = MTestCheckRecv(0, &recvtype);
+                    if (err) {
+                        errs += err;
+                    }
+                }
+                else {
+                    MPI_Win_fence(0, win);
+                }
+                MPI_Win_free(&win);
+                MTestFreeDatatype(&sendtype);
+                MTestFreeDatatype(&recvtype);
+            }
+        }
         MTestFreeComm(&comm);
     }
 
-    MTest_Finalize( errs );
+    MTest_Finalize(errs);
     MPI_Finalize();
     return 0;
 }
index 4366e10..b0bf958 100644 (file)
 static char MTEST_Descrip[] = "Test MPI_Accumulate with fence";
 */
 
-int main( int argc, char *argv[] )
+int main(int argc, char *argv[])
 {
     int errs = 0;
     int rank, size, source;
-    int minsize = 2, count, i; 
-    MPI_Comm      comm;
-    MPI_Win       win;
-    int           *winbuf, *sbuf;
+    int minsize = 2, count, i;
+    MPI_Comm comm;
+    MPI_Win win;
+    int *winbuf, *sbuf;
 
-    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;
-       /* Determine the sender and receiver */
-       MPI_Comm_rank( comm, &rank );
-       MPI_Comm_size( comm, &size );
-       source = 0;
-       
-       for (count = 1; count < 65000; count = count * 2) {
-           /* We compare with an integer value that can be as large as
-              size * (count * count + (1/2)*(size-1))
-              For large machines (size large), this can exceed the 
-              maximum integer for some large values of count.  We check
-              that in advance and break this loop if the above value 
-              would exceed MAX_INT.  Specifically,
+    /* 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;
+        /* Determine the sender and receiver */
+        MPI_Comm_rank(comm, &rank);
+        MPI_Comm_size(comm, &size);
+        source = 0;
 
-              size*count*count + (1/2)*size*(size-1) > MAX_INT
-              count*count > (MAX_INT/size - (1/2)*(size-1))
-           */
-           if (count * count > (MAX_INT/size - (size-1)/2)) break;
-           winbuf = (int *)malloc( count * sizeof(int) );
-           sbuf   = (int *)malloc( count * sizeof(int) );
+        for (count = 1; count < 65000; count = count * 2) {
+            /* We compare with an integer value that can be as large as
+             * size * (count * count + (1/2)*(size-1))
+             * For large machines (size large), this can exceed the
+             * maximum integer for some large values of count.  We check
+             * that in advance and break this loop if the above value
+             * would exceed MAX_INT.  Specifically,
+             *
+             * size*count*count + (1/2)*size*(size-1) > MAX_INT
+             * count*count > (MAX_INT/size - (1/2)*(size-1))
+             */
+            if (count * count > (MAX_INT / size - (size - 1) / 2))
+                break;
+            winbuf = (int *) malloc(count * sizeof(int));
+            sbuf = (int *) malloc(count * sizeof(int));
 
-           for (i=0; i<count; i++) winbuf[i] = 0;
-           for (i=0; i<count; i++) sbuf[i] = rank + i * count;
-           MPI_Win_create( winbuf, count * sizeof(int), sizeof(int),
-                           MPI_INFO_NULL, comm, &win );
-           MPI_Win_fence( 0, win );
-           MPI_Accumulate( sbuf, count, MPI_INT, source, 0, count, MPI_INT,
-                               MPI_SUM, win );
-           MPI_Win_fence( 0, win );
-           if (rank == source) {
-               /* Check the results */
-               for (i=0; i<count; i++) {
-                   int result = i * count * size + (size*(size-1))/2;
-                   if (winbuf[i] != result) {
-                       if (errs < 10) {
-                           fprintf( stderr, "Winbuf[%d] = %d, expected %d (count = %d, size = %d)\n",
-                                    i, winbuf[i], result, count, size );
-                       }
-                       errs++;
-                   }
-               }
-           }
-           free( winbuf );
-           free( sbuf );
-           MPI_Win_free( &win );
-       }
+            for (i = 0; i < count; i++)
+                winbuf[i] = 0;
+            for (i = 0; i < count; i++)
+                sbuf[i] = rank + i * count;
+            MPI_Win_create(winbuf, count * sizeof(int), sizeof(int), MPI_INFO_NULL, comm, &win);
+            MPI_Win_fence(0, win);
+            MPI_Accumulate(sbuf, count, MPI_INT, source, 0, count, MPI_INT, MPI_SUM, win);
+            MPI_Win_fence(0, win);
+            if (rank == source) {
+                /* Check the results */
+                for (i = 0; i < count; i++) {
+                    int result = i * count * size + (size * (size - 1)) / 2;
+                    if (winbuf[i] != result) {
+                        if (errs < 10) {
+                            fprintf(stderr,
+                                    "Winbuf[%d] = %d, expected %d (count = %d, size = %d)\n", i,
+                                    winbuf[i], result, count, size);
+                        }
+                        errs++;
+                    }
+                }
+            }
+            free(winbuf);
+            free(sbuf);
+            MPI_Win_free(&win);
+        }
         MTestFreeComm(&comm);
     }
 
-    MTest_Finalize( errs );
+    MTest_Finalize(errs);
     MPI_Finalize();
     return 0;
 }
index 96c6516..0d11fb4 100644 (file)
@@ -19,77 +19,79 @@ static char MTEST_Descrip[] = "Test MPI_Accumulate with fence";
 
 /* same as accfence2.c, but uses alloc_mem */
 
-int main( int argc, char *argv[] )
+int main(int argc, char *argv[])
 {
     int errs = 0;
     int rank, size, source;
-    int minsize = 2, count, i; 
-    MPI_Comm      comm;
-    MPI_Win       win;
-    int           *winbuf, *sbuf;
+    int minsize = 2, count, i;
+    MPI_Comm comm;
+    MPI_Win win;
+    int *winbuf, *sbuf;
 
-    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;
-       /* Determine the sender and receiver */
-       MPI_Comm_rank( comm, &rank );
-       MPI_Comm_size( comm, &size );
-       source = 0;
-       
-       for (count = 32768; count < 65000; count = count * 2) {
+    /* 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;
+        /* Determine the sender and receiver */
+        MPI_Comm_rank(comm, &rank);
+        MPI_Comm_size(comm, &size);
+        source = 0;
 
+        for (count = 32768; count < 65000; count = count * 2) {
 
-           /* We compare with an integer value that can be as large as
-              size * (count * count + (1/2)*(size-1))
-              For large machines (size large), this can exceed the 
-              maximum integer for some large values of count.  We check
-              that in advance and break this loop if the above value 
-              would exceed MAX_INT.  Specifically,
+            /* We compare with an integer value that can be as large as
+             * size * (count * count + (1/2)*(size-1))
+             * For large machines (size large), this can exceed the
+             * maximum integer for some large values of count.  We check
+             * that in advance and break this loop if the above value
+             * would exceed MAX_INT.  Specifically,
+             *
+             * size*count*count + (1/2)*size*(size-1) > MAX_INT
+             * count*count > (MAX_INT/size - (1/2)*(size-1))
+             */
+            if (count * count > (MAX_INT / size - (size - 1) / 2))
+                break;
 
-              size*count*count + (1/2)*size*(size-1) > MAX_INT
-              count*count > (MAX_INT/size - (1/2)*(size-1))
-           */
-           if (count * count > (MAX_INT/size - (size-1)/2)) break;
+            MPI_Alloc_mem(count * sizeof(int), MPI_INFO_NULL, &winbuf);
+            MPI_Alloc_mem(count * sizeof(int), MPI_INFO_NULL, &sbuf);
 
-           MPI_Alloc_mem( count * sizeof(int), MPI_INFO_NULL, &winbuf );
-           MPI_Alloc_mem( count * sizeof(int), MPI_INFO_NULL, &sbuf );
+            for (i = 0; i < count; i++)
+                winbuf[i] = 0;
+            for (i = 0; i < count; i++)
+                sbuf[i] = rank + i * count;
+            MPI_Win_create(winbuf, count * sizeof(int), sizeof(int), MPI_INFO_NULL, comm, &win);
+            MPI_Win_fence(0, win);
+            MPI_Accumulate(sbuf, count, MPI_INT, source, 0, count, MPI_INT, MPI_SUM, win);
+            MPI_Win_fence(0, win);
+            if (rank == source) {
+                /* Check the results */
+                for (i = 0; i < count; i++) {
+                    int result = i * count * size + (size * (size - 1)) / 2;
+                    if (winbuf[i] != result) {
+                        if (errs < 10) {
+                            fprintf(stderr,
+                                    "Winbuf[%d] = %d, expected %d (count = %d, size = %d)\n", i,
+                                    winbuf[i], result, count, size);
+                        }
+                        errs++;
+                    }
+                }
+            }
 
-           for (i=0; i<count; i++) winbuf[i] = 0;
-           for (i=0; i<count; i++) sbuf[i] = rank + i * count;
-           MPI_Win_create( winbuf, count * sizeof(int), sizeof(int),
-                           MPI_INFO_NULL, comm, &win );
-           MPI_Win_fence( 0, win );
-           MPI_Accumulate( sbuf, count, MPI_INT, source, 0, count, MPI_INT,
-                               MPI_SUM, win );
-           MPI_Win_fence( 0, win );
-           if (rank == source) {
-               /* Check the results */
-               for (i=0; i<count; i++) {
-                   int result = i * count * size + (size*(size-1))/2;
-                   if (winbuf[i] != result) {
-                       if (errs < 10) {
-                           fprintf( stderr, "Winbuf[%d] = %d, expected %d (count = %d, size = %d)\n",
-                                    i, winbuf[i], result, count, size );
-                       }
-                       errs++;
-                   }
-               }
-           }
-
-           MPI_Win_free( &win );
+            MPI_Win_free(&win);
 
             MPI_Free_mem(winbuf);
             MPI_Free_mem(sbuf);
-       }
+        }
         MTestFreeComm(&comm);
     }
 
-    MTest_Finalize( errs );
+    MTest_Finalize(errs);
     MPI_Finalize();
     return 0;
 }
index 4b4976e..67ab3b4 100644 (file)
 static char MTEST_Descrip[] = "Accumulate/replace with Post/Start/Complete/Wait";
 */
 
-int main( int argc, char *argv[] )
+int main(int argc, char *argv[])
 {
     int errs = 0, err;
     int rank, size, source, dest;
-    int minsize = 2, count; 
-    MPI_Comm      comm;
-    MPI_Win       win;
-    MPI_Aint      extent;
-    MPI_Group     wingroup, neighbors;
+    int minsize = 2, count;
+    MPI_Comm comm;
+    MPI_Win win;
+    MPI_Aint extent, lb;
+    MPI_Group wingroup, neighbors;
     MTestDatatype sendtype, recvtype;
 
-    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;
-       /* Determine the sender and receiver */
-       MPI_Comm_rank( comm, &rank );
-       MPI_Comm_size( comm, &size );
-       source = 0;
-       dest   = size - 1;
-       
-       for (count = 1; count < 65000; count = count * 2) {
-           while (MTestGetDatatypes( &sendtype, &recvtype, count )) {
-               /* Make sure that everyone has a recv buffer */
-               recvtype.InitBuf( &recvtype );
+    /* 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;
+        /* Determine the sender and receiver */
+        MPI_Comm_rank(comm, &rank);
+        MPI_Comm_size(comm, &size);
+        source = 0;
+        dest = size - 1;
 
-               MPI_Type_extent( recvtype.datatype, &extent );
-               MPI_Win_create( recvtype.buf, recvtype.count * extent, 
-                               (int)extent, MPI_INFO_NULL, comm, &win );
-               MPI_Win_get_group( win, &wingroup );
-               if (rank == source) {
-                   /* To improve reporting of problems about operations, we
-                      change the error handler to errors return */
-                   MPI_Win_set_errhandler( win, MPI_ERRORS_RETURN );
-                   sendtype.InitBuf( &sendtype );
-                   
-                   /* Neighbor is dest only */
-                   MPI_Group_incl( wingroup, 1, &dest, &neighbors );
-                   err = MPI_Win_start( neighbors, 0, win );
-                   if (err) {
-                       errs++;
-                       if (errs < 10) {
-                           MTestPrintError( err );
-                       }
-                   }
-                   MPI_Group_free( &neighbors );
-                   err = MPI_Accumulate( sendtype.buf, sendtype.count, 
-                                         sendtype.datatype, dest, 0, 
-                                         recvtype.count, recvtype.datatype, 
-                                         MPI_REPLACE, win );
-                   if (err) {
-                       errs++;
-                       MTestPrintError( err );
-                   }
-                   err = MPI_Win_complete( win );
-                   if (err) {
-                       errs++;
-                       if (errs < 10) {
-                           MTestPrintError( err );
-                       }
-                   }
-               }
-               else if (rank == dest) {
-                   MPI_Group_incl( wingroup, 1, &source, &neighbors );
-                   MPI_Win_post( neighbors, 0, win );
-                   MPI_Group_free( &neighbors );
-                   MPI_Win_wait( win );
-                   /* This should have the same effect, in terms of
-                      transfering data, as a send/recv pair */
-                   err = MTestCheckRecv( 0, &recvtype );
-                   if (err) {
-                       errs += errs;
-                   }
-               }
-               else {
-                   /* Nothing; the other processes need not call any 
-                      MPI routines */
-                   ;
-               }
-               MPI_Win_free( &win );
-               MTestFreeDatatype( &sendtype );
-               MTestFreeDatatype( &recvtype );
-               MPI_Group_free( &wingroup );
-           }
-       }
-       MTestFreeComm( &comm );
+        MTEST_DATATYPE_FOR_EACH_COUNT(count) {
+            while (MTestGetDatatypes(&sendtype, &recvtype, count)) {
+                /* Make sure that everyone has a recv buffer */
+                recvtype.InitBuf(&recvtype);
+
+                MPI_Type_extent(recvtype.datatype, &extent);
+                MPI_Type_lb(recvtype.datatype, &lb);
+                MPI_Win_create(recvtype.buf, recvtype.count * extent + lb,
+                               (int) extent, MPI_INFO_NULL, comm, &win);
+                MPI_Win_get_group(win, &wingroup);
+                if (rank == source) {
+                    /* To improve reporting of problems about operations, we
+                     * change the error handler to errors return */
+                    MPI_Win_set_errhandler(win, MPI_ERRORS_RETURN);
+                    sendtype.InitBuf(&sendtype);
+
+                    /* Neighbor is dest only */
+                    MPI_Group_incl(wingroup, 1, &dest, &neighbors);
+                    err = MPI_Win_start(neighbors, 0, win);
+                    if (err) {
+                        errs++;
+                        if (errs < 10) {
+                            MTestPrintError(err);
+                        }
+                    }
+                    MPI_Group_free(&neighbors);
+                    err = MPI_Accumulate(sendtype.buf, sendtype.count,
+                                         sendtype.datatype, dest, 0,
+                                         recvtype.count, recvtype.datatype, MPI_REPLACE, win);
+                    if (err) {
+                        errs++;
+                        MTestPrintError(err);
+                    }
+                    err = MPI_Win_complete(win);
+                    if (err) {
+                        errs++;
+                        if (errs < 10) {
+                            MTestPrintError(err);
+                        }
+                    }
+                }
+                else if (rank == dest) {
+                    MPI_Group_incl(wingroup, 1, &source, &neighbors);
+                    MPI_Win_post(neighbors, 0, win);
+                    MPI_Group_free(&neighbors);
+                    MPI_Win_wait(win);
+                    /* This should have the same effect, in terms of
+                     * transfering data, as a send/recv pair */
+                    err = MTestCheckRecv(0, &recvtype);
+                    if (err) {
+                        errs += errs;
+                    }
+                }
+                else {
+                    /* Nothing; the other processes need not call any
+                     * MPI routines */
+                    ;
+                }
+                MPI_Win_free(&win);
+                MTestFreeDatatype(&sendtype);
+                MTestFreeDatatype(&recvtype);
+                MPI_Group_free(&wingroup);
+            }
+        }
+        MTestFreeComm(&comm);
     }
 
-    MTest_Finalize( errs );
+    MTest_Finalize(errs);
     MPI_Finalize();
     return 0;
 }
index 22767fb..661f72f 100644 (file)
@@ -12,8 +12,8 @@
 #include "mpitest.h"
 
 #define NUM_TIMES 500
-#define MAX_BUF_SIZE (400 * 1024 * 1024) /* 400 MB */
-#define PUT_SIZE (1024 * 1024) /* 1MB */
+#define MAX_BUF_SIZE (400 * 1024 * 1024)        /* 400 MB */
+#define PUT_SIZE (1024 * 1024)  /* 1MB */
 
 /*
 static char MTEST_Descrip[] = "ADLB mimic test";
@@ -61,36 +61,34 @@ int main(int argc, char **argv)
     MPI_Comm_rank(MPI_COMM_WORLD, &comm_rank);
 
     if (comm_size <= 2) {
-       fprintf( stderr, "This test requires at least 3 processes\n" );
-       MPI_Abort( MPI_COMM_WORLD, 1 );
+        fprintf(stderr, "This test requires at least 3 processes\n");
+        MPI_Abort(MPI_COMM_WORLD, 1);
     }
 
     max_buf_size = comm_size * put_size;
     if (max_buf_size > MAX_BUF_SIZE) {
-       fprintf( stderr, "Too many processes in COMM_WORLD (max is %d)\n",
-                MAX_BUF_SIZE / put_size );
-       MPI_Abort( MPI_COMM_WORLD, 1 );
+        fprintf(stderr, "Too many processes in COMM_WORLD (max is %d)\n", MAX_BUF_SIZE / put_size);
+        MPI_Abort(MPI_COMM_WORLD, 1);
     }
 
     /* If alloc mem returns an error (because too much memory is requested */
-    MPI_Errhandler_set( MPI_COMM_WORLD, MPI_ERRORS_RETURN );
+    MPI_Errhandler_set(MPI_COMM_WORLD, MPI_ERRORS_RETURN);
 
     rc = MPI_Alloc_mem(max_buf_size, MPI_INFO_NULL, (void *) &rma_win_addr);
     if (rc) {
-       MTestPrintErrorMsg( "Unable to MPI_Alloc_mem space (not an error)", rc );
-       MPI_Abort( MPI_COMM_WORLD, 0 );
+        MTestPrintErrorMsg("Unable to MPI_Alloc_mem space (not an error)", rc);
+        MPI_Abort(MPI_COMM_WORLD, 0);
     }
 
     memset(rma_win_addr, 0, max_buf_size);
-    MPI_Win_create((void *) rma_win_addr, max_buf_size, 1, MPI_INFO_NULL, 
-                  MPI_COMM_WORLD, &win);
+    MPI_Win_create((void *) rma_win_addr, max_buf_size, 1, MPI_INFO_NULL, MPI_COMM_WORLD, &win);
 
     /* Note that it is not necessary to use MPI_Alloc_mem for the memory that
-       is not part of the MPI_Win.  */
+     * is not part of the MPI_Win.  */
     rc = MPI_Alloc_mem(put_size, MPI_INFO_NULL, (void *) &local_buf);
     if (rc) {
-       MTestPrintErrorMsg( "Unable to MPI_Alloc_mem space (not an error)", rc );
-       MPI_Abort( MPI_COMM_WORLD, 0 );
+        MTestPrintErrorMsg("Unable to MPI_Alloc_mem space (not an error)", rc);
+        MPI_Abort(MPI_COMM_WORLD, 0);
     }
 
     for (i = 0; i < put_size; i++)
@@ -98,7 +96,7 @@ int main(int argc, char **argv)
 
     MPI_Barrier(MPI_COMM_WORLD);
 
-    if (comm_rank == 0) { /* target */
+    if (comm_rank == 0) {       /* target */
         for (i = 0; i < (NUM_TIMES * (comm_size - 2)); i++) {
             /* Wait for a message from the server to notify me that
              * someone put some data in my window */
@@ -108,9 +106,8 @@ int main(int argc, char **argv)
              * data in my local window. Check the last byte to make
              * sure we got it correctly. */
             MPI_Win_lock(MPI_LOCK_SHARED, 0, 0, win);
-            MPI_Get((void *) &check, 1, MPI_CHAR, 0, 
-                   ((by_rank + 1) * put_size) - 1, 1,
-                    MPI_CHAR, win);
+            MPI_Get((void *) &check, 1, MPI_CHAR, 0,
+                    ((by_rank + 1) * put_size) - 1, 1, MPI_CHAR, win);
             MPI_Win_unlock(0, win);
 
             /* If this is not the value I expect, count it as an error */
@@ -125,13 +122,12 @@ int main(int argc, char **argv)
         }
     }
 
-    else if (comm_rank == 1) { /* server */
+    else if (comm_rank == 1) {  /* server */
         for (i = 0; i < (NUM_TIMES * (comm_size - 2)); i++) {
             /* Wait for a message from any of the origin processes
              * informing me that it has put data to the target
              * process */
-            MPI_Recv(NULL, 0, MPI_INT, MPI_ANY_SOURCE, 0, MPI_COMM_WORLD, 
-                    &status);
+            MPI_Recv(NULL, 0, MPI_INT, MPI_ANY_SOURCE, 0, MPI_COMM_WORLD, &status);
             by_rank = status.MPI_SOURCE;
 
             /* Tell the target process that it should be seeing some
@@ -140,12 +136,12 @@ int main(int argc, char **argv)
         }
     }
 
-    else { /* origin */
+    else {      /* origin */
         for (i = 0; i < NUM_TIMES; i++) {
             /* Put some data in the target window */
             MPI_Win_lock(MPI_LOCK_SHARED, 0, 0, win);
-            MPI_Put(local_buf, put_size, MPI_CHAR, 0, comm_rank * put_size, 
-                   put_size, MPI_CHAR, win);
+            MPI_Put(local_buf, put_size, MPI_CHAR, 0, comm_rank * put_size,
+                    put_size, MPI_CHAR, win);
             MPI_Win_unlock(0, win);
 
             /* Tell the server that the put has completed */
diff --git a/teshsuite/smpi/mpich3-test/rma/aint.c b/teshsuite/smpi/mpich3-test/rma/aint.c
new file mode 100644 (file)
index 0000000..72c10d2
--- /dev/null
@@ -0,0 +1,82 @@
+/* -*- Mode: C; c-basic-offset:4 ; indent-tabs-mode:nil ; -*- */
+/*
+ *
+ *  (C) 2014 by Argonne National Laboratory.
+ *      See COPYRIGHT in top-level directory.
+ */
+
+/*
+ * This program tests MPI_Aint_add/diff in MPI-3.1.
+ * The two functions are often used in RMA code.
+ * See https://svn.mpi-forum.org/trac/mpi-forum-web/ticket/349
+ */
+
+#include <stdio.h>
+#include <mpi.h>
+#include "mpitest.h"
+
+int main(int argc, char **argv)
+{
+    int rank, nproc;
+    int errs = 0;
+    int array[1024];
+    int val = 0;
+    int target_rank;
+    MPI_Aint bases[2];
+    MPI_Aint disp, offset;
+    MPI_Win win;
+
+    MTest_Init(&argc, &argv);
+
+    MPI_Comm_rank(MPI_COMM_WORLD, &rank);
+    MPI_Comm_size(MPI_COMM_WORLD, &nproc);
+
+    if (rank == 0 && nproc != 2) {
+        MTestError("Must run with 2 ranks\n");
+    }
+
+    /* Get the base address in the middle of the array */
+    if (rank == 0) {
+        target_rank = 1;
+        array[0] = 1234;
+        MPI_Get_address(&array[512], &bases[0]);
+    }
+    else if (rank == 1) {
+        target_rank = 0;
+        array[1023] = 1234;
+        MPI_Get_address(&array[512], &bases[1]);
+    }
+
+    /* Exchange bases */
+    MPI_Allgather(MPI_IN_PLACE, 0, MPI_DATATYPE_NULL, bases, 1, MPI_AINT, MPI_COMM_WORLD);
+
+    MPI_Win_create_dynamic(MPI_INFO_NULL, MPI_COMM_WORLD, &win);
+    MPI_Win_attach(win, array, sizeof(int) * 1024);
+
+    /* Do MPI_Aint addressing arithmetic */
+    if (rank == 0) {
+        disp = sizeof(int) * 511;
+        offset = MPI_Aint_add(bases[1], disp);  /* offset points to array[1023] */
+    }
+    else if (rank == 1) {
+        disp = sizeof(int) * 512;
+        offset = MPI_Aint_diff(bases[0], disp); /* offset points to array[0] */
+    }
+
+    /* Get val and verify it */
+    MPI_Win_fence(MPI_MODE_NOPRECEDE, win);
+    MPI_Get(&val, 1, MPI_INT, target_rank, offset, 1, MPI_INT, win);
+    MPI_Win_fence(MPI_MODE_NOSUCCEED, win);
+
+    if (val != 1234) {
+        errs++;
+        printf("%d -- Got %d, expected 1234\n", rank, val);
+    }
+
+    MPI_Win_detach(win, array);
+    MPI_Win_free(&win);
+
+    MTest_Finalize(errs);
+    MPI_Finalize();
+    return 0;
+}
index 1969941..1255628 100644 (file)
 static char MTEST_Descrip[] = "Simple test that alloc_mem and free_mem work together";
 */
 
-int main( int argc, char *argv[] )
+int main(int argc, char *argv[])
 {
     int errs = 0, err;
     int j, count;
     char *ap;
 
-    MTest_Init( &argc, &argv );
+    MTest_Init(&argc, &argv);
 
-    MPI_Errhandler_set( MPI_COMM_WORLD, MPI_ERRORS_RETURN );
-    for (count=1; count < 128000; count *= 2) {
-       
-       err = MPI_Alloc_mem( count, MPI_INFO_NULL, &ap );
-       if (err) {
-           int errclass;
-           /* An error of  MPI_ERR_NO_MEM is allowed */
-           MPI_Error_class( err, &errclass );
-           if (errclass != MPI_ERR_NO_MEM) {
-               errs++;
-               MTestPrintError( err );
-           }
-           
-       }
-       else {
-           /* Access all of this memory */
-           for (j=0; j<count; j++) {
-               ap[j] = (char)(j & 0x7f);
-           }
-           MPI_Free_mem( ap );
-       }
+    MPI_Errhandler_set(MPI_COMM_WORLD, MPI_ERRORS_RETURN);
+    for (count = 1; count < 128000; count *= 2) {
+
+        err = MPI_Alloc_mem(count, MPI_INFO_NULL, &ap);
+        if (err) {
+            int errclass;
+            /* An error of  MPI_ERR_NO_MEM is allowed */
+            MPI_Error_class(err, &errclass);
+            if (errclass != MPI_ERR_NO_MEM) {
+                errs++;
+                MTestPrintError(err);
+            }
+
+        }
+        else {
+            /* Access all of this memory */
+            for (j = 0; j < count; j++) {
+                ap[j] = (char) (j & 0x7f);
+            }
+            MPI_Free_mem(ap);
+        }
     }
 
-    MTest_Finalize( errs );
+    MTest_Finalize(errs);
     MPI_Finalize();
     return 0;
 }
diff --git a/teshsuite/smpi/mpich3-test/rma/at_complete.c b/teshsuite/smpi/mpich3-test/rma/at_complete.c
new file mode 100644 (file)
index 0000000..f389a30
--- /dev/null
@@ -0,0 +1,140 @@
+/* -*- Mode: C; c-basic-offset:4 ; indent-tabs-mode:nil ; -*- */
+/*
+ *  (C) 2014 by Argonne National Laboratory.
+ *      See COPYRIGHT in top-level directory.
+ */
+
+#include <stdio.h>
+#include <mpi.h>
+
+#define PUT_SIZE 1
+#define GET_SIZE 100000
+#define WIN_SIZE (PUT_SIZE+GET_SIZE)
+#define LOOP 100
+
+int main(int argc, char **argv)
+{
+    MPI_Win win;
+    int i, k, rank, nproc;
+    int win_buf[WIN_SIZE], orig_get_buf[GET_SIZE], orig_put_buf[PUT_SIZE];
+    int orig_rank = 0, dest_rank = 1;
+    int errors = 0;
+    MPI_Group comm_group, orig_group, dest_group;
+
+    MPI_Init(&argc, &argv);
+
+    MPI_Comm_rank(MPI_COMM_WORLD, &rank);
+    MPI_Comm_size(MPI_COMM_WORLD, &nproc);
+
+    MPI_Comm_group(MPI_COMM_WORLD, &comm_group);
+    MPI_Group_incl(comm_group, 1, &orig_rank, &orig_group);
+    MPI_Group_incl(comm_group, 1, &dest_rank, &dest_group);
+
+    for (i = 0; i < PUT_SIZE; i++)
+        orig_put_buf[i] = 1;
+    for (i = 0; i < GET_SIZE; i++)
+        orig_get_buf[i] = 0;
+    for (i = 0; i < WIN_SIZE; i++)
+        win_buf[i] = 1;
+
+    MPI_Win_create(win_buf, sizeof(int) * WIN_SIZE, sizeof(int), MPI_INFO_NULL,
+                   MPI_COMM_WORLD, &win);
+
+    for (k = 0; k < LOOP; k++) {
+
+        /* test for FENCE */
+
+        if (rank == orig_rank) {
+            MPI_Win_fence(MPI_MODE_NOPRECEDE, win);
+            MPI_Get(orig_get_buf, GET_SIZE, MPI_INT,
+                    dest_rank, PUT_SIZE /*disp */ , GET_SIZE, MPI_INT, win);
+            MPI_Put(orig_put_buf, PUT_SIZE, MPI_INT,
+                    dest_rank, 0 /*disp */ , PUT_SIZE, MPI_INT, win);
+            MPI_Win_fence(MPI_MODE_NOSUCCEED, win);
+
+            /* check GET result values */
+            for (i = 0; i < GET_SIZE; i++) {
+                if (orig_get_buf[i] != 1) {
+                    printf("LOOP=%d, FENCE, orig_get_buf[%d] = %d, expected 1.\n",
+                           k, i, orig_get_buf[i]);
+                    errors++;
+                }
+            }
+        }
+        else if (rank == dest_rank) {
+            MPI_Win_fence(MPI_MODE_NOPRECEDE, win);
+            MPI_Win_fence(MPI_MODE_NOSUCCEED, win);
+
+            /* modify the last element in window */
+            MPI_Win_lock(MPI_LOCK_SHARED, rank, 0, win);
+            win_buf[WIN_SIZE - 1] = 2;
+            MPI_Win_unlock(rank, win);
+        }
+
+        MPI_Barrier(MPI_COMM_WORLD);
+        /* reset buffers */
+        for (i = 0; i < PUT_SIZE; i++)
+            orig_put_buf[i] = 1;
+        for (i = 0; i < GET_SIZE; i++)
+            orig_get_buf[i] = 0;
+        MPI_Win_lock(MPI_LOCK_SHARED, rank, 0, win);
+        for (i = 0; i < WIN_SIZE; i++)
+            win_buf[i] = 1;
+        MPI_Win_unlock(rank, win);
+        MPI_Barrier(MPI_COMM_WORLD);
+
+        /* test for PSCW */
+
+        if (rank == orig_rank) {
+            MPI_Win_start(dest_group, 0, win);
+            MPI_Get(orig_get_buf, GET_SIZE, MPI_INT,
+                    dest_rank, PUT_SIZE /*disp */ , GET_SIZE, MPI_INT, win);
+            MPI_Put(orig_put_buf, PUT_SIZE, MPI_INT,
+                    dest_rank, 0 /*disp */ , PUT_SIZE, MPI_INT, win);
+            MPI_Win_complete(win);
+
+            /* check GET result values */
+            for (i = 0; i < GET_SIZE; i++) {
+                if (orig_get_buf[i] != 1) {
+                    printf("LOOP=%d, PSCW, orig_get_buf[%d] = %d, expected 1.\n",
+                           k, i, orig_get_buf[i]);
+                    errors++;
+                }
+            }
+        }
+        else if (rank == dest_rank) {
+            MPI_Win_post(orig_group, 0, win);
+            MPI_Win_wait(win);
+
+            /* modify the last element in window */
+            MPI_Win_lock(MPI_LOCK_SHARED, rank, 0, win);
+            win_buf[WIN_SIZE - 1] = 2;
+            MPI_Win_unlock(rank, win);
+        }
+
+        MPI_Barrier(MPI_COMM_WORLD);
+        /* reset buffers */
+        for (i = 0; i < PUT_SIZE; i++)
+            orig_put_buf[i] = 1;
+        for (i = 0; i < GET_SIZE; i++)
+            orig_get_buf[i] = 0;
+        MPI_Win_lock(MPI_LOCK_SHARED, rank, 0, win);
+        for (i = 0; i < WIN_SIZE; i++)
+            win_buf[i] = 1;
+        MPI_Win_unlock(rank, win);
+        MPI_Barrier(MPI_COMM_WORLD);
+    }
+
+    MPI_Win_free(&win);
+
+    MPI_Group_free(&orig_group);
+    MPI_Group_free(&dest_group);
+    MPI_Group_free(&comm_group);
+
+    if (rank == orig_rank && errors == 0) {
+        printf(" No Errors\n");
+    }
+
+    MPI_Finalize();
+    return 0;
+}
diff --git a/teshsuite/smpi/mpich3-test/rma/atomic_get.c b/teshsuite/smpi/mpich3-test/rma/atomic_get.c
new file mode 100644 (file)
index 0000000..54bffa6
--- /dev/null
@@ -0,0 +1,183 @@
+/* -*- Mode: C; c-basic-offset:4 ; indent-tabs-mode:nil ; -*- */
+/*
+ *  (C) 2015 by Argonne National Laboratory.
+ *      See COPYRIGHT in top-level directory.
+ */
+
+/* This test is going to test atomic GET (GACC/FOP+MPI_NO_OP).
+ *
+ * There are totally three processes involved in this test. Both
+ * rank 1 and rank 2 issue RMA operations to rank 0. Rank 2 issues
+ * atomic PUT (ACC+MPI_REPLACE), whereas rank 1 issues atomic
+ * GET (GACC/FOP+MPI_NO_OP). The datatype used in the test is
+ * pair-type. The initial value of pair-type data in origin buffer
+ * of atomic PUT is set so that the two basic values equal with
+ * each other. Due to the atomicity of GET, the expected resulting
+ * data should also have equivalent basic values. */
+
+#include "mpi.h"
+#include <stdio.h>
+
+#define LOOP 100
+#define DATA_SIZE 100
+#define OPS_NUM 10000
+#define GACC_SZ 10
+
+typedef struct pair_struct {
+    long double a;
+    int b;
+} pair_struct_t;
+
+int main(int argc, char *argv[])
+{
+    int rank, nproc;
+    int i, j, k;
+    int errors = 0, curr_errors = 0;
+    MPI_Win win;
+    pair_struct_t *tar_buf = NULL;
+    pair_struct_t *orig_buf = NULL;
+    pair_struct_t *result_buf = NULL;
+
+    /* This test needs to work with 3 processes. */
+
+    MPI_Init(&argc, &argv);
+
+    MPI_Comm_size(MPI_COMM_WORLD, &nproc);
+    MPI_Comm_rank(MPI_COMM_WORLD, &rank);
+
+    MPI_Alloc_mem(sizeof(pair_struct_t) * DATA_SIZE, MPI_INFO_NULL, &orig_buf);
+    MPI_Alloc_mem(sizeof(pair_struct_t) * DATA_SIZE, MPI_INFO_NULL, &result_buf);
+
+    MPI_Win_allocate(sizeof(pair_struct_t) * DATA_SIZE, sizeof(pair_struct_t),
+                     MPI_INFO_NULL, MPI_COMM_WORLD, &tar_buf, &win);
+
+    for (j = 0; j < LOOP * 6; j++) {
+
+        MPI_Win_lock(MPI_LOCK_EXCLUSIVE, rank, 0, win);
+
+        /* initialize data */
+        for (i = 0; i < DATA_SIZE; i++) {
+            tar_buf[i].a = 0.0;
+            tar_buf[i].b = 0;
+            result_buf[i].a = 0.0;
+            result_buf[i].b = 0;
+        }
+
+        MPI_Win_unlock(rank, win);
+
+        MPI_Barrier(MPI_COMM_WORLD);
+
+        MPI_Win_fence(0, win);
+
+        if (rank == 2) {
+            if (j < 2 * LOOP) {
+                /* Work with FOP test (Test #1 to Test #2) */
+                for (i = 0; i < OPS_NUM; i++) {
+
+                    int curr_val = j * OPS_NUM + i;
+                    orig_buf[0].a = (long double) (curr_val);
+                    orig_buf[0].b = curr_val;
+
+                    MPI_Accumulate(orig_buf, 1, MPI_LONG_DOUBLE_INT,
+                                   0, 0, 1, MPI_LONG_DOUBLE_INT, MPI_REPLACE, win);
+                }
+            }
+            else {
+                /* Work with GACC test (Test #3 to Test #6) */
+                for (i = 0; i < OPS_NUM / GACC_SZ; i++) {
+
+                    for (k = 0; k < GACC_SZ; k++) {
+                        int curr_val = j * OPS_NUM + i * GACC_SZ + k;
+                        orig_buf[k].a = (long double) (curr_val);
+                        orig_buf[k].b = curr_val;
+                    }
+
+                    MPI_Accumulate(orig_buf, GACC_SZ, MPI_LONG_DOUBLE_INT,
+                                   0, 0, GACC_SZ, MPI_LONG_DOUBLE_INT, MPI_REPLACE, win);
+                }
+            }
+        }
+        else if (rank == 1) {
+            /* equals to an atomic GET */
+            if (j < LOOP) {
+                for (i = 0; i < DATA_SIZE; i++) {
+                    /* Test #1: FOP + MPI_NO_OP */
+                    MPI_Fetch_and_op(orig_buf, &(result_buf[i]), MPI_LONG_DOUBLE_INT,
+                                     0, 0, MPI_NO_OP, win);
+                }
+            }
+            else if (j < 2 * LOOP) {
+                for (i = 0; i < DATA_SIZE; i++) {
+                    /* Test #2: FOP + MPI_NO_OP + NULL origin buffer address */
+                    MPI_Fetch_and_op(NULL, &(result_buf[i]), MPI_LONG_DOUBLE_INT,
+                                     0, 0, MPI_NO_OP, win);
+                }
+            }
+            else if (j < 3 * LOOP) {
+                for (i = 0; i < DATA_SIZE / GACC_SZ; i++) {
+                    /* Test #3: GACC + MPI_NO_OP */
+                    MPI_Get_accumulate(orig_buf, GACC_SZ, MPI_LONG_DOUBLE_INT,
+                                       &(result_buf[i * GACC_SZ]), GACC_SZ, MPI_LONG_DOUBLE_INT,
+                                       0, 0, GACC_SZ, MPI_LONG_DOUBLE_INT, MPI_NO_OP, win);
+                }
+            }
+            else if (j < 4 * LOOP) {
+                for (i = 0; i < DATA_SIZE / GACC_SZ; i++) {
+                    /* Test #4: GACC + MPI_NO_OP + NULL origin buffer address */
+                    MPI_Get_accumulate(NULL, GACC_SZ, MPI_LONG_DOUBLE_INT,
+                                       &(result_buf[i * GACC_SZ]), GACC_SZ, MPI_LONG_DOUBLE_INT,
+                                       0, 0, GACC_SZ, MPI_LONG_DOUBLE_INT, MPI_NO_OP, win);
+                }
+            }
+            else if (j < 5 * LOOP) {
+                for (i = 0; i < DATA_SIZE / GACC_SZ; i++) {
+                    /* Test #5: GACC + MPI_NO_OP + zero origin count */
+                    MPI_Get_accumulate(orig_buf, 0, MPI_LONG_DOUBLE_INT,
+                                       &(result_buf[i * GACC_SZ]), GACC_SZ, MPI_LONG_DOUBLE_INT,
+                                       0, 0, GACC_SZ, MPI_LONG_DOUBLE_INT, MPI_NO_OP, win);
+                }
+            }
+            else if (j < 6 * LOOP) {
+                for (i = 0; i < DATA_SIZE / GACC_SZ; i++) {
+                    /* Test #5: GACC + MPI_NO_OP + NULL origin datatype */
+                    MPI_Get_accumulate(orig_buf, GACC_SZ, MPI_DATATYPE_NULL,
+                                       &(result_buf[i * GACC_SZ]), GACC_SZ, MPI_LONG_DOUBLE_INT,
+                                       0, 0, GACC_SZ, MPI_LONG_DOUBLE_INT, MPI_NO_OP, win);
+                }
+            }
+        }
+
+        MPI_Win_fence(0, win);
+
+        /* check results */
+        if (rank == 1) {
+            for (i = 0; i < DATA_SIZE; i++) {
+                if (result_buf[i].a != (long double) (result_buf[i].b)) {
+                    if (curr_errors < 10) {
+                        printf("LOOP %d: result_buf[%d].a = %Lf, result_buf[%d].b = %d\n",
+                               j, i, result_buf[i].a, i, result_buf[i].b);
+                    }
+                    curr_errors++;
+                }
+            }
+        }
+
+        if (j % LOOP == 0) {
+            errors += curr_errors;
+            curr_errors = 0;
+        }
+    }
+
+    MPI_Win_free(&win);
+
+    MPI_Free_mem(orig_buf);
+    MPI_Free_mem(result_buf);
+
+    if (rank == 1) {
+        if (errors == 0)
+            printf(" No Errors\n");
+    }
+
+    MPI_Finalize();
+    return 0;
+}
diff --git a/teshsuite/smpi/mpich3-test/rma/atomic_rmw_cas.c b/teshsuite/smpi/mpich3-test/rma/atomic_rmw_cas.c
new file mode 100644 (file)
index 0000000..dfd7228
--- /dev/null
@@ -0,0 +1,137 @@
+/* -*- Mode: C; c-basic-offset:4 ; indent-tabs-mode:nil ; -*- */
+/*
+ *
+ *  (C) 2015 by Argonne National Laboratory.
+ *      See COPYRIGHT in top-level directory.
+ */
+
+/* This test is going to test the atomicity for "read-modify-write" in CAS
+ * operations */
+
+/* There are three processes involved in this test: P0 (origin_shm), P1 (origin_am),
+ * and P2 (dest). P0 and P1 issues one CAS to P2 via SHM and AM respectively.
+ * For P0, origin value is 1 and compare value is 0; for P1, origin value is 0 and
+ * compare value is 1; for P2, initial target value is 0. The correct results can
+ * only be one of the following cases:
+ *
+ *   (1) result value on P0: 0, result value on P1: 0, target value on P2: 1.
+ *   (2) result value on P0: 0, result value on P1: 1, target value on P2: 0.
+ *
+ * All other results are not correct. */
+
+#include "mpi.h"
+#include <stdio.h>
+
+#define LOOP_SIZE 10000
+#define CHECK_TAG 123
+
+int main(int argc, char *argv[])
+{
+    int rank, size, k;
+    int errors = 0;
+    int origin_shm, origin_am, dest;
+    int *orig_buf = NULL, *result_buf = NULL, *compare_buf = NULL,
+        *target_buf = NULL, *check_buf = NULL;
+    int target_value = 0;
+    MPI_Win win;
+
+    MPI_Init(&argc, &argv);
+
+    MPI_Comm_rank(MPI_COMM_WORLD, &rank);
+    MPI_Comm_size(MPI_COMM_WORLD, &size);
+    if (size != 3) {
+        /* run this test with three processes */
+        goto exit_test;
+    }
+
+    /* this works when MPIR_PARAM_CH3_ODD_EVEN_CLIQUES is set */
+    dest = 2;
+    origin_shm = 0;
+    origin_am = 1;
+
+    if (rank != dest) {
+        MPI_Alloc_mem(sizeof(int), MPI_INFO_NULL, &orig_buf);
+        MPI_Alloc_mem(sizeof(int), MPI_INFO_NULL, &result_buf);
+        MPI_Alloc_mem(sizeof(int), MPI_INFO_NULL, &compare_buf);
+    }
+
+    MPI_Win_allocate(sizeof(int), sizeof(int), MPI_INFO_NULL, MPI_COMM_WORLD, &target_buf, &win);
+
+    for (k = 0; k < LOOP_SIZE; k++) {
+
+        /* init buffers */
+        if (rank == origin_shm) {
+            orig_buf[0] = 1;
+            compare_buf[0] = 0;
+            result_buf[0] = 0;
+        }
+        else if (rank == origin_am) {
+            orig_buf[0] = 0;
+            compare_buf[0] = 1;
+            result_buf[0] = 0;
+        }
+        else {
+            MPI_Win_lock(MPI_LOCK_SHARED, rank, 0, win);
+            target_buf[0] = 0;
+            MPI_Win_unlock(rank, win);
+        }
+
+        MPI_Barrier(MPI_COMM_WORLD);
+
+        /* perform FOP */
+        MPI_Win_lock_all(0, win);
+        if (rank != dest) {
+            MPI_Compare_and_swap(orig_buf, compare_buf, result_buf, MPI_INT, dest, 0, win);
+            MPI_Win_flush(dest, win);
+        }
+        MPI_Win_unlock_all(win);
+
+        MPI_Barrier(MPI_COMM_WORLD);
+
+        /* check results */
+        if (rank != dest) {
+            MPI_Gather(result_buf, 1, MPI_INT, check_buf, 1, MPI_INT, dest, MPI_COMM_WORLD);
+        }
+        else {
+            MPI_Win_lock(MPI_LOCK_SHARED, rank, 0, win);
+            target_value = target_buf[0];
+            MPI_Win_unlock(rank, win);
+
+            MPI_Alloc_mem(sizeof(int) * 3, MPI_INFO_NULL, &check_buf);
+            MPI_Gather(&target_value, 1, MPI_INT, check_buf, 1, MPI_INT, dest, MPI_COMM_WORLD);
+
+            if (!(check_buf[dest] == 0 && check_buf[origin_shm] == 0 && check_buf[origin_am] == 1)
+                && !(check_buf[dest] == 1 && check_buf[origin_shm] == 0 &&
+                     check_buf[origin_am] == 0)) {
+
+                printf
+                    ("Wrong results: target result = %d, origin_shm result = %d, origin_am result = %d\n",
+                     check_buf[dest], check_buf[origin_shm], check_buf[origin_am]);
+
+                printf
+                    ("Expected results (1): target result = 1, origin_shm result = 0, origin_am result = 0\n");
+                printf
+                    ("Expected results (2): target result = 0, origin_shm result = 0, origin_am result = 1\n");
+
+                errors++;
+            }
+
+            MPI_Free_mem(check_buf);
+        }
+    }
+
+    MPI_Win_free(&win);
+
+    if (rank == origin_am || rank == origin_shm) {
+        MPI_Free_mem(orig_buf);
+        MPI_Free_mem(result_buf);
+        MPI_Free_mem(compare_buf);
+    }
+
+  exit_test:
+    if (rank == dest && errors == 0)
+        printf(" No Errors\n");
+
+    MPI_Finalize();
+    return 0;
+}
diff --git a/teshsuite/smpi/mpich3-test/rma/atomic_rmw_fop.c b/teshsuite/smpi/mpich3-test/rma/atomic_rmw_fop.c
new file mode 100644 (file)
index 0000000..42875f6
--- /dev/null
@@ -0,0 +1,143 @@
+/* -*- Mode: C; c-basic-offset:4 ; indent-tabs-mode:nil ; -*- */
+/*
+ *
+ *  (C) 2015 by Argonne National Laboratory.
+ *      See COPYRIGHT in top-level directory.
+ */
+
+/* This test is going to test the atomicity for "read-modify-write" in FOP
+ * operations */
+
+/* There are three processes involved in this test: P0 (origin_shm), P1 (origin_am),
+ * and P2 (dest). P0 and P1 issues multiple FOP with MPI_SUM and integer (value 1)
+ * to P2 via SHM and AM respectively. The correct results should be that the
+ * results on P0 and P1 never be the same. */
+
+#include "mpi.h"
+#include <stdio.h>
+
+#define AM_BUF_SIZE  10
+#define SHM_BUF_SIZE 1000
+#define WIN_BUF_SIZE 1
+
+#define LOOP_SIZE 15
+#define CHECK_TAG 123
+
+int main(int argc, char *argv[])
+{
+    int rank, size, i, j, k;
+    int errors = 0, all_errors = 0;
+    int origin_shm, origin_am, dest;
+    int my_buf_size;
+    int *orig_buf = NULL, *result_buf = NULL, *target_buf = NULL, *check_buf = NULL;
+    MPI_Win win;
+    MPI_Status status;
+
+    MPI_Init(&argc, &argv);
+
+    MPI_Comm_rank(MPI_COMM_WORLD, &rank);
+    MPI_Comm_size(MPI_COMM_WORLD, &size);
+    if (size != 3) {
+        /* run this test with three processes */
+        goto exit_test;
+    }
+
+    /* this works when MPIR_PARAM_CH3_ODD_EVEN_CLIQUES is set */
+    dest = 2;
+    origin_shm = 0;
+    origin_am = 1;
+
+    if (rank == origin_am)
+        my_buf_size = AM_BUF_SIZE;
+    else if (rank == origin_shm)
+        my_buf_size = SHM_BUF_SIZE;
+
+    if (rank != dest) {
+        MPI_Alloc_mem(sizeof(int) * my_buf_size, MPI_INFO_NULL, &orig_buf);
+        MPI_Alloc_mem(sizeof(int) * my_buf_size, MPI_INFO_NULL, &result_buf);
+    }
+
+    MPI_Win_allocate(sizeof(int) * WIN_BUF_SIZE, sizeof(int), MPI_INFO_NULL,
+                     MPI_COMM_WORLD, &target_buf, &win);
+
+    for (k = 0; k < LOOP_SIZE; k++) {
+
+        /* init buffers */
+        if (rank != dest) {
+            for (i = 0; i < my_buf_size; i++) {
+                orig_buf[i] = 1;
+                result_buf[i] = 0;
+            }
+        }
+        else {
+            MPI_Win_lock(MPI_LOCK_SHARED, rank, 0, win);
+            for (i = 0; i < WIN_BUF_SIZE; i++) {
+                target_buf[i] = 0;
+            }
+            MPI_Win_unlock(rank, win);
+        }
+
+        MPI_Barrier(MPI_COMM_WORLD);
+
+        /* perform FOP */
+        MPI_Win_lock_all(0, win);
+        if (rank != dest) {
+            for (i = 0; i < my_buf_size; i++) {
+                MPI_Fetch_and_op(&(orig_buf[i]), &(result_buf[i]), MPI_INT, dest, 0, MPI_SUM, win);
+                MPI_Win_flush(dest, win);
+            }
+        }
+        MPI_Win_unlock_all(win);
+
+        MPI_Barrier(MPI_COMM_WORLD);
+
+        if (rank != dest) {
+            /* check results on P0 and P2 (origin) */
+            if (rank == origin_am) {
+                MPI_Send(result_buf, AM_BUF_SIZE, MPI_INT, origin_shm, CHECK_TAG, MPI_COMM_WORLD);
+            }
+            else if (rank == origin_shm) {
+                MPI_Alloc_mem(sizeof(int) * AM_BUF_SIZE, MPI_INFO_NULL, &check_buf);
+                MPI_Recv(check_buf, AM_BUF_SIZE, MPI_INT, origin_am, CHECK_TAG, MPI_COMM_WORLD,
+                         &status);
+                for (i = 0; i < AM_BUF_SIZE; i++) {
+                    for (j = 0; j < SHM_BUF_SIZE; j++) {
+                        if (check_buf[i] == result_buf[j]) {
+                            printf
+                                ("LOOP=%d, rank=%d, FOP, both check_buf[%d] and result_buf[%d] equal to %d, expected to be different. \n",
+                                 k, rank, i, j, check_buf[i]);
+                            errors++;
+                        }
+                    }
+                }
+                MPI_Free_mem(check_buf);
+            }
+        }
+        else {
+            MPI_Win_lock(MPI_LOCK_SHARED, rank, 0, win);
+            /* check results on P1 */
+            if (target_buf[0] != AM_BUF_SIZE + SHM_BUF_SIZE) {
+                printf("LOOP=%d, rank=%d, FOP, target_buf[0] = %d, expected %d. \n",
+                       k, rank, target_buf[0], AM_BUF_SIZE + SHM_BUF_SIZE);
+                errors++;
+            }
+            MPI_Win_unlock(rank, win);
+        }
+    }
+
+    MPI_Win_free(&win);
+
+    if (rank == origin_am || rank == origin_shm) {
+        MPI_Free_mem(orig_buf);
+        MPI_Free_mem(result_buf);
+    }
+
+  exit_test:
+    MPI_Reduce(&errors, &all_errors, 1, MPI_INT, MPI_SUM, 0, MPI_COMM_WORLD);
+
+    if (rank == 0 && all_errors == 0)
+        printf(" No Errors\n");
+
+    MPI_Finalize();
+    return 0;
+}
diff --git a/teshsuite/smpi/mpich3-test/rma/atomic_rmw_gacc.c b/teshsuite/smpi/mpich3-test/rma/atomic_rmw_gacc.c
new file mode 100644 (file)
index 0000000..0e73e2d
--- /dev/null
@@ -0,0 +1,276 @@
+/* -*- Mode: C; c-basic-offset:4 ; indent-tabs-mode:nil ; -*- */
+/*
+ *
+ *  (C) 2015 by Argonne National Laboratory.
+ *      See COPYRIGHT in top-level directory.
+ */
+
+/* This test is going to test the atomicity for "read-modify-write" in GACC
+ * operations */
+
+/* This test is similiar with atomic_rmw_fop.c.
+ * There are three processes involved in this test: P0 (origin_shm), P1 (origin_am),
+ * and P2 (dest). P0 and P1 issues multiple GACC with MPI_SUM and OP_COUNT integers
+ * (value 1) to P2 via SHM and AM respectively. The correct results should be that the
+ * results on P0 and P1 never be the same for intergers on the corresponding index
+ * in [0...OP_COUNT-1].
+ */
+
+#include "mpi.h"
+#include <stdio.h>
+
+#define OP_COUNT 10
+#define AM_BUF_NUM  10
+#define SHM_BUF_NUM 10000
+#define WIN_BUF_NUM 1
+
+#define LOOP_SIZE 15
+#define CHECK_TAG 123
+
+int rank, size;
+int dest, origin_shm, origin_am;
+int *orig_buf = NULL, *result_buf = NULL, *target_buf = NULL, *check_buf = NULL;
+MPI_Win win;
+
+void checkResults(int loop_k, int *errors)
+{
+    int i, j, m;
+    MPI_Status status;
+
+    if (rank != dest) {
+        /* check results on P0 and P2 (origin) */
+        if (rank == origin_am) {
+            MPI_Send(result_buf, AM_BUF_NUM * OP_COUNT, MPI_INT, origin_shm, CHECK_TAG,
+                     MPI_COMM_WORLD);
+        }
+        else if (rank == origin_shm) {
+            MPI_Alloc_mem(sizeof(int) * AM_BUF_NUM * OP_COUNT, MPI_INFO_NULL, &check_buf);
+            MPI_Recv(check_buf, AM_BUF_NUM * OP_COUNT, MPI_INT, origin_am, CHECK_TAG,
+                     MPI_COMM_WORLD, &status);
+            for (i = 0; i < AM_BUF_NUM; i++) {
+                for (j = 0; j < SHM_BUF_NUM; j++) {
+                    for (m = 0; m < OP_COUNT; m++) {
+                        if (check_buf[i * OP_COUNT + m] == result_buf[j * OP_COUNT + m]) {
+                            printf
+                                ("LOOP=%d, rank=%d, FOP, both check_buf[%d] and result_buf[%d] equal to %d, expected to be different. \n",
+                                 loop_k, rank, i * OP_COUNT + m, j * OP_COUNT + m,
+                                 check_buf[i * OP_COUNT + m]);
+                            (*errors)++;
+                        }
+                    }
+                }
+            }
+            MPI_Free_mem(check_buf);
+        }
+    }
+    else {
+        MPI_Win_lock(MPI_LOCK_SHARED, rank, 0, win);
+        /* check results on P1 */
+        for (i = 0; i < OP_COUNT; i++) {
+            if (target_buf[i] != AM_BUF_NUM + SHM_BUF_NUM) {
+                printf("LOOP=%d, rank=%d, FOP, target_buf[%d] = %d, expected %d. \n",
+                       loop_k, rank, i, target_buf[i], AM_BUF_NUM + SHM_BUF_NUM);
+                (*errors)++;
+            }
+        }
+        MPI_Win_unlock(rank, win);
+    }
+}
+
+int main(int argc, char *argv[])
+{
+    int i, k;
+    int errors = 0, all_errors = 0;
+    int my_buf_num;
+    MPI_Datatype origin_dtp, target_dtp;
+
+    MPI_Init(&argc, &argv);
+
+    MPI_Comm_rank(MPI_COMM_WORLD, &rank);
+    MPI_Comm_size(MPI_COMM_WORLD, &size);
+    if (size != 3) {
+        /* run this test with three processes */
+        goto exit_test;
+    }
+
+    MPI_Type_contiguous(OP_COUNT, MPI_INT, &origin_dtp);
+    MPI_Type_commit(&origin_dtp);
+    MPI_Type_contiguous(OP_COUNT, MPI_INT, &target_dtp);
+    MPI_Type_commit(&target_dtp);
+
+    /* this works when MPIR_PARAM_CH3_ODD_EVEN_CLIQUES is set */
+    dest = 2;
+    origin_shm = 0;
+    origin_am = 1;
+
+    if (rank == origin_am)
+        my_buf_num = AM_BUF_NUM;
+    else if (rank == origin_shm)
+        my_buf_num = SHM_BUF_NUM;
+
+    if (rank != dest) {
+        MPI_Alloc_mem(sizeof(int) * my_buf_num * OP_COUNT, MPI_INFO_NULL, &orig_buf);
+        MPI_Alloc_mem(sizeof(int) * my_buf_num * OP_COUNT, MPI_INFO_NULL, &result_buf);
+    }
+
+    MPI_Win_allocate(sizeof(int) * WIN_BUF_NUM * OP_COUNT, sizeof(int), MPI_INFO_NULL,
+                     MPI_COMM_WORLD, &target_buf, &win);
+
+    for (k = 0; k < LOOP_SIZE; k++) {
+
+        /* ====== Part 1: test basic datatypes ======== */
+
+        /* init buffers */
+        if (rank != dest) {
+            for (i = 0; i < my_buf_num * OP_COUNT; i++) {
+                orig_buf[i] = 1;
+                result_buf[i] = 0;
+            }
+        }
+        else {
+            MPI_Win_lock(MPI_LOCK_SHARED, rank, 0, win);
+            for (i = 0; i < WIN_BUF_NUM * OP_COUNT; i++) {
+                target_buf[i] = 0;
+            }
+            MPI_Win_unlock(rank, win);
+        }
+
+        MPI_Barrier(MPI_COMM_WORLD);
+
+        MPI_Win_lock_all(0, win);
+        if (rank != dest) {
+            for (i = 0; i < my_buf_num; i++) {
+                MPI_Get_accumulate(&(orig_buf[i * OP_COUNT]), OP_COUNT, MPI_INT,
+                                   &(result_buf[i * OP_COUNT]), OP_COUNT, MPI_INT,
+                                   dest, 0, OP_COUNT, MPI_INT, MPI_SUM, win);
+                MPI_Win_flush(dest, win);
+            }
+        }
+        MPI_Win_unlock_all(win);
+
+        MPI_Barrier(MPI_COMM_WORLD);
+
+        checkResults(k, &errors);
+
+        /* ====== Part 2: test derived datatypes (origin derived, target derived) ======== */
+
+        /* init buffers */
+        if (rank != dest) {
+            for (i = 0; i < my_buf_num * OP_COUNT; i++) {
+                orig_buf[i] = 1;
+                result_buf[i] = 0;
+            }
+        }
+        else {
+            MPI_Win_lock(MPI_LOCK_SHARED, rank, 0, win);
+            for (i = 0; i < WIN_BUF_NUM * OP_COUNT; i++) {
+                target_buf[i] = 0;
+            }
+            MPI_Win_unlock(rank, win);
+        }
+
+        MPI_Barrier(MPI_COMM_WORLD);
+
+        MPI_Win_lock_all(0, win);
+        if (rank != dest) {
+            for (i = 0; i < my_buf_num; i++) {
+                MPI_Get_accumulate(&(orig_buf[i * OP_COUNT]), 1, origin_dtp,
+                                   &(result_buf[i * OP_COUNT]), 1, origin_dtp,
+                                   dest, 0, 1, target_dtp, MPI_SUM, win);
+                MPI_Win_flush(dest, win);
+            }
+        }
+        MPI_Win_unlock_all(win);
+
+        MPI_Barrier(MPI_COMM_WORLD);
+
+        checkResults(k, &errors);
+
+        /* ====== Part 3: test derived datatypes (origin basic, target derived) ======== */
+
+        /* init buffers */
+        if (rank != dest) {
+            for (i = 0; i < my_buf_num * OP_COUNT; i++) {
+                orig_buf[i] = 1;
+                result_buf[i] = 0;
+            }
+        }
+        else {
+            MPI_Win_lock(MPI_LOCK_SHARED, rank, 0, win);
+            for (i = 0; i < WIN_BUF_NUM * OP_COUNT; i++) {
+                target_buf[i] = 0;
+            }
+            MPI_Win_unlock(rank, win);
+        }
+
+        MPI_Barrier(MPI_COMM_WORLD);
+
+        MPI_Win_lock_all(0, win);
+        if (rank != dest) {
+            for (i = 0; i < my_buf_num; i++) {
+                MPI_Get_accumulate(&(orig_buf[i * OP_COUNT]), OP_COUNT, MPI_INT,
+                                   &(result_buf[i * OP_COUNT]), OP_COUNT, MPI_INT,
+                                   dest, 0, 1, target_dtp, MPI_SUM, win);
+                MPI_Win_flush(dest, win);
+            }
+        }
+        MPI_Win_unlock_all(win);
+
+        MPI_Barrier(MPI_COMM_WORLD);
+
+        checkResults(k, &errors);
+
+        /* ====== Part 4: test derived datatypes (origin derived target basic) ======== */
+
+        /* init buffers */
+        if (rank != dest) {
+            for (i = 0; i < my_buf_num * OP_COUNT; i++) {
+                orig_buf[i] = 1;
+                result_buf[i] = 0;
+            }
+        }
+        else {
+            MPI_Win_lock(MPI_LOCK_SHARED, rank, 0, win);
+            for (i = 0; i < WIN_BUF_NUM * OP_COUNT; i++) {
+                target_buf[i] = 0;
+            }
+            MPI_Win_unlock(rank, win);
+        }
+
+        MPI_Barrier(MPI_COMM_WORLD);
+
+        MPI_Win_lock_all(0, win);
+        if (rank != dest) {
+            for (i = 0; i < my_buf_num; i++) {
+                MPI_Get_accumulate(&(orig_buf[i * OP_COUNT]), 1, origin_dtp,
+                                   &(result_buf[i * OP_COUNT]), 1, origin_dtp,
+                                   dest, 0, OP_COUNT, MPI_INT, MPI_SUM, win);
+                MPI_Win_flush(dest, win);
+            }
+        }
+        MPI_Win_unlock_all(win);
+
+        MPI_Barrier(MPI_COMM_WORLD);
+
+        checkResults(k, &errors);
+    }
+
+    MPI_Win_free(&win);
+
+    if (rank == origin_am || rank == origin_shm) {
+        MPI_Free_mem(orig_buf);
+        MPI_Free_mem(result_buf);
+    }
+
+    MPI_Type_free(&origin_dtp);
+    MPI_Type_free(&target_dtp);
+
+  exit_test:
+    MPI_Reduce(&errors, &all_errors, 1, MPI_INT, MPI_SUM, 0, MPI_COMM_WORLD);
+
+    if (rank == 0 && all_errors == 0)
+        printf(" No Errors\n");
+
+    MPI_Finalize();
+    return 0;
+}
index 972dda7..9d6ef87 100644 (file)
@@ -13,117 +13,113 @@ static char MTestDescrip[] = "Test creating and inserting attributes in \
 different orders to ensure that the list management code handles all cases.";
 */
 
-int checkAttrs( MPI_Win win, int n, int key[], int attrval[] );
-int checkNoAttrs( MPI_Win win, int n, int key[] );
+int checkAttrs(MPI_Win win, int n, int key[], int attrval[]);
+int checkNoAttrs(MPI_Win win, int n, int key[]);
 
-int main( int argc, char *argv[] )
+int main(int argc, char *argv[])
 {
     int errs = 0;
     int key[3], attrval[3];
     int i;
     int buf[1];
     MPI_Comm comm;
-    MPI_Win  win;
+    MPI_Win win;
 
-    MTest_Init( &argc, &argv );
+    MTest_Init(&argc, &argv);
 
     {
-       comm = MPI_COMM_WORLD;
-       MPI_Win_create( buf, sizeof(int), sizeof(int), MPI_INFO_NULL,
-                       comm, &win );
-
-       /* Create key values */
-       for (i=0; i<3; i++) {
-           MPI_Win_create_keyval( MPI_NULL_COPY_FN, MPI_NULL_DELETE_FN,
-                              &key[i], (void *)0 );
-           attrval[i] = 1024 * i;
-       }
-       
-       /* Insert attribute in several orders.  Test after put with get,
-        then delete, then confirm delete with get. */
-
-       MPI_Win_set_attr( win, key[2], &attrval[2] );
-       MPI_Win_set_attr( win, key[1], &attrval[1] );
-       MPI_Win_set_attr( win, key[0], &attrval[0] );
-
-       errs += checkAttrs( win, 3, key, attrval );
-       
-       MPI_Win_delete_attr( win, key[0] );
-       MPI_Win_delete_attr( win, key[1] );
-       MPI_Win_delete_attr( win, key[2] );
-
-       errs += checkNoAttrs( win, 3, key );
-       
-       MPI_Win_set_attr( win, key[1], &attrval[1] );
-       MPI_Win_set_attr( win, key[2], &attrval[2] );
-       MPI_Win_set_attr( win, key[0], &attrval[0] );
-
-       errs += checkAttrs( win, 3, key, attrval );
-       
-       MPI_Win_delete_attr( win, key[2] );
-       MPI_Win_delete_attr( win, key[1] );
-       MPI_Win_delete_attr( win, key[0] );
-
-       errs += checkNoAttrs( win, 3, key );
-
-       MPI_Win_set_attr( win, key[0], &attrval[0] );
-       MPI_Win_set_attr( win, key[1], &attrval[1] );
-       MPI_Win_set_attr( win, key[2], &attrval[2] );
-
-       errs += checkAttrs( win, 3, key, attrval );
-       
-       MPI_Win_delete_attr( win, key[1] );
-       MPI_Win_delete_attr( win, key[2] );
-       MPI_Win_delete_attr( win, key[0] );
-
-       errs += checkNoAttrs( win, 3, key );
-       
-       for (i=0; i<3; i++) {
-           MPI_Win_free_keyval( &key[i] );
-       }
-       MPI_Win_free( &win );
+        comm = MPI_COMM_WORLD;
+        MPI_Win_create(buf, sizeof(int), sizeof(int), MPI_INFO_NULL, comm, &win);
+
+        /* Create key values */
+        for (i = 0; i < 3; i++) {
+            MPI_Win_create_keyval(MPI_NULL_COPY_FN, MPI_NULL_DELETE_FN, &key[i], (void *) 0);
+            attrval[i] = 1024 * i;
+        }
+
+        /* Insert attribute in several orders.  Test after put with get,
+         * then delete, then confirm delete with get. */
+
+        MPI_Win_set_attr(win, key[2], &attrval[2]);
+        MPI_Win_set_attr(win, key[1], &attrval[1]);
+        MPI_Win_set_attr(win, key[0], &attrval[0]);
+
+        errs += checkAttrs(win, 3, key, attrval);
+
+        MPI_Win_delete_attr(win, key[0]);
+        MPI_Win_delete_attr(win, key[1]);
+        MPI_Win_delete_attr(win, key[2]);
+
+        errs += checkNoAttrs(win, 3, key);
+
+        MPI_Win_set_attr(win, key[1], &attrval[1]);
+        MPI_Win_set_attr(win, key[2], &attrval[2]);
+        MPI_Win_set_attr(win, key[0], &attrval[0]);
+
+        errs += checkAttrs(win, 3, key, attrval);
+
+        MPI_Win_delete_attr(win, key[2]);
+        MPI_Win_delete_attr(win, key[1]);
+        MPI_Win_delete_attr(win, key[0]);
+
+        errs += checkNoAttrs(win, 3, key);
+
+        MPI_Win_set_attr(win, key[0], &attrval[0]);
+        MPI_Win_set_attr(win, key[1], &attrval[1]);
+        MPI_Win_set_attr(win, key[2], &attrval[2]);
+
+        errs += checkAttrs(win, 3, key, attrval);
+
+        MPI_Win_delete_attr(win, key[1]);
+        MPI_Win_delete_attr(win, key[2]);
+        MPI_Win_delete_attr(win, key[0]);
+
+        errs += checkNoAttrs(win, 3, key);
+
+        for (i = 0; i < 3; i++) {
+            MPI_Win_free_keyval(&key[i]);
+        }
+        MPI_Win_free(&win);
     }
-    
-    MTest_Finalize( errs );
+
+    MTest_Finalize(errs);
     MPI_Finalize();
     return 0;
-  
+
 }
 
-int checkAttrs( MPI_Win win, int n, int key[], int attrval[] )
+int checkAttrs(MPI_Win win, int n, int key[], int attrval[])
 {
     int errs = 0;
     int i, flag, *val_p;
 
-    for (i=0; i<n; i++) {
-       MPI_Win_get_attr( win, key[i], &val_p, &flag );
-       if (!flag) {
-           errs++;
-           fprintf( stderr, "Attribute for key %d not set\n", i );
-       }
-       else if (val_p != &attrval[i]) {
-           errs++;
-           fprintf( stderr, "Atribute value for key %d not correct\n",
-                    i );
-       }
+    for (i = 0; i < n; i++) {
+        MPI_Win_get_attr(win, key[i], &val_p, &flag);
+        if (!flag) {
+            errs++;
+            fprintf(stderr, "Attribute for key %d not set\n", i);
+        }
+        else if (val_p != &attrval[i]) {
+            errs++;
+            fprintf(stderr, "Atribute value for key %d not correct\n", i);
+        }
     }
 
     return errs;
 }
 
-int checkNoAttrs( MPI_Win win, int n, int key[] )
+int checkNoAttrs(MPI_Win win, int n, int key[])
 {
     int errs = 0;
     int i, flag, *val_p;
 
-    for (i=0; i<n; i++) {
-       MPI_Win_get_attr( win, key[i], &val_p, &flag );
-       if (flag) {
-           errs++;
-           fprintf( stderr, "Attribute for key %d set but should be deleted\n", i );
-       }
+    for (i = 0; i < n; i++) {
+        MPI_Win_get_attr(win, key[i], &val_p, &flag);
+        if (flag) {
+            errs++;
+            fprintf(stderr, "Attribute for key %d set but should be deleted\n", i);
+        }
     }
 
     return errs;
 }
-       
index fc1ccc9..1ecda21 100644 (file)
@@ -8,73 +8,71 @@
 #include "mpi.h"
 #include "mpitest.h"
 
-int main( int argc, char **argv)
+int main(int argc, char **argv)
 {
-    int    errs = 0;
+    int errs = 0;
     void *v;
-    int  flag;
-    int  rank, size;
+    int flag;
+    int rank, size;
     int base[1024];
     MPI_Aint n;
-    int     disp;
+    int disp;
     MPI_Win win;
 
-    MTest_Init( &argc, &argv );
-    MPI_Comm_size( MPI_COMM_WORLD, &size );
-    MPI_Comm_rank( MPI_COMM_WORLD, &rank );
+    MTest_Init(&argc, &argv);
+    MPI_Comm_size(MPI_COMM_WORLD, &size);
+    MPI_Comm_rank(MPI_COMM_WORLD, &rank);
 
     /* Create a window; then extract the values */
-    n    = 1024;
+    n = 1024;
     disp = 4;
-    MPI_Win_create( base, n, disp, MPI_INFO_NULL, MPI_COMM_WORLD, &win );
+    MPI_Win_create(base, n, disp, MPI_INFO_NULL, MPI_COMM_WORLD, &win);
 
-    MPI_Win_get_attr( win, MPI_WIN_BASE, &v, &flag );
+    MPI_Win_get_attr(win, MPI_WIN_BASE, &v, &flag);
     if (!flag) {
-       errs++;
-       fprintf( stderr, "Could not get WIN_BASE\n" );
+        errs++;
+        fprintf(stderr, "Could not get WIN_BASE\n");
     }
     else {
-       /* MPI 2.1, section 11.2.2.  v must be a pointer to the start of the 
-        window.  It is not a pointer to a pointer to the start of the window. 
-       */
-       if ((int*)v != base) {
-           errs++;
-           fprintf( stderr, "Got incorrect value for WIN_BASE (%p, should be %p)", 
-                    v, base );
-       }
+        /* MPI 2.1, section 11.2.2.  v must be a pointer to the start of the
+         * window.  It is not a pointer to a pointer to the start of the window.
+         */
+        if ((int *) v != base) {
+            errs++;
+            fprintf(stderr, "Got incorrect value for WIN_BASE (%p, should be %p)", v, base);
+        }
     }
 
-    MPI_Win_get_attr( win, MPI_WIN_SIZE, &v, &flag );
+    MPI_Win_get_attr(win, MPI_WIN_SIZE, &v, &flag);
     if (!flag) {
-       errs++;
-       fprintf( stderr, "Could not get WIN_SIZE\n" );
+        errs++;
+        fprintf(stderr, "Could not get WIN_SIZE\n");
     }
     else {
-       MPI_Aint vval = *(MPI_Aint*)v;
-       if (vval != n) {
-           errs++;
-           fprintf( stderr, "Got wrong value for WIN_SIZE (%ld, should be %ld)\n", 
-                    (long) vval, (long) n );
-       }
+        MPI_Aint vval = *(MPI_Aint *) v;
+        if (vval != n) {
+            errs++;
+            fprintf(stderr, "Got wrong value for WIN_SIZE (%ld, should be %ld)\n",
+                    (long) vval, (long) n);
+        }
     }
 
-    MPI_Win_get_attr( win, MPI_WIN_DISP_UNIT, &v, &flag );
+    MPI_Win_get_attr(win, MPI_WIN_DISP_UNIT, &v, &flag);
     if (!flag) {
-       errs++;
-       fprintf( stderr, "Could not get WIN_DISP_UNIT\n" );
+        errs++;
+        fprintf(stderr, "Could not get WIN_DISP_UNIT\n");
     }
     else {
-       int vval = *(int*)v;
-       if (vval != disp) {
-           errs++;
-           fprintf( stderr, "Got wrong value for WIN_DISP_UNIT (%d, should be %d)\n",
-                    vval, disp );
-       }
+        int vval = *(int *) v;
+        if (vval != disp) {
+            errs++;
+            fprintf(stderr, "Got wrong value for WIN_DISP_UNIT (%d, should be %d)\n", vval, disp);
+        }
     }
 
     MPI_Win_free(&win);
-    MTest_Finalize( errs );
-    MPI_Finalize( );
-    
+    MTest_Finalize(errs);
+    MPI_Finalize();
+
     return 0;
 }
index 96eace1..c9f1696 100644 (file)
 
 #define ITER 100
 
-int main(int argc, char **argv) {
-    int       i, j, rank, nproc;
-    int       errors = 0, all_errors = 0;
-    int      *val_ptr;
-    MPI_Win   win;
+int main(int argc, char **argv)
+{
+    int i, rank, nproc;
+    int errors = 0, all_errors = 0;
+    int *val_ptr;
+    MPI_Win win;
 
     MPI_Init(&argc, &argv);
 
@@ -39,8 +40,8 @@ int main(int argc, char **argv) {
         MPI_Compare_and_swap(&next, &i, &result, MPI_INT, rank, 0, win);
         MPI_Win_unlock(rank, win);
         if (result != i) {
-            SQUELCH( printf("%d->%d -- Error: next=%d compare=%d result=%d val=%d\n", rank,
-                           rank, next, i, result, *val_ptr); );
+            SQUELCH(printf("%d->%d -- Error: next=%d compare=%d result=%d val=%d\n", rank,
+                           rank, next, i, result, *val_ptr););
             errors++;
         }
     }
@@ -55,12 +56,12 @@ int main(int argc, char **argv) {
 
     for (i = 0; i < ITER; i++) {
         int next = i + 1, result = -1;
-        MPI_Win_lock(MPI_LOCK_EXCLUSIVE, (rank+1)%nproc, 0, win);
-        MPI_Compare_and_swap(&next, &i, &result, MPI_INT, (rank+1)%nproc, 0, win);
-        MPI_Win_unlock((rank+1)%nproc, win);
+        MPI_Win_lock(MPI_LOCK_EXCLUSIVE, (rank + 1) % nproc, 0, win);
+        MPI_Compare_and_swap(&next, &i, &result, MPI_INT, (rank + 1) % nproc, 0, win);
+        MPI_Win_unlock((rank + 1) % nproc, win);
         if (result != i) {
-            SQUELCH( printf("%d->%d -- Error: next=%d compare=%d result=%d val=%d\n", rank,
-                           (rank+1)%nproc, next, i, result, *val_ptr); );
+            SQUELCH(printf("%d->%d -- Error: next=%d compare=%d result=%d val=%d\n", rank,
+                           (rank + 1) % nproc, next, i, result, *val_ptr););
             errors++;
         }
     }
@@ -89,7 +90,7 @@ int main(int argc, char **argv) {
 
     if (rank == 0 && nproc > 1) {
         if (*val_ptr != ITER) {
-            SQUELCH( printf("%d - Error: expected=%d val=%d\n", rank, ITER, *val_ptr); );
+            SQUELCH(printf("%d - Error: expected=%d val=%d\n", rank, ITER, *val_ptr););
             errors++;
         }
     }
index 2b2be30..b549c9b 100644 (file)
@@ -26,80 +26,82 @@ int test_put(void);
 
 int test_put(void)
 {
-  MPI_Win  dst_win;
-  double  *dst_buf;
-  double   src_buf[MAXELEMS];
-  int      i, j;
-  int      errs = 0;
+    MPI_Win dst_win;
+    double *dst_buf;
+    double src_buf[MAXELEMS];
+    int i, j;
+    int errs = 0;
 
-  MPI_Alloc_mem(sizeof(double)*nproc*MAXELEMS, MPI_INFO_NULL, &dst_buf);
-  MPI_Win_create(dst_buf, sizeof(double)*nproc*MAXELEMS, 1, MPI_INFO_NULL, 
-                MPI_COMM_WORLD, &dst_win);
+    MPI_Alloc_mem(sizeof(double) * nproc * MAXELEMS, MPI_INFO_NULL, &dst_buf);
+    MPI_Win_create(dst_buf, sizeof(double) * nproc * MAXELEMS, 1, MPI_INFO_NULL,
+                   MPI_COMM_WORLD, &dst_win);
 
-  for (i = 0; i < MAXELEMS; i++)
-    src_buf[i] = me + 1.0;
+    for (i = 0; i < MAXELEMS; i++)
+        src_buf[i] = me + 1.0;
 
-  MPI_Win_lock(MPI_LOCK_EXCLUSIVE, me, 0, dst_win);
+    MPI_Win_lock(MPI_LOCK_EXCLUSIVE, me, 0, dst_win);
 
-  for (i = 0; i < nproc*MAXELEMS; i++)
-    dst_buf[i] = 0.0;
+    for (i = 0; i < nproc * MAXELEMS; i++)
+        dst_buf[i] = 0.0;
 
-  MPI_Win_unlock(me, dst_win);
+    MPI_Win_unlock(me, dst_win);
 
-  MPI_Barrier(MPI_COMM_WORLD);
+    MPI_Barrier(MPI_COMM_WORLD);
 
-  for(i = 0; i < nproc; i++) {
-    /* int target = (me + i) % nproc; */
-    int target = i;
-    for(j = 0; j < COUNT; j++) {
-      if (verbose) printf("%2d -> %2d [%2d]\n", me, target, j); 
-      MPI_Win_lock(MPI_LOCK_EXCLUSIVE, target, 0, dst_win);
-      MPI_Put(&src_buf[j], sizeof(double), MPI_BYTE, target, 
-             (me*MAXELEMS+j)*sizeof(double), sizeof(double), MPI_BYTE, dst_win);
-      MPI_Win_unlock(target, dst_win);
+    for (i = 0; i < nproc; i++) {
+        /* int target = (me + i) % nproc; */
+        int target = i;
+        for (j = 0; j < COUNT; j++) {
+            if (verbose)
+                printf("%2d -> %2d [%2d]\n", me, target, j);
+            MPI_Win_lock(MPI_LOCK_EXCLUSIVE, target, 0, dst_win);
+            MPI_Put(&src_buf[j], sizeof(double), MPI_BYTE, target,
+                    (me * MAXELEMS + j) * sizeof(double), sizeof(double), MPI_BYTE, dst_win);
+            MPI_Win_unlock(target, dst_win);
+        }
     }
-  }
-
-  MPI_Barrier(MPI_COMM_WORLD);
-
-  /* Check that the correct data was returned.  This assumes that the 
-     systems have the same data representations */
-  for (i=0; i<nproc; i++) {
-      for (j=0; j<COUNT; j++) {
-         if (dst_buf[i*MAXELEMS+j] != 1.0 + i) {
-             errs++;
-             printf( "dst_buf[%d] = %e, expected %e\n",
-                     i*MAXELEMS+j, dst_buf[i*MAXELEMS+j], 1.0 + i );
-         }
-      }
-  }
-
-  MPI_Win_free(&dst_win);
-  MPI_Free_mem(dst_buf);
-
-  return errs;
+
+    MPI_Barrier(MPI_COMM_WORLD);
+
+    /* Check that the correct data was returned.  This assumes that the
+     * systems have the same data representations */
+    for (i = 0; i < nproc; i++) {
+        for (j = 0; j < COUNT; j++) {
+            if (dst_buf[i * MAXELEMS + j] != 1.0 + i) {
+                errs++;
+                printf("dst_buf[%d] = %e, expected %e\n",
+                       i * MAXELEMS + j, dst_buf[i * MAXELEMS + j], 1.0 + i);
+            }
+        }
+    }
+
+    MPI_Win_free(&dst_win);
+    MPI_Free_mem(dst_buf);
+
+    return errs;
 }
 
 
-int main(int argc, char* argv[]) {
+int main(int argc, char *argv[])
+{
     int errs = 0;
 
     MTest_Init(&argc, &argv);
     MPI_Comm_size(MPI_COMM_WORLD, &nproc);
     MPI_Comm_rank(MPI_COMM_WORLD, &me);
-    
+
     assert(COUNT <= MAXELEMS);
-    
+
     if (me == 0 && verbose) {
-       printf("Test starting on %d processes\n", nproc); 
-       fflush(stdout);
+        printf("Test starting on %d processes\n", nproc);
+        fflush(stdout);
     }
-    
+
     errs = test_put();
-    
+
     MPI_Barrier(MPI_COMM_WORLD);
-    
-    MTest_Finalize( errs );
+
+    MTest_Finalize(errs);
     MPI_Finalize();
-    return MTestReturnValue( errs );
+    return MTestReturnValue(errs);
 }
index 6a539a0..312cf31 100644 (file)
@@ -24,76 +24,82 @@ static const int verbose = 0;
 void test_put(void);
 void test_put(void)
 {
-  MPI_Win  dst_win;
-  double  *dst_buf;
-  double   src_buf[MAXELEMS];
-  int      i, j;
-
-  MPI_Alloc_mem(sizeof(double)*nproc*MAXELEMS, MPI_INFO_NULL, &dst_buf);
-  MPI_Win_create(dst_buf, sizeof(double)*nproc*MAXELEMS, 1, MPI_INFO_NULL, MPI_COMM_WORLD, &dst_win);
-
-  for (i = 0; i < MAXELEMS; i++)
-    src_buf[i] = me + 1.0;
-
-  MPI_Win_lock(MPI_LOCK_EXCLUSIVE, me, 0, dst_win);
-
-  for (i = 0; i < nproc*MAXELEMS; i++)
-    dst_buf[i] = 0.0;
-
-  MPI_Win_unlock(me, dst_win);
-
-  MPI_Barrier(MPI_COMM_WORLD);
-
-  for(i = 0; i < nproc; i++) {
-    int target = i;
-
-    for(j = 0; j < COUNT; j++) {
-      if (verbose) printf("%2d -> %2d [%2d]\n", me, target, j); 
-      MPI_Win_lock(MPI_LOCK_EXCLUSIVE, target, 0, dst_win);
-      MPI_Put(&src_buf[j], sizeof(double), MPI_BYTE, target, (me*MAXELEMS+j)*sizeof(double), sizeof(double), MPI_BYTE, dst_win);
-      MPI_Win_unlock(target, dst_win);
-    }
-
-    for(j = 0; j < COUNT; j++) {
-      if (verbose) printf("%2d <- %2d [%2d]\n", me, target, j); 
-      MPI_Win_lock(MPI_LOCK_EXCLUSIVE, target, 0, dst_win);
-      MPI_Get(&src_buf[j], sizeof(double), MPI_BYTE, target, (me*MAXELEMS+j)*sizeof(double), sizeof(double), MPI_BYTE, dst_win);
-      MPI_Win_unlock(target, dst_win);
+    MPI_Win dst_win;
+    double *dst_buf;
+    double src_buf[MAXELEMS];
+    int i, j;
+
+    MPI_Alloc_mem(sizeof(double) * nproc * MAXELEMS, MPI_INFO_NULL, &dst_buf);
+    MPI_Win_create(dst_buf, sizeof(double) * nproc * MAXELEMS, 1, MPI_INFO_NULL, MPI_COMM_WORLD,
+                   &dst_win);
+
+    for (i = 0; i < MAXELEMS; i++)
+        src_buf[i] = me + 1.0;
+
+    MPI_Win_lock(MPI_LOCK_EXCLUSIVE, me, 0, dst_win);
+
+    for (i = 0; i < nproc * MAXELEMS; i++)
+        dst_buf[i] = 0.0;
+
+    MPI_Win_unlock(me, dst_win);
+
+    MPI_Barrier(MPI_COMM_WORLD);
+
+    for (i = 0; i < nproc; i++) {
+        int target = i;
+
+        for (j = 0; j < COUNT; j++) {
+            if (verbose)
+                printf("%2d -> %2d [%2d]\n", me, target, j);
+            MPI_Win_lock(MPI_LOCK_EXCLUSIVE, target, 0, dst_win);
+            MPI_Put(&src_buf[j], sizeof(double), MPI_BYTE, target,
+                    (me * MAXELEMS + j) * sizeof(double), sizeof(double), MPI_BYTE, dst_win);
+            MPI_Win_unlock(target, dst_win);
+        }
+
+        for (j = 0; j < COUNT; j++) {
+            if (verbose)
+                printf("%2d <- %2d [%2d]\n", me, target, j);
+            MPI_Win_lock(MPI_LOCK_EXCLUSIVE, target, 0, dst_win);
+            MPI_Get(&src_buf[j], sizeof(double), MPI_BYTE, target,
+                    (me * MAXELEMS + j) * sizeof(double), sizeof(double), MPI_BYTE, dst_win);
+            MPI_Win_unlock(target, dst_win);
+        }
     }
-  }
 
-  MPI_Barrier(MPI_COMM_WORLD);
+    MPI_Barrier(MPI_COMM_WORLD);
 
-  MPI_Win_free(&dst_win);
-  MPI_Free_mem(dst_buf);
+    MPI_Win_free(&dst_win);
+    MPI_Free_mem(dst_buf);
 }
 
 
-int main(int argc, char* argv[]) {
-  MPI_Init(&argc, &argv);
-  MPI_Comm_size(MPI_COMM_WORLD, &nproc);
-  MPI_Comm_rank(MPI_COMM_WORLD, &me);
+int main(int argc, char *argv[])
+{
+    MPI_Init(&argc, &argv);
+    MPI_Comm_size(MPI_COMM_WORLD, &nproc);
+    MPI_Comm_rank(MPI_COMM_WORLD, &me);
 
-  assert(COUNT <= MAXELEMS);
+    assert(COUNT <= MAXELEMS);
 
-  if (me == 0 && verbose) {
-    printf("Test starting on %d processes\n", nproc); 
-    fflush(stdout);
-  }
+    if (me == 0 && verbose) {
+        printf("Test starting on %d processes\n", nproc);
+        fflush(stdout);
+    }
 
-  test_put();
+    test_put();
 
-  MPI_Barrier(MPI_COMM_WORLD);
+    MPI_Barrier(MPI_COMM_WORLD);
 
-  MPI_Finalize();
+    MPI_Finalize();
 
-  if (me == 0 && verbose) {
-    printf("Test completed.\n");
-    fflush(stdout);
-  }
+    if (me == 0 && verbose) {
+        printf("Test completed.\n");
+        fflush(stdout);
+    }
 
-  if (me == 0)
-    printf(" No Errors\n");
+    if (me == 0)
+        printf(" No Errors\n");
 
-  return 0;
+    return 0;
 }
index 9d37da6..459c8b6 100644 (file)
 /* Run with 1 process.
 
    This program does an MPI_Get with an indexed datatype. The datatype
-   comprises a single integer at an initial displacement of 1 integer. 
+   comprises a single integer at an initial displacement of 1 integer.
    That is, the first integer in the array is to be skipped.
 
    This program found a bug in IBM's MPI in which MPI_Get ignored the
-   displacement and got the first integer instead of the second. 
+   displacement and got the first integer instead of the second.
 */
 
 int main(int argc, char **argv)
 {
     int rank, nprocs, mpi_err, *array;
-    int getval, disp, errs=0;
+    int getval, disp, errs = 0;
     MPI_Win win;
     MPI_Datatype type;
-    
-    MTest_Init(&argc,&argv); 
+
+    MTest_Init(&argc, &argv);
 
     MPI_Comm_rank(MPI_COMM_WORLD, &rank);
     MPI_Comm_size(MPI_COMM_WORLD, &nprocs);
 
     if (rank == 0) {
         /* To improve reporting of problems about operations, we
-           change the error handler to errors return */
-        MPI_Comm_set_errhandler( MPI_COMM_SELF, MPI_ERRORS_RETURN );
-        /* create an indexed datatype that points to the second integer 
-           in an array (the first integer is skipped). */
-        disp  =  1;
+         * change the error handler to errors return */
+        MPI_Comm_set_errhandler(MPI_COMM_SELF, MPI_ERRORS_RETURN);
+
+        /* create an indexed datatype that points to the second integer
+         * in an array (the first integer is skipped). */
+        disp = 1;
         mpi_err = MPI_Type_create_indexed_block(1, 1, &disp, MPI_INT, &type);
-        if (mpi_err != MPI_SUCCESS) goto err_return;
+        if (mpi_err != MPI_SUCCESS)
+            goto err_return;
         mpi_err = MPI_Type_commit(&type);
-        if (mpi_err != MPI_SUCCESS) goto err_return;
-        /* allocate window of size 2 integers*/
-        mpi_err = MPI_Alloc_mem(2*sizeof(int), MPI_INFO_NULL, &array);
-        if (mpi_err != MPI_SUCCESS) goto err_return;
+        if (mpi_err != MPI_SUCCESS)
+            goto err_return;
+
+        /* allocate window of size 2 integers */
+        mpi_err = MPI_Alloc_mem(2 * sizeof(int), MPI_INFO_NULL, &array);
+        if (mpi_err != MPI_SUCCESS)
+            goto err_return;
+
         /* create window object */
-        mpi_err = MPI_Win_create(array, 2*sizeof(int), sizeof(int), MPI_INFO_NULL, MPI_COMM_SELF, &win);
-        if (mpi_err != MPI_SUCCESS) goto err_return;
-  
+        mpi_err =
+            MPI_Win_create(array, 2 * sizeof(int), sizeof(int), MPI_INFO_NULL, MPI_COMM_SELF, &win);
+        if (mpi_err != MPI_SUCCESS)
+            goto err_return;
+
         /* initialize array */
         array[0] = 100;
         array[1] = 200;
+
         getval = 0;
-        
+
         /* To improve reporting of problems about operations, we
-           change the error handler to errors return */
-        MPI_Win_set_errhandler( win, MPI_ERRORS_RETURN );
+         * change the error handler to errors return */
+        MPI_Win_set_errhandler(win, MPI_ERRORS_RETURN);
+
         mpi_err = MPI_Win_lock(MPI_LOCK_EXCLUSIVE, 0, 0, win);
-        if (mpi_err != MPI_SUCCESS) goto err_return;
+        if (mpi_err != MPI_SUCCESS)
+            goto err_return;
+
         /* get the current value of element array[1] */
         mpi_err = MPI_Get(&getval, 1, MPI_INT, 0, 0, 1, type, win);
-        if (mpi_err != MPI_SUCCESS) goto err_return;
+        if (mpi_err != MPI_SUCCESS)
+            goto err_return;
+
         mpi_err = MPI_Win_unlock(0, win);
-        if (mpi_err != MPI_SUCCESS) goto err_return;
+        if (mpi_err != MPI_SUCCESS)
+            goto err_return;
+
         /* getval should contain the value of array[1] */
         if (getval != array[1]) {
             errs++;
             printf("getval=%d, should be %d\n", getval, array[1]);
         }
+
         MPI_Free_mem(array);
         MPI_Win_free(&win);
         MPI_Type_free(&type);
@@ -86,13 +94,11 @@ int main(int argc, char **argv)
     MPI_Finalize();
     return 0;
 
- err_return:
 err_return:
     printf("MPI function error returned an error\n");
-    MTestPrintError( mpi_err );
+    MTestPrintError(mpi_err);
     errs++;
     MTest_Finalize(errs);
     MPI_Finalize();
     return 1;
 }
-
-
diff --git a/teshsuite/smpi/mpich3-test/rma/derived-acc-flush_local.c b/teshsuite/smpi/mpich3-test/rma/derived-acc-flush_local.c
new file mode 100644 (file)
index 0000000..032a022
--- /dev/null
@@ -0,0 +1,130 @@
+/* -*- Mode: C; c-basic-offset:4 ; indent-tabs-mode:nil ; -*- */
+/*
+ *  (C) 2015 by Argonne National Laboratory.
+ *      See COPYRIGHT in top-level directory.
+ */
+
+/* This code tests the case when one process issues large number
+ * of MPI_Accumulate operations (with large derived datatype) and
+ * issues a MPI_Win_flush_local at end. */
+
+/* FIXME: we should merge this into a comprehensive test for RMA
+ * operations + MPI_Win_flush_local. */
+
+#include "mpi.h"
+#include <stdio.h>
+#include <stdlib.h>
+#include <time.h>
+
+#define DATA_SIZE 1000000
+#define COUNT 5000
+#define BLOCKLENGTH (DATA_SIZE/COUNT)
+#define STRIDE BLOCKLENGTH
+#define OPS_NUM 500
+
+int main(int argc, char *argv[])
+{
+    int rank, nproc;
+    int i;
+    MPI_Win win;
+    int *tar_buf = NULL;
+    int *orig_buf = NULL;
+    MPI_Datatype derived_dtp;
+    int errors = 0;
+
+    MPI_Init(&argc, &argv);
+
+    MPI_Comm_size(MPI_COMM_WORLD, &nproc);
+    MPI_Comm_rank(MPI_COMM_WORLD, &rank);
+
+    if (nproc < 3) {
+        fprintf(stderr, "Run this program with at least 3 processes\n");
+        MPI_Abort(MPI_COMM_WORLD, 1);
+    }
+
+    MPI_Alloc_mem(sizeof(int) * DATA_SIZE, MPI_INFO_NULL, &orig_buf);
+    MPI_Alloc_mem(sizeof(int) * DATA_SIZE, MPI_INFO_NULL, &tar_buf);
+
+    for (i = 0; i < DATA_SIZE; i++) {
+        orig_buf[i] = 1;
+        tar_buf[i] = 0;
+    }
+
+    MPI_Type_vector(COUNT, BLOCKLENGTH - 1, STRIDE, MPI_INT, &derived_dtp);
+    MPI_Type_commit(&derived_dtp);
+
+    MPI_Win_create(tar_buf, sizeof(int) * DATA_SIZE, sizeof(int),
+                   MPI_INFO_NULL, MPI_COMM_WORLD, &win);
+
+    /***** test between rank 0 and rank 1 *****/
+
+    if (rank == 1) {
+        MPI_Win_lock(MPI_LOCK_SHARED, 0, 0, win);
+
+        for (i = 0; i < OPS_NUM; i++) {
+            MPI_Accumulate(orig_buf, 1, derived_dtp,
+                           0, 0, DATA_SIZE - COUNT, MPI_INT, MPI_SUM, win);
+            MPI_Win_flush_local(0, win);
+        }
+
+        MPI_Win_unlock(0, win);
+    }
+
+    MPI_Barrier(MPI_COMM_WORLD);
+
+    /* check results */
+    if (rank == 0) {
+        for (i = 0; i < DATA_SIZE - COUNT; i++) {
+            if (tar_buf[i] != OPS_NUM) {
+                printf("tar_buf[%d] = %d, expected %d\n", i, tar_buf[i], OPS_NUM);
+                errors++;
+            }
+        }
+    }
+
+    for (i = 0; i < DATA_SIZE; i++) {
+        tar_buf[i] = 0;
+    }
+
+    MPI_Barrier(MPI_COMM_WORLD);
+
+    /***** test between rank 0 and rank 2 *****/
+
+    if (rank == 2) {
+        MPI_Win_lock(MPI_LOCK_SHARED, 0, 0, win);
+
+        for (i = 0; i < OPS_NUM; i++) {
+            MPI_Accumulate(orig_buf, 1, derived_dtp,
+                           0, 0, DATA_SIZE - COUNT, MPI_INT, MPI_SUM, win);
+            MPI_Win_flush_local(0, win);
+        }
+
+        MPI_Win_unlock(0, win);
+    }
+
+    MPI_Barrier(MPI_COMM_WORLD);
+
+    /* check results */
+    if (rank == 0) {
+        for (i = 0; i < DATA_SIZE - COUNT; i++) {
+            if (tar_buf[i] != OPS_NUM) {
+                printf("tar_buf[%d] = %d, expected %d\n", i, tar_buf[i], OPS_NUM);
+                errors++;
+            }
+        }
+
+        if (errors == 0)
+            printf(" No Errors\n");
+    }
+
+    MPI_Win_free(&win);
+
+    MPI_Type_free(&derived_dtp);
+
+    MPI_Free_mem(orig_buf);
+    MPI_Free_mem(tar_buf);
+
+    MPI_Finalize();
+
+    return 0;
+}
index 7a3222a..bd07732 100644 (file)
@@ -6,7 +6,7 @@
  */
 
 /*
- * This test looks at the behavior of MPI_Win_fence and epochs.  Each 
+ * This test looks at the behavior of MPI_Win_fence and epochs.  Each
  * MPI_Win_fence may both begin and end both the exposure and access epochs.
  * Thus, it is not necessary to use MPI_Win_fence in pairs.
  *
@@ -32,160 +32,192 @@ static char MTEST_Descrip[] = "Put with Fences used to separate epochs";
 
 #define MAX_PERR 10
 
-int PrintRecvedError( const char *, MTestDatatype *, MTestDatatype * );
+int PrintRecvedError(const char *, MTestDatatype *, MTestDatatype *);
 
-int main( int argc, char **argv )
+int main(int argc, char **argv)
 {
     int errs = 0, err;
     int rank, size, source, dest;
-    int minsize = 2, count; 
-    MPI_Comm      comm;
-    MPI_Win       win;
-    MPI_Aint      extent;
+    int minsize = 2, count;
+    MPI_Comm comm;
+    MPI_Win win;
+    MPI_Aint extent,lb;
     MTestDatatype sendtype, recvtype;
-    int           onlyInt = 0;
+    int onlyInt = 0;
 
-    MTest_Init( &argc, &argv );
+    MTest_Init(&argc, &argv);
     /* Check for a simple choice of communicator and datatypes */
-    if (getenv( "MTEST_SIMPLE" )) onlyInt = 1;
-
-    while (MTestGetIntracommGeneral( &comm, minsize, 1 )) {
-       if (comm == MPI_COMM_NULL) continue;
-       /* Determine the sender and receiver */
-       MPI_Comm_rank( comm, &rank );
-       MPI_Comm_size( comm, &size );
-       source = 0;
-       dest   = size - 1;
-       
-       for (count = 1; count < 65000; count = count * 2) {
-           while (MTestGetDatatypes( &sendtype, &recvtype, count )) {
-
-               MTestPrintfMsg( 1, 
-                      "Putting count = %d of sendtype %s receive type %s\n", 
-                               count, MTestGetDatatypeName( &sendtype ),
-                               MTestGetDatatypeName( &recvtype ) );
-
-               /* Make sure that everyone has a recv buffer */
-               recvtype.InitBuf( &recvtype );
-
-               MPI_Type_extent( recvtype.datatype, &extent );
-               MPI_Win_create( recvtype.buf, recvtype.count * extent, 
-                               extent, MPI_INFO_NULL, comm, &win );
-               /* To improve reporting of problems about operations, we
-                  change the error handler to errors return */
-               MPI_Win_set_errhandler( win, MPI_ERRORS_RETURN );
-
-               /* At this point, we have all of the elements that we 
-                  need to begin the multiple fence and put tests */
-               /* Fence 1 */
-               err = MPI_Win_fence( MPI_MODE_NOPRECEDE, win ); 
-               if (err) { if (errs++ < MAX_PERR) MTestPrintError(err); }
-               /* Source puts */
-               if (rank == source) {
-                   sendtype.InitBuf( &sendtype );
-                   
-                   err = MPI_Put( sendtype.buf, sendtype.count, 
-                                  sendtype.datatype, dest, 0, 
-                                  recvtype.count, recvtype.datatype, win );
-                   if (err) { if (errs++ < MAX_PERR) MTestPrintError(err); }
-               }
-
-               /* Fence 2 */
-               err = MPI_Win_fence( 0, win );
-               if (err) { if (errs++ < MAX_PERR) MTestPrintError(err); }
-               /* dest checks data, then Dest puts */
-               if (rank == dest) {
-                   err = MTestCheckRecv( 0, &recvtype );
-                   if (err) { if (errs++ < MAX_PERR) { 
-                           PrintRecvedError( "fence 2", &sendtype, &recvtype );
-                       }
-                   }
-                   sendtype.InitBuf( &sendtype );
-                   
-                   err = MPI_Put( sendtype.buf, sendtype.count, 
-                                  sendtype.datatype, source, 0, 
-                                  recvtype.count, recvtype.datatype, win );
-                   if (err) { if (errs++ < MAX_PERR) MTestPrintError(err); }
-               }
-
-               /* Fence 3 */
-               err = MPI_Win_fence( 0, win );
-               if (err) { if (errs++ < MAX_PERR) MTestPrintError(err); }
-               /* src checks data, then Src and dest puts*/
-               if (rank == source) {
-                   err = MTestCheckRecv( 0, &recvtype );
-                   if (err) { if (errs++ < MAX_PERR) { 
-                           PrintRecvedError( "fence 3", &sendtype, &recvtype );
-                       }
-                   }
-                   sendtype.InitBuf( &sendtype );
-                   
-                   err = MPI_Put( sendtype.buf, sendtype.count, 
-                                  sendtype.datatype, dest, 0, 
-                                  recvtype.count, recvtype.datatype, win );
-                   if (err) { if (errs++ < MAX_PERR) MTestPrintError(err); }
-               }
-               if (rank == dest) {
-                   sendtype.InitBuf( &sendtype );
-                   
-                   err = MPI_Put( sendtype.buf, sendtype.count, 
-                                  sendtype.datatype, source, 0, 
-                                  recvtype.count, recvtype.datatype, win );
-                   if (err) { if (errs++ < MAX_PERR) MTestPrintError(err); }
-               }
-
-               /* Fence 4 */
-               err = MPI_Win_fence( MPI_MODE_NOSUCCEED, win );
-               if (err) { if (errs++ < MAX_PERR) MTestPrintError(err); }
-               /* src and dest checks data */
-               if (rank == source) {
-                   err = MTestCheckRecv( 0, &recvtype );
-                   if (err) { if (errs++ < MAX_PERR) { 
-                           PrintRecvedError( "src fence4", &sendtype, &recvtype );
-                       }
-                   }
-               }
-               if (rank == dest) {
-                   err = MTestCheckRecv( 0, &recvtype );
-                   if (err) { if (errs++ < MAX_PERR) { 
-                           PrintRecvedError( "dest fence4", &sendtype, &recvtype );
-                       }
-                   }
-               }
-
-               MPI_Win_free( &win );
-               MTestFreeDatatype( &sendtype );
-               MTestFreeDatatype( &recvtype );
-
-               /* Only do one datatype in the simple case */
-               if (onlyInt) break;
-           }
-           /* Only do one count in the simple case */
-           if (onlyInt) break;
-       }
+    if (getenv("MTEST_SIMPLE"))
+        onlyInt = 1;
+
+    while (MTestGetIntracommGeneral(&comm, minsize, 1)) {
+        if (comm == MPI_COMM_NULL)
+            continue;
+        /* Determine the sender and receiver */
+        MPI_Comm_rank(comm, &rank);
+        MPI_Comm_size(comm, &size);
+        source = 0;
+        dest = size - 1;
+
+        MTEST_DATATYPE_FOR_EACH_COUNT(count) {
+            while (MTestGetDatatypes(&sendtype, &recvtype, count)) {
+
+                MTestPrintfMsg(1,
+                               "Putting count = %d of sendtype %s receive type %s\n",
+                               count, MTestGetDatatypeName(&sendtype),
+                               MTestGetDatatypeName(&recvtype));
+
+                /* Make sure that everyone has a recv buffer */
+                recvtype.InitBuf(&recvtype);
+
+                MPI_Type_extent(recvtype.datatype, &extent);
+                MPI_Type_lb(recvtype.datatype, &lb);
+                MPI_Win_create(recvtype.buf, recvtype.count * extent + lb,
+                               extent, MPI_INFO_NULL, comm, &win);
+                /* To improve reporting of problems about operations, we
+                 * change the error handler to errors return */
+                MPI_Win_set_errhandler(win, MPI_ERRORS_RETURN);
+
+                /* At this point, we have all of the elements that we
+                 * need to begin the multiple fence and put tests */
+                /* Fence 1 */
+                err = MPI_Win_fence(MPI_MODE_NOPRECEDE, win);
+                if (err) {
+                    if (errs++ < MAX_PERR)
+                        MTestPrintError(err);
+                }
+                /* Source puts */
+                if (rank == source) {
+                    sendtype.InitBuf(&sendtype);
+
+                    err = MPI_Put(sendtype.buf, sendtype.count,
+                                  sendtype.datatype, dest, 0,
+                                  recvtype.count, recvtype.datatype, win);
+                    if (err) {
+                        if (errs++ < MAX_PERR)
+                            MTestPrintError(err);
+                    }
+                }
+
+                /* Fence 2 */
+                err = MPI_Win_fence(0, win);
+                if (err) {
+                    if (errs++ < MAX_PERR)
+                        MTestPrintError(err);
+                }
+                /* dest checks data, then Dest puts */
+                if (rank == dest) {
+                    err = MTestCheckRecv(0, &recvtype);
+                    if (err) {
+                        if (errs++ < MAX_PERR) {
+                            PrintRecvedError("fence 2", &sendtype, &recvtype);
+                        }
+                    }
+                    sendtype.InitBuf(&sendtype);
+
+                    err = MPI_Put(sendtype.buf, sendtype.count,
+                                  sendtype.datatype, source, 0,
+                                  recvtype.count, recvtype.datatype, win);
+                    if (err) {
+                        if (errs++ < MAX_PERR)
+                            MTestPrintError(err);
+                    }
+                }
+
+                /* Fence 3 */
+                err = MPI_Win_fence(0, win);
+                if (err) {
+                    if (errs++ < MAX_PERR)
+                        MTestPrintError(err);
+                }
+                /* src checks data, then Src and dest puts */
+                if (rank == source) {
+                    err = MTestCheckRecv(0, &recvtype);
+                    if (err) {
+                        if (errs++ < MAX_PERR) {
+                            PrintRecvedError("fence 3", &sendtype, &recvtype);
+                        }
+                    }
+                    sendtype.InitBuf(&sendtype);
+
+                    err = MPI_Put(sendtype.buf, sendtype.count,
+                                  sendtype.datatype, dest, 0,
+                                  recvtype.count, recvtype.datatype, win);
+                    if (err) {
+                        if (errs++ < MAX_PERR)
+                            MTestPrintError(err);
+                    }
+                }
+                if (rank == dest) {
+                    sendtype.InitBuf(&sendtype);
+
+                    err = MPI_Put(sendtype.buf, sendtype.count,
+                                  sendtype.datatype, source, 0,
+                                  recvtype.count, recvtype.datatype, win);
+                    if (err) {
+                        if (errs++ < MAX_PERR)
+                            MTestPrintError(err);
+                    }
+                }
+
+                /* Fence 4 */
+                err = MPI_Win_fence(MPI_MODE_NOSUCCEED, win);
+                if (err) {
+                    if (errs++ < MAX_PERR)
+                        MTestPrintError(err);
+                }
+                /* src and dest checks data */
+                if (rank == source) {
+                    err = MTestCheckRecv(0, &recvtype);
+                    if (err) {
+                        if (errs++ < MAX_PERR) {
+                            PrintRecvedError("src fence4", &sendtype, &recvtype);
+                        }
+                    }
+                }
+                if (rank == dest) {
+                    err = MTestCheckRecv(0, &recvtype);
+                    if (err) {
+                        if (errs++ < MAX_PERR) {
+                            PrintRecvedError("dest fence4", &sendtype, &recvtype);
+                        }
+                    }
+                }
+
+                MPI_Win_free(&win);
+                MTestFreeDatatype(&sendtype);
+                MTestFreeDatatype(&recvtype);
+
+                /* Only do one datatype in the simple case */
+                if (onlyInt)
+                    break;
+            }
+            /* Only do one count in the simple case */
+            if (onlyInt)
+                break;
+        }
         MTestFreeComm(&comm);
-       /* Only do one communicator in the simple case */
-       if (onlyInt) break;
+        /* Only do one communicator in the simple case */
+        if (onlyInt)
+            break;
     }
 
-    MTest_Finalize( errs );
+    MTest_Finalize(errs);
+
+
 
-    
-    
     MPI_Finalize();
     return 0;
 }
 
 
-int PrintRecvedError( const char *msg, 
-                     MTestDatatype *sendtypePtr, MTestDatatype *recvtypePtr )
+int PrintRecvedError(const char *msg, MTestDatatype * sendtypePtr, MTestDatatype * recvtypePtr)
 {
-    printf( "At step %s, Data in target buffer did not match for destination datatype %s (put with source datatype %s)\n", 
-           msg, 
-           MTestGetDatatypeName( recvtypePtr ),
-           MTestGetDatatypeName( sendtypePtr ) );
+    printf
+        ("At step %s, Data in target buffer did not match for destination datatype %s (put with source datatype %s)\n",
+         msg, MTestGetDatatypeName(recvtypePtr), MTestGetDatatypeName(sendtypePtr));
     /* Redo the test, with the errors printed */
     recvtypePtr->printErrors = 1;
-    (void)MTestCheckRecv( 0, recvtypePtr );
+    (void) MTestCheckRecv(0, recvtypePtr);
     return 0;
 }
index d3f53c0..ac50128 100644 (file)
@@ -78,8 +78,7 @@ int main(int argc, char *argv[])
 
             if (result_data != one) {
                 errors++;
-                printf("Expected: result_data = %d   Actual: result_data = %d\n",
-                       one, result_data);
+                printf("Expected: result_data = %d   Actual: result_data = %d\n", one, result_data);
             }
         }
 
index f8b7fb2..bd10bb6 100644 (file)
@@ -42,7 +42,8 @@
 
 #define CMP(x, y) ((x - ((TYPE_C) (y))) > 1.0e-9)
 
-void reset_vars(TYPE_C *val_ptr, TYPE_C *res_ptr, MPI_Win win) {
+void reset_vars(TYPE_C * val_ptr, TYPE_C * res_ptr, MPI_Win win)
+{
     int i, rank, nproc;
 
     MPI_Comm_rank(MPI_COMM_WORLD, &rank);
@@ -58,24 +59,28 @@ void reset_vars(TYPE_C *val_ptr, TYPE_C *res_ptr, MPI_Win win) {
     MPI_Barrier(MPI_COMM_WORLD);
 }
 
-int main(int argc, char **argv) {
-    int       i, rank, nproc, mpi_type_size;
-    int       errors = 0, all_errors = 0;
-    TYPE_C   *val_ptr, *res_ptr;
-    MPI_Win   win;
+int main(int argc, char **argv)
+{
+    int i, rank, nproc, mpi_type_size;
+    int errors = 0, all_errors = 0;
+    TYPE_C *val_ptr, *res_ptr;
+    MPI_Win win;
 
     MPI_Init(&argc, &argv);
 
     MPI_Comm_rank(MPI_COMM_WORLD, &rank);
     MPI_Comm_size(MPI_COMM_WORLD, &nproc);
+
     MPI_Type_size(TYPE_MPI, &mpi_type_size);
     assert(mpi_type_size == sizeof(TYPE_C));
 
-    val_ptr = malloc(sizeof(TYPE_C)*nproc);
-    res_ptr = malloc(sizeof(TYPE_C)*nproc);
+    val_ptr = malloc(sizeof(TYPE_C) * nproc);
+    res_ptr = malloc(sizeof(TYPE_C) * nproc);
+    MTEST_VG_MEM_INIT(val_ptr, sizeof(TYPE_C) * nproc);
+    MTEST_VG_MEM_INIT(res_ptr, sizeof(TYPE_C) * nproc);
 
-    MPI_Win_create(val_ptr, sizeof(TYPE_C)*nproc, sizeof(TYPE_C), MPI_INFO_NULL, MPI_COMM_WORLD, &win);
+    MPI_Win_create(val_ptr, sizeof(TYPE_C) * nproc, sizeof(TYPE_C), MPI_INFO_NULL, MPI_COMM_WORLD,
+                   &win);
 
     /* Test self communication */
 
@@ -89,8 +94,10 @@ int main(int argc, char **argv) {
     }
 
     MPI_Win_lock(MPI_LOCK_EXCLUSIVE, rank, 0, win);
-    if ( CMP(val_ptr[0], ITER) ) {
-        SQUELCH( printf("%d->%d -- SELF: expected "TYPE_FMT", got "TYPE_FMT"\n", rank, rank, (TYPE_C) ITER, val_ptr[0]); );
+    if (CMP(val_ptr[0], ITER)) {
+        SQUELCH(printf
+                ("%d->%d -- SELF: expected " TYPE_FMT ", got " TYPE_FMT "\n", rank, rank,
+                 (TYPE_C) ITER, val_ptr[0]););
         errors++;
     }
     MPI_Win_unlock(rank, win);
@@ -101,11 +108,13 @@ int main(int argc, char **argv) {
 
     for (i = 0; i < ITER; i++) {
         TYPE_C one = 1, result = -1;
-        MPI_Win_lock(MPI_LOCK_EXCLUSIVE, (rank+1)%nproc, 0, win);
-        MPI_Fetch_and_op(&one, &result, TYPE_MPI, (rank+1)%nproc, 0, MPI_SUM, win);
-        MPI_Win_unlock((rank+1)%nproc, win);
-        if ( CMP(result, i) ) {
-            SQUELCH( printf("%d->%d -- NEIGHBOR[%d]: expected result "TYPE_FMT", got "TYPE_FMT"\n", (rank+1)%nproc, rank, i, (TYPE_C) i, result); );
+        MPI_Win_lock(MPI_LOCK_EXCLUSIVE, (rank + 1) % nproc, 0, win);
+        MPI_Fetch_and_op(&one, &result, TYPE_MPI, (rank + 1) % nproc, 0, MPI_SUM, win);
+        MPI_Win_unlock((rank + 1) % nproc, win);
+        if (CMP(result, i)) {
+            SQUELCH(printf
+                    ("%d->%d -- NEIGHBOR[%d]: expected result " TYPE_FMT ", got " TYPE_FMT "\n",
+                     (rank + 1) % nproc, rank, i, (TYPE_C) i, result););
             errors++;
         }
     }
@@ -113,8 +122,10 @@ int main(int argc, char **argv) {
     MPI_Barrier(MPI_COMM_WORLD);
 
     MPI_Win_lock(MPI_LOCK_EXCLUSIVE, rank, 0, win);
-    if ( CMP(val_ptr[0], ITER) ) {
-        SQUELCH( printf("%d->%d -- NEIGHBOR: expected "TYPE_FMT", got "TYPE_FMT"\n", (rank+1)%nproc, rank, (TYPE_C) ITER, val_ptr[0]); );
+    if (CMP(val_ptr[0], ITER)) {
+        SQUELCH(printf
+                ("%d->%d -- NEIGHBOR: expected " TYPE_FMT ", got " TYPE_FMT "\n",
+                 (rank + 1) % nproc, rank, (TYPE_C) ITER, val_ptr[0]););
         errors++;
     }
     MPI_Win_unlock(rank, win);
@@ -136,8 +147,10 @@ int main(int argc, char **argv) {
 
     MPI_Win_lock(MPI_LOCK_EXCLUSIVE, rank, 0, win);
     if (rank == 0 && nproc > 1) {
-        if ( CMP(val_ptr[0], ITER*(nproc-1)) ) {
-            SQUELCH( printf("*->%d - CONTENTION: expected="TYPE_FMT" val="TYPE_FMT"\n", rank, (TYPE_C) ITER*(nproc-1), val_ptr[0]); );
+        if (CMP(val_ptr[0], ITER * (nproc - 1))) {
+            SQUELCH(printf
+                    ("*->%d - CONTENTION: expected=" TYPE_FMT " val=" TYPE_FMT "\n", rank,
+                     (TYPE_C) ITER * (nproc - 1), val_ptr[0]););
             errors++;
         }
     }
@@ -159,8 +172,10 @@ int main(int argc, char **argv) {
         MPI_Barrier(MPI_COMM_WORLD);
 
         for (j = 0; j < nproc; j++) {
-            if ( CMP(res_ptr[j], i*rank) ) {
-                SQUELCH( printf("%d->%d -- ALL-TO-ALL (FENCE) [%d]: expected result "TYPE_FMT", got "TYPE_FMT"\n", rank, j, i, (TYPE_C) i*rank, res_ptr[j]); );
+            if (CMP(res_ptr[j], i * rank)) {
+                SQUELCH(printf
+                        ("%d->%d -- ALL-TO-ALL (FENCE) [%d]: expected result " TYPE_FMT ", got "
+                         TYPE_FMT "\n", rank, j, i, (TYPE_C) i * rank, res_ptr[j]););
                 errors++;
             }
         }
@@ -169,8 +184,10 @@ int main(int argc, char **argv) {
     MPI_Barrier(MPI_COMM_WORLD);
     MPI_Win_lock(MPI_LOCK_EXCLUSIVE, rank, 0, win);
     for (i = 0; i < nproc; i++) {
-        if ( CMP(val_ptr[i], ITER*i) ) {
-            SQUELCH( printf("%d->%d -- ALL-TO-ALL (FENCE): expected "TYPE_FMT", got "TYPE_FMT"\n", i, rank, (TYPE_C) ITER*i, val_ptr[i]); );
+        if (CMP(val_ptr[i], ITER * i)) {
+            SQUELCH(printf
+                    ("%d->%d -- ALL-TO-ALL (FENCE): expected " TYPE_FMT ", got " TYPE_FMT "\n", i,
+                     rank, (TYPE_C) ITER * i, val_ptr[i]););
             errors++;
         }
     }
@@ -192,8 +209,10 @@ int main(int argc, char **argv) {
         MPI_Barrier(MPI_COMM_WORLD);
 
         for (j = 0; j < nproc; j++) {
-            if ( CMP(res_ptr[j], i*rank) ) {
-                SQUELCH( printf("%d->%d -- ALL-TO-ALL (LOCK-ALL) [%d]: expected result "TYPE_FMT", got "TYPE_FMT"\n", rank, j, i, (TYPE_C) i*rank, res_ptr[j]); );
+            if (CMP(res_ptr[j], i * rank)) {
+                SQUELCH(printf
+                        ("%d->%d -- ALL-TO-ALL (LOCK-ALL) [%d]: expected result " TYPE_FMT ", got "
+                         TYPE_FMT "\n", rank, j, i, (TYPE_C) i * rank, res_ptr[j]););
                 errors++;
             }
         }
@@ -202,8 +221,10 @@ int main(int argc, char **argv) {
     MPI_Barrier(MPI_COMM_WORLD);
     MPI_Win_lock(MPI_LOCK_EXCLUSIVE, rank, 0, win);
     for (i = 0; i < nproc; i++) {
-        if ( CMP(val_ptr[i], ITER*i) ) {
-            SQUELCH( printf("%d->%d -- ALL-TO-ALL (LOCK-ALL): expected "TYPE_FMT", got "TYPE_FMT"\n", i, rank, (TYPE_C) ITER*i, val_ptr[i]); );
+        if (CMP(val_ptr[i], ITER * i)) {
+            SQUELCH(printf
+                    ("%d->%d -- ALL-TO-ALL (LOCK-ALL): expected " TYPE_FMT ", got " TYPE_FMT "\n",
+                     i, rank, (TYPE_C) ITER * i, val_ptr[i]););
             errors++;
         }
     }
@@ -226,8 +247,10 @@ int main(int argc, char **argv) {
         MPI_Barrier(MPI_COMM_WORLD);
 
         for (j = 0; j < nproc; j++) {
-            if ( CMP(res_ptr[j], i*rank) ) {
-                SQUELCH( printf("%d->%d -- ALL-TO-ALL (LOCK-ALL+FLUSH) [%d]: expected result "TYPE_FMT", got "TYPE_FMT"\n", rank, j, i, (TYPE_C) i*rank, res_ptr[j]); );
+            if (CMP(res_ptr[j], i * rank)) {
+                SQUELCH(printf
+                        ("%d->%d -- ALL-TO-ALL (LOCK-ALL+FLUSH) [%d]: expected result " TYPE_FMT
+                         ", got " TYPE_FMT "\n", rank, j, i, (TYPE_C) i * rank, res_ptr[j]););
                 errors++;
             }
         }
@@ -236,8 +259,10 @@ int main(int argc, char **argv) {
     MPI_Barrier(MPI_COMM_WORLD);
     MPI_Win_lock(MPI_LOCK_EXCLUSIVE, rank, 0, win);
     for (i = 0; i < nproc; i++) {
-        if ( CMP(val_ptr[i], ITER*i) ) {
-            SQUELCH( printf("%d->%d -- ALL-TO-ALL (LOCK-ALL+FLUSH): expected "TYPE_FMT", got "TYPE_FMT"\n", i, rank, (TYPE_C) ITER*i, val_ptr[i]); );
+        if (CMP(val_ptr[i], ITER * i)) {
+            SQUELCH(printf
+                    ("%d->%d -- ALL-TO-ALL (LOCK-ALL+FLUSH): expected " TYPE_FMT ", got " TYPE_FMT
+                     "\n", i, rank, (TYPE_C) ITER * i, val_ptr[i]););
             errors++;
         }
     }
@@ -255,15 +280,15 @@ int main(int argc, char **argv) {
     MPI_Barrier(MPI_COMM_WORLD);
 
     for (i = 0; i < ITER; i++) {
-        int target = (rank+1) % nproc;
+        int target = (rank + 1) % nproc;
 
         MPI_Win_lock(MPI_LOCK_EXCLUSIVE, target, 0, win);
         MPI_Fetch_and_op(NULL, res_ptr, TYPE_MPI, target, 0, MPI_NO_OP, win);
         MPI_Win_unlock(target, win);
 
         if (res_ptr[0] != (TYPE_C) target) {
-            SQUELCH( printf("%d->%d -- NOP[%d]: expected "TYPE_FMT", got "TYPE_FMT"\n",
-                            target, rank, i, (TYPE_C) target, res_ptr[0]); );
+            SQUELCH(printf("%d->%d -- NOP[%d]: expected " TYPE_FMT ", got " TYPE_FMT "\n",
+                           target, rank, i, (TYPE_C) target, res_ptr[0]););
             errors++;
         }
     }
@@ -287,8 +312,8 @@ int main(int argc, char **argv) {
         MPI_Win_unlock(target, win);
 
         if (res_ptr[0] != (TYPE_C) target) {
-            SQUELCH( printf("%d->%d -- NOP_SELF[%d]: expected "TYPE_FMT", got "TYPE_FMT"\n",
-                            target, rank, i, (TYPE_C) target, res_ptr[0]); );
+            SQUELCH(printf("%d->%d -- NOP_SELF[%d]: expected " TYPE_FMT ", got " TYPE_FMT "\n",
+                           target, rank, i, (TYPE_C) target, res_ptr[0]););
             errors++;
         }
     }
index dd12a4c..493e158 100644 (file)
@@ -3,64 +3,62 @@
  *  (C) 2001 by Argonne National Laboratory.
  *      See COPYRIGHT in top-level directory.
  */
-#include "mpi.h" 
+#include "mpi.h"
 #include "stdio.h"
 #include "stdlib.h"
 #include "mpitest.h"
 
 /* Fetch and add example from Using MPI-2 (the non-scalable version,
-   Fig. 6.12). */ 
+   Fig. 6.12). */
 
 
-#define NTIMES 20  /* no of times each process calls the counter
-                      routine */
+#define NTIMES 20       /* no of times each process calls the counter
+                         * routine */
 
-int localvalue=0;  /* contribution of this process to the counter. We
-                    define it as a global variable because attribute
-                    caching on the window is not enabled yet. */ 
+int localvalue = 0;             /* contribution of this process to the counter. We
+                                 * define it as a global variable because attribute
+                                 * caching on the window is not enabled yet. */
 
 void Get_nextval(MPI_Win win, int *val_array, MPI_Datatype get_type,
                  int rank, int nprocs, int *value);
 
 int compar(const void *a, const void *b);
 
-int main(int argc, char *argv[]) 
-{ 
-    int rank, nprocs, i, blens[2], disps[2], *counter_mem, *val_array,
-        *results, *counter_vals;
+int main(int argc, char *argv[])
+{
+    int rank, nprocs, i, blens[2], disps[2], *counter_mem, *val_array, *results, *counter_vals;
     MPI_Datatype get_type;
     MPI_Win win;
     int errs = 0;
-    MTest_Init(&argc,&argv); 
-    MPI_Comm_size(MPI_COMM_WORLD,&nprocs); 
-    MPI_Comm_rank(MPI_COMM_WORLD,&rank); 
+
+    MTest_Init(&argc, &argv);
+    MPI_Comm_size(MPI_COMM_WORLD, &nprocs);
+    MPI_Comm_rank(MPI_COMM_WORLD, &rank);
 
     if (rank == 0) {
         /* allocate counter memory and initialize to 0 */
         counter_mem = (int *) calloc(nprocs, sizeof(int));
-        MPI_Win_create(counter_mem, nprocs*sizeof(int), sizeof(int),
+        MPI_Win_create(counter_mem, nprocs * sizeof(int), sizeof(int),
                        MPI_INFO_NULL, MPI_COMM_WORLD, &win);
 
-        MPI_Win_free(&win); 
+        MPI_Win_free(&win);
         free(counter_mem);
 
-        /* gather the results from other processes, sort them, and check 
-           whether they represent a counter being incremented by 1 */
+        /* gather the results from other processes, sort them, and check
+         * whether they represent a counter being incremented by 1 */
 
-        results = (int *) malloc(NTIMES*nprocs*sizeof(int));
-        for (i=0; i<NTIMES*nprocs; i++)
+        results = (int *) malloc(NTIMES * nprocs * sizeof(int));
+        for (i = 0; i < NTIMES * nprocs; i++)
             results[i] = -1;
 
-        MPI_Gather(MPI_IN_PLACE, 0, MPI_DATATYPE_NULL, results, NTIMES, MPI_INT, 
-                   0, MPI_COMM_WORLD);
+        MPI_Gather(MPI_IN_PLACE, 0, MPI_DATATYPE_NULL, results, NTIMES, MPI_INT, 0, MPI_COMM_WORLD);
 
-        qsort(results+NTIMES, NTIMES*(nprocs-1), sizeof(int), compar);
+        qsort(results + NTIMES, NTIMES * (nprocs - 1), sizeof(int), compar);
 
-        for (i=NTIMES+1; i<(NTIMES*nprocs); i++)
-            if (results[i] != results[i-1] + 1)
+        for (i = NTIMES + 1; i < (NTIMES * nprocs); i++)
+            if (results[i] != results[i - 1] + 1)
                 errs++;
-        
+
         free(results);
     }
     else {
@@ -74,14 +72,14 @@ int main(int argc, char *argv[])
 
         val_array = (int *) malloc(nprocs * sizeof(int));
 
-        /* allocate array to store the values obtained from the 
-           fetch-and-add counter */
+        /* allocate array to store the values obtained from the
+         * fetch-and-add counter */
         counter_vals = (int *) malloc(NTIMES * sizeof(int));
 
-        MPI_Win_create(NULL, 0, 1, MPI_INFO_NULL, MPI_COMM_WORLD, &win); 
+        MPI_Win_create(NULL, 0, 1, MPI_INFO_NULL, MPI_COMM_WORLD, &win);
 
-        for (i=0; i<NTIMES; i++) {
-            Get_nextval(win, val_array, get_type, rank, nprocs, counter_vals+i);
+        for (i = 0; i < NTIMES; i++) {
+            Get_nextval(win, val_array, get_type, rank, nprocs, counter_vals + i);
             /* printf("Rank %d, counter %d\n", rank, value); */
         }
 
@@ -91,30 +89,29 @@ int main(int argc, char *argv[])
         MPI_Type_free(&get_type);
 
         /* gather the results to the root */
-        MPI_Gather(counter_vals, NTIMES, MPI_INT, NULL, 0, MPI_DATATYPE_NULL, 
-                   0, MPI_COMM_WORLD);
+        MPI_Gather(counter_vals, NTIMES, MPI_INT, NULL, 0, MPI_DATATYPE_NULL, 0, MPI_COMM_WORLD);
         free(counter_vals);
     }
 
     MTest_Finalize(errs);
-    MPI_Finalize(); 
-    return 0; 
-} 
+    MPI_Finalize();
+    return 0;
+}
 
 
 void Get_nextval(MPI_Win win, int *val_array, MPI_Datatype get_type,
-                 int rank, int nprocs, int *value) 
+                 int rank, int nprocs, int *value)
 {
-    int one=1, i;
+    int one = 1, i;
 
     MPI_Win_lock(MPI_LOCK_EXCLUSIVE, 0, 0, win);
     MPI_Accumulate(&one, 1, MPI_INT, 0, rank, 1, MPI_INT, MPI_SUM, win);
-    MPI_Get(val_array, 1, get_type, 0, 0, 1, get_type, win); 
+    MPI_Get(val_array, 1, get_type, 0, 0, 1, get_type, win);
     MPI_Win_unlock(0, win);
 
     *value = 0;
     val_array[rank] = localvalue;
-    for (i=0; i<nprocs; i++)
+    for (i = 0; i < nprocs; i++)
         *value = *value + val_array[i];
 
     localvalue++;
@@ -122,6 +119,5 @@ void Get_nextval(MPI_Win win, int *val_array, MPI_Datatype get_type,
 
 int compar(const void *a, const void *b)
 {
-    return (*((int *)a) - *((int *)b));
+    return (*((int *) a) - *((int *) b));
 }
-
index 0ecde99..0a70155 100644 (file)
@@ -3,74 +3,73 @@
  *  (C) 2001 by Argonne National Laboratory.
  *      See COPYRIGHT in top-level directory.
  */
-#include "mpi.h" 
+#include "mpi.h"
 #include "stdio.h"
 #include "stdlib.h"
 #include "mpitest.h"
 
 /* Fetch and add example from Using MPI-2 (the non-scalable version,
-   Fig. 6.12). */ 
+   Fig. 6.12). */
 
 /* same as fetchandadd.c but uses alloc_mem */
 
-#define NTIMES 20  /* no of times each process calls the counter
-                      routine */
+#define NTIMES 20       /* no of times each process calls the counter
+                         * routine */
 
-int localvalue=0;  /* contribution of this process to the counter. We
-                    define it as a global variable because attribute
-                    caching on the window is not enabled yet. */ 
+int localvalue = 0;             /* contribution of this process to the counter. We
+                                 * define it as a global variable because attribute
+                                 * caching on the window is not enabled yet. */
 
 void Get_nextval(MPI_Win win, int *val_array, MPI_Datatype get_type,
                  int rank, int nprocs, int *value);
 
 int compar(const void *a, const void *b);
 
-int main(int argc, char *argv[]) 
-{ 
-    int rank, nprocs, i, blens[2], disps[2], *counter_mem, *val_array,
-        *results, *counter_vals;
+int main(int argc, char *argv[])
+{
+    int rank, nprocs, i, blens[2], disps[2], *counter_mem, *val_array, *results, *counter_vals;
     MPI_Datatype get_type;
     MPI_Win win;
     int errs = 0;
-    MTest_Init(&argc,&argv); 
-    MPI_Comm_size(MPI_COMM_WORLD,&nprocs); 
-    MPI_Comm_rank(MPI_COMM_WORLD,&rank); 
+
+    MTest_Init(&argc, &argv);
+    MPI_Comm_size(MPI_COMM_WORLD, &nprocs);
+    MPI_Comm_rank(MPI_COMM_WORLD, &rank);
 
     if (rank == 0) {
         /* allocate counter memory and initialize to 0 */
         /* counter_mem = (int *) calloc(nprocs, sizeof(int)); */
 
-        i = MPI_Alloc_mem(nprocs*sizeof(int), MPI_INFO_NULL, &counter_mem);
+        i = MPI_Alloc_mem(nprocs * sizeof(int), MPI_INFO_NULL, &counter_mem);
         if (i) {
             printf("Can't allocate memory in test program\n");
             MPI_Abort(MPI_COMM_WORLD, 1);
         }
 
-        for (i=0; i<nprocs; i++) counter_mem[i] = 0;
+        for (i = 0; i < nprocs; i++)
+            counter_mem[i] = 0;
 
-        MPI_Win_create(counter_mem, nprocs*sizeof(int), sizeof(int),
+        MPI_Win_create(counter_mem, nprocs * sizeof(int), sizeof(int),
                        MPI_INFO_NULL, MPI_COMM_WORLD, &win);
 
-        MPI_Win_free(&win); 
+        MPI_Win_free(&win);
         MPI_Free_mem(counter_mem);
 
-        /* gather the results from other processes, sort them, and check 
-           whether they represent a counter being incremented by 1 */
+        /* gather the results from other processes, sort them, and check
+         * whether they represent a counter being incremented by 1 */
 
-        results = (int *) malloc(NTIMES*nprocs*sizeof(int));
-        for (i=0; i<NTIMES*nprocs; i++)
+        results = (int *) malloc(NTIMES * nprocs * sizeof(int));
+        for (i = 0; i < NTIMES * nprocs; i++)
             results[i] = -1;
 
-        MPI_Gather(MPI_IN_PLACE, 0, MPI_DATATYPE_NULL, results, NTIMES, MPI_INT, 
-                   0, MPI_COMM_WORLD);
+        MPI_Gather(MPI_IN_PLACE, 0, MPI_DATATYPE_NULL, results, NTIMES, MPI_INT, 0, MPI_COMM_WORLD);
 
-        qsort(results+NTIMES, NTIMES*(nprocs-1), sizeof(int), compar);
+        qsort(results + NTIMES, NTIMES * (nprocs - 1), sizeof(int), compar);
 
-        for (i=NTIMES+1; i<(NTIMES*nprocs); i++)
-            if (results[i] != results[i-1] + 1)
+        for (i = NTIMES + 1; i < (NTIMES * nprocs); i++)
+            if (results[i] != results[i - 1] + 1)
                 errs++;
-        
+
         free(results);
     }
     else {
@@ -84,14 +83,14 @@ int main(int argc, char *argv[])
 
         val_array = (int *) malloc(nprocs * sizeof(int));
 
-        /* allocate array to store the values obtained from the 
-           fetch-and-add counter */
+        /* allocate array to store the values obtained from the
+         * fetch-and-add counter */
         counter_vals = (int *) malloc(NTIMES * sizeof(int));
 
-        MPI_Win_create(NULL, 0, 1, MPI_INFO_NULL, MPI_COMM_WORLD, &win); 
+        MPI_Win_create(NULL, 0, 1, MPI_INFO_NULL, MPI_COMM_WORLD, &win);
 
-        for (i=0; i<NTIMES; i++) {
-            Get_nextval(win, val_array, get_type, rank, nprocs, counter_vals+i);
+        for (i = 0; i < NTIMES; i++) {
+            Get_nextval(win, val_array, get_type, rank, nprocs, counter_vals + i);
             /* printf("Rank %d, counter %d\n", rank, value); */
         }
 
@@ -101,30 +100,29 @@ int main(int argc, char *argv[])
         MPI_Type_free(&get_type);
 
         /* gather the results to the root */
-        MPI_Gather(counter_vals, NTIMES, MPI_INT, NULL, 0, MPI_DATATYPE_NULL, 
-                   0, MPI_COMM_WORLD);
+        MPI_Gather(counter_vals, NTIMES, MPI_INT, NULL, 0, MPI_DATATYPE_NULL, 0, MPI_COMM_WORLD);
         free(counter_vals);
     }
 
     MTest_Finalize(errs);
-    MPI_Finalize(); 
-    return 0; 
-} 
+    MPI_Finalize();
+    return 0;
+}
 
 
 void Get_nextval(MPI_Win win, int *val_array, MPI_Datatype get_type,
-                 int rank, int nprocs, int *value) 
+                 int rank, int nprocs, int *value)
 {
-    int one=1, i;
+    int one = 1, i;
 
     MPI_Win_lock(MPI_LOCK_EXCLUSIVE, 0, 0, win);
     MPI_Accumulate(&one, 1, MPI_INT, 0, rank, 1, MPI_INT, MPI_SUM, win);
-    MPI_Get(val_array, 1, get_type, 0, 0, 1, get_type, win); 
+    MPI_Get(val_array, 1, get_type, 0, 0, 1, get_type, win);
     MPI_Win_unlock(0, win);
 
     *value = 0;
     val_array[rank] = localvalue;
-    for (i=0; i<nprocs; i++)
+    for (i = 0; i < nprocs; i++)
         *value = *value + val_array[i];
 
     localvalue++;
@@ -132,6 +130,5 @@ void Get_nextval(MPI_Win win, int *val_array, MPI_Datatype get_type,
 
 int compar(const void *a, const void *b)
 {
-    return (*((int *)a) - *((int *)b));
+    return (*((int *) a) - *((int *) b));
 }
-
index 8b3c8f3..4229a9e 100644 (file)
@@ -3,78 +3,78 @@
  *  (C) 2001 by Argonne National Laboratory.
  *      See COPYRIGHT in top-level directory.
  */
-#include "mpi.h" 
+#include "mpi.h"
 #include "stdio.h"
 #include "stdlib.h"
 #include "mpitest.h"
 
 /* This is the tree-based scalable version of the fetch-and-add
    example from Using MPI-2, pg 206-207. The code in the book (Fig
-   6.16) has bugs that are fixed below. */ 
+   6.16) has bugs that are fixed below. */
 
 
-#define NTIMES 20  /* no of times each process calls the counter
-                      routine */
+#define NTIMES 20       /* no of times each process calls the counter
+                         * routine */
 
-int localvalue=0;  /* contribution of this process to the counter. We
-                    define it as a global variable because attribute
-                    caching on the window is not enabled yet. */ 
+int localvalue = 0;             /* contribution of this process to the counter. We
+                                 * define it as a global variable because attribute
+                                 * caching on the window is not enabled yet. */
 
 void Get_nextval_tree(MPI_Win win, int *get_array, MPI_Datatype get_type,
-                 MPI_Datatype acc_type, int nlevels, int *value);
+                      MPI_Datatype acc_type, int nlevels, int *value);
 
 int compar(const void *a, const void *b);
 
-int main(int argc, char *argv[]) 
-{ 
+int main(int argc, char *argv[])
+{
     int rank, nprocs, i, *counter_mem, *get_array, *get_idx, *acc_idx,
         mask, nlevels, level, idx, tmp_rank, pof2;
     MPI_Datatype get_type, acc_type;
     MPI_Win win;
     int errs = 0, *results, *counter_vals;
-    MTest_Init(&argc,&argv); 
-    MPI_Comm_size(MPI_COMM_WORLD,&nprocs); 
-    MPI_Comm_rank(MPI_COMM_WORLD,&rank); 
+
+    MTest_Init(&argc, &argv);
+    MPI_Comm_size(MPI_COMM_WORLD, &nprocs);
+    MPI_Comm_rank(MPI_COMM_WORLD, &rank);
 
     if (rank == 0) {
         /* allocate counter memory and initialize to 0 */
 
         /* find the next power-of-two >= nprocs */
         pof2 = 1;
-        while (pof2 < nprocs) pof2 *= 2;
+        while (pof2 < nprocs)
+            pof2 *= 2;
 
-        counter_mem = (int *) calloc(pof2*2, sizeof(int));
-        MPI_Win_create(counter_mem, pof2*2*sizeof(int), sizeof(int),
+        counter_mem = (int *) calloc(pof2 * 2, sizeof(int));
+        MPI_Win_create(counter_mem, pof2 * 2 * sizeof(int), sizeof(int),
                        MPI_INFO_NULL, MPI_COMM_WORLD, &win);
 
-        MPI_Win_free(&win); 
+        MPI_Win_free(&win);
         free(counter_mem);
 
-        /* gather the results from other processes, sort them, and check 
-           whether they represent a counter being incremented by 1 */
+        /* gather the results from other processes, sort them, and check
+         * whether they represent a counter being incremented by 1 */
 
-        results = (int *) malloc(NTIMES*nprocs*sizeof(int));
-        for (i=0; i<NTIMES*nprocs; i++)
+        results = (int *) malloc(NTIMES * nprocs * sizeof(int));
+        for (i = 0; i < NTIMES * nprocs; i++)
             results[i] = -1;
 
-        MPI_Gather(MPI_IN_PLACE, 0, MPI_DATATYPE_NULL, results, NTIMES, MPI_INT, 
-                   0, MPI_COMM_WORLD);
+        MPI_Gather(MPI_IN_PLACE, 0, MPI_DATATYPE_NULL, results, NTIMES, MPI_INT, 0, MPI_COMM_WORLD);
 
-        qsort(results+NTIMES, NTIMES*(nprocs-1), sizeof(int), compar);
+        qsort(results + NTIMES, NTIMES * (nprocs - 1), sizeof(int), compar);
 
-        for (i=NTIMES+1; i<(NTIMES*nprocs); i++)
-            if (results[i] != results[i-1] + 1)
+        for (i = NTIMES + 1; i < (NTIMES * nprocs); i++)
+            if (results[i] != results[i - 1] + 1)
                 errs++;
-        
+
         free(results);
     }
     else {
-        /* Get the largest power of two smaller than nprocs */ 
-        mask = 1; 
+        /* Get the largest power of two smaller than nprocs */
+        mask = 1;
         nlevels = 0;
         while (mask < nprocs) {
-            mask <<= 1; 
+            mask <<= 1;
             nlevels++;
         }
         mask >>= 1;
@@ -83,28 +83,28 @@ int main(int argc, char *argv[])
         get_idx = (int *) malloc(nlevels * sizeof(int));
         acc_idx = (int *) malloc(nlevels * sizeof(int));
 
-        level = 0; 
-        idx   = 0; 
+        level = 0;
+        idx = 0;
         tmp_rank = rank;
-        while (mask >= 1) { 
-            if (tmp_rank < mask) { 
+        while (mask >= 1) {
+            if (tmp_rank < mask) {
                 /* go to left for acc_idx, go to right for
-                   get_idx. set idx=acc_idx for next iteration */ 
-                acc_idx[level] = idx + 1; 
-                get_idx[level] = idx + mask*2; 
-                idx            = idx + 1; 
-            } 
-            else { 
+                 * get_idx. set idx=acc_idx for next iteration */
+                acc_idx[level] = idx + 1;
+                get_idx[level] = idx + mask * 2;
+                idx = idx + 1;
+            }
+            else {
                 /* go to right for acc_idx, go to left for
-                   get_idx. set idx=acc_idx for next iteration */ 
-                acc_idx[level] = idx + mask*2; 
-                get_idx[level] = idx + 1; 
-                idx            = idx + mask*2; 
-            } 
+                 * get_idx. set idx=acc_idx for next iteration */
+                acc_idx[level] = idx + mask * 2;
+                get_idx[level] = idx + 1;
+                idx = idx + mask * 2;
+            }
             level++;
             tmp_rank = tmp_rank % mask;
-            mask >>= 1; 
-        } 
+            mask >>= 1;
+        }
 
 /*        for (i=0; i<nlevels; i++)
             printf("Rank %d, acc_idx[%d]=%d, get_idx[%d]=%d\n", rank,
@@ -116,15 +116,14 @@ int main(int argc, char *argv[])
         MPI_Type_commit(&get_type);
         MPI_Type_commit(&acc_type);
 
-        /* allocate array to store the values obtained from the 
-           fetch-and-add counter */
+        /* allocate array to store the values obtained from the
+         * fetch-and-add counter */
         counter_vals = (int *) malloc(NTIMES * sizeof(int));
 
-        MPI_Win_create(NULL, 0, 1, MPI_INFO_NULL, MPI_COMM_WORLD, &win); 
+        MPI_Win_create(NULL, 0, 1, MPI_INFO_NULL, MPI_COMM_WORLD, &win);
 
-        for (i=0; i<NTIMES; i++) {
-            Get_nextval_tree(win, get_array, get_type, acc_type,
-                             nlevels, counter_vals+i); 
+        for (i = 0; i < NTIMES; i++) {
+            Get_nextval_tree(win, get_array, get_type, acc_type, nlevels, counter_vals + i);
             /* printf("Rank %d, counter %d\n", rank, value); */
         }
 
@@ -135,16 +134,15 @@ int main(int argc, char *argv[])
         MPI_Type_free(&get_type);
         MPI_Type_free(&acc_type);
 
-         /* gather the results to the root */
-        MPI_Gather(counter_vals, NTIMES, MPI_INT, NULL, 0, MPI_DATATYPE_NULL, 
-                   0, MPI_COMM_WORLD);
+        /* gather the results to the root */
+        MPI_Gather(counter_vals, NTIMES, MPI_INT, NULL, 0, MPI_DATATYPE_NULL, 0, MPI_COMM_WORLD);
         free(counter_vals);
-   }
+    }
 
     MTest_Finalize(errs);
-    MPI_Finalize(); 
-    return MTestReturnValue( errs );
-} 
+    MPI_Finalize();
+    return MTestReturnValue(errs);
+}
 
 
 void Get_nextval_tree(MPI_Win win, int *get_array, MPI_Datatype get_type,
@@ -152,17 +150,17 @@ void Get_nextval_tree(MPI_Win win, int *get_array, MPI_Datatype get_type,
 {
     int *one, i;
 
-    one = (int *) malloc(nlevels*sizeof(int));
-    for (i=0; i<nlevels; i++) one[i] = 1;
+    one = (int *) malloc(nlevels * sizeof(int));
+    for (i = 0; i < nlevels; i++)
+        one[i] = 1;
 
     MPI_Win_lock(MPI_LOCK_EXCLUSIVE, 0, 0, win);
-    MPI_Accumulate(one, nlevels, MPI_INT, 0, 0, 1, acc_type,
-                   MPI_SUM, win);
+    MPI_Accumulate(one, nlevels, MPI_INT, 0, 0, 1, acc_type, MPI_SUM, win);
     MPI_Get(get_array, nlevels, MPI_INT, 0, 0, 1, get_type, win);
     MPI_Win_unlock(0, win);
 
     *value = localvalue;
-    for (i=0; i<nlevels; i++)
+    for (i = 0; i < nlevels; i++)
         *value = *value + get_array[i];
 
     localvalue++;
@@ -172,5 +170,5 @@ void Get_nextval_tree(MPI_Win win, int *get_array, MPI_Datatype get_type,
 
 int compar(const void *a, const void *b)
 {
-    return (*((int *)a) - *((int *)b));
+    return (*((int *) a) - *((int *) b));
 }
index f5ca1e0..1205bdd 100644 (file)
@@ -3,90 +3,91 @@
  *  (C) 2001 by Argonne National Laboratory.
  *      See COPYRIGHT in top-level directory.
  */
-#include "mpi.h" 
+#include "mpi.h"
 #include "stdio.h"
 #include "stdlib.h"
 #include "mpitest.h"
 
 /* This is the tree-based scalable version of the fetch-and-add
    example from Using MPI-2, pg 206-207. The code in the book (Fig
-   6.16) has bugs that are fixed below. */ 
+   6.16) has bugs that are fixed below. */
 
 /* same as fetchandadd_tree.c but uses alloc_mem */
 
-#define NTIMES 20  /* no of times each process calls the counter
-                      routine */
+#define NTIMES 20       /* no of times each process calls the counter
+                         * routine */
 
-int localvalue=0;  /* contribution of this process to the counter. We
-                    define it as a global variable because attribute
-                    caching on the window is not enabled yet. */ 
+int localvalue = 0;             /* contribution of this process to the counter. We
+                                 * define it as a global variable because attribute
+                                 * caching on the window is not enabled yet. */
 
 void Get_nextval_tree(MPI_Win win, int *get_array, MPI_Datatype get_type,
-                 MPI_Datatype acc_type, int nlevels, int *value);
+                      MPI_Datatype acc_type, int nlevels, int *value);
 
 int compar(const void *a, const void *b);
 
-int main(int argc, char *argv[]) 
-{ 
+int main(int argc, char *argv[])
+{
     int rank, nprocs, i, *counter_mem, *get_array, *get_idx, *acc_idx,
         mask, nlevels, level, idx, tmp_rank, pof2;
     MPI_Datatype get_type, acc_type;
     MPI_Win win;
     int errs = 0, *results, *counter_vals;
-    MTest_Init(&argc,&argv); 
-    MPI_Comm_size(MPI_COMM_WORLD,&nprocs); 
-    MPI_Comm_rank(MPI_COMM_WORLD,&rank); 
+
+    MTest_Init(&argc, &argv);
+    MPI_Comm_size(MPI_COMM_WORLD, &nprocs);
+    MPI_Comm_rank(MPI_COMM_WORLD, &rank);
 
     if (rank == 0) {
         /* allocate counter memory and initialize to 0 */
 
         /* find the next power-of-two >= nprocs */
         pof2 = 1;
-        while (pof2 < nprocs) pof2 *= 2;
+        while (pof2 < nprocs)
+            pof2 *= 2;
 
         /* counter_mem = (int *) calloc(pof2*2, sizeof(int)); */
 
-        i = MPI_Alloc_mem(pof2*2*sizeof(int), MPI_INFO_NULL, &counter_mem);
+        i = MPI_Alloc_mem(pof2 * 2 * sizeof(int), MPI_INFO_NULL, &counter_mem);
         if (i) {
             printf("Can't allocate memory in test program\n");
             MPI_Abort(MPI_COMM_WORLD, 1);
         }
 
-        for (i=0; i<(pof2*2); i++) counter_mem[i] = 0;
+        for (i = 0; i < (pof2 * 2); i++)
+            counter_mem[i] = 0;
 
-        MPI_Win_create(counter_mem, pof2*2*sizeof(int), sizeof(int),
+        MPI_Win_create(counter_mem, pof2 * 2 * sizeof(int), sizeof(int),
                        MPI_INFO_NULL, MPI_COMM_WORLD, &win);
 
-        MPI_Win_free(&win); 
+        MPI_Win_free(&win);
 
         /* free(counter_mem) */
         MPI_Free_mem(counter_mem);
 
-        /* gather the results from other processes, sort them, and check 
-           whether they represent a counter being incremented by 1 */
+        /* gather the results from other processes, sort them, and check
+         * whether they represent a counter being incremented by 1 */
 
-        results = (int *) malloc(NTIMES*nprocs*sizeof(int));
-        for (i=0; i<NTIMES*nprocs; i++)
+        results = (int *) malloc(NTIMES * nprocs * sizeof(int));
+        for (i = 0; i < NTIMES * nprocs; i++)
             results[i] = -1;
 
-        MPI_Gather(MPI_IN_PLACE, 0, MPI_DATATYPE_NULL, results, NTIMES, MPI_INT, 
-                   0, MPI_COMM_WORLD);
+        MPI_Gather(MPI_IN_PLACE, 0, MPI_DATATYPE_NULL, results, NTIMES, MPI_INT, 0, MPI_COMM_WORLD);
 
-        qsort(results+NTIMES, NTIMES*(nprocs-1), sizeof(int), compar);
+        qsort(results + NTIMES, NTIMES * (nprocs - 1), sizeof(int), compar);
 
-        for (i=NTIMES+1; i<(NTIMES*nprocs); i++)
-            if (results[i] != results[i-1] + 1)
+        for (i = NTIMES + 1; i < (NTIMES * nprocs); i++)
+            if (results[i] != results[i - 1] + 1)
                 errs++;
-        
+
         free(results);
     }
     else {
-        /* Get the largest power of two smaller than nprocs */ 
-        mask = 1; 
+        /* Get the largest power of two smaller than nprocs */
+        mask = 1;
         nlevels = 0;
         while (mask < nprocs) {
-            mask <<= 1; 
+            mask <<= 1;
             nlevels++;
         }
         mask >>= 1;
@@ -95,28 +96,28 @@ int main(int argc, char *argv[])
         get_idx = (int *) malloc(nlevels * sizeof(int));
         acc_idx = (int *) malloc(nlevels * sizeof(int));
 
-        level = 0; 
-        idx   = 0; 
+        level = 0;
+        idx = 0;
         tmp_rank = rank;
-        while (mask >= 1) { 
-            if (tmp_rank < mask) { 
+        while (mask >= 1) {
+            if (tmp_rank < mask) {
                 /* go to left for acc_idx, go to right for
-                   get_idx. set idx=acc_idx for next iteration */ 
-                acc_idx[level] = idx + 1; 
-                get_idx[level] = idx + mask*2; 
-                idx            = idx + 1; 
-            } 
-            else { 
+                 * get_idx. set idx=acc_idx for next iteration */
+                acc_idx[level] = idx + 1;
+                get_idx[level] = idx + mask * 2;
+                idx = idx + 1;
+            }
+            else {
                 /* go to right for acc_idx, go to left for
-                   get_idx. set idx=acc_idx for next iteration */ 
-                acc_idx[level] = idx + mask*2; 
-                get_idx[level] = idx + 1; 
-                idx            = idx + mask*2; 
-            } 
+                 * get_idx. set idx=acc_idx for next iteration */
+                acc_idx[level] = idx + mask * 2;
+                get_idx[level] = idx + 1;
+                idx = idx + mask * 2;
+            }
             level++;
             tmp_rank = tmp_rank % mask;
-            mask >>= 1; 
-        } 
+            mask >>= 1;
+        }
 
 /*        for (i=0; i<nlevels; i++)
             printf("Rank %d, acc_idx[%d]=%d, get_idx[%d]=%d\n", rank,
@@ -128,15 +129,14 @@ int main(int argc, char *argv[])
         MPI_Type_commit(&get_type);
         MPI_Type_commit(&acc_type);
 
-        /* allocate array to store the values obtained from the 
-           fetch-and-add counter */
+        /* allocate array to store the values obtained from the
+         * fetch-and-add counter */
         counter_vals = (int *) malloc(NTIMES * sizeof(int));
 
-        MPI_Win_create(NULL, 0, 1, MPI_INFO_NULL, MPI_COMM_WORLD, &win); 
+        MPI_Win_create(NULL, 0, 1, MPI_INFO_NULL, MPI_COMM_WORLD, &win);
 
-        for (i=0; i<NTIMES; i++) {
-            Get_nextval_tree(win, get_array, get_type, acc_type,
-                             nlevels, counter_vals+i); 
+        for (i = 0; i < NTIMES; i++) {
+            Get_nextval_tree(win, get_array, get_type, acc_type, nlevels, counter_vals + i);
             /* printf("Rank %d, counter %d\n", rank, value); */
         }
 
@@ -147,16 +147,15 @@ int main(int argc, char *argv[])
         MPI_Type_free(&get_type);
         MPI_Type_free(&acc_type);
 
-         /* gather the results to the root */
-        MPI_Gather(counter_vals, NTIMES, MPI_INT, NULL, 0, MPI_DATATYPE_NULL, 
-                   0, MPI_COMM_WORLD);
+        /* gather the results to the root */
+        MPI_Gather(counter_vals, NTIMES, MPI_INT, NULL, 0, MPI_DATATYPE_NULL, 0, MPI_COMM_WORLD);
         free(counter_vals);
-   }
+    }
 
     MTest_Finalize(errs);
-    MPI_Finalize(); 
-    return MTestReturnValue( errs );
-} 
+    MPI_Finalize();
+    return MTestReturnValue(errs);
+}
 
 
 void Get_nextval_tree(MPI_Win win, int *get_array, MPI_Datatype get_type,
@@ -164,17 +163,17 @@ void Get_nextval_tree(MPI_Win win, int *get_array, MPI_Datatype get_type,
 {
     int *one, i;
 
-    one = (int *) malloc(nlevels*sizeof(int));
-    for (i=0; i<nlevels; i++) one[i] = 1;
+    one = (int *) malloc(nlevels * sizeof(int));
+    for (i = 0; i < nlevels; i++)
+        one[i] = 1;
 
     MPI_Win_lock(MPI_LOCK_EXCLUSIVE, 0, 0, win);
-    MPI_Accumulate(one, nlevels, MPI_INT, 0, 0, 1, acc_type,
-                   MPI_SUM, win);
+    MPI_Accumulate(one, nlevels, MPI_INT, 0, 0, 1, acc_type, MPI_SUM, win);
     MPI_Get(get_array, nlevels, MPI_INT, 0, 0, 1, get_type, win);
     MPI_Win_unlock(0, win);
 
     *value = localvalue;
-    for (i=0; i<nlevels; i++)
+    for (i = 0; i < nlevels; i++)
         *value = *value + get_array[i];
 
     localvalue++;
@@ -184,5 +183,5 @@ void Get_nextval_tree(MPI_Win win, int *get_array, MPI_Datatype get_type,
 
 int compar(const void *a, const void *b)
 {
-    return (*((int *)a) - *((int *)b));
+    return (*((int *) a) - *((int *) b));
 }
index 7aed170..620eb61 100644 (file)
@@ -21,72 +21,66 @@ executed";
 
 /* Copy increments the attribute value */
 /* Note that we can really ignore this because there is no win dup */
-int copy_fn( MPI_Win oldwin, int keyval, void *extra_state,
-            void *attribute_val_in, void *attribute_val_out, 
-            int *flag);
-int copy_fn( MPI_Win oldwin, int keyval, void *extra_state,
-            void *attribute_val_in, void *attribute_val_out, 
-            int *flag)
+int copy_fn(MPI_Win oldwin, int keyval, void *extra_state,
+            void *attribute_val_in, void *attribute_val_out, int *flag);
+int copy_fn(MPI_Win oldwin, int keyval, void *extra_state,
+            void *attribute_val_in, void *attribute_val_out, int *flag)
 {
     /* Copy the address of the attribute */
-    *(void **)attribute_val_out = attribute_val_in;
+    *(void **) attribute_val_out = attribute_val_in;
     /* Change the value */
-    *(int *)attribute_val_in = *(int *)attribute_val_in + 1;
+    *(int *) attribute_val_in = *(int *) attribute_val_in + 1;
     *flag = 1;
     return MPI_SUCCESS;
 }
 
 /* Delete decrements the attribute value */
-int delete_fn( MPI_Win win, int keyval, void *attribute_val, 
-              void *extra_state);
-int delete_fn( MPI_Win win, int keyval, void *attribute_val, 
-              void *extra_state)
+int delete_fn(MPI_Win win, int keyval, void *attribute_val, void *extra_state);
+int delete_fn(MPI_Win win, int keyval, void *attribute_val, void *extra_state)
 {
-    *(int *)attribute_val = *(int *)attribute_val - 1;
+    *(int *) attribute_val = *(int *) attribute_val - 1;
     return MPI_SUCCESS;
 }
 
-int main( int argc, char *argv[] )
+int main(int argc, char *argv[])
 {
     int errs = 0;
     int attrval;
-    int i, key[32], keyval, saveKeyval;
+    int i, key[32], keyval;
     MPI_Win win;
-    MTest_Init( &argc, &argv );
+    MTest_Init(&argc, &argv);
 
-    while (MTestGetWin( &win, 0 )) {
-       if (win == MPI_WIN_NULL) continue;
+    while (MTestGetWin(&win, 0)) {
+        if (win == MPI_WIN_NULL)
+            continue;
 
-       MPI_Win_create_keyval( copy_fn, delete_fn, &keyval, (void *)0 );
-       saveKeyval = keyval;   /* in case we need to free explicitly */
-       attrval = 1;
-       MPI_Win_set_attr( win, keyval, (void*)&attrval );
-       /* See MPI-1, 5.7.1.  Freeing the keyval does not remove it if it
-          is in use in an attribute */
-       MPI_Win_free_keyval( &keyval );
-       
-       /* We create some dummy keyvals here in case the same keyval
-          is reused */
-       for (i=0; i<32; i++) {
-           MPI_Win_create_keyval( MPI_NULL_COPY_FN, MPI_NULL_DELETE_FN,
-                              &key[i], (void *)0 );
-       }
+        MPI_Win_create_keyval(copy_fn, delete_fn, &keyval, (void *) 0);
+        attrval = 1;
+        MPI_Win_set_attr(win, keyval, (void *) &attrval);
+        /* See MPI-1, 5.7.1.  Freeing the keyval does not remove it if it
+         * is in use in an attribute */
+        MPI_Win_free_keyval(&keyval);
+
+        /* We create some dummy keyvals here in case the same keyval
+         * is reused */
+        for (i = 0; i < 32; i++) {
+            MPI_Win_create_keyval(MPI_NULL_COPY_FN, MPI_NULL_DELETE_FN, &key[i], (void *) 0);
+        }
 
         MTestFreeWin(&win);
 
-       /* Check that the original attribute was freed */
-       if (attrval != 0) {
-           errs++;
-           printf( "Attribute not decremented when win %s freed\n",
-                   MTestGetWinName() );
-       }
-       /* Free those other keyvals */
-       for (i=0; i<32; i++) {
-           MPI_Win_free_keyval( &key[i] );
-       }
+        /* Check that the original attribute was freed */
+        if (attrval != 0) {
+            errs++;
+            printf("Attribute not decremented when win %s freed\n", MTestGetWinName());
+        }
+        /* Free those other keyvals */
+        for (i = 0; i < 32; i++) {
+            MPI_Win_free_keyval(&key[i]);
+        }
 
     }
-    MTest_Finalize( errs );
+    MTest_Finalize(errs);
     MPI_Finalize();
 
     return 0;
index 1f21470..502db11 100644 (file)
@@ -10,7 +10,7 @@
 
 #define ITER 100
 
-int main( int argc, char *argv[] )
+int main(int argc, char *argv[])
 {
     int rank, nproc, i;
     int errors = 0, all_errors = 0;
@@ -22,19 +22,21 @@ int main( int argc, char *argv[] )
     MPI_Comm_size(MPI_COMM_WORLD, &nproc);
 
     if (nproc < 2) {
-        if (rank == 0) printf("Error: must be run with two or more processes\n");
+        if (rank == 0)
+            printf("Error: must be run with two or more processes\n");
         MPI_Abort(MPI_COMM_WORLD, 1);
     }
 
     /** Create using MPI_Win_create() **/
 
     if (rank == 0) {
-      MPI_Alloc_mem(sizeof(int), MPI_INFO_NULL, &buf);
-      *buf = nproc-1;
-    } else
-      buf = NULL;
+        MPI_Alloc_mem(sizeof(int), MPI_INFO_NULL, &buf);
+        *buf = nproc - 1;
+    }
+    else
+        buf = NULL;
 
-    MPI_Win_create(buf, sizeof(int)*(rank == 0), 1, MPI_INFO_NULL, MPI_COMM_WORLD, &window);
+    MPI_Win_create(buf, sizeof(int) * (rank == 0), 1, MPI_INFO_NULL, MPI_COMM_WORLD, &window);
 
     /* Test flush of an empty epoch */
     MPI_Win_lock(MPI_LOCK_SHARED, 0, 0, window);
@@ -53,21 +55,22 @@ int main( int argc, char *argv[] )
          * to the right.  Each process, in turn, performs third-party
          * communication via process 0's window. */
         if (rank > 0) {
-            MPI_Recv(NULL, 0, MPI_BYTE, rank-1, 0, MPI_COMM_WORLD, MPI_STATUS_IGNORE);
+            MPI_Recv(NULL, 0, MPI_BYTE, rank - 1, 0, MPI_COMM_WORLD, MPI_STATUS_IGNORE);
         }
 
-        MPI_Get_accumulate(&rank, 1, MPI_INT, &val, 1, MPI_INT, 0, 0, 1, MPI_INT, MPI_REPLACE, window);
+        MPI_Get_accumulate(&rank, 1, MPI_INT, &val, 1, MPI_INT, 0, 0, 1, MPI_INT, MPI_REPLACE,
+                           window);
         MPI_Win_flush(0, window);
 
-        exp = (rank + nproc-1) % nproc;
+        exp = (rank + nproc - 1) % nproc;
 
         if (val != exp) {
             printf("%d - Got %d, expected %d\n", rank, val, exp);
             errors++;
         }
 
-        if (rank < nproc-1) {
-            MPI_Send(NULL, 0, MPI_BYTE, rank+1, 0, MPI_COMM_WORLD);
+        if (rank < nproc - 1) {
+            MPI_Send(NULL, 0, MPI_BYTE, rank + 1, 0, MPI_COMM_WORLD);
         }
 
         MPI_Barrier(MPI_COMM_WORLD);
@@ -76,7 +79,8 @@ int main( int argc, char *argv[] )
     MPI_Win_unlock(0, window);
 
     MPI_Win_free(&window);
-    if (buf) MPI_Free_mem(buf);
+    if (buf)
+        MPI_Free_mem(buf);
 
     MPI_Reduce(&errors, &all_errors, 1, MPI_INT, MPI_SUM, 0, MPI_COMM_WORLD);
 
diff --git a/teshsuite/smpi/mpich3-test/rma/get-struct.c b/teshsuite/smpi/mpich3-test/rma/get-struct.c
new file mode 100644 (file)
index 0000000..b85cfe5
--- /dev/null
@@ -0,0 +1,173 @@
+/* -*- Mode: C; c-basic-offset:4 ; indent-tabs-mode:nil ; -*- */
+/*
+ *  (C) 2014 by Argonne National Laboratory.
+ *      See COPYRIGHT in top-level directory.
+ */
+#include "mpi.h"
+#include "mpitest.h"
+#include <stdio.h>
+#include <string.h>
+
+/* Communicating a datatype built out of structs
+ * This test was motivated by the failure of an example program for
+ * RMA involving simple operations on a struct that included a struct
+ *
+ * The observed failure was a SEGV in the MPI_Get
+ *
+ *
+ */
+#define MAX_KEY_SIZE 64
+#define MAX_VALUE_SIZE 256
+typedef struct {
+    MPI_Aint disp;
+    int rank;
+    void *lptr;
+} Rptr;
+typedef struct {
+    Rptr next;
+    char key[MAX_KEY_SIZE], value[MAX_VALUE_SIZE];
+} ListElm;
+Rptr nullDptr = { 0, -1, 0 };
+
+int testCases = -1;
+#define BYTE_ONLY 0x1
+#define TWO_STRUCT 0x2
+int isOneLevel = 0;
+
+int main(int argc, char **argv)
+{
+    int errors = 0;
+    Rptr headDptr;
+    ListElm *headLptr = 0;
+    int i, wrank;
+    MPI_Datatype dptrType, listelmType;
+    MPI_Win listwin;
+
+    MTest_Init(&argc, &argv);
+    MPI_Comm_rank(MPI_COMM_WORLD, &wrank);
+
+    for (i = 1; i < argc; i++) {
+        if (strcmp(argv[i], "-byteonly") == 0) {
+            testCases = BYTE_ONLY;
+        }
+        else if (strcmp(argv[i], "-twostruct") == 0) {
+            testCases = TWO_STRUCT;
+        }
+        else if (strcmp(argv[i], "-onelevel") == 0) {
+            isOneLevel = 1;
+        }
+        else {
+            printf("Unrecognized argument %s\n", argv[i]);
+        }
+    }
+
+    /* Create the datatypes that we will use to move the data */
+    {
+        int blens[3];
+        MPI_Aint displ[3];
+        MPI_Datatype dtypes[3];
+        ListElm sampleElm;
+
+        blens[0] = 1;
+        blens[1] = 1;
+        MPI_Get_address(&nullDptr.disp, &displ[0]);
+        MPI_Get_address(&nullDptr.rank, &displ[1]);
+        displ[1] = displ[1] - displ[0];
+        displ[0] = 0;
+        dtypes[0] = MPI_AINT;
+        dtypes[1] = MPI_INT;
+        MPI_Type_create_struct(2, blens, displ, dtypes, &dptrType);
+        MPI_Type_commit(&dptrType);
+
+        if (isOneLevel) {
+            blens[0] = sizeof(nullDptr);
+            dtypes[0] = MPI_BYTE;
+        }
+        else {
+            blens[0] = 1;
+            dtypes[0] = dptrType;
+        }
+        blens[1] = MAX_KEY_SIZE;
+        dtypes[1] = MPI_CHAR;
+        blens[2] = MAX_VALUE_SIZE;
+        dtypes[2] = MPI_CHAR;
+        MPI_Get_address(&sampleElm.next, &displ[0]);
+        MPI_Get_address(&sampleElm.key[0], &displ[1]);
+        MPI_Get_address(&sampleElm.value[0], &displ[2]);
+        displ[2] -= displ[0];
+        displ[1] -= displ[0];
+        displ[0] = 0;
+        for (i = 0; i < 3; i++) {
+            MTestPrintfMsg(0, "%d:count=%d,disp=%ld\n", i, blens[i], displ[i]);
+        }
+        MPI_Type_create_struct(3, blens, displ, dtypes, &listelmType);
+        MPI_Type_commit(&listelmType);
+    }
+
+    MPI_Win_create_dynamic(MPI_INFO_NULL, MPI_COMM_WORLD, &listwin);
+
+    headDptr.rank = 0;
+    if (wrank == 0) {
+        /* Create 1 list element (the head) and initialize it */
+        MPI_Alloc_mem(sizeof(ListElm), MPI_INFO_NULL, &headLptr);
+        MPI_Get_address(headLptr, &headDptr.disp);
+        headLptr->next.rank = -1;
+        headLptr->next.disp = (MPI_Aint) MPI_BOTTOM;
+        headLptr->next.lptr = 0;
+        strncpy(headLptr->key, "key1", MAX_KEY_SIZE);
+        strncpy(headLptr->value, "value1", MAX_VALUE_SIZE);
+        MPI_Win_attach(listwin, headLptr, sizeof(ListElm));
+    }
+    MPI_Bcast(&headDptr.disp, 1, MPI_AINT, 0, MPI_COMM_WORLD);
+
+    MPI_Barrier(MPI_COMM_WORLD);
+
+    if (wrank == 1) {
+        ListElm headcopy;
+
+        MPI_Win_lock_all(0, listwin);
+        /* Get head element with simple get of BYTES */
+        if (testCases & BYTE_ONLY) {
+            headcopy.next.rank = 100;
+            headcopy.next.disp = 0xefefefef;
+            MPI_Get(&headcopy, sizeof(ListElm), MPI_BYTE,
+                    headDptr.rank, headDptr.disp, sizeof(ListElm), MPI_BYTE, listwin);
+            MPI_Win_flush(headDptr.rank, listwin);
+            if (headcopy.next.rank != -1 && headcopy.next.disp != (MPI_Aint) MPI_BOTTOM) {
+                errors++;
+                printf("MPI_BYTE: headcopy contains incorrect next:<%d,%ld>\n",
+                       headcopy.next.rank, (long) headcopy.next.disp);
+            }
+        }
+
+        if (testCases & TWO_STRUCT) {
+            headcopy.next.rank = 100;
+            headcopy.next.disp = 0xefefefef;
+            /* Get head element using struct of struct type.  This is
+             * not an identical get to the simple BYTE one above but should
+             * work */
+            MPI_Get(&headcopy, 1, listelmType, headDptr.rank, headDptr.disp,
+                    1, listelmType, listwin);
+            MPI_Win_flush(headDptr.rank, listwin);
+            if (headcopy.next.rank != -1 && headcopy.next.disp != (MPI_Aint) MPI_BOTTOM) {
+                errors++;
+                printf("ListelmType: headcopy contains incorrect next:<%d,%ld>\n",
+                       headcopy.next.rank, (long) headcopy.next.disp);
+            }
+        }
+
+        MPI_Win_unlock_all(listwin);
+    }
+    MPI_Barrier(MPI_COMM_WORLD);
+    if (wrank == 0) {
+        MPI_Win_detach(listwin, headLptr);
+        MPI_Free_mem(headLptr);
+    }
+    MPI_Win_free(&listwin);
+    MPI_Type_free(&dptrType);
+    MPI_Type_free(&listelmType);
+
+    MTest_Finalize(errors);
+    MPI_Finalize();
+    return MTestReturnValue(errors);
+}
index ecf3258..c1a38db 100644 (file)
 
 #include "mpitest.h"
 
-int       errors  = 0;
-const int NITER   = 1000;
+int errors = 0;
+const int NITER = 1000;
 const int acc_val = 3;
 
 int main(int argc, char **argv)
 {
-    int         rank, nproc;
-    int         out_val, i, counter = 0;
-    MPI_Win     win;
+    int rank, nproc;
+    int out_val, i, counter = 0;
+    MPI_Win win;
 
     MPI_Init(&argc, &argv);
 
     MPI_Comm_rank(MPI_COMM_WORLD, &rank);
     MPI_Comm_size(MPI_COMM_WORLD, &nproc);
 
-    MPI_Win_create(&counter, sizeof(int), sizeof(int), MPI_INFO_NULL,
-                   MPI_COMM_WORLD, &win);
+    MPI_Win_create(&counter, sizeof(int), sizeof(int), MPI_INFO_NULL, MPI_COMM_WORLD, &win);
 
     for (i = 0; i < NITER; i++) {
         MPI_Win_lock(MPI_LOCK_SHARED, rank, 0, win);
         MPI_Get_accumulate(&acc_val, 1, MPI_INT, &out_val, 1, MPI_INT,
-                            rank, 0, 1, MPI_INT, MPI_SUM, win);
+                           rank, 0, 1, MPI_INT, MPI_SUM, win);
         MPI_Win_unlock(rank, win);
 
-        if (out_val != acc_val*i) {
+        if (out_val != acc_val * i) {
             errors++;
-            printf("Error: got %d, expected %d at iter %d\n", out_val, acc_val*i, i);
+            printf("Error: got %d, expected %d at iter %d\n", out_val, acc_val * i, i);
             break;
         }
     }
index 5a533fe..0ffee69 100644 (file)
@@ -39,7 +39,9 @@
 #  define TYPE_MPI TYPE_MPI_BASE
 #endif
 
-void reset_bufs(TYPE_C *win_ptr, TYPE_C *res_ptr, TYPE_C *val_ptr, TYPE_C value, MPI_Win win) {
+static void reset_bufs(TYPE_C * win_ptr, TYPE_C * res_ptr, TYPE_C * val_ptr, TYPE_C value,
+                       MPI_Win win)
+{
     int rank, nproc, i;
 
     MPI_Barrier(MPI_COMM_WORLD);
@@ -48,10 +50,10 @@ void reset_bufs(TYPE_C *win_ptr, TYPE_C *res_ptr, TYPE_C *val_ptr, TYPE_C value,
     MPI_Comm_size(MPI_COMM_WORLD, &nproc);
 
     MPI_Win_lock(MPI_LOCK_EXCLUSIVE, rank, 0, win);
-    memset(win_ptr, 0, sizeof(TYPE_C)*nproc*COUNT);
+    memset(win_ptr, 0, sizeof(TYPE_C) * nproc * COUNT);
     MPI_Win_unlock(rank, win);
 
-    memset(res_ptr, -1, sizeof(TYPE_C)*nproc*COUNT);
+    memset(res_ptr, -1, sizeof(TYPE_C) * nproc * COUNT);
 
     for (i = 0; i < COUNT; i++)
         val_ptr[i] = value;
@@ -59,11 +61,12 @@ void reset_bufs(TYPE_C *win_ptr, TYPE_C *res_ptr, TYPE_C *val_ptr, TYPE_C value,
     MPI_Barrier(MPI_COMM_WORLD);
 }
 
-int main(int argc, char **argv) {
-    int       i, rank, nproc;
-    int       errors = 0, all_errors = 0;
-    TYPE_C   *win_ptr, *res_ptr, *val_ptr;
-    MPI_Win   win;
+int main(int argc, char **argv)
+{
+    int i, rank, nproc;
+    int errors = 0, all_errors = 0;
+    TYPE_C *win_ptr, *res_ptr, *val_ptr;
+    MPI_Win win;
 #if defined (GACC_TYPE_DERIVED)
     MPI_Datatype derived_type;
 #endif
@@ -73,16 +76,16 @@ int main(int argc, char **argv) {
     MPI_Comm_rank(MPI_COMM_WORLD, &rank);
     MPI_Comm_size(MPI_COMM_WORLD, &nproc);
 
-    win_ptr = malloc(sizeof(TYPE_C)*nproc*COUNT);
-    res_ptr = malloc(sizeof(TYPE_C)*nproc*COUNT);
-    val_ptr = malloc(sizeof(TYPE_C)*COUNT);
+    win_ptr = malloc(sizeof(TYPE_C) * nproc * COUNT);
+    res_ptr = malloc(sizeof(TYPE_C) * nproc * COUNT);
+    val_ptr = malloc(sizeof(TYPE_C) * COUNT);
 
 #if defined (GACC_TYPE_DERIVED)
     MPI_Type_contiguous(1, TYPE_MPI_BASE, &derived_type);
     MPI_Type_commit(&derived_type);
 #endif
 
-    MPI_Win_create(win_ptr, sizeof(TYPE_C)*nproc*COUNT, sizeof(TYPE_C),
+    MPI_Win_create(win_ptr, sizeof(TYPE_C) * nproc * COUNT, sizeof(TYPE_C),
                    MPI_INFO_NULL, MPI_COMM_WORLD, &win);
 
     /* Test self communication */
@@ -91,16 +94,16 @@ int main(int argc, char **argv) {
 
     for (i = 0; i < ITER; i++) {
         MPI_Win_lock(MPI_LOCK_EXCLUSIVE, rank, 0, win);
-        MPI_Get_accumulate(val_ptr, COUNT, TYPE_MPI, res_ptr, COUNT, TYPE_MPI, 
-                            rank, 0, COUNT, TYPE_MPI, MPI_SUM, win);
+        MPI_Get_accumulate(val_ptr, COUNT, TYPE_MPI, res_ptr, COUNT, TYPE_MPI,
+                           rank, 0, COUNT, TYPE_MPI, MPI_SUM, win);
         MPI_Win_unlock(rank, win);
     }
 
     MPI_Win_lock(MPI_LOCK_EXCLUSIVE, rank, 0, win);
     for (i = 0; i < COUNT; i++) {
         if (win_ptr[i] != ITER) {
-            SQUELCH( printf("%d->%d -- SELF[%d]: expected "TYPE_FMT", got "TYPE_FMT"\n",
-                            rank, rank, i, (TYPE_C) ITER, win_ptr[i]); );
+            SQUELCH(printf("%d->%d -- SELF[%d]: expected " TYPE_FMT ", got " TYPE_FMT "\n",
+                           rank, rank, i, (TYPE_C) ITER, win_ptr[i]););
             errors++;
         }
     }
@@ -111,10 +114,10 @@ int main(int argc, char **argv) {
     reset_bufs(win_ptr, res_ptr, val_ptr, 1, win);
 
     for (i = 0; i < ITER; i++) {
-        MPI_Win_lock(MPI_LOCK_EXCLUSIVE, (rank+1)%nproc, 0, win);
-        MPI_Get_accumulate(val_ptr, COUNT, TYPE_MPI, res_ptr, COUNT, TYPE_MPI, 
-                            (rank+1)%nproc, 0, COUNT, TYPE_MPI, MPI_SUM, win);
-        MPI_Win_unlock((rank+1)%nproc, win);
+        MPI_Win_lock(MPI_LOCK_EXCLUSIVE, (rank + 1) % nproc, 0, win);
+        MPI_Get_accumulate(val_ptr, COUNT, TYPE_MPI, res_ptr, COUNT, TYPE_MPI,
+                           (rank + 1) % nproc, 0, COUNT, TYPE_MPI, MPI_SUM, win);
+        MPI_Win_unlock((rank + 1) % nproc, win);
     }
 
     MPI_Barrier(MPI_COMM_WORLD);
@@ -122,8 +125,8 @@ int main(int argc, char **argv) {
     MPI_Win_lock(MPI_LOCK_EXCLUSIVE, rank, 0, win);
     for (i = 0; i < COUNT; i++) {
         if (win_ptr[i] != ITER) {
-            SQUELCH( printf("%d->%d -- NEIGHBOR[%d]: expected "TYPE_FMT", got "TYPE_FMT"\n",
-                            (rank+1)%nproc, rank, i, (TYPE_C) ITER, win_ptr[i]); );
+            SQUELCH(printf("%d->%d -- NEIGHBOR[%d]: expected " TYPE_FMT ", got " TYPE_FMT "\n",
+                           (rank + 1) % nproc, rank, i, (TYPE_C) ITER, win_ptr[i]););
             errors++;
         }
     }
@@ -136,8 +139,8 @@ int main(int argc, char **argv) {
     if (rank != 0) {
         for (i = 0; i < ITER; i++) {
             MPI_Win_lock(MPI_LOCK_EXCLUSIVE, 0, 0, win);
-            MPI_Get_accumulate(val_ptr, COUNT, TYPE_MPI, res_ptr, COUNT, TYPE_MPI, 
-                                0, 0, COUNT, TYPE_MPI, MPI_SUM, win);
+            MPI_Get_accumulate(val_ptr, COUNT, TYPE_MPI, res_ptr, COUNT, TYPE_MPI,
+                               0, 0, COUNT, TYPE_MPI, MPI_SUM, win);
             MPI_Win_unlock(0, win);
         }
     }
@@ -147,9 +150,9 @@ int main(int argc, char **argv) {
     MPI_Win_lock(MPI_LOCK_EXCLUSIVE, rank, 0, win);
     if (rank == 0 && nproc > 1) {
         for (i = 0; i < COUNT; i++) {
-            if (win_ptr[i] != ITER*(nproc-1)) {
-                SQUELCH( printf("*->%d - CONTENTION[%d]: expected="TYPE_FMT" val="TYPE_FMT"\n",
-                                rank, i, (TYPE_C) ITER*(nproc-1), win_ptr[i]); );
+            if (win_ptr[i] != ITER * (nproc - 1)) {
+                SQUELCH(printf("*->%d - CONTENTION[%d]: expected=" TYPE_FMT " val=" TYPE_FMT "\n",
+                               rank, i, (TYPE_C) ITER * (nproc - 1), win_ptr[i]););
                 errors++;
             }
         }
@@ -165,8 +168,8 @@ int main(int argc, char **argv) {
 
         MPI_Win_fence(MPI_MODE_NOPRECEDE, win);
         for (j = 0; j < nproc; j++) {
-            MPI_Get_accumulate(val_ptr, COUNT, TYPE_MPI, &res_ptr[j*COUNT], COUNT, TYPE_MPI,
-                                j, rank*COUNT, COUNT, TYPE_MPI, MPI_SUM, win);
+            MPI_Get_accumulate(val_ptr, COUNT, TYPE_MPI, &res_ptr[j * COUNT], COUNT, TYPE_MPI,
+                               j, rank * COUNT, COUNT, TYPE_MPI, MPI_SUM, win);
         }
         MPI_Win_fence(MPI_MODE_NOSUCCEED, win);
         MPI_Barrier(MPI_COMM_WORLD);
@@ -174,9 +177,11 @@ int main(int argc, char **argv) {
         for (j = 0; j < nproc; j++) {
             int c;
             for (c = 0; c < COUNT; c++) {
-                if (res_ptr[j*COUNT+c] != i*rank) {
-                    SQUELCH( printf("%d->%d -- ALL-TO-ALL (FENCE) [%d]: iter %d, expected result "TYPE_FMT", got "TYPE_FMT"\n", 
-                                    rank, j, c, i, (TYPE_C) i*rank, res_ptr[j*COUNT+c]); );
+                if (res_ptr[j * COUNT + c] != i * rank) {
+                    SQUELCH(printf
+                            ("%d->%d -- ALL-TO-ALL (FENCE) [%d]: iter %d, expected result " TYPE_FMT
+                             ", got " TYPE_FMT "\n", rank, j, c, i, (TYPE_C) i * rank,
+                             res_ptr[j * COUNT + c]););
                     errors++;
                 }
             }
@@ -188,9 +193,10 @@ int main(int argc, char **argv) {
     for (i = 0; i < nproc; i++) {
         int c;
         for (c = 0; c < COUNT; c++) {
-            if (win_ptr[i*COUNT+c] != ITER*i) {
-                SQUELCH( printf("%d->%d -- ALL-TO-ALL (FENCE): expected "TYPE_FMT", got "TYPE_FMT"\n", 
-                                i, rank, (TYPE_C) ITER*i, win_ptr[i*COUNT+c]); );
+            if (win_ptr[i * COUNT + c] != ITER * i) {
+                SQUELCH(printf
+                        ("%d->%d -- ALL-TO-ALL (FENCE): expected " TYPE_FMT ", got " TYPE_FMT "\n",
+                         i, rank, (TYPE_C) ITER * i, win_ptr[i * COUNT + c]););
                 errors++;
             }
         }
@@ -206,8 +212,8 @@ int main(int argc, char **argv) {
 
         MPI_Win_lock_all(0, win);
         for (j = 0; j < nproc; j++) {
-            MPI_Get_accumulate(val_ptr, COUNT, TYPE_MPI, &res_ptr[j*COUNT], COUNT, TYPE_MPI,
-                                j, rank*COUNT, COUNT, TYPE_MPI, MPI_SUM, win);
+            MPI_Get_accumulate(val_ptr, COUNT, TYPE_MPI, &res_ptr[j * COUNT], COUNT, TYPE_MPI,
+                               j, rank * COUNT, COUNT, TYPE_MPI, MPI_SUM, win);
         }
         MPI_Win_unlock_all(win);
         MPI_Barrier(MPI_COMM_WORLD);
@@ -215,9 +221,11 @@ int main(int argc, char **argv) {
         for (j = 0; j < nproc; j++) {
             int c;
             for (c = 0; c < COUNT; c++) {
-                if (res_ptr[j*COUNT+c] != i*rank) {
-                    SQUELCH( printf("%d->%d -- ALL-TO-ALL (LOCK-ALL) [%d]: iter %d, expected result "TYPE_FMT", got "TYPE_FMT"\n", 
-                                    rank, j, c, i, (TYPE_C) i*rank, res_ptr[j*COUNT+c]); );
+                if (res_ptr[j * COUNT + c] != i * rank) {
+                    SQUELCH(printf
+                            ("%d->%d -- ALL-TO-ALL (LOCK-ALL) [%d]: iter %d, expected result "
+                             TYPE_FMT ", got " TYPE_FMT "\n", rank, j, c, i, (TYPE_C) i * rank,
+                             res_ptr[j * COUNT + c]););
                     errors++;
                 }
             }
@@ -229,9 +237,10 @@ int main(int argc, char **argv) {
     for (i = 0; i < nproc; i++) {
         int c;
         for (c = 0; c < COUNT; c++) {
-            if (win_ptr[i*COUNT+c] != ITER*i) {
-                SQUELCH( printf("%d->%d -- ALL-TO-ALL (LOCK-ALL): expected "TYPE_FMT", got "TYPE_FMT"\n", 
-                                i, rank, (TYPE_C) ITER*i, win_ptr[i*COUNT+c]); );
+            if (win_ptr[i * COUNT + c] != ITER * i) {
+                SQUELCH(printf
+                        ("%d->%d -- ALL-TO-ALL (LOCK-ALL): expected " TYPE_FMT ", got " TYPE_FMT
+                         "\n", i, rank, (TYPE_C) ITER * i, win_ptr[i * COUNT + c]););
                 errors++;
             }
         }
@@ -247,8 +256,8 @@ int main(int argc, char **argv) {
 
         MPI_Win_lock_all(0, win);
         for (j = 0; j < nproc; j++) {
-            MPI_Get_accumulate(val_ptr, COUNT, TYPE_MPI, &res_ptr[j*COUNT], COUNT, TYPE_MPI,
-                                j, rank*COUNT, COUNT, TYPE_MPI, MPI_SUM, win);
+            MPI_Get_accumulate(val_ptr, COUNT, TYPE_MPI, &res_ptr[j * COUNT], COUNT, TYPE_MPI,
+                               j, rank * COUNT, COUNT, TYPE_MPI, MPI_SUM, win);
             MPI_Win_flush(j, win);
         }
         MPI_Win_unlock_all(win);
@@ -257,9 +266,11 @@ int main(int argc, char **argv) {
         for (j = 0; j < nproc; j++) {
             int c;
             for (c = 0; c < COUNT; c++) {
-                if (res_ptr[j*COUNT+c] != i*rank) {
-                    SQUELCH( printf("%d->%d -- ALL-TO-ALL (LOCK-ALL+FLUSH) [%d]: iter %d, expected result "TYPE_FMT", got "TYPE_FMT"\n", 
-                                    rank, j, c, i, (TYPE_C) i*rank, res_ptr[j*COUNT+c]); );
+                if (res_ptr[j * COUNT + c] != i * rank) {
+                    SQUELCH(printf
+                            ("%d->%d -- ALL-TO-ALL (LOCK-ALL+FLUSH) [%d]: iter %d, expected result "
+                             TYPE_FMT ", got " TYPE_FMT "\n", rank, j, c, i, (TYPE_C) i * rank,
+                             res_ptr[j * COUNT + c]););
                     errors++;
                 }
             }
@@ -271,9 +282,10 @@ int main(int argc, char **argv) {
     for (i = 0; i < nproc; i++) {
         int c;
         for (c = 0; c < COUNT; c++) {
-            if (win_ptr[i*COUNT+c] != ITER*i) {
-                SQUELCH( printf("%d->%d -- ALL-TO-ALL (LOCK-ALL+FLUSH): expected "TYPE_FMT", got "TYPE_FMT"\n", 
-                                i, rank, (TYPE_C) ITER*i, win_ptr[i*COUNT+c]); );
+            if (win_ptr[i * COUNT + c] != ITER * i) {
+                SQUELCH(printf
+                        ("%d->%d -- ALL-TO-ALL (LOCK-ALL+FLUSH): expected " TYPE_FMT ", got "
+                         TYPE_FMT "\n", i, rank, (TYPE_C) ITER * i, win_ptr[i * COUNT + c]););
                 errors++;
             }
         }
@@ -285,52 +297,58 @@ int main(int argc, char **argv) {
     reset_bufs(win_ptr, res_ptr, val_ptr, 1, win);
 
     MPI_Win_lock(MPI_LOCK_EXCLUSIVE, rank, 0, win);
-    for (i = 0; i < COUNT*nproc; i++)
+    for (i = 0; i < COUNT * nproc; i++)
         win_ptr[i] = (TYPE_C) rank;
     MPI_Win_unlock(rank, win);
     MPI_Barrier(MPI_COMM_WORLD);
 
     for (i = 0; i < ITER; i++) {
-        int j, target = (rank+1) % nproc;
+        int j, target = (rank + 1) % nproc;
 
         /* Test: origin_buf = NULL */
+        memset(res_ptr, -1, sizeof(TYPE_C) * nproc * COUNT); /* reset result buffer. */
+
         MPI_Win_lock(MPI_LOCK_EXCLUSIVE, target, 0, win);
         MPI_Get_accumulate(NULL, COUNT, TYPE_MPI, res_ptr, COUNT, TYPE_MPI,
-                            target, 0, COUNT, TYPE_MPI, MPI_NO_OP, win);
+                           target, 0, COUNT, TYPE_MPI, MPI_NO_OP, win);
         MPI_Win_unlock(target, win);
 
         for (j = 0; j < COUNT; j++) {
             if (res_ptr[j] != (TYPE_C) target) {
-                SQUELCH( printf("%d->%d -- NOP(1)[%d]: expected "TYPE_FMT", got "TYPE_FMT"\n",
-                                target, rank, i, (TYPE_C) target, res_ptr[i]); );
+                SQUELCH(printf("%d->%d -- NOP(1)[%d]: expected " TYPE_FMT ", got " TYPE_FMT "\n",
+                               target, rank, i, (TYPE_C) target, res_ptr[i]););
                 errors++;
             }
         }
 
         /* Test: origin_buf = NULL, origin_count = 0 */
+        memset(res_ptr, -1, sizeof(TYPE_C) * nproc * COUNT);
+
         MPI_Win_lock(MPI_LOCK_EXCLUSIVE, target, 0, win);
         MPI_Get_accumulate(NULL, 0, TYPE_MPI, res_ptr, COUNT, TYPE_MPI,
-                            target, 0, COUNT, TYPE_MPI, MPI_NO_OP, win);
+                           target, 0, COUNT, TYPE_MPI, MPI_NO_OP, win);
         MPI_Win_unlock(target, win);
 
         for (j = 0; j < COUNT; j++) {
             if (res_ptr[j] != (TYPE_C) target) {
-                SQUELCH( printf("%d->%d -- NOP(2)[%d]: expected "TYPE_FMT", got "TYPE_FMT"\n",
-                                target, rank, i, (TYPE_C) target, res_ptr[i]); );
+                SQUELCH(printf("%d->%d -- NOP(2)[%d]: expected " TYPE_FMT ", got " TYPE_FMT "\n",
+                               target, rank, i, (TYPE_C) target, res_ptr[i]););
                 errors++;
             }
         }
 
         /* Test: origin_buf = NULL, origin_count = 0, origin_dtype = NULL */
+        memset(res_ptr, -1, sizeof(TYPE_C) * nproc * COUNT);
+
         MPI_Win_lock(MPI_LOCK_EXCLUSIVE, target, 0, win);
         MPI_Get_accumulate(NULL, 0, MPI_DATATYPE_NULL, res_ptr, COUNT, TYPE_MPI,
-                            target, 0, COUNT, TYPE_MPI, MPI_NO_OP, win);
+                           target, 0, COUNT, TYPE_MPI, MPI_NO_OP, win);
         MPI_Win_unlock(target, win);
 
         for (j = 0; j < COUNT; j++) {
             if (res_ptr[j] != (TYPE_C) target) {
-                SQUELCH( printf("%d->%d -- NOP(2)[%d]: expected "TYPE_FMT", got "TYPE_FMT"\n",
-                                target, rank, i, (TYPE_C) target, res_ptr[i]); );
+                SQUELCH(printf("%d->%d -- NOP(2)[%d]: expected " TYPE_FMT ", got " TYPE_FMT "\n",
+                               target, rank, i, (TYPE_C) target, res_ptr[i]););
                 errors++;
             }
         }
@@ -341,7 +359,7 @@ int main(int argc, char **argv) {
     reset_bufs(win_ptr, res_ptr, val_ptr, 1, win);
 
     MPI_Win_lock(MPI_LOCK_EXCLUSIVE, rank, 0, win);
-    for (i = 0; i < COUNT*nproc; i++)
+    for (i = 0; i < COUNT * nproc; i++)
         win_ptr[i] = (TYPE_C) rank;
     MPI_Win_unlock(rank, win);
     MPI_Barrier(MPI_COMM_WORLD);
@@ -350,43 +368,52 @@ int main(int argc, char **argv) {
         int j, target = rank;
 
         /* Test: origin_buf = NULL */
+        memset(res_ptr, -1, sizeof(TYPE_C) * nproc * COUNT);
+
         MPI_Win_lock(MPI_LOCK_EXCLUSIVE, target, 0, win);
         MPI_Get_accumulate(NULL, COUNT, TYPE_MPI, res_ptr, COUNT, TYPE_MPI,
-                            target, 0, COUNT, TYPE_MPI, MPI_NO_OP, win);
+                           target, 0, COUNT, TYPE_MPI, MPI_NO_OP, win);
         MPI_Win_unlock(target, win);
 
         for (j = 0; j < COUNT; j++) {
             if (res_ptr[j] != (TYPE_C) target) {
-                SQUELCH( printf("%d->%d -- NOP_SELF(1)[%d]: expected "TYPE_FMT", got "TYPE_FMT"\n",
-                                target, rank, i, (TYPE_C) target, res_ptr[i]); );
+                SQUELCH(printf
+                        ("%d->%d -- NOP_SELF(1)[%d]: expected " TYPE_FMT ", got " TYPE_FMT "\n",
+                         target, rank, i, (TYPE_C) target, res_ptr[i]););
                 errors++;
             }
         }
 
         /* Test: origin_buf = NULL, origin_count = 0 */
+        memset(res_ptr, -1, sizeof(TYPE_C) * nproc * COUNT);
+
         MPI_Win_lock(MPI_LOCK_EXCLUSIVE, target, 0, win);
         MPI_Get_accumulate(NULL, 0, TYPE_MPI, res_ptr, COUNT, TYPE_MPI,
-                            target, 0, COUNT, TYPE_MPI, MPI_NO_OP, win);
+                           target, 0, COUNT, TYPE_MPI, MPI_NO_OP, win);
         MPI_Win_unlock(target, win);
 
         for (j = 0; j < COUNT; j++) {
             if (res_ptr[j] != (TYPE_C) target) {
-                SQUELCH( printf("%d->%d -- NOP_SELF(2)[%d]: expected "TYPE_FMT", got "TYPE_FMT"\n",
-                                target, rank, i, (TYPE_C) target, res_ptr[i]); );
+                SQUELCH(printf
+                        ("%d->%d -- NOP_SELF(2)[%d]: expected " TYPE_FMT ", got " TYPE_FMT "\n",
+                         target, rank, i, (TYPE_C) target, res_ptr[i]););
                 errors++;
             }
         }
 
         /* Test: origin_buf = NULL, origin_count = 0, origin_dtype = NULL */
+        memset(res_ptr, -1, sizeof(TYPE_C) * nproc * COUNT);
+
         MPI_Win_lock(MPI_LOCK_EXCLUSIVE, target, 0, win);
         MPI_Get_accumulate(NULL, 0, MPI_DATATYPE_NULL, res_ptr, COUNT, TYPE_MPI,
-                            target, 0, COUNT, TYPE_MPI, MPI_NO_OP, win);
+                           target, 0, COUNT, TYPE_MPI, MPI_NO_OP, win);
         MPI_Win_unlock(target, win);
 
         for (j = 0; j < COUNT; j++) {
             if (res_ptr[j] != (TYPE_C) target) {
-                SQUELCH( printf("%d->%d -- NOP_SELF(2)[%d]: expected "TYPE_FMT", got "TYPE_FMT"\n",
-                                target, rank, i, (TYPE_C) target, res_ptr[i]); );
+                SQUELCH(printf
+                        ("%d->%d -- NOP_SELF(2)[%d]: expected " TYPE_FMT ", got " TYPE_FMT "\n",
+                         target, rank, i, (TYPE_C) target, res_ptr[i]););
                 errors++;
             }
         }
index 2aaba82..6b06893 100644 (file)
  */
 #include "mpi.h"
 #include <stdio.h>
+#include <string.h>
+#include <limits.h>
 #include "mpitest.h"
 
+#define LARGE_CNT_CONTIG    5500000
+#define LARGE_CNT_NONCONTIG 1500000
+
 /*
 static char MTEST_Descrip[] = "Get with Fence";
 */
 
-int main( int argc, char *argv[] )
+static inline int test(MPI_Comm comm, int rank, int source, int dest,
+                       MTestDatatype * sendtype, MTestDatatype * recvtype)
 {
     int errs = 0, err;
+    int disp_unit;
+    MPI_Aint extent, lb;
+    MPI_Win win;
+
+    MTestPrintfMsg(1,
+                   "Getting count = %ld of sendtype %s - count = %ld receive type %s\n",
+                   sendtype->count, MTestGetDatatypeName(sendtype), recvtype->count,
+                   MTestGetDatatypeName(recvtype));
+    /* Make sure that everyone has a recv buffer */
+    recvtype->InitBuf(recvtype);
+    sendtype->InitBuf(sendtype);
+    /* By default, print information about errors */
+    recvtype->printErrors = 1;
+    sendtype->printErrors = 1;
+
+    MPI_Type_extent(sendtype->datatype, &extent);
+    MPI_Type_lb(sendtype->datatype, &lb);
+    disp_unit = extent < INT_MAX ? extent : 1;
+    MPI_Win_create(sendtype->buf, sendtype->count * extent + lb, disp_unit, MPI_INFO_NULL, comm, &win);
+    MPI_Win_fence(0, win);
+    if (rank == source) {
+        /* The source does not need to do anything besides the
+         * fence */
+        MPI_Win_fence(0, win);
+    }
+    else if (rank == dest) {
+        /* To improve reporting of problems about operations, we
+         * change the error handler to errors return */
+        MPI_Win_set_errhandler(win, MPI_ERRORS_RETURN);
+
+        /* This should have the same effect, in terms of
+         * transfering data, as a send/recv pair */
+        err = MPI_Get(recvtype->buf, recvtype->count,
+                      recvtype->datatype, source, 0, sendtype->count, sendtype->datatype, win);
+        if (err) {
+            errs++;
+            if (errs < 10) {
+                MTestPrintError(err);
+            }
+        }
+        err = MPI_Win_fence(0, win);
+        if (err) {
+            errs++;
+            if (errs < 10) {
+                MTestPrintError(err);
+            }
+        }
+        err = MTestCheckRecv(0, recvtype);
+        if (err) {
+            errs += err;
+        }
+    }
+    else {
+        MPI_Win_fence(0, win);
+    }
+    MPI_Win_free(&win);
+
+    return errs;
+}
+
+
+int main(int argc, char *argv[])
+{
+    int errs = 0;
     int rank, size, source, dest;
-    int minsize = 2, count; 
-    MPI_Comm      comm;
-    MPI_Win       win;
-    MPI_Aint      extent;
+    int minsize = 2, count;
+    MPI_Comm comm;
     MTestDatatype sendtype, recvtype;
 
-    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;
-       /* Determine the sender and receiver */
-       MPI_Comm_rank( comm, &rank );
-       MPI_Comm_size( comm, &size );
-       source = 0;
-       dest   = size - 1;
-       
-       for (count = 1; count < 65000; count = count * 2) {
-           while (MTestGetDatatypes( &sendtype, &recvtype, count )) {
-               /* Make sure that everyone has a recv buffer */
-               recvtype.InitBuf( &recvtype );
-               sendtype.InitBuf( &sendtype );
-               /* By default, print information about errors */
-               recvtype.printErrors = 1;
-               sendtype.printErrors = 1;
-
-               MPI_Type_extent( sendtype.datatype, &extent );
-               MPI_Win_create( sendtype.buf, sendtype.count * extent, 
-                               (int)extent, MPI_INFO_NULL, comm, &win );
-               MPI_Win_fence( 0, win );
-               if (rank == source) {
-                   /* The source does not need to do anything besides the
-                      fence */
-                   MPI_Win_fence( 0, win );
-               }
-               else if (rank == dest) {
-                   /* To improve reporting of problems about operations, we
-                      change the error handler to errors return */
-                   MPI_Win_set_errhandler( win, MPI_ERRORS_RETURN );
-
-                   /* This should have the same effect, in terms of
-                      transfering data, as a send/recv pair */
-                   err = MPI_Get( recvtype.buf, recvtype.count, 
-                                  recvtype.datatype, source, 0, 
-                                  sendtype.count, sendtype.datatype, win );
-                   if (err) {
-                       errs++;
-                       if (errs < 10) {
-                           MTestPrintError( err );
-                       }
-                   }
-                   err = MPI_Win_fence( 0, win );
-                   if (err) {
-                       errs++;
-                       if (errs < 10) {
-                           MTestPrintError( err );
-                       }
-                   }
-                   err = MTestCheckRecv( 0, &recvtype );
-                   if (err) {
-                       errs += err;
-                   }
-               }
-               else {
-                   MPI_Win_fence( 0, win );
-               }
-               MPI_Win_free( &win );
-               MTestFreeDatatype( &recvtype );
-               MTestFreeDatatype( &sendtype );
-           }
-       }
+    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;
+        /* Determine the sender and receiver */
+        MPI_Comm_rank(comm, &rank);
+        MPI_Comm_size(comm, &size);
+        source = 0;
+        dest = size - 1;
+
+        MTEST_DATATYPE_FOR_EACH_COUNT(count) {
+            while (MTestGetDatatypes(&sendtype, &recvtype, count)) {
+                errs += test(comm, rank, source, dest, &sendtype, &recvtype);
+                MTestFreeDatatype(&sendtype);
+                MTestFreeDatatype(&recvtype);
+            }
+        }
         MTestFreeComm(&comm);
     }
 
-    MTest_Finalize( errs );
+    /* Part #2: simple large size test - contiguous and noncontiguous */
+    if (sizeof(void *) > 4) {   /* Only if > 32-bit architecture */
+        MPI_Comm_rank(MPI_COMM_WORLD, &rank);
+        MPI_Comm_size(MPI_COMM_WORLD, &size);
+        source = 0;
+        dest = size - 1;
+
+        MTestGetDatatypes(&sendtype, &recvtype, LARGE_CNT_CONTIG);
+        errs += test(MPI_COMM_WORLD, rank, source, dest, &sendtype, &recvtype);
+
+        do {
+            MTestFreeDatatype(&sendtype);
+            MTestFreeDatatype(&recvtype);
+            MTestGetDatatypes(&sendtype, &recvtype, LARGE_CNT_NONCONTIG);
+        } while (strstr(MTestGetDatatypeName(&sendtype), "vector") == NULL);
+        errs += test(MPI_COMM_WORLD, rank, source, dest, &sendtype, &recvtype);
+        MTestFreeDatatype(&sendtype);
+        MTestFreeDatatype(&recvtype);
+    }
+
+    MTest_Finalize(errs);
     MPI_Finalize();
     return 0;
 }
index 4dd0c0d..051bb5f 100644 (file)
 static char MTEST_Descrip[] = "Test of Win_get_group";
 */
 
-int main( int argc, char *argv[] )
+int main(int argc, char *argv[])
 {
     int errs = 0;
     int result;
     int buf[10];
-    MPI_Win   win;
+    MPI_Win win;
     MPI_Group group, wingroup;
     int minsize = 2;
-    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_Win_create( buf, sizeof(int) * 10, sizeof(int), 
-                       MPI_INFO_NULL, comm, &win );
-       MPI_Win_get_group( win, &wingroup );
-       MPI_Comm_group( comm, &group );
-       MPI_Group_compare( group, wingroup, &result );
-       if (result != MPI_IDENT) {
-           errs++;
-           fprintf( stderr, "Group returned by Win_get_group not the same as the input group\n" );
-       }
-       MPI_Group_free( &wingroup );
-       MPI_Group_free( &group );
-       MPI_Win_free( &win );
+        MPI_Win_create(buf, sizeof(int) * 10, sizeof(int), MPI_INFO_NULL, comm, &win);
+        MPI_Win_get_group(win, &wingroup);
+        MPI_Comm_group(comm, &group);
+        MPI_Group_compare(group, wingroup, &result);
+        if (result != MPI_IDENT) {
+            errs++;
+            fprintf(stderr, "Group returned by Win_get_group not the same as the input group\n");
+        }
+        MPI_Group_free(&wingroup);
+        MPI_Group_free(&group);
+        MPI_Win_free(&win);
         MTestFreeComm(&comm);
     }
 
-    MTest_Finalize( errs );
+    MTest_Finalize(errs);
     MPI_Finalize();
     return 0;
 }
diff --git a/teshsuite/smpi/mpich3-test/rma/ircpi.c b/teshsuite/smpi/mpich3-test/rma/ircpi.c
deleted file mode 100644 (file)
index 99a83ed..0000000
+++ /dev/null
@@ -1,71 +0,0 @@
-/* -*- Mode: C; c-basic-offset:4 ; indent-tabs-mode:nil ; -*- */
-/*
- *  (C) 2001 by Argonne National Laboratory.
- *      See COPYRIGHT in top-level directory.
- */
-#include "mpi.h" 
-#include "stdio.h"
-#include <math.h> 
-
-/* From Using MPI-2 */
-
-int main(int argc, char *argv[]) 
-{ 
-    int n, myid, numprocs, i, ierr; 
-    double PI25DT = 3.141592653589793238462643; 
-    double mypi, pi, h, sum, x; 
-    MPI_Win nwin, piwin; 
-    MPI_Init(&argc,&argv); 
-    MPI_Comm_size(MPI_COMM_WORLD,&numprocs); 
-    MPI_Comm_rank(MPI_COMM_WORLD,&myid); 
-    if (myid == 0) { 
-       MPI_Win_create(&n, sizeof(int), 1, MPI_INFO_NULL, 
-                      MPI_COMM_WORLD, &nwin); 
-       MPI_Win_create(&pi, sizeof(double), 1, MPI_INFO_NULL, 
-                      MPI_COMM_WORLD, &piwin);  
-    } 
-    else { 
-       MPI_Win_create(MPI_BOTTOM, 0, 1, MPI_INFO_NULL, 
-                      MPI_COMM_WORLD, &nwin); 
-       MPI_Win_create(MPI_BOTTOM, 0, 1, MPI_INFO_NULL, 
-                      MPI_COMM_WORLD, &piwin); 
-    } 
-    while (1) { 
-        if (myid == 0) { 
-            fprintf(stdout, "Enter the number of intervals: (0 quits) ");
-           fflush(stdout); 
-            ierr=scanf("%d",&n); 
-           pi = 0.0;                    
-        } 
-       MPI_Win_fence(0, nwin); 
-       if (myid != 0)  
-           MPI_Get(&n, 1, MPI_INT, 0, 0, 1, MPI_INT, nwin); 
-       MPI_Win_fence(0, nwin); 
-        if (n == 0) 
-            break; 
-        else { 
-            h   = 1.0 / (double) n; 
-            sum = 0.0; 
-            for (i = myid + 1; i <= n; i += numprocs) { 
-                x = h * ((double)i - 0.5); 
-                sum += (4.0 / (1.0 + x*x)); 
-            } 
-            mypi = h * sum; 
-           MPI_Win_fence( 0, piwin); 
-           MPI_Accumulate(&mypi, 1, MPI_DOUBLE, 0, 0, 1, MPI_DOUBLE, 
-                          MPI_SUM, piwin); 
-           MPI_Win_fence(0, piwin); 
-            if (myid == 0) { 
-                fprintf(stdout, "pi is approximately %.16f, Error is %.16f\n", 
-                       pi, fabs(pi - PI25DT)); 
-               fflush(stdout);
-           }
-        } 
-    } 
-    MPI_Win_free(&nwin); 
-    MPI_Win_free(&piwin); 
-    MPI_Finalize(); 
-    return 0; 
-} 
diff --git a/teshsuite/smpi/mpich3-test/rma/large-acc-flush_local.c b/teshsuite/smpi/mpich3-test/rma/large-acc-flush_local.c
new file mode 100644 (file)
index 0000000..fd0a4fa
--- /dev/null
@@ -0,0 +1,73 @@
+/* -*- Mode: C; c-basic-offset:4 ; indent-tabs-mode:nil ; -*- */
+/*
+ *  (C) 2015 by Argonne National Laboratory.
+ *      See COPYRIGHT in top-level directory.
+ */
+
+/* This code tests the case when origin process issues 10 ACC
+ * operations for each data size to the target process, and each
+ * operation is followed by a MPI_Win_flush_local. */
+
+/* FIXME: we should merge this into a comprehensive test for RMA
+ * operations + MPI_Win_flush_local. */
+
+#include "mpi.h"
+#include <stdio.h>
+#include <stdlib.h>
+#include <time.h>
+
+#define MIN_DATA_SIZE (262144)
+#define MAX_DATA_SIZE (8 * 262144)
+#define OPS_NUM 10
+#define LOOP 500
+
+int main(int argc, char *argv[])
+{
+    int rank, nproc, i, j;
+    MPI_Win win;
+    int *tar_buf = NULL;
+    int *orig_buf = NULL;
+    int data_size;
+
+    MPI_Init(&argc, &argv);
+
+    MPI_Comm_size(MPI_COMM_WORLD, &nproc);
+    MPI_Comm_rank(MPI_COMM_WORLD, &rank);
+
+    MPI_Alloc_mem(MAX_DATA_SIZE, MPI_INFO_NULL, &orig_buf);
+    MPI_Alloc_mem(MAX_DATA_SIZE, MPI_INFO_NULL, &tar_buf);
+
+    /* run this test for LOOP times */
+
+    for (j = 0; j < LOOP; j++) {
+
+        MPI_Win_create(tar_buf, MAX_DATA_SIZE, 1, MPI_INFO_NULL, MPI_COMM_WORLD, &win);
+
+        MPI_Win_lock_all(0, win);
+
+        if (rank != 0) {
+            for (data_size = MIN_DATA_SIZE; data_size <= MAX_DATA_SIZE; data_size *= 2) {
+                for (i = 0; i < OPS_NUM; i++) {
+                    MPI_Accumulate(orig_buf, data_size, MPI_BYTE,
+                                   0, 0, data_size, MPI_BYTE, MPI_SUM, win);
+                    MPI_Win_flush_local(0, win);
+                }
+                MPI_Win_flush(0, win);
+            }
+        }
+
+        MPI_Win_unlock_all(win);
+
+        MPI_Win_free(&win);
+    }
+
+    if (rank == 0)
+        printf(" No Errors\n");
+
+    MPI_Free_mem(orig_buf);
+    MPI_Free_mem(tar_buf);
+
+    MPI_Finalize();
+
+    return 0;
+}
diff --git a/teshsuite/smpi/mpich3-test/rma/large-small-acc.c b/teshsuite/smpi/mpich3-test/rma/large-small-acc.c
new file mode 100644 (file)
index 0000000..de5b08f
--- /dev/null
@@ -0,0 +1,88 @@
+/* -*- Mode: C; c-basic-offset:4 ; indent-tabs-mode:nil ; -*- */
+/*
+ *  (C) 2015 by Argonne National Laboratory.
+ *      See COPYRIGHT in top-level directory.
+ */
+
+/* This code tests the case when a large ACC is issued, and then
+ * several small ACCs is issued between the same origin and target.
+ * The purpose of this test is to check if the ordering of ACCs
+ * is guaranteed. */
+
+#include "mpi.h"
+#include <stdio.h>
+#include <stdint.h>
+
+#define LOOP 5
+#define DATA_COUNT 8192
+
+int main(int argc, char *argv[])
+{
+    int rank, nprocs;
+    MPI_Win win;
+    uint64_t buf[DATA_COUNT], orig_buf[DATA_COUNT];
+    uint64_t small_orig_buf_1 = 2, small_orig_buf_2[2] = { 3, 3 };
+    int i, j, error = 0;
+
+    MPI_Init(&argc, &argv);
+    MPI_Comm_size(MPI_COMM_WORLD, &nprocs);
+    MPI_Comm_rank(MPI_COMM_WORLD, &rank);
+
+    for (j = 0; j < LOOP; j++) {
+
+        error = 0;
+
+        for (i = 0; i < DATA_COUNT; i++) {
+            buf[i] = 0;
+            orig_buf[i] = 1;
+        }
+
+        MPI_Win_create(buf, sizeof(uint64_t) * DATA_COUNT, sizeof(uint64_t),
+                       MPI_INFO_NULL, MPI_COMM_WORLD, &win);
+
+        MPI_Win_fence(0, win);
+
+        if (rank == 0) {
+            /* ACC (atomic PUT) to win_buf[0...DATA_COUNT-1] */
+            MPI_Accumulate(orig_buf, DATA_COUNT, MPI_UINT64_T, 1, 0, DATA_COUNT, MPI_UINT64_T,
+                           MPI_REPLACE, win);
+            /* ACC (atomic PUT) to win_buf[0] */
+            MPI_Accumulate(&small_orig_buf_1, 1, MPI_UINT64_T, 1, 0, 1, MPI_UINT64_T, MPI_REPLACE,
+                           win);
+            /* ACC (atomic PUT) to win_buf[1,2] */
+            MPI_Accumulate(&small_orig_buf_2, 2, MPI_UINT64_T, 1, 1, 2, MPI_UINT64_T, MPI_REPLACE,
+                           win);
+        }
+
+        MPI_Win_fence(0, win);
+
+        if (rank == 1) {
+            for (i = 0; i < DATA_COUNT; i++) {
+                if (i == 0) {
+                    if (buf[i] != 2) {
+                        error++;
+                    }
+                }
+                else if (i == 1 || i == 2) {
+                    if (buf[i] != 3) {
+                        error++;
+                    }
+                }
+                else {
+                    if (buf[i] != 1) {
+                        error++;
+                    }
+                }
+            }
+        }
+
+        MPI_Win_free(&win);
+    }
+
+    if (rank == 1 && error == 0) {
+        printf(" No Errors\n");
+    }
+
+    MPI_Finalize();
+    return 0;
+}
index 7b59c90..126ab62 100644 (file)
@@ -7,7 +7,7 @@
 
 /*            MPI-3 distributed linked list construction example
  *            --------------------------------------------------
- * 
+ *
  * Construct a distributed shared linked list using proposed MPI-3 dynamic
  * windows.  Initially process 0 creates the head of the list, attaches it to
  * the window, and broadcasts the pointer to all processes.  All processes then
@@ -23,7 +23,7 @@
 #include <assert.h>
 #include "mpitest.h"
 
-#if HAVE_UNISTD_H
+#ifdef HAVE_UNISTD_H
 #include <unistd.h>
 #endif
 
@@ -33,7 +33,7 @@
 
 /* Linked list pointer */
 typedef struct {
-    int      rank;
+    int rank;
     MPI_Aint disp;
 } llist_ptr_t;
 
@@ -44,28 +44,30 @@ typedef struct {
 } llist_elem_t;
 
 static const llist_ptr_t nil = { -1, (MPI_Aint) MPI_BOTTOM };
+
 static const int verbose = 0;
 
 /* List of locally allocated list elements. */
 static llist_elem_t **my_elems = NULL;
-static int my_elems_size  = 0;
+static int my_elems_size = 0;
 static int my_elems_count = 0;
 
 /* Allocate a new shared linked list element */
-MPI_Aint alloc_elem(int value, MPI_Win win) {
+MPI_Aint alloc_elem(int value, MPI_Win win)
+{
     MPI_Aint disp;
     llist_elem_t *elem_ptr;
 
     /* Allocate the new element and register it with the window */
     MPI_Alloc_mem(sizeof(llist_elem_t), MPI_INFO_NULL, &elem_ptr);
     elem_ptr->value = value;
-    elem_ptr->next  = nil;
+    elem_ptr->next = nil;
     MPI_Win_attach(win, elem_ptr, sizeof(llist_elem_t));
 
     /* Add the element to the list of local elements so we can free it later. */
     if (my_elems_size == my_elems_count) {
         my_elems_size += 100;
-        my_elems = realloc(my_elems, my_elems_size*sizeof(void*));
+        my_elems = realloc(my_elems, my_elems_size * sizeof(void *));
     }
     my_elems[my_elems_count] = elem_ptr;
     my_elems_count++;
@@ -74,10 +76,11 @@ MPI_Aint alloc_elem(int value, MPI_Win win) {
     return disp;
 }
 
-int main(int argc, char **argv) {
-    int           procid, nproc, i;
-    MPI_Win       llist_win;
-    llist_ptr_t   head_ptr, tail_ptr;
+int main(int argc, char **argv)
+{
+    int procid, nproc, i;
+    MPI_Win llist_win;
+    llist_ptr_t head_ptr, tail_ptr;
 
     MPI_Init(&argc, &argv);
 
@@ -105,15 +108,16 @@ int main(int argc, char **argv) {
         new_elem_ptr.disp = alloc_elem(procid, llist_win);
 
         /* Append the new node to the list.  This might take multiple attempts if
-           others have already appended and our tail pointer is stale. */
+         * others have already appended and our tail pointer is stale. */
         do {
             llist_ptr_t next_tail_ptr = nil;
 
             MPI_Win_lock(MPI_LOCK_EXCLUSIVE, tail_ptr.rank, 0, llist_win);
 
-            MPI_Compare_and_swap((void*) &new_elem_ptr.rank, (void*) &nil.rank,
-                                  (void*) &next_tail_ptr.rank, MPI_INT, tail_ptr.rank,
-                                  (MPI_Aint) &(((llist_elem_t*)tail_ptr.disp)->next.rank), llist_win);
+            MPI_Compare_and_swap((void *) &new_elem_ptr.rank, (void *) &nil.rank,
+                                 (void *) &next_tail_ptr.rank, MPI_INT, tail_ptr.rank,
+                                 (MPI_Aint) & (((llist_elem_t *) tail_ptr.disp)->next.rank),
+                                 llist_win);
 
             MPI_Win_unlock(tail_ptr.rank, llist_win);
             success = (next_tail_ptr.rank == nil.rank);
@@ -124,26 +128,28 @@ int main(int argc, char **argv) {
                 MPI_Win_lock(MPI_LOCK_EXCLUSIVE, tail_ptr.rank, 0, llist_win);
 
                 MPI_Put(&new_elem_ptr.disp, 1, MPI_AINT, tail_ptr.rank,
-                        (MPI_Aint) &(((llist_elem_t*)tail_ptr.disp)->next.disp), 1,
+                        (MPI_Aint) & (((llist_elem_t *) tail_ptr.disp)->next.disp), 1,
                         MPI_AINT, llist_win);
 
                 MPI_Win_unlock(tail_ptr.rank, llist_win);
                 tail_ptr = new_elem_ptr;
 
                 /* For implementations that use pt-to-pt messaging, force progress for other threads'
-                   RMA operations. */
+                 * RMA operations. */
                 for (i = 0; i < NPROBE; i++)
-                    MPI_Iprobe(MPI_ANY_SOURCE, MPI_ANY_TAG, MPI_COMM_WORLD, &flag, MPI_STATUS_IGNORE);
+                    MPI_Iprobe(MPI_ANY_SOURCE, MPI_ANY_TAG, MPI_COMM_WORLD, &flag,
+                               MPI_STATUS_IGNORE);
 
-            } else {
+            }
+            else {
                 /* Tail pointer is stale, fetch the displacement.  May take multiple tries
-                   if it is being updated. */
+                 * if it is being updated. */
                 do {
                     MPI_Win_lock(MPI_LOCK_EXCLUSIVE, tail_ptr.rank, 0, llist_win);
 
-                    MPI_Get( &next_tail_ptr.disp, 1, MPI_AINT, tail_ptr.rank,
-                             (MPI_Aint) &(((llist_elem_t*)tail_ptr.disp)->next.disp),
-                             1, MPI_AINT, llist_win);
+                    MPI_Get(&next_tail_ptr.disp, 1, MPI_AINT, tail_ptr.rank,
+                            (MPI_Aint) & (((llist_elem_t *) tail_ptr.disp)->next.disp),
+                            1, MPI_AINT, llist_win);
 
                     MPI_Win_unlock(tail_ptr.rank, llist_win);
                 } while (next_tail_ptr.disp == nil.disp);
@@ -155,13 +161,13 @@ int main(int argc, char **argv) {
     MPI_Barrier(MPI_COMM_WORLD);
 
     /* Traverse the list and verify that all processes inserted exactly the correct
-       number of elements. */
+     * number of elements. */
     if (procid == 0) {
-        int  have_root = 0;
-        int  errors    = 0;
+        int have_root = 0;
+        int errors = 0;
         int *counts, count = 0;
 
-        counts = (int*) malloc(sizeof(int) * nproc);
+        counts = (int *) malloc(sizeof(int) * nproc);
         assert(counts != NULL);
 
         for (i = 0; i < nproc; i++)
@@ -204,14 +210,15 @@ int main(int argc, char **argv) {
         }
 
         if (verbose)
-          printf("\n\n");
+            printf("\n\n");
 
         /* Verify the counts we collected */
         for (i = 0; i < nproc; i++) {
             int expected = NUM_ELEMS;
 
             if (counts[i] != expected) {
-                printf("Error: Rank %d inserted %d elements, expected %d\n", i, counts[i], expected);
+                printf("Error: Rank %d inserted %d elements, expected %d\n", i, counts[i],
+                       expected);
                 errors++;
             }
         }
@@ -223,8 +230,8 @@ int main(int argc, char **argv) {
     MPI_Win_free(&llist_win);
 
     /* Free all the elements in the list */
-    for ( ; my_elems_count > 0; my_elems_count--)
-        MPI_Free_mem(my_elems[my_elems_count-1]);
+    for (; my_elems_count > 0; my_elems_count--)
+        MPI_Free_mem(my_elems[my_elems_count - 1]);
 
     MPI_Finalize();
     return 0;
index 304ac47..5e0dfa4 100644 (file)
@@ -19,7 +19,7 @@
 #include <assert.h>
 #include "mpitest.h"
 
-#if HAVE_UNISTD_H
+#ifdef HAVE_UNISTD_H
 #include <unistd.h>
 #endif
 
@@ -33,7 +33,7 @@
 
 /* Linked list pointer */
 typedef struct {
-    int      rank;
+    int rank;
     MPI_Aint disp;
 } llist_ptr_t;
 
@@ -44,29 +44,31 @@ typedef struct {
 } llist_elem_t;
 
 static const llist_ptr_t nil = { -1, (MPI_Aint) MPI_BOTTOM };
+
 static const int verbose = 0;
 static const int print_perf = 0;
 
 /* List of locally allocated list elements. */
 static llist_elem_t **my_elems = NULL;
-static int my_elems_size  = 0;
+static int my_elems_size = 0;
 static int my_elems_count = 0;
 
 /* Allocate a new shared linked list element */
-MPI_Aint alloc_elem(int value, MPI_Win win) {
+MPI_Aint alloc_elem(int value, MPI_Win win)
+{
     MPI_Aint disp;
     llist_elem_t *elem_ptr;
 
     /* Allocate the new element and register it with the window */
     MPI_Alloc_mem(sizeof(llist_elem_t), MPI_INFO_NULL, &elem_ptr);
     elem_ptr->value = value;
-    elem_ptr->next  = nil;
+    elem_ptr->next = nil;
     MPI_Win_attach(win, elem_ptr, sizeof(llist_elem_t));
 
     /* Add the element to the list of local elements so we can free it later. */
     if (my_elems_size == my_elems_count) {
         my_elems_size += 100;
-        my_elems = realloc(my_elems, my_elems_size*sizeof(void*));
+        my_elems = realloc(my_elems, my_elems_size * sizeof(void *));
     }
     my_elems[my_elems_count] = elem_ptr;
     my_elems_count++;
@@ -75,12 +77,13 @@ MPI_Aint alloc_elem(int value, MPI_Win win) {
     return disp;
 }
 
-int main(int argc, char **argv) {
-    int           procid, nproc, i, j, my_nelem;
-    int           pollint = 0;
-    double        time;
-    MPI_Win       llist_win;
-    llist_ptr_t   head_ptr, tail_ptr;
+int main(int argc, char **argv)
+{
+    int procid, nproc, i, j, my_nelem;
+    int pollint = 0;
+    double time;
+    MPI_Win llist_win;
+    llist_ptr_t head_ptr, tail_ptr;
 
     MPI_Init(&argc, &argv);
 
@@ -105,7 +108,7 @@ int main(int argc, char **argv) {
     else
         i = 0;
 
-    my_nelem = NUM_ELEMS/nproc;
+    my_nelem = NUM_ELEMS / nproc;
     if (procid < NUM_ELEMS % nproc)
         my_nelem++;
 
@@ -115,31 +118,33 @@ int main(int argc, char **argv) {
     /* Lock the window for shared access to all targets */
     MPI_Win_lock_all(0, llist_win);
 
-    for ( ; i < my_nelem; i++) {
+    for (; i < my_nelem; i++) {
         llist_ptr_t new_elem_ptr;
         int success = 0;
 
+        MTEST_VG_MEM_INIT(&new_elem_ptr, sizeof(llist_ptr_t));
+
         /* Create a new list element and register it with the window */
         new_elem_ptr.rank = procid;
         new_elem_ptr.disp = alloc_elem(procid, llist_win);
 
         /* Append the new node to the list.  This might take multiple attempts if
-           others have already appended and our tail pointer is stale. */
+         * others have already appended and our tail pointer is stale. */
         do {
             int flag;
 
             /* The tail is at my left neighbor, append my element. */
-            if (tail_ptr.rank == (procid + nproc-1) % nproc)
-            {
+            if (tail_ptr.rank == (procid + nproc - 1) % nproc) {
                 if (verbose)
-                    printf("%d: Appending to <%d, %p>\n", procid, tail_ptr.rank, (void*) tail_ptr.disp);
+                    printf("%d: Appending to <%d, %p>\n", procid, tail_ptr.rank,
+                           (void *) tail_ptr.disp);
 #if 1
                 MPI_Accumulate(&new_elem_ptr, sizeof(llist_ptr_t), MPI_BYTE, tail_ptr.rank,
-                               (MPI_Aint) &(((llist_elem_t*)tail_ptr.disp)->next), sizeof(llist_ptr_t),
-                               MPI_BYTE, MPI_REPLACE, llist_win);
+                               (MPI_Aint) & (((llist_elem_t *) tail_ptr.disp)->next),
+                               sizeof(llist_ptr_t), MPI_BYTE, MPI_REPLACE, llist_win);
 #else
                 MPI_Put(&new_elem_ptr, sizeof(llist_ptr_t), MPI_BYTE, tail_ptr.rank,
-                        (MPI_Aint) &(((llist_elem_t*)tail_ptr.disp)->next), sizeof(llist_ptr_t),
+                        (MPI_Aint) & (((llist_elem_t *) tail_ptr.disp)->next), sizeof(llist_ptr_t),
                         MPI_BYTE, llist_win);
 #endif
                 MPI_Win_flush(tail_ptr.rank, llist_win);
@@ -149,28 +154,29 @@ int main(int argc, char **argv) {
             }
 
             /* Otherwise, chase the tail. */
-            else
-            {
+            else {
                 llist_ptr_t next_tail_ptr;
 
-                MPI_Get_accumulate( NULL, 0, MPI_DATATYPE_NULL, &next_tail_ptr,
-                                    sizeof(llist_ptr_t), MPI_BYTE, tail_ptr.rank,
-                                    (MPI_Aint) &(((llist_elem_t*)tail_ptr.disp)->next),
-                                    sizeof(llist_ptr_t), MPI_BYTE, MPI_NO_OP, llist_win);
+                MPI_Get_accumulate(NULL, 0, MPI_DATATYPE_NULL, &next_tail_ptr,
+                                   sizeof(llist_ptr_t), MPI_BYTE, tail_ptr.rank,
+                                   (MPI_Aint) & (((llist_elem_t *) tail_ptr.disp)->next),
+                                   sizeof(llist_ptr_t), MPI_BYTE, MPI_NO_OP, llist_win);
 
                 MPI_Win_flush(tail_ptr.rank, llist_win);
 
                 if (next_tail_ptr.rank != nil.rank) {
                     if (verbose)
-                        printf("%d: Chasing to <%d, %p>\n", procid, next_tail_ptr.rank, (void*) next_tail_ptr.disp);
+                        printf("%d: Chasing to <%d, %p>\n", procid, next_tail_ptr.rank,
+                               (void *) next_tail_ptr.disp);
                     tail_ptr = next_tail_ptr;
-                    pollint = MAX(MIN_NPROBE, pollint/2);
+                    pollint = MAX(MIN_NPROBE, pollint / 2);
                 }
                 else {
                     for (j = 0; j < pollint; j++)
-                        MPI_Iprobe(MPI_ANY_SOURCE, MPI_ANY_TAG, MPI_COMM_WORLD, &flag, MPI_STATUS_IGNORE);
+                        MPI_Iprobe(MPI_ANY_SOURCE, MPI_ANY_TAG, MPI_COMM_WORLD, &flag,
+                                   MPI_STATUS_IGNORE);
 
-                    pollint = MIN(MAX_NPROBE, pollint*2);
+                    pollint = MIN(MAX_NPROBE, pollint * 2);
                 }
             }
         } while (!success);
@@ -181,12 +187,12 @@ int main(int argc, char **argv) {
     time = MPI_Wtime() - time;
 
     /* Traverse the list and verify that all processes inserted exactly the correct
-       number of elements. */
+     * number of elements. */
     if (procid == 0) {
-        int  errors    = 0;
+        int errors = 0;
         int *counts, count = 0;
 
-        counts = (int*) malloc(sizeof(int) * nproc);
+        counts = (int *) malloc(sizeof(int) * nproc);
         assert(counts != NULL);
 
         for (i = 0; i < nproc; i++)
@@ -222,18 +228,19 @@ int main(int argc, char **argv) {
         MPI_Win_unlock_all(llist_win);
 
         if (verbose)
-          printf("\n\n");
+            printf("\n\n");
 
         /* Verify the counts we collected */
         for (i = 0; i < nproc; i++) {
             int expected;
 
-            expected = NUM_ELEMS/nproc;
+            expected = NUM_ELEMS / nproc;
             if (i < NUM_ELEMS % nproc)
                 expected++;
 
             if (counts[i] != expected) {
-                printf("Error: Rank %d inserted %d elements, expected %d\n", i, counts[i], expected);
+                printf("Error: Rank %d inserted %d elements, expected %d\n", i, counts[i],
+                       expected);
                 errors++;
             }
         }
@@ -248,15 +255,16 @@ int main(int argc, char **argv) {
         MPI_Reduce(&time, &max_time, 1, MPI_DOUBLE, MPI_MAX, 0, MPI_COMM_WORLD);
 
         if (procid == 0) {
-            printf("Total time = %0.2f sec, elem/sec = %0.2f, sec/elem = %0.2f usec\n", max_time, NUM_ELEMS/max_time, max_time/NUM_ELEMS*1.0e6);
+            printf("Total time = %0.2f sec, elem/sec = %0.2f, sec/elem = %0.2f usec\n", max_time,
+                   NUM_ELEMS / max_time, max_time / NUM_ELEMS * 1.0e6);
         }
     }
 
     MPI_Win_free(&llist_win);
 
     /* Free all the elements in the list */
-    for ( ; my_elems_count > 0; my_elems_count--)
-        MPI_Free_mem(my_elems[my_elems_count-1]);
+    for (; my_elems_count > 0; my_elems_count--)
+        MPI_Free_mem(my_elems[my_elems_count - 1]);
 
     MPI_Finalize();
     return 0;
index 288be5d..c52208e 100644 (file)
@@ -19,7 +19,7 @@
 #include <assert.h>
 #include "mpitest.h"
 
-#if HAVE_UNISTD_H
+#ifdef HAVE_UNISTD_H
 #include <unistd.h>
 #endif
 
@@ -33,7 +33,7 @@
 
 /* Linked list pointer */
 typedef struct {
-    int      rank;
+    int rank;
     MPI_Aint disp;
 } llist_ptr_t;
 
@@ -44,29 +44,31 @@ typedef struct {
 } llist_elem_t;
 
 static const llist_ptr_t nil = { -1, (MPI_Aint) MPI_BOTTOM };
+
 static const int verbose = 0;
 static const int print_perf = 0;
 
 /* List of locally allocated list elements. */
 static llist_elem_t **my_elems = NULL;
-static int my_elems_size  = 0;
+static int my_elems_size = 0;
 static int my_elems_count = 0;
 
 /* Allocate a new shared linked list element */
-MPI_Aint alloc_elem(int value, MPI_Win win) {
+MPI_Aint alloc_elem(int value, MPI_Win win)
+{
     MPI_Aint disp;
     llist_elem_t *elem_ptr;
 
     /* Allocate the new element and register it with the window */
     MPI_Alloc_mem(sizeof(llist_elem_t), MPI_INFO_NULL, &elem_ptr);
     elem_ptr->value = value;
-    elem_ptr->next  = nil;
+    elem_ptr->next = nil;
     MPI_Win_attach(win, elem_ptr, sizeof(llist_elem_t));
 
     /* Add the element to the list of local elements so we can free it later. */
     if (my_elems_size == my_elems_count) {
         my_elems_size += 100;
-        my_elems = realloc(my_elems, my_elems_size*sizeof(void*));
+        my_elems = realloc(my_elems, my_elems_size * sizeof(void *));
     }
     my_elems[my_elems_count] = elem_ptr;
     my_elems_count++;
@@ -75,12 +77,13 @@ MPI_Aint alloc_elem(int value, MPI_Win win) {
     return disp;
 }
 
-int main(int argc, char **argv) {
-    int           procid, nproc, i, j, my_nelem;
-    int           pollint = 0;
-    double        time;
-    MPI_Win       llist_win;
-    llist_ptr_t   head_ptr, tail_ptr;
+int main(int argc, char **argv)
+{
+    int procid, nproc, i, j, my_nelem;
+    int pollint = 0;
+    double time;
+    MPI_Win llist_win;
+    llist_ptr_t head_ptr, tail_ptr;
 
     MPI_Init(&argc, &argv);
 
@@ -104,40 +107,42 @@ int main(int argc, char **argv) {
         i = 1;
     else
         i = 0;
-    my_nelem = NUM_ELEMS/nproc;
+    my_nelem = NUM_ELEMS / nproc;
     if (procid < NUM_ELEMS % nproc)
         my_nelem++;
 
     MPI_Barrier(MPI_COMM_WORLD);
     time = MPI_Wtime();
 
-    for ( ; i < my_nelem; i++) {
+    for (; i < my_nelem; i++) {
         llist_ptr_t new_elem_ptr;
         int success = 0;
 
+        MTEST_VG_MEM_INIT(&new_elem_ptr, sizeof(llist_ptr_t));
+
         /* Create a new list element and register it with the window */
         new_elem_ptr.rank = procid;
         new_elem_ptr.disp = alloc_elem(procid, llist_win);
 
         /* Append the new node to the list.  This might take multiple attempts if
-           others have already appended and our tail pointer is stale. */
+         * others have already appended and our tail pointer is stale. */
         do {
             int flag;
 
             /* The tail is at my left neighbor, append my element. */
-            if (tail_ptr.rank == (procid + nproc-1) % nproc)
-            {
+            if (tail_ptr.rank == (procid + nproc - 1) % nproc) {
                 if (verbose)
-                    printf("%d: Appending to <%d, %p>\n", procid, tail_ptr.rank, (void*) tail_ptr.disp);
+                    printf("%d: Appending to <%d, %p>\n", procid, tail_ptr.rank,
+                           (void *) tail_ptr.disp);
 
                 MPI_Win_lock(MPI_LOCK_EXCLUSIVE, tail_ptr.rank, 0, llist_win);
 #if USE_ACC
                 MPI_Accumulate(&new_elem_ptr, sizeof(llist_ptr_t), MPI_BYTE, tail_ptr.rank,
-                               (MPI_Aint) &(((llist_elem_t*)tail_ptr.disp)->next), sizeof(llist_ptr_t),
-                               MPI_BYTE, MPI_REPLACE, llist_win);
+                               (MPI_Aint) & (((llist_elem_t *) tail_ptr.disp)->next),
+                               sizeof(llist_ptr_t), MPI_BYTE, MPI_REPLACE, llist_win);
 #else
                 MPI_Put(&new_elem_ptr, sizeof(llist_ptr_t), MPI_BYTE, tail_ptr.rank,
-                        (MPI_Aint) &(((llist_elem_t*)tail_ptr.disp)->next), sizeof(llist_ptr_t),
+                        (MPI_Aint) & (((llist_elem_t *) tail_ptr.disp)->next), sizeof(llist_ptr_t),
                         MPI_BYTE, llist_win);
 #endif
                 MPI_Win_unlock(tail_ptr.rank, llist_win);
@@ -147,34 +152,35 @@ int main(int argc, char **argv) {
             }
 
             /* Otherwise, chase the tail. */
-            else
-            {
+            else {
                 llist_ptr_t next_tail_ptr;
 
                 MPI_Win_lock(MPI_LOCK_EXCLUSIVE, tail_ptr.rank, 0, llist_win);
 #if USE_ACC
-                MPI_Get_accumulate( NULL, 0, MPI_DATATYPE_NULL, &next_tail_ptr,
-                                    sizeof(llist_ptr_t), MPI_BYTE, tail_ptr.rank,
-                                    (MPI_Aint) &(((llist_elem_t*)tail_ptr.disp)->next),
-                                    sizeof(llist_ptr_t), MPI_BYTE, MPI_NO_OP, llist_win);
+                MPI_Get_accumulate(NULL, 0, MPI_DATATYPE_NULL, &next_tail_ptr,
+                                   sizeof(llist_ptr_t), MPI_BYTE, tail_ptr.rank,
+                                   (MPI_Aint) & (((llist_elem_t *) tail_ptr.disp)->next),
+                                   sizeof(llist_ptr_t), MPI_BYTE, MPI_NO_OP, llist_win);
 #else
                 MPI_Get(&next_tail_ptr, sizeof(llist_ptr_t), MPI_BYTE, tail_ptr.rank,
-                        (MPI_Aint) &(((llist_elem_t*)tail_ptr.disp)->next),
+                        (MPI_Aint) & (((llist_elem_t *) tail_ptr.disp)->next),
                         sizeof(llist_ptr_t), MPI_BYTE, llist_win);
 #endif
                 MPI_Win_unlock(tail_ptr.rank, llist_win);
 
                 if (next_tail_ptr.rank != nil.rank) {
                     if (verbose)
-                        printf("%d: Chasing to <%d, %p>\n", procid, next_tail_ptr.rank, (void*) next_tail_ptr.disp);
+                        printf("%d: Chasing to <%d, %p>\n", procid, next_tail_ptr.rank,
+                               (void *) next_tail_ptr.disp);
                     tail_ptr = next_tail_ptr;
-                    pollint = MAX(MIN_NPROBE, pollint/2);
+                    pollint = MAX(MIN_NPROBE, pollint / 2);
                 }
                 else {
                     for (j = 0; j < pollint; j++)
-                        MPI_Iprobe(MPI_ANY_SOURCE, MPI_ANY_TAG, MPI_COMM_WORLD, &flag, MPI_STATUS_IGNORE);
+                        MPI_Iprobe(MPI_ANY_SOURCE, MPI_ANY_TAG, MPI_COMM_WORLD, &flag,
+                                   MPI_STATUS_IGNORE);
 
-                    pollint = MIN(MAX_NPROBE, pollint*2);
+                    pollint = MIN(MAX_NPROBE, pollint * 2);
                 }
             }
         } while (!success);
@@ -184,12 +190,12 @@ int main(int argc, char **argv) {
     time = MPI_Wtime() - time;
 
     /* Traverse the list and verify that all processes inserted exactly the correct
-       number of elements. */
+     * number of elements. */
     if (procid == 0) {
-        int  errors    = 0;
+        int errors = 0;
         int *counts, count = 0;
 
-        counts = (int*) malloc(sizeof(int) * nproc);
+        counts = (int *) malloc(sizeof(int) * nproc);
         assert(counts != NULL);
 
         for (i = 0; i < nproc; i++)
@@ -225,18 +231,19 @@ int main(int argc, char **argv) {
         MPI_Win_unlock_all(llist_win);
 
         if (verbose)
-          printf("\n\n");
+            printf("\n\n");
 
         /* Verify the counts we collected */
         for (i = 0; i < nproc; i++) {
             int expected;
 
-            expected = NUM_ELEMS/nproc;
+            expected = NUM_ELEMS / nproc;
             if (i < NUM_ELEMS % nproc)
                 expected++;
 
             if (counts[i] != expected) {
-                printf("Error: Rank %d inserted %d elements, expected %d\n", i, counts[i], expected);
+                printf("Error: Rank %d inserted %d elements, expected %d\n", i, counts[i],
+                       expected);
                 errors++;
             }
         }
@@ -251,15 +258,16 @@ int main(int argc, char **argv) {
         MPI_Reduce(&time, &max_time, 1, MPI_DOUBLE, MPI_MAX, 0, MPI_COMM_WORLD);
 
         if (procid == 0) {
-            printf("Total time = %0.2f sec, elem/sec = %0.2f, sec/elem = %0.2f usec\n", max_time, NUM_ELEMS/max_time, max_time/NUM_ELEMS*1.0e6);
+            printf("Total time = %0.2f sec, elem/sec = %0.2f, sec/elem = %0.2f usec\n", max_time,
+                   NUM_ELEMS / max_time, max_time / NUM_ELEMS * 1.0e6);
         }
     }
 
     MPI_Win_free(&llist_win);
 
     /* Free all the elements in the list */
-    for ( ; my_elems_count > 0; my_elems_count--)
-        MPI_Free_mem(my_elems[my_elems_count-1]);
+    for (; my_elems_count > 0; my_elems_count--)
+        MPI_Free_mem(my_elems[my_elems_count - 1]);
 
     MPI_Finalize();
     return 0;
index 662cbc8..9577b16 100644 (file)
@@ -19,7 +19,7 @@
 #include <assert.h>
 #include "mpitest.h"
 
-#if HAVE_UNISTD_H
+#ifdef HAVE_UNISTD_H
 #include <unistd.h>
 #endif
 
@@ -33,7 +33,7 @@
 
 /* Linked list pointer */
 typedef struct {
-    int      rank;
+    int rank;
     MPI_Aint disp;
 } llist_ptr_t;
 
@@ -44,29 +44,31 @@ typedef struct {
 } llist_elem_t;
 
 static const llist_ptr_t nil = { -1, (MPI_Aint) MPI_BOTTOM };
+
 static const int verbose = 0;
 static const int print_perf = 0;
 
 /* List of locally allocated list elements. */
 static llist_elem_t **my_elems = NULL;
-static int my_elems_size  = 0;
+static int my_elems_size = 0;
 static int my_elems_count = 0;
 
 /* Allocate a new shared linked list element */
-MPI_Aint alloc_elem(int value, MPI_Win win) {
+MPI_Aint alloc_elem(int value, MPI_Win win)
+{
     MPI_Aint disp;
     llist_elem_t *elem_ptr;
 
     /* Allocate the new element and register it with the window */
     MPI_Alloc_mem(sizeof(llist_elem_t), MPI_INFO_NULL, &elem_ptr);
     elem_ptr->value = value;
-    elem_ptr->next  = nil;
+    elem_ptr->next = nil;
     MPI_Win_attach(win, elem_ptr, sizeof(llist_elem_t));
 
     /* Add the element to the list of local elements so we can free it later. */
     if (my_elems_size == my_elems_count) {
         my_elems_size += 100;
-        my_elems = realloc(my_elems, my_elems_size*sizeof(void*));
+        my_elems = realloc(my_elems, my_elems_size * sizeof(void *));
     }
     my_elems[my_elems_count] = elem_ptr;
     my_elems_count++;
@@ -75,12 +77,13 @@ MPI_Aint alloc_elem(int value, MPI_Win win) {
     return disp;
 }
 
-int main(int argc, char **argv) {
-    int           procid, nproc, i, j, my_nelem;
-    int           pollint = 0;
-    double        time;
-    MPI_Win       llist_win;
-    llist_ptr_t   head_ptr, tail_ptr;
+int main(int argc, char **argv)
+{
+    int procid, nproc, i, j, my_nelem;
+    int pollint = 0;
+    double time;
+    MPI_Win llist_win;
+    llist_ptr_t head_ptr, tail_ptr;
 
     MPI_Init(&argc, &argv);
 
@@ -105,31 +108,33 @@ int main(int argc, char **argv) {
     else
         i = 0;
 
-    my_nelem = NUM_ELEMS/nproc;
+    my_nelem = NUM_ELEMS / nproc;
     if (procid < NUM_ELEMS % nproc)
         my_nelem++;
 
     MPI_Barrier(MPI_COMM_WORLD);
     time = MPI_Wtime();
 
-    for ( ; i < my_nelem; i++) {
+    for (; i < my_nelem; i++) {
         llist_ptr_t new_elem_ptr;
         int success = 0;
 
+        MTEST_VG_MEM_INIT(&new_elem_ptr, sizeof(llist_ptr_t));
+
         /* Create a new list element and register it with the window */
         new_elem_ptr.rank = procid;
         new_elem_ptr.disp = alloc_elem(procid, llist_win);
 
         /* Append the new node to the list.  This might take multiple attempts if
-           others have already appended and our tail pointer is stale. */
+         * others have already appended and our tail pointer is stale. */
         do {
             int flag;
 
             /* The tail is at my left neighbor, append my element. */
-            if (tail_ptr.rank == (procid + nproc-1) % nproc)
-            {
+            if (tail_ptr.rank == (procid + nproc - 1) % nproc) {
                 if (verbose)
-                    printf("%d: Appending to <%d, %p>\n", procid, tail_ptr.rank, (void*) tail_ptr.disp);
+                    printf("%d: Appending to <%d, %p>\n", procid, tail_ptr.rank,
+                           (void *) tail_ptr.disp);
 
 #ifdef USE_MODE_NOCHECK
                 MPI_Win_lock(MPI_LOCK_SHARED, tail_ptr.rank, MPI_MODE_NOCHECK, llist_win);
@@ -137,8 +142,8 @@ int main(int argc, char **argv) {
                 MPI_Win_lock(MPI_LOCK_SHARED, tail_ptr.rank, 0, llist_win);
 #endif
                 MPI_Accumulate(&new_elem_ptr, sizeof(llist_ptr_t), MPI_BYTE, tail_ptr.rank,
-                               (MPI_Aint) &(((llist_elem_t*)tail_ptr.disp)->next), sizeof(llist_ptr_t),
-                               MPI_BYTE, MPI_REPLACE, llist_win);
+                               (MPI_Aint) & (((llist_elem_t *) tail_ptr.disp)->next),
+                               sizeof(llist_ptr_t), MPI_BYTE, MPI_REPLACE, llist_win);
                 MPI_Win_unlock(tail_ptr.rank, llist_win);
 
                 success = 1;
@@ -146,8 +151,7 @@ int main(int argc, char **argv) {
             }
 
             /* Otherwise, chase the tail. */
-            else
-            {
+            else {
                 llist_ptr_t next_tail_ptr;
 
 #ifdef USE_MODE_NOCHECK
@@ -155,23 +159,25 @@ int main(int argc, char **argv) {
 #else
                 MPI_Win_lock(MPI_LOCK_SHARED, tail_ptr.rank, 0, llist_win);
 #endif
-                MPI_Get_accumulate( NULL, 0, MPI_DATATYPE_NULL, &next_tail_ptr,
-                                    sizeof(llist_ptr_t), MPI_BYTE, tail_ptr.rank,
-                                    (MPI_Aint) &(((llist_elem_t*)tail_ptr.disp)->next),
-                                    sizeof(llist_ptr_t), MPI_BYTE, MPI_NO_OP, llist_win);
+                MPI_Get_accumulate(NULL, 0, MPI_DATATYPE_NULL, &next_tail_ptr,
+                                   sizeof(llist_ptr_t), MPI_BYTE, tail_ptr.rank,
+                                   (MPI_Aint) & (((llist_elem_t *) tail_ptr.disp)->next),
+                                   sizeof(llist_ptr_t), MPI_BYTE, MPI_NO_OP, llist_win);
                 MPI_Win_unlock(tail_ptr.rank, llist_win);
 
                 if (next_tail_ptr.rank != nil.rank) {
                     if (verbose)
-                        printf("%d: Chasing to <%d, %p>\n", procid, next_tail_ptr.rank, (void*) next_tail_ptr.disp);
+                        printf("%d: Chasing to <%d, %p>\n", procid, next_tail_ptr.rank,
+                               (void *) next_tail_ptr.disp);
                     tail_ptr = next_tail_ptr;
-                    pollint = MAX(MIN_NPROBE, pollint/2);
+                    pollint = MAX(MIN_NPROBE, pollint / 2);
                 }
                 else {
                     for (j = 0; j < pollint; j++)
-                        MPI_Iprobe(MPI_ANY_SOURCE, MPI_ANY_TAG, MPI_COMM_WORLD, &flag, MPI_STATUS_IGNORE);
+                        MPI_Iprobe(MPI_ANY_SOURCE, MPI_ANY_TAG, MPI_COMM_WORLD, &flag,
+                                   MPI_STATUS_IGNORE);
 
-                    pollint = MIN(MAX_NPROBE, pollint*2);
+                    pollint = MIN(MAX_NPROBE, pollint * 2);
                 }
             }
         } while (!success);
@@ -181,12 +187,12 @@ int main(int argc, char **argv) {
     time = MPI_Wtime() - time;
 
     /* Traverse the list and verify that all processes inserted exactly the correct
-       number of elements. */
+     * number of elements. */
     if (procid == 0) {
-        int  errors    = 0;
+        int errors = 0;
         int *counts, count = 0;
 
-        counts = (int*) malloc(sizeof(int) * nproc);
+        counts = (int *) malloc(sizeof(int) * nproc);
         assert(counts != NULL);
 
         for (i = 0; i < nproc; i++)
@@ -222,18 +228,19 @@ int main(int argc, char **argv) {
         MPI_Win_unlock_all(llist_win);
 
         if (verbose)
-          printf("\n\n");
+            printf("\n\n");
 
         /* Verify the counts we collected */
         for (i = 0; i < nproc; i++) {
             int expected;
 
-            expected = NUM_ELEMS/nproc;
+            expected = NUM_ELEMS / nproc;
             if (i < NUM_ELEMS % nproc)
                 expected++;
 
             if (counts[i] != expected) {
-                printf("Error: Rank %d inserted %d elements, expected %d\n", i, counts[i], expected);
+                printf("Error: Rank %d inserted %d elements, expected %d\n", i, counts[i],
+                       expected);
                 errors++;
             }
         }
@@ -248,15 +255,16 @@ int main(int argc, char **argv) {
         MPI_Reduce(&time, &max_time, 1, MPI_DOUBLE, MPI_MAX, 0, MPI_COMM_WORLD);
 
         if (procid == 0) {
-            printf("Total time = %0.2f sec, elem/sec = %0.2f, sec/elem = %0.2f usec\n", max_time, NUM_ELEMS/max_time, max_time/NUM_ELEMS*1.0e6);
+            printf("Total time = %0.2f sec, elem/sec = %0.2f, sec/elem = %0.2f usec\n", max_time,
+                   NUM_ELEMS / max_time, max_time / NUM_ELEMS * 1.0e6);
         }
     }
 
     MPI_Win_free(&llist_win);
 
     /* Free all the elements in the list */
-    for ( ; my_elems_count > 0; my_elems_count--)
-        MPI_Free_mem(my_elems[my_elems_count-1]);
+    for (; my_elems_count > 0; my_elems_count--)
+        MPI_Free_mem(my_elems[my_elems_count - 1]);
 
     MPI_Finalize();
     return 0;
index 82a3ec2..61b7618 100644 (file)
@@ -7,7 +7,7 @@
 
 /*            MPI-3 distributed linked list construction example
  *            --------------------------------------------------
- * 
+ *
  * Construct a distributed shared linked list using proposed MPI-3 dynamic
  * windows.  Initially process 0 creates the head of the list, attaches it to
  * the window, and broadcasts the pointer to all processes.  All processes then
@@ -23,7 +23,7 @@
 #include <assert.h>
 #include "mpitest.h"
 
-#if HAVE_UNISTD_H
+#ifdef HAVE_UNISTD_H
 #include <unistd.h>
 #endif
 
@@ -33,7 +33,7 @@
 
 /* Linked list pointer */
 typedef struct {
-    int      rank;
+    int rank;
     MPI_Aint disp;
 } llist_ptr_t;
 
@@ -44,28 +44,30 @@ typedef struct {
 } llist_elem_t;
 
 static const llist_ptr_t nil = { -1, (MPI_Aint) MPI_BOTTOM };
+
 static const int verbose = 0;
 
 /* List of locally allocated list elements. */
 static llist_elem_t **my_elems = NULL;
-static int my_elems_size  = 0;
+static int my_elems_size = 0;
 static int my_elems_count = 0;
 
 /* Allocate a new shared linked list element */
-MPI_Aint alloc_elem(int value, MPI_Win win) {
+MPI_Aint alloc_elem(int value, MPI_Win win)
+{
     MPI_Aint disp;
     llist_elem_t *elem_ptr;
 
     /* Allocate the new element and register it with the window */
     MPI_Alloc_mem(sizeof(llist_elem_t), MPI_INFO_NULL, &elem_ptr);
     elem_ptr->value = value;
-    elem_ptr->next  = nil;
+    elem_ptr->next = nil;
     MPI_Win_attach(win, elem_ptr, sizeof(llist_elem_t));
 
     /* Add the element to the list of local elements so we can free it later. */
     if (my_elems_size == my_elems_count) {
         my_elems_size += 100;
-        my_elems = realloc(my_elems, my_elems_size*sizeof(void*));
+        my_elems = realloc(my_elems, my_elems_size * sizeof(void *));
     }
     my_elems[my_elems_count] = elem_ptr;
     my_elems_count++;
@@ -74,10 +76,11 @@ MPI_Aint alloc_elem(int value, MPI_Win win) {
     return disp;
 }
 
-int main(int argc, char **argv) {
-    int           procid, nproc, i;
-    MPI_Win       llist_win;
-    llist_ptr_t   head_ptr, tail_ptr;
+int main(int argc, char **argv)
+{
+    int procid, nproc, i;
+    MPI_Win llist_win;
+    llist_ptr_t head_ptr, tail_ptr;
 
     MPI_Init(&argc, &argv);
 
@@ -105,15 +108,16 @@ int main(int argc, char **argv) {
         new_elem_ptr.disp = alloc_elem(procid, llist_win);
 
         /* Append the new node to the list.  This might take multiple attempts if
-           others have already appended and our tail pointer is stale. */
+         * others have already appended and our tail pointer is stale. */
         do {
             llist_ptr_t next_tail_ptr = nil;
 
             MPI_Win_lock(MPI_LOCK_SHARED, tail_ptr.rank, MPI_MODE_NOCHECK, llist_win);
 
-            MPI_Compare_and_swap((void*) &new_elem_ptr.rank, (void*) &nil.rank,
-                                  (void*) &next_tail_ptr.rank, MPI_INT, tail_ptr.rank,
-                                  (MPI_Aint) &(((llist_elem_t*)tail_ptr.disp)->next.rank), llist_win);
+            MPI_Compare_and_swap((void *) &new_elem_ptr.rank, (void *) &nil.rank,
+                                 (void *) &next_tail_ptr.rank, MPI_INT, tail_ptr.rank,
+                                 (MPI_Aint) & (((llist_elem_t *) tail_ptr.disp)->next.rank),
+                                 llist_win);
 
             MPI_Win_unlock(tail_ptr.rank, llist_win);
             success = (next_tail_ptr.rank == nil.rank);
@@ -125,36 +129,36 @@ int main(int argc, char **argv) {
                 MPI_Win_lock(MPI_LOCK_SHARED, tail_ptr.rank, MPI_MODE_NOCHECK, llist_win);
 
                 MPI_Fetch_and_op(&new_elem_ptr.disp, &result, MPI_AINT, tail_ptr.rank,
-                                  (MPI_Aint) &(((llist_elem_t*)tail_ptr.disp)->next.disp),
-                                  MPI_REPLACE, llist_win);
+                                 (MPI_Aint) & (((llist_elem_t *) tail_ptr.disp)->next.disp),
+                                 MPI_REPLACE, llist_win);
 
                 /* Note: accumulate is faster, since we don't need the result.  Replacing with
-                   Fetch_and_op to create a more complete test case. */
+                 * Fetch_and_op to create a more complete test case. */
                 /*
-                MPI_Accumulate(&new_elem_ptr.disp, 1, MPI_AINT, tail_ptr.rank,
-                               (MPI_Aint) &(((llist_elem_t*)tail_ptr.disp)->next.disp), 1,
-                               MPI_AINT, MPI_REPLACE, llist_win);
-                */
+                 * MPI_Accumulate(&new_elem_ptr.disp, 1, MPI_AINT, tail_ptr.rank,
+                 * (MPI_Aint) &(((llist_elem_t*)tail_ptr.disp)->next.disp), 1,
+                 * MPI_AINT, MPI_REPLACE, llist_win);
+                 */
 
                 MPI_Win_unlock(tail_ptr.rank, llist_win);
                 tail_ptr = new_elem_ptr;
 
                 /* For implementations that use pt-to-pt messaging, force progress for other threads'
-                   RMA operations. */
+                 * RMA operations. */
                 for (i = 0; i < NPROBE; i++)
-                    MPI_Iprobe(MPI_ANY_SOURCE, MPI_ANY_TAG, MPI_COMM_WORLD, &flag, MPI_STATUS_IGNORE);
+                    MPI_Iprobe(MPI_ANY_SOURCE, MPI_ANY_TAG, MPI_COMM_WORLD, &flag,
+                               MPI_STATUS_IGNORE);
 
-            } else {
+            }
+            else {
                 /* Tail pointer is stale, fetch the displacement.  May take multiple tries
-                   if it is being updated. */
+                 * if it is being updated. */
                 do {
-                    MPI_Aint junk = 0;
-
                     MPI_Win_lock(MPI_LOCK_SHARED, tail_ptr.rank, MPI_MODE_NOCHECK, llist_win);
 
                     MPI_Fetch_and_op(NULL, &next_tail_ptr.disp, MPI_AINT, tail_ptr.rank,
-                                      (MPI_Aint) &(((llist_elem_t*)tail_ptr.disp)->next.disp),
-                                      MPI_NO_OP, llist_win);
+                                     (MPI_Aint) & (((llist_elem_t *) tail_ptr.disp)->next.disp),
+                                     MPI_NO_OP, llist_win);
 
                     MPI_Win_unlock(tail_ptr.rank, llist_win);
                 } while (next_tail_ptr.disp == nil.disp);
@@ -166,13 +170,13 @@ int main(int argc, char **argv) {
     MPI_Barrier(MPI_COMM_WORLD);
 
     /* Traverse the list and verify that all processes inserted exactly the correct
-       number of elements. */
+     * number of elements. */
     if (procid == 0) {
-        int  have_root = 0;
-        int  errors    = 0;
+        int have_root = 0;
+        int errors = 0;
         int *counts, count = 0;
 
-        counts = (int*) malloc(sizeof(int) * nproc);
+        counts = (int *) malloc(sizeof(int) * nproc);
         assert(counts != NULL);
 
         for (i = 0; i < nproc; i++)
@@ -215,14 +219,15 @@ int main(int argc, char **argv) {
         }
 
         if (verbose)
-          printf("\n\n");
+            printf("\n\n");
 
         /* Verify the counts we collected */
         for (i = 0; i < nproc; i++) {
             int expected = NUM_ELEMS;
 
             if (counts[i] != expected) {
-                printf("Error: Rank %d inserted %d elements, expected %d\n", i, counts[i], expected);
+                printf("Error: Rank %d inserted %d elements, expected %d\n", i, counts[i],
+                       expected);
                 errors++;
             }
         }
@@ -234,8 +239,8 @@ int main(int argc, char **argv) {
     MPI_Win_free(&llist_win);
 
     /* Free all the elements in the list */
-    for ( ; my_elems_count > 0; my_elems_count--)
-        MPI_Free_mem(my_elems[my_elems_count-1]);
+    for (; my_elems_count > 0; my_elems_count--)
+        MPI_Free_mem(my_elems[my_elems_count - 1]);
 
     MPI_Finalize();
     return 0;
index 2690692..699623c 100644 (file)
@@ -23,7 +23,7 @@
 #include <assert.h>
 #include "mpitest.h"
 
-#if HAVE_UNISTD_H
+#ifdef HAVE_UNISTD_H
 #include <unistd.h>
 #endif
 
@@ -33,7 +33,7 @@
 
 /* Linked list pointer */
 typedef struct {
-    int      rank;
+    int rank;
     MPI_Aint disp;
 } llist_ptr_t;
 
@@ -44,28 +44,30 @@ typedef struct {
 } llist_elem_t;
 
 static const llist_ptr_t nil = { -1, (MPI_Aint) MPI_BOTTOM };
+
 static const int verbose = 0;
 
 /* List of locally allocated list elements. */
 static llist_elem_t **my_elems = NULL;
-static int my_elems_size  = 0;
+static int my_elems_size = 0;
 static int my_elems_count = 0;
 
 /* Allocate a new shared linked list element */
-MPI_Aint alloc_elem(int value, MPI_Win win) {
+MPI_Aint alloc_elem(int value, MPI_Win win)
+{
     MPI_Aint disp;
     llist_elem_t *elem_ptr;
 
     /* Allocate the new element and register it with the window */
     MPI_Alloc_mem(sizeof(llist_elem_t), MPI_INFO_NULL, &elem_ptr);
     elem_ptr->value = value;
-    elem_ptr->next  = nil;
+    elem_ptr->next = nil;
     MPI_Win_attach(win, elem_ptr, sizeof(llist_elem_t));
 
     /* Add the element to the list of local elements so we can free it later. */
     if (my_elems_size == my_elems_count) {
         my_elems_size += 100;
-        my_elems = realloc(my_elems, my_elems_size*sizeof(void*));
+        my_elems = realloc(my_elems, my_elems_size * sizeof(void *));
     }
     my_elems[my_elems_count] = elem_ptr;
     my_elems_count++;
@@ -74,10 +76,11 @@ MPI_Aint alloc_elem(int value, MPI_Win win) {
     return disp;
 }
 
-int main(int argc, char **argv) {
-    int           procid, nproc, i;
-    MPI_Win       llist_win;
-    llist_ptr_t   head_ptr, tail_ptr;
+int main(int argc, char **argv)
+{
+    int procid, nproc, i;
+    MPI_Win llist_win;
+    llist_ptr_t head_ptr, tail_ptr;
 
     MPI_Init(&argc, &argv);
 
@@ -108,13 +111,14 @@ int main(int argc, char **argv) {
         new_elem_ptr.disp = alloc_elem(procid, llist_win);
 
         /* Append the new node to the list.  This might take multiple attempts if
-           others have already appended and our tail pointer is stale. */
+         * others have already appended and our tail pointer is stale. */
         do {
             llist_ptr_t next_tail_ptr = nil;
 
-            MPI_Compare_and_swap((void*) &new_elem_ptr.rank, (void*) &nil.rank,
-                                  (void*) &next_tail_ptr.rank, MPI_INT, tail_ptr.rank,
-                                  (MPI_Aint) &(((llist_elem_t*)tail_ptr.disp)->next.rank), llist_win);
+            MPI_Compare_and_swap((void *) &new_elem_ptr.rank, (void *) &nil.rank,
+                                 (void *) &next_tail_ptr.rank, MPI_INT, tail_ptr.rank,
+                                 (MPI_Aint) & (((llist_elem_t *) tail_ptr.disp)->next.rank),
+                                 llist_win);
 
             MPI_Win_flush(tail_ptr.rank, llist_win);
             success = (next_tail_ptr.rank == nil.rank);
@@ -123,25 +127,27 @@ int main(int argc, char **argv) {
                 int i, flag;
 
                 MPI_Accumulate(&new_elem_ptr.disp, 1, MPI_AINT, tail_ptr.rank,
-                               (MPI_Aint) &(((llist_elem_t*)tail_ptr.disp)->next.disp), 1,
+                               (MPI_Aint) & (((llist_elem_t *) tail_ptr.disp)->next.disp), 1,
                                MPI_AINT, MPI_REPLACE, llist_win);
 
                 MPI_Win_flush(tail_ptr.rank, llist_win);
                 tail_ptr = new_elem_ptr;
 
                 /* For implementations that use pt-to-pt messaging, force progress for other threads'
-                   RMA operations. */
+                 * RMA operations. */
                 for (i = 0; i < NPROBE; i++)
-                    MPI_Iprobe(MPI_ANY_SOURCE, MPI_ANY_TAG, MPI_COMM_WORLD, &flag, MPI_STATUS_IGNORE);
+                    MPI_Iprobe(MPI_ANY_SOURCE, MPI_ANY_TAG, MPI_COMM_WORLD, &flag,
+                               MPI_STATUS_IGNORE);
 
-            } else {
+            }
+            else {
                 /* Tail pointer is stale, fetch the displacement.  May take multiple tries
-                   if it is being updated. */
+                 * if it is being updated. */
                 do {
-                    MPI_Get_accumulate( NULL, 0, MPI_DATATYPE_NULL, &next_tail_ptr.disp,
-                                        1, MPI_AINT, tail_ptr.rank,
-                                        (MPI_Aint) &(((llist_elem_t*)tail_ptr.disp)->next.disp),
-                                        1, MPI_AINT, MPI_NO_OP, llist_win);
+                    MPI_Get_accumulate(NULL, 0, MPI_DATATYPE_NULL, &next_tail_ptr.disp,
+                                       1, MPI_AINT, tail_ptr.rank,
+                                       (MPI_Aint) & (((llist_elem_t *) tail_ptr.disp)->next.disp),
+                                       1, MPI_AINT, MPI_NO_OP, llist_win);
                     MPI_Win_flush(tail_ptr.rank, llist_win);
                 } while (next_tail_ptr.disp == nil.disp);
                 tail_ptr = next_tail_ptr;
@@ -153,13 +159,13 @@ int main(int argc, char **argv) {
     MPI_Barrier(MPI_COMM_WORLD);
 
     /* Traverse the list and verify that all processes inserted exactly the correct
-       number of elements. */
+     * number of elements. */
     if (procid == 0) {
-        int  have_root = 0;
-        int  errors    = 0;
+        int have_root = 0;
+        int errors = 0;
         int *counts, count = 0;
 
-        counts = (int*) malloc(sizeof(int) * nproc);
+        counts = (int *) malloc(sizeof(int) * nproc);
         assert(counts != NULL);
 
         for (i = 0; i < nproc; i++)
@@ -204,14 +210,15 @@ int main(int argc, char **argv) {
         MPI_Win_unlock_all(llist_win);
 
         if (verbose)
-          printf("\n\n");
+            printf("\n\n");
 
         /* Verify the counts we collected */
         for (i = 0; i < nproc; i++) {
             int expected = NUM_ELEMS;
 
             if (counts[i] != expected) {
-                printf("Error: Rank %d inserted %d elements, expected %d\n", i, counts[i], expected);
+                printf("Error: Rank %d inserted %d elements, expected %d\n", i, counts[i],
+                       expected);
                 errors++;
             }
         }
@@ -223,8 +230,8 @@ int main(int argc, char **argv) {
     MPI_Win_free(&llist_win);
 
     /* Free all the elements in the list */
-    for ( ; my_elems_count > 0; my_elems_count--)
-        MPI_Free_mem(my_elems[my_elems_count-1]);
+    for (; my_elems_count > 0; my_elems_count--)
+        MPI_Free_mem(my_elems[my_elems_count - 1]);
 
     MPI_Finalize();
     return 0;
diff --git a/teshsuite/smpi/mpich3-test/rma/lock_contention_dt.c b/teshsuite/smpi/mpich3-test/rma/lock_contention_dt.c
new file mode 100644 (file)
index 0000000..394f799
--- /dev/null
@@ -0,0 +1,99 @@
+/* -*- Mode: C; c-basic-offset:4 ; indent-tabs-mode:nil ; -*- */
+/*
+ *
+ *  (C) 2015 by Argonne National Laboratory.
+ *      See COPYRIGHT in top-level directory.
+ */
+#include "mpi.h"
+#include <stdio.h>
+#include <stdlib.h>
+#include "mpitest.h"
+
+/*
+static char MTEST_Descrip[] = "Test lock contention while streaming ACC-like operations";
+*/
+
+int main(int argc, char *argv[])
+{
+    int errs = 0;
+    int rank, size;
+    int target = 1;
+    int minsize = 2, count;
+    MPI_Comm comm;
+    MPI_Win win;
+    MPI_Aint lb, extent;
+    MTestDatatype sendtype, recvtype;
+
+    MTest_Init(&argc, &argv);
+
+    while (MTestGetIntracommGeneral(&comm, minsize, 1)) {
+        if (comm == MPI_COMM_NULL)
+            continue;
+
+        MPI_Comm_rank(comm, &rank);
+        MPI_Comm_size(comm, &size);
+
+        MTEST_DATATYPE_FOR_EACH_COUNT(count) {
+            while (MTestGetDatatypes(&sendtype, &recvtype, count)) {
+                recvtype.printErrors = 1;
+                recvtype.InitBuf(&recvtype);
+                MPI_Type_get_extent(recvtype.datatype, &lb, &extent);
+
+                MPI_Win_create(recvtype.buf, lb + recvtype.count * extent,
+                               (int) extent, MPI_INFO_NULL, comm, &win);
+                if (rank != target) {
+                    sendtype.InitBuf(&sendtype);
+
+                    MPI_Win_lock(MPI_LOCK_EXCLUSIVE, target, 0, win);
+                    MPI_Accumulate(sendtype.buf, sendtype.count,
+                                   sendtype.datatype, target, 0,
+                                   recvtype.count, recvtype.datatype, MPI_REPLACE, win);
+                    MPI_Win_unlock(target, win);
+                    MPI_Barrier(comm);
+
+                    char *resbuf = (char *) calloc(lb + extent * recvtype.count, sizeof(char));
+
+                    /*wait for the destination to finish checking and reinitializing the buffer */
+                    MPI_Barrier(comm);
+
+                    MPI_Win_lock(MPI_LOCK_EXCLUSIVE, target, 0, win);
+                    MPI_Get_accumulate(sendtype.buf, sendtype.count,
+                                       sendtype.datatype, resbuf, recvtype.count, recvtype.datatype,
+                                       target, 0, recvtype.count, recvtype.datatype, MPI_REPLACE,
+                                       win);
+                    MPI_Win_unlock(target, win);
+                    MPI_Barrier(comm);
+                    free(resbuf);
+                }
+                else {  /* Target checks the result */
+                    int err;
+                    MPI_Barrier(comm);
+                    MPI_Win_lock(MPI_LOCK_EXCLUSIVE, rank, 0, win);
+                    err = MTestCheckRecv(0, &recvtype);
+                    if (err)
+                        errs++;
+                    recvtype.InitBuf(&recvtype);
+                    MPI_Win_unlock(rank, win);
+
+                    /*signal the source that checking and reinitialization is done */
+                    MPI_Barrier(comm);
+
+                    MPI_Barrier(comm);
+                    MPI_Win_lock(MPI_LOCK_EXCLUSIVE, rank, 0, win);
+                    err = MTestCheckRecv(0, &recvtype);
+                    if (err)
+                        errs++;
+                    MPI_Win_unlock(rank, win);
+                }
+
+                MPI_Win_free(&win);
+                MTestFreeDatatype(&sendtype);
+                MTestFreeDatatype(&recvtype);
+            }
+        }
+        MTestFreeComm(&comm);
+    }
+    MTest_Finalize(errs);
+    MPI_Finalize();
+    return 0;
+}
diff --git a/teshsuite/smpi/mpich3-test/rma/lock_dt.c b/teshsuite/smpi/mpich3-test/rma/lock_dt.c
new file mode 100644 (file)
index 0000000..f98d4f4
--- /dev/null
@@ -0,0 +1,101 @@
+/* -*- Mode: C; c-basic-offset:4 ; indent-tabs-mode:nil ; -*- */
+/*
+ *
+ *  (C) 2015 by Argonne National Laboratory.
+ *      See COPYRIGHT in top-level directory.
+ */
+#include "mpi.h"
+#include <stdio.h>
+#include <stdlib.h>
+#include "mpitest.h"
+
+/*
+static char MTEST_Descrip[] = "Test for streaming ACC-like operations with lock";
+*/
+
+int main(int argc, char *argv[])
+{
+    int errs = 0;
+    int rank, size, source, dest;
+    int minsize = 2, count;
+    MPI_Comm comm;
+    MPI_Win win;
+    MPI_Aint lb, extent;
+    MTestDatatype sendtype, recvtype;
+
+    MTest_Init(&argc, &argv);
+
+    while (MTestGetIntracommGeneral(&comm, minsize, 1)) {
+        if (comm == MPI_COMM_NULL)
+            continue;
+
+        MPI_Comm_rank(comm, &rank);
+        MPI_Comm_size(comm, &size);
+        source = 0;
+        dest = size - 1;
+
+        MTEST_DATATYPE_FOR_EACH_COUNT(count) {
+            while (MTestGetDatatypes(&sendtype, &recvtype, count)) {
+                recvtype.printErrors = 1;
+                /* Make sure that everyone has a recv buffer */
+                recvtype.InitBuf(&recvtype);
+                MPI_Type_get_extent(recvtype.datatype, &lb, &extent);
+
+                MPI_Win_create(recvtype.buf, lb + recvtype.count * extent,
+                               (int) extent, MPI_INFO_NULL, comm, &win);
+                if (rank == source) {
+                    sendtype.InitBuf(&sendtype);
+
+                    MPI_Win_lock(MPI_LOCK_SHARED, dest, 0, win);
+                    MPI_Accumulate(sendtype.buf, sendtype.count,
+                                   sendtype.datatype, dest, 0,
+                                   recvtype.count, recvtype.datatype, MPI_REPLACE, win);
+                    MPI_Win_unlock(dest, win);
+                    MPI_Barrier(comm);
+
+                    char *resbuf = (char *) calloc(lb + extent * recvtype.count, sizeof(char));
+
+                    /*wait for the destination to finish checking and reinitializing the buffer */
+                    MPI_Barrier(comm);
+
+                    MPI_Win_lock(MPI_LOCK_SHARED, dest, 0, win);
+                    MPI_Get_accumulate(sendtype.buf, sendtype.count,
+                                       sendtype.datatype, resbuf, recvtype.count, recvtype.datatype,
+                                       dest, 0, recvtype.count, recvtype.datatype, MPI_REPLACE,
+                                       win);
+                    MPI_Win_unlock(dest, win);
+                    MPI_Barrier(comm);
+                    free(resbuf);
+                }
+                else if (rank == dest) {
+                    int err;
+                    MPI_Barrier(comm);
+                    MPI_Win_lock(MPI_LOCK_SHARED, dest, 0, win);
+                    err = MTestCheckRecv(0, &recvtype);
+                    if (err)
+                        errs++;
+                    recvtype.InitBuf(&recvtype);
+                    MPI_Win_unlock(dest, win);
+
+                    /*signal the source that checking and reinitialization is done */
+                    MPI_Barrier(comm);
+
+                    MPI_Barrier(comm);
+                    MPI_Win_lock(MPI_LOCK_SHARED, dest, 0, win);
+                    err = MTestCheckRecv(0, &recvtype);
+                    if (err)
+                        errs++;
+                    MPI_Win_unlock(dest, win);
+                }
+
+                MPI_Win_free(&win);
+                MTestFreeDatatype(&sendtype);
+                MTestFreeDatatype(&recvtype);
+            }
+        }
+        MTestFreeComm(&comm);
+    }
+    MTest_Finalize(errs);
+    MPI_Finalize();
+    return 0;
+}
diff --git a/teshsuite/smpi/mpich3-test/rma/lock_dt_flush.c b/teshsuite/smpi/mpich3-test/rma/lock_dt_flush.c
new file mode 100644 (file)
index 0000000..336da04
--- /dev/null
@@ -0,0 +1,110 @@
+/* -*- Mode: C; c-basic-offset:4 ; indent-tabs-mode:nil ; -*- */
+/*
+ *
+ *  (C) 2015 by Argonne National Laboratory.
+ *      See COPYRIGHT in top-level directory.
+ */
+#include "mpi.h"
+#include <stdio.h>
+#include <stdlib.h>
+#include "mpitest.h"
+
+/*
+static char MTEST_Descrip[] = "Test for streaming ACC-like operations with lock+flush";
+*/
+
+int main(int argc, char *argv[])
+{
+    int errs = 0;
+    int err = 0;
+    int rank, size, source, dest;
+    int minsize = 2, count;
+    MPI_Comm comm;
+    MPI_Win win;
+    MPI_Aint lb, extent;
+    MTestDatatype sendtype, recvtype;
+
+    MTest_Init(&argc, &argv);
+
+    while (MTestGetIntracommGeneral(&comm, minsize, 1)) {
+        if (comm == MPI_COMM_NULL)
+            continue;
+        MPI_Comm_rank(comm, &rank);
+        MPI_Comm_size(comm, &size);
+        source = 0;
+        dest = size - 1;
+
+        MTEST_DATATYPE_FOR_EACH_COUNT(count) {
+            while (MTestGetDatatypes(&sendtype, &recvtype, count)) {
+                recvtype.printErrors = 1;
+                recvtype.InitBuf(&recvtype);
+                MPI_Type_get_extent(recvtype.datatype, &lb, &extent);
+
+                MPI_Win_create(recvtype.buf, lb + recvtype.count * extent,
+                               (int) extent, MPI_INFO_NULL, comm, &win);
+                if (rank == source) {
+                    sendtype.InitBuf(&sendtype);
+
+                    MPI_Win_lock(MPI_LOCK_SHARED, dest, 0, win);
+                    MPI_Accumulate(sendtype.buf, sendtype.count,
+                                   sendtype.datatype, dest, 0,
+                                   recvtype.count, recvtype.datatype, MPI_REPLACE, win);
+                    MPI_Win_flush(dest, win);
+                    /*signal to dest that the ops are flushed so that it starts checking the result */
+                    MPI_Barrier(comm);
+                    /*make sure dest finishes checking the result before issuing unlock */
+                    MPI_Barrier(comm);
+                    MPI_Win_unlock(dest, win);
+
+                    char *resbuf = (char *) calloc(lb + extent * recvtype.count, sizeof(char));
+
+                    /*wait for the destination to finish checking  and reinitializing the buffer */
+                    MPI_Barrier(comm);
+
+                    MPI_Win_lock(MPI_LOCK_SHARED, dest, 0, win);
+                    MPI_Get_accumulate(sendtype.buf, sendtype.count,
+                                       sendtype.datatype, resbuf, recvtype.count, recvtype.datatype,
+                                       dest, 0, recvtype.count, recvtype.datatype, MPI_REPLACE,
+                                       win);
+                    MPI_Win_flush(dest, win);
+                    /*signal to dest that the ops are flushed so that it starts checking the result */
+                    MPI_Barrier(comm);
+                    /*make sure dest finishes checking the result before issuing unlock */
+                    MPI_Barrier(comm);
+                    MPI_Win_unlock(dest, win);
+                    free(resbuf);
+                }
+                else if (rank == dest) {
+
+                    MPI_Barrier(comm);
+                    MPI_Win_lock(MPI_LOCK_SHARED, dest, 0, win);
+                    err = MTestCheckRecv(0, &recvtype);
+                    if (err)
+                        errs++;
+                    recvtype.InitBuf(&recvtype);
+                    MPI_Barrier(comm);
+                    MPI_Win_unlock(dest, win);
+
+                    /*signal the source that checking and reinitialization is done */
+                    MPI_Barrier(comm);
+
+                    MPI_Barrier(comm);
+                    MPI_Win_lock(MPI_LOCK_SHARED, dest, 0, win);
+                    err = MTestCheckRecv(0, &recvtype);
+                    if (err)
+                        errs++;
+                    MPI_Barrier(comm);
+                    MPI_Win_unlock(dest, win);
+                }
+
+                MPI_Win_free(&win);
+                MTestFreeDatatype(&sendtype);
+                MTestFreeDatatype(&recvtype);
+            }
+        }
+        MTestFreeComm(&comm);
+    }
+    MTest_Finalize(errs);
+    MPI_Finalize();
+    return 0;
+}
diff --git a/teshsuite/smpi/mpich3-test/rma/lock_dt_flushlocal.c b/teshsuite/smpi/mpich3-test/rma/lock_dt_flushlocal.c
new file mode 100644 (file)
index 0000000..fe6db8a
--- /dev/null
@@ -0,0 +1,111 @@
+/* -*- Mode: C; c-basic-offset:4 ; indent-tabs-mode:nil ; -*- */
+/*
+ *
+ *  (C) 2015 by Argonne National Laboratory.
+ *      See COPYRIGHT in top-level directory.
+ */
+#include "mpi.h"
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+#include "mpitest.h"
+
+/*
+static char MTEST_Descrip[] = "Test for streaming ACC-like operations with lock+flush_local";
+*/
+
+int main(int argc, char *argv[])
+{
+    int errs = 0;
+    int err = 0;
+    int rank, size, source, dest;
+    int minsize = 2, count;
+    MPI_Comm comm;
+    MPI_Win win;
+    MPI_Aint lb, extent;
+    MTestDatatype sendtype, recvtype;
+
+    MTest_Init(&argc, &argv);
+
+    while (MTestGetIntracommGeneral(&comm, minsize, 1)) {
+        if (comm == MPI_COMM_NULL)
+            continue;
+        /* Determine the sender and receiver */
+        MPI_Comm_rank(comm, &rank);
+        MPI_Comm_size(comm, &size);
+        source = 0;
+        dest = size - 1;
+
+        MTEST_DATATYPE_FOR_EACH_COUNT(count) {
+            while (MTestGetDatatypes(&sendtype, &recvtype, count)) {
+                recvtype.printErrors = 1;
+                recvtype.InitBuf(&recvtype);
+                MPI_Type_get_extent(recvtype.datatype, &lb, &extent);
+
+                MPI_Win_create(recvtype.buf, lb + recvtype.count * extent,
+                               (int) extent, MPI_INFO_NULL, comm, &win);
+                if (rank == source) {
+                    MPI_Aint slb, sextent;
+                    MPI_Type_get_extent(sendtype.datatype, &slb, &sextent);
+                    sendtype.InitBuf(&sendtype);
+
+                    MPI_Win_lock(MPI_LOCK_SHARED, dest, 0, win);
+                    MPI_Accumulate(sendtype.buf, sendtype.count,
+                                   sendtype.datatype, dest, 0,
+                                   recvtype.count, recvtype.datatype, MPI_REPLACE, win);
+                    MPI_Win_flush_local(dest, win);
+                    /* reset the send buffer to test local completion */
+                    memset(sendtype.buf, 0, slb + sextent * sendtype.count);
+                    MPI_Win_unlock(dest, win);
+                    MPI_Barrier(comm);
+
+                    sendtype.InitBuf(&sendtype);
+                    char *resbuf = (char *) calloc(lb + extent * recvtype.count, sizeof(char));
+
+                    /*wait for the destination to finish checking and reinitializing the buffer */
+                    MPI_Barrier(comm);
+
+                    MPI_Win_lock(MPI_LOCK_SHARED, dest, 0, win);
+                    MPI_Get_accumulate(sendtype.buf, sendtype.count,
+                                       sendtype.datatype, resbuf, recvtype.count, recvtype.datatype,
+                                       dest, 0, recvtype.count, recvtype.datatype, MPI_REPLACE,
+                                       win);
+                    MPI_Win_flush_local(dest, win);
+                    /* reset the send buffer to test local completion */
+                    memset(sendtype.buf, 0, slb + sextent * sendtype.count);
+                    MPI_Win_unlock(dest, win);
+                    MPI_Barrier(comm);
+                    free(resbuf);
+                }
+                else if (rank == dest) {
+
+                    MPI_Barrier(comm);
+                    MPI_Win_lock(MPI_LOCK_SHARED, dest, 0, win);
+                    err = MTestCheckRecv(0, &recvtype);
+                    if (err)
+                        errs++;
+                    recvtype.InitBuf(&recvtype);
+                    MPI_Win_unlock(dest, win);
+
+                    /*signal the source that checking and reinitialization is done */
+                    MPI_Barrier(comm);
+
+                    MPI_Barrier(comm);
+                    MPI_Win_lock(MPI_LOCK_SHARED, dest, 0, win);
+                    err = MTestCheckRecv(0, &recvtype);
+                    if (err)
+                        errs++;
+                    MPI_Win_unlock(dest, win);
+                }
+
+                MPI_Win_free(&win);
+                MTestFreeDatatype(&sendtype);
+                MTestFreeDatatype(&recvtype);
+            }
+        }
+        MTestFreeComm(&comm);
+    }
+    MTest_Finalize(errs);
+    MPI_Finalize();
+    return 0;
+}
diff --git a/teshsuite/smpi/mpich3-test/rma/lock_nested.c b/teshsuite/smpi/mpich3-test/rma/lock_nested.c
new file mode 100644 (file)
index 0000000..58d03fa
--- /dev/null
@@ -0,0 +1,52 @@
+/* -*- Mode: C; c-basic-offset:4 ; -*- */
+/*
+ * (C) 2016 by Argonne National Laboratory.
+ *     See COPYRIGHT in top-level directory.
+ */
+
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+#include <mpi.h>
+
+#define BUFSIZE 4
+
+/* This program tests nested lock. Process 0 locks the other processes
+ * one by one, then unlock each of them.*/
+
+int main(int argc, char *argv[])
+{
+    int rank = 0, nprocs = 0, dst = 0;
+    int winbuf[BUFSIZE];
+    MPI_Win win = MPI_WIN_NULL;
+
+    MPI_Init(&argc, &argv);
+    MPI_Comm_rank(MPI_COMM_WORLD, &rank);
+    MPI_Comm_size(MPI_COMM_WORLD, &nprocs);
+
+    memset(winbuf, 0, sizeof(int) * BUFSIZE);
+    MPI_Win_create(winbuf, sizeof(int) * BUFSIZE, sizeof(int), MPI_INFO_NULL, MPI_COMM_WORLD, &win);
+
+    if (rank == 0) {
+        /* lock each process */
+        for (dst = 0; dst < nprocs; dst++) {
+            MPI_Win_lock(MPI_LOCK_SHARED, dst, 0, win);
+        }
+
+        /* unlock each process */
+        for (dst = nprocs - 1; dst >= 0; dst--) {
+            MPI_Win_unlock(dst, win);
+        }
+    }
+
+    MPI_Barrier(MPI_COMM_WORLD);
+    MPI_Win_free(&win);
+
+    if (rank == 0) {
+        fprintf(stdout, " No Errors\n");
+        fflush(stdout);
+    }
+
+    MPI_Finalize();
+    return 0;
+}
diff --git a/teshsuite/smpi/mpich3-test/rma/lockall_dt.c b/teshsuite/smpi/mpich3-test/rma/lockall_dt.c
new file mode 100644 (file)
index 0000000..bdb7e97
--- /dev/null
@@ -0,0 +1,107 @@
+/* -*- Mode: C; c-basic-offset:4 ; indent-tabs-mode:nil ; -*- */
+/*
+ *
+ *  (C) 2015 by Argonne National Laboratory.
+ *      See COPYRIGHT in top-level directory.
+ */
+#include "mpi.h"
+#include <stdio.h>
+#include <stdlib.h>
+#include "mpitest.h"
+
+/*
+static char MTEST_Descrip[] = "Test for streaming ACC-like operations with lock_all";
+*/
+
+int main(int argc, char *argv[])
+{
+    int errs = 0;
+    int rank, size;
+    int minsize = 2, count;
+    MPI_Comm comm;
+    MPI_Win win;
+    MPI_Aint lb, extent;
+    MTestDatatype sendtype, recvtype;
+
+    MTest_Init(&argc, &argv);
+
+    while (MTestGetIntracommGeneral(&comm, minsize, 1)) {
+        if (comm == MPI_COMM_NULL)
+            continue;
+
+        MPI_Comm_rank(comm, &rank);
+        MPI_Comm_size(comm, &size);
+        int source = 0;
+
+        MTEST_DATATYPE_FOR_EACH_COUNT(count) {
+            while (MTestGetDatatypes(&sendtype, &recvtype, count)) {
+                recvtype.printErrors = 1;
+                recvtype.InitBuf(&recvtype);
+                MPI_Type_get_extent(recvtype.datatype, &lb, &extent);
+
+                MPI_Win_create(recvtype.buf, lb + recvtype.count * extent,
+                               (int) extent, MPI_INFO_NULL, comm, &win);
+                if (rank == source) {
+                    int dest;
+                    sendtype.InitBuf(&sendtype);
+
+                    MPI_Win_lock_all(0, win);
+                    for (dest = 0; dest < size; dest++)
+                        if (dest != source) {
+                            MPI_Accumulate(sendtype.buf, sendtype.count,
+                                           sendtype.datatype, dest, 0,
+                                           recvtype.count, recvtype.datatype, MPI_REPLACE, win);
+                        }
+                    MPI_Win_unlock_all(win);
+                    MPI_Barrier(comm);
+
+                    char *resbuf = (char *) calloc(lb + extent * recvtype.count, sizeof(char));
+
+                    /*wait for the destinations to finish checking and reinitializing the buffers */
+                    MPI_Barrier(comm);
+
+                    MPI_Win_lock_all(0, win);
+                    for (dest = 0; dest < size; dest++)
+                        if (dest != source) {
+                            MPI_Get_accumulate(sendtype.buf, sendtype.count,
+                                               sendtype.datatype, resbuf, recvtype.count,
+                                               recvtype.datatype, dest, 0, recvtype.count,
+                                               recvtype.datatype, MPI_REPLACE, win);
+
+                        }
+                    MPI_Win_unlock_all(win);
+                    MPI_Barrier(comm);
+                    free(resbuf);
+                }
+                else {
+                    int err;
+                    MPI_Barrier(comm);
+                    MPI_Win_lock(MPI_LOCK_SHARED, rank, 0, win);
+                    err = MTestCheckRecv(0, &recvtype);
+                    if (err)
+                        errs++;
+                    recvtype.InitBuf(&recvtype);
+                    MPI_Win_unlock(rank, win);
+
+                    /*signal the source that checking and reinitialization is done */
+                    MPI_Barrier(comm);
+
+                    MPI_Barrier(comm);
+                    MPI_Win_lock(MPI_LOCK_SHARED, rank, 0, win);
+                    err = MTestCheckRecv(0, &recvtype);
+                    if (err)
+                        errs++;
+                    MPI_Win_unlock(rank, win);
+                }
+
+                MPI_Win_free(&win);
+                MTestFreeDatatype(&sendtype);
+                MTestFreeDatatype(&recvtype);
+            }
+        }
+        MTestFreeComm(&comm);
+    }
+    MTest_Finalize(errs);
+    MPI_Finalize();
+    return 0;
+}
diff --git a/teshsuite/smpi/mpich3-test/rma/lockall_dt_flush.c b/teshsuite/smpi/mpich3-test/rma/lockall_dt_flush.c
new file mode 100644 (file)
index 0000000..f6ddde3
--- /dev/null
@@ -0,0 +1,117 @@
+/* -*- Mode: C; c-basic-offset:4 ; indent-tabs-mode:nil ; -*- */
+/*
+ *
+ *  (C) 2015 by Argonne National Laboratory.
+ *      See COPYRIGHT in top-level directory.
+ */
+#include "mpi.h"
+#include <stdio.h>
+#include <stdlib.h>
+#include "mpitest.h"
+
+/*
+static char MTEST_Descrip[] = "Test for streaming ACC-like operations with lock_all+flush";
+*/
+
+int main(int argc, char *argv[])
+{
+    int errs = 0;
+    int rank, size;
+    int minsize = 2, count;
+    MPI_Comm comm;
+    MPI_Win win;
+    MPI_Aint lb, extent;
+    MTestDatatype sendtype, recvtype;
+
+    MTest_Init(&argc, &argv);
+
+    while (MTestGetIntracommGeneral(&comm, minsize, 1)) {
+        if (comm == MPI_COMM_NULL)
+            continue;
+
+        MPI_Comm_rank(comm, &rank);
+        MPI_Comm_size(comm, &size);
+        int source = 0;
+
+        MTEST_DATATYPE_FOR_EACH_COUNT(count) {
+            while (MTestGetDatatypes(&sendtype, &recvtype, count)) {
+                recvtype.printErrors = 1;
+                recvtype.InitBuf(&recvtype);
+                MPI_Type_get_extent(recvtype.datatype, &lb, &extent);
+
+                MPI_Win_create(recvtype.buf, lb + recvtype.count * extent,
+                               (int) extent, MPI_INFO_NULL, comm, &win);
+                if (rank == source) {
+                    int dest;
+                    sendtype.InitBuf(&sendtype);
+
+                    MPI_Win_lock_all(0, win);
+
+                    for (dest = 0; dest < size; dest++)
+                        if (dest != source) {
+                            MPI_Accumulate(sendtype.buf, sendtype.count,
+                                           sendtype.datatype, dest, 0,
+                                           recvtype.count, recvtype.datatype, MPI_REPLACE, win);
+                            MPI_Win_flush(dest, win);
+                        }
+                    /*signal to dest that the ops are flushed so that it starts checking the result */
+                    MPI_Barrier(comm);
+                    /*make sure dest finishes checking the result before issuing unlock */
+                    MPI_Barrier(comm);
+                    MPI_Win_unlock_all(win);
+
+                    char *resbuf = (char *) calloc(lb + extent * recvtype.count, sizeof(char));
+
+                    /*wait for the destinations to finish checking and reinitializing the buffers */
+                    MPI_Barrier(comm);
+
+                    MPI_Win_lock_all(0, win);
+                    for (dest = 0; dest < size; dest++)
+                        if (dest != source) {
+                            MPI_Get_accumulate(sendtype.buf, sendtype.count,
+                                               sendtype.datatype, resbuf, recvtype.count,
+                                               recvtype.datatype, dest, 0, recvtype.count,
+                                               recvtype.datatype, MPI_REPLACE, win);
+                            MPI_Win_flush(dest, win);
+                        }
+                    /*signal to dest that the ops are flushed so that it starts checking the result */
+                    MPI_Barrier(comm);
+                    /*make sure dest finishes checking the result before issuing unlock */
+                    MPI_Barrier(comm);
+                    MPI_Win_unlock_all(win);
+                    free(resbuf);
+                }
+                else {
+                    int err;
+                    MPI_Barrier(comm);
+                    MPI_Win_lock(MPI_LOCK_SHARED, rank, 0, win);
+                    err = MTestCheckRecv(0, &recvtype);
+                    if (err)
+                        errs++;
+                    recvtype.InitBuf(&recvtype);
+                    MPI_Barrier(comm);
+                    MPI_Win_unlock(rank, win);
+
+                    /*signal the source that checking and reinitialization is done */
+                    MPI_Barrier(comm);
+
+                    MPI_Barrier(comm);
+                    MPI_Win_lock(MPI_LOCK_SHARED, rank, 0, win);
+                    err = MTestCheckRecv(0, &recvtype);
+                    if (err)
+                        errs++;
+                    MPI_Barrier(comm);
+                    MPI_Win_unlock(rank, win);
+                }
+
+                MPI_Win_free(&win);
+                MTestFreeDatatype(&sendtype);
+                MTestFreeDatatype(&recvtype);
+            }
+        }
+        MTestFreeComm(&comm);
+    }
+    MTest_Finalize(errs);
+    MPI_Finalize();
+    return 0;
+}
diff --git a/teshsuite/smpi/mpich3-test/rma/lockall_dt_flushall.c b/teshsuite/smpi/mpich3-test/rma/lockall_dt_flushall.c
new file mode 100644 (file)
index 0000000..9fdf416
--- /dev/null
@@ -0,0 +1,118 @@
+/* -*- Mode: C; c-basic-offset:4 ; indent-tabs-mode:nil ; -*- */
+/*
+ *
+ *  (C) 2015 by Argonne National Laboratory.
+ *      See COPYRIGHT in top-level directory.
+ */
+#include "mpi.h"
+#include <stdio.h>
+#include <stdlib.h>
+#include "mpitest.h"
+
+/*
+static char MTEST_Descrip[] = "Test for streaming ACC-like operations with lock_all+flush_all";
+*/
+
+int main(int argc, char *argv[])
+{
+    int errs = 0;
+    int rank, size;
+    int minsize = 2, count;
+    MPI_Comm comm;
+    MPI_Win win;
+    MPI_Aint lb, extent;
+    MTestDatatype sendtype, recvtype;
+
+    MTest_Init(&argc, &argv);
+
+    while (MTestGetIntracommGeneral(&comm, minsize, 1)) {
+        if (comm == MPI_COMM_NULL)
+            continue;
+
+        MPI_Comm_rank(comm, &rank);
+        MPI_Comm_size(comm, &size);
+        int source = 0;
+
+        MTEST_DATATYPE_FOR_EACH_COUNT(count) {
+            while (MTestGetDatatypes(&sendtype, &recvtype, count)) {
+                recvtype.printErrors = 1;
+                recvtype.InitBuf(&recvtype);
+                MPI_Type_get_extent(recvtype.datatype, &lb, &extent);
+
+                MPI_Win_create(recvtype.buf, lb + recvtype.count * extent,
+                               (int) extent, MPI_INFO_NULL, comm, &win);
+                if (rank == source) {
+                    int dest;
+                    sendtype.InitBuf(&sendtype);
+
+                    MPI_Win_lock_all(0, win);
+                    for (dest = 0; dest < size; dest++)
+                        if (dest != source) {
+                            MPI_Accumulate(sendtype.buf, sendtype.count,
+                                           sendtype.datatype, dest, 0,
+                                           recvtype.count, recvtype.datatype, MPI_REPLACE, win);
+                        }
+
+                    MPI_Win_flush_all(win);
+                    /*signal to dest that the ops are flushed so that it starts checking the result */
+                    MPI_Barrier(comm);
+                    /*make sure dest finishes checking the result before issuing unlock */
+                    MPI_Barrier(comm);
+                    MPI_Win_unlock_all(win);
+
+                    char *resbuf = (char *) calloc(lb + extent * recvtype.count, sizeof(char));
+
+                    /*wait for the destination to finish checking and reinitializing the buffer */
+                    MPI_Barrier(comm);
+
+                    MPI_Win_lock_all(0, win);
+                    for (dest = 0; dest < size; dest++)
+                        if (dest != source) {
+                            MPI_Get_accumulate(sendtype.buf, sendtype.count,
+                                               sendtype.datatype, resbuf, recvtype.count,
+                                               recvtype.datatype, dest, 0, recvtype.count,
+                                               recvtype.datatype, MPI_REPLACE, win);
+
+                        }
+                    MPI_Win_flush_all(win);
+                    /*signal to dest that the ops are flushed so that it starts checking the result */
+                    MPI_Barrier(comm);
+                    /*make sure dest finishes checking the result before issuing unlock */
+                    MPI_Barrier(comm);
+                    MPI_Win_unlock_all(win);
+                    free(resbuf);
+                }
+                else {
+                    int err;
+                    MPI_Barrier(comm);
+                    MPI_Win_lock(MPI_LOCK_SHARED, rank, 0, win);
+                    err = MTestCheckRecv(0, &recvtype);
+                    if (err)
+                        errs++;
+                    recvtype.InitBuf(&recvtype);
+                    MPI_Barrier(comm);
+                    MPI_Win_unlock(rank, win);
+
+                    /*signal the source that checking and reinitialization is done */
+                    MPI_Barrier(comm);
+
+                    MPI_Barrier(comm);
+                    MPI_Win_lock(MPI_LOCK_SHARED, rank, 0, win);
+                    err = MTestCheckRecv(0, &recvtype);
+                    if (err)
+                        errs++;
+                    MPI_Barrier(comm);
+                    MPI_Win_unlock(rank, win);
+                }
+
+                MPI_Win_free(&win);
+                MTestFreeDatatype(&sendtype);
+                MTestFreeDatatype(&recvtype);
+            }
+        }
+        MTestFreeComm(&comm);
+    }
+    MTest_Finalize(errs);
+    MPI_Finalize();
+    return 0;
+}
diff --git a/teshsuite/smpi/mpich3-test/rma/lockall_dt_flushlocal.c b/teshsuite/smpi/mpich3-test/rma/lockall_dt_flushlocal.c
new file mode 100644 (file)
index 0000000..a3726b6
--- /dev/null
@@ -0,0 +1,117 @@
+/* -*- Mode: C; c-basic-offset:4 ; indent-tabs-mode:nil ; -*- */
+/*
+ *
+ *  (C) 2015 by Argonne National Laboratory.
+ *      See COPYRIGHT in top-level directory.
+ */
+#include "mpi.h"
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+#include "mpitest.h"
+
+/*
+static char MTEST_Descrip[] = "Test for streaming ACC-like operations with lock_all+flush_local";
+*/
+
+int main(int argc, char *argv[])
+{
+    int errs = 0;
+    int rank, size;
+    int minsize = 2, count;
+    MPI_Comm comm;
+    MPI_Win win;
+    MPI_Aint lb, extent;
+    MTestDatatype sendtype, recvtype;
+
+    MTest_Init(&argc, &argv);
+
+    while (MTestGetIntracommGeneral(&comm, minsize, 1)) {
+        if (comm == MPI_COMM_NULL)
+            continue;
+
+        MPI_Comm_rank(comm, &rank);
+        MPI_Comm_size(comm, &size);
+        int source = 0;
+
+        MTEST_DATATYPE_FOR_EACH_COUNT(count) {
+            while (MTestGetDatatypes(&sendtype, &recvtype, count)) {
+                recvtype.printErrors = 1;
+                recvtype.InitBuf(&recvtype);
+                MPI_Type_get_extent(recvtype.datatype, &lb, &extent);
+
+                MPI_Win_create(recvtype.buf, lb + recvtype.count * extent,
+                               (int) extent, MPI_INFO_NULL, comm, &win);
+                if (rank == source) {
+                    int dest;
+                    MPI_Aint slb, sextent;
+                    MPI_Type_get_extent(sendtype.datatype, &slb, &sextent);
+                    sendtype.InitBuf(&sendtype);
+
+                    MPI_Win_lock_all(0, win);
+
+                    for (dest = 0; dest < size; dest++)
+                        if (dest != source) {
+                            MPI_Accumulate(sendtype.buf, sendtype.count,
+                                           sendtype.datatype, dest, 0,
+                                           recvtype.count, recvtype.datatype, MPI_REPLACE, win);
+                            MPI_Win_flush_local(dest, win);
+                        }
+                    /* reset the send buffer to test local completion */
+                    memset(sendtype.buf, 0, slb + sextent * sendtype.count);
+                    MPI_Win_unlock_all(win);
+                    MPI_Barrier(comm);
+
+                    sendtype.InitBuf(&sendtype);
+                    char *resbuf = (char *) calloc(lb + extent * recvtype.count, sizeof(char));
+
+                    /*wait for the destinations to finish checking and reinitializing the buffers */
+                    MPI_Barrier(comm);
+
+                    MPI_Win_lock_all(0, win);
+                    for (dest = 0; dest < size; dest++)
+                        if (dest != source) {
+                            MPI_Get_accumulate(sendtype.buf, sendtype.count,
+                                               sendtype.datatype, resbuf, recvtype.count,
+                                               recvtype.datatype, dest, 0, recvtype.count,
+                                               recvtype.datatype, MPI_REPLACE, win);
+                            MPI_Win_flush_local(dest, win);
+                        }
+                    /* reset the send buffer to test local completion */
+                    memset(sendtype.buf, 0, slb + sextent * sendtype.count);
+                    MPI_Win_unlock_all(win);
+                    MPI_Barrier(comm);
+                    free(resbuf);
+                }
+                else {
+                    int err;
+                    MPI_Barrier(comm);
+                    MPI_Win_lock(MPI_LOCK_SHARED, rank, 0, win);
+                    err = MTestCheckRecv(0, &recvtype);
+                    if (err)
+                        errs++;
+                    recvtype.InitBuf(&recvtype);
+                    MPI_Win_unlock(rank, win);
+
+                    /*signal the source that checking and reinitialization is done */
+                    MPI_Barrier(comm);
+
+                    MPI_Barrier(comm);
+                    MPI_Win_lock(MPI_LOCK_SHARED, rank, 0, win);
+                    err = MTestCheckRecv(0, &recvtype);
+                    if (err)
+                        errs++;
+                    MPI_Win_unlock(rank, win);
+                }
+
+                MPI_Win_free(&win);
+                MTestFreeDatatype(&sendtype);
+                MTestFreeDatatype(&recvtype);
+            }
+        }
+        MTestFreeComm(&comm);
+    }
+    MTest_Finalize(errs);
+    MPI_Finalize();
+    return 0;
+}
diff --git a/teshsuite/smpi/mpich3-test/rma/lockall_dt_flushlocalall.c b/teshsuite/smpi/mpich3-test/rma/lockall_dt_flushlocalall.c
new file mode 100644 (file)
index 0000000..9d662fa
--- /dev/null
@@ -0,0 +1,118 @@
+/* -*- Mode: C; c-basic-offset:4 ; indent-tabs-mode:nil ; -*- */
+/*
+ *
+ *  (C) 2015 by Argonne National Laboratory.
+ *      See COPYRIGHT in top-level directory.
+ */
+#include "mpi.h"
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+#include "mpitest.h"
+
+/*
+static char MTEST_Descrip[] = "Test for streaming ACC-like operations with lock_all+flush_local_all";
+*/
+
+int main(int argc, char *argv[])
+{
+    int errs = 0;
+    int rank, size;
+    int minsize = 2, count;
+    MPI_Comm comm;
+    MPI_Win win;
+    MPI_Aint lb, extent;
+    MTestDatatype sendtype, recvtype;
+
+    MTest_Init(&argc, &argv);
+
+    while (MTestGetIntracommGeneral(&comm, minsize, 1)) {
+        if (comm == MPI_COMM_NULL)
+            continue;
+
+        MPI_Comm_rank(comm, &rank);
+        MPI_Comm_size(comm, &size);
+        int source = 0;
+
+        MTEST_DATATYPE_FOR_EACH_COUNT(count) {
+            while (MTestGetDatatypes(&sendtype, &recvtype, count)) {
+                recvtype.printErrors = 1;
+                recvtype.InitBuf(&recvtype);
+                MPI_Type_get_extent(recvtype.datatype, &lb, &extent);
+
+                MPI_Win_create(recvtype.buf, lb + recvtype.count * extent,
+                               (int) extent, MPI_INFO_NULL, comm, &win);
+                if (rank == source) {
+                    int dest;
+                    MPI_Aint slb, sextent;
+                    MPI_Type_get_extent(sendtype.datatype, &slb, &sextent);
+                    sendtype.InitBuf(&sendtype);
+
+                    MPI_Win_lock_all(0, win);
+                    for (dest = 0; dest < size; dest++)
+                        if (dest != source) {
+                            MPI_Accumulate(sendtype.buf, sendtype.count,
+                                           sendtype.datatype, dest, 0,
+                                           recvtype.count, recvtype.datatype, MPI_REPLACE, win);
+                        }
+
+                    MPI_Win_flush_local_all(win);
+                    /* reset the send buffer to test local completion */
+                    memset(sendtype.buf, 0, slb + sextent * sendtype.count);
+                    MPI_Win_unlock_all(win);
+                    MPI_Barrier(comm);
+
+                    sendtype.InitBuf(&sendtype);
+                    char *resbuf = (char *) calloc(lb + extent * recvtype.count, sizeof(char));
+
+                    /*wait for the destination to finish checking and reinitializing the buffer */
+                    MPI_Barrier(comm);
+
+                    MPI_Win_lock_all(0, win);
+                    for (dest = 0; dest < size; dest++)
+                        if (dest != source) {
+                            MPI_Get_accumulate(sendtype.buf, sendtype.count,
+                                               sendtype.datatype, resbuf, recvtype.count,
+                                               recvtype.datatype, dest, 0, recvtype.count,
+                                               recvtype.datatype, MPI_REPLACE, win);
+
+                        }
+                    MPI_Win_flush_local_all(win);
+                    /* reset the send buffer to test local completion */
+                    memset(sendtype.buf, 0, slb + sextent * sendtype.count);
+                    MPI_Win_unlock_all(win);
+                    MPI_Barrier(comm);
+                    free(resbuf);
+                }
+                else {
+                    int err;
+                    MPI_Barrier(comm);
+                    MPI_Win_lock(MPI_LOCK_SHARED, rank, 0, win);
+                    err = MTestCheckRecv(0, &recvtype);
+                    if (err)
+                        errs++;
+                    recvtype.InitBuf(&recvtype);
+                    MPI_Win_unlock(rank, win);
+
+                    /*signal the source that checking and reinitialization is done */
+                    MPI_Barrier(comm);
+
+                    MPI_Barrier(comm);
+                    MPI_Win_lock(MPI_LOCK_SHARED, rank, 0, win);
+                    err = MTestCheckRecv(0, &recvtype);
+                    if (err)
+                        errs++;
+                    MPI_Win_unlock(rank, win);
+                }
+
+                MPI_Win_free(&win);
+                MTestFreeDatatype(&sendtype);
+                MTestFreeDatatype(&recvtype);
+            }
+        }
+        MTestFreeComm(&comm);
+    }
+    MTest_Finalize(errs);
+    MPI_Finalize();
+    return 0;
+}
index 8fbce4b..8165119 100644 (file)
@@ -25,9 +25,9 @@ int main(int argc, char *argv[])
     int errs = 0;
     int trank = 1;
 
-    MTest_Init(&argc,&argv);
-    MPI_Comm_size(MPI_COMM_WORLD,&nprocs);
-    MPI_Comm_rank(MPI_COMM_WORLD,&rank);
+    MTest_Init(&argc, &argv);
+    MPI_Comm_size(MPI_COMM_WORLD, &nprocs);
+    MPI_Comm_rank(MPI_COMM_WORLD, &rank);
 
     if (nprocs < 3) {
         fprintf(stderr, "Run this program with 3 or more processes\n");
@@ -38,54 +38,54 @@ int main(int argc, char *argv[])
 
     if (rank < 3) {
         if (rank == 0) {
-            for (i=0; i<SIZE2; i++) {
+            for (i = 0; i < SIZE2; i++) {
                 A[i] = B[i] = i;
             }
         }
         else if (rank == 2) {
-            for (i=0; i<SIZE2; i++) {
+            for (i = 0; i < SIZE2; i++) {
                 A[i] = B[i] = -1;
             }
         }
         else if (rank == 1) {
-            for (i=0; i<SIZE2; i++) {
-                B[i] = (-4)*i;
+            for (i = 0; i < SIZE2; i++) {
+                B[i] = (-4) * i;
             }
         }
 
-        MPI_Win_create(B, SIZE2*sizeof(int), sizeof(int), MPI_INFO_NULL, CommThree, &win);
+        MPI_Win_create(B, SIZE2 * sizeof(int), sizeof(int), MPI_INFO_NULL, CommThree, &win);
 
         if (rank == 0) {
-            for (i=0; i<SIZE1; i++) {
+            for (i = 0; i < SIZE1; i++) {
                 MPI_Win_lock(MPI_LOCK_EXCLUSIVE, trank, 0, win);
-                MPI_Put(A+i, 1, MPI_INT, trank, i, 1, MPI_INT, win);
+                MPI_Put(A + i, 1, MPI_INT, trank, i, 1, MPI_INT, win);
                 /*  MPI_Put(A+i, 1, MPI_INT, trank, i, 1, MPI_INT, win);
-                    MPI_Put(A+i, 1, MPI_INT, trank, i, 1, MPI_INT, win); */
+                 * MPI_Put(A+i, 1, MPI_INT, trank, i, 1, MPI_INT, win); */
                 MPI_Win_unlock(trank, win);
             }
 
             MPI_Win_free(&win);
         }
         else if (rank == 2) {
-            for (i=0; i<SIZE1; i++) {
+            for (i = 0; i < SIZE1; i++) {
                 MPI_Win_lock(MPI_LOCK_EXCLUSIVE, trank, 0, win);
-                MPI_Get(A+i, 1, MPI_INT, trank, SIZE1+i, 1, MPI_INT, win);
+                MPI_Get(A + i, 1, MPI_INT, trank, SIZE1 + i, 1, MPI_INT, win);
                 MPI_Win_unlock(trank, win);
             }
 
             MPI_Win_free(&win);
 
-            for (i=0; i<SIZE1; i++)
-                if (A[i] != (-4)*(i+SIZE1)) {
-                    printf("Get Error: A[%d] is %d, should be %d\n", i, A[i], (-4)*(i+SIZE1));
+            for (i = 0; i < SIZE1; i++)
+                if (A[i] != (-4) * (i + SIZE1)) {
+                    printf("Get Error: A[%d] is %d, should be %d\n", i, A[i], (-4) * (i + SIZE1));
                     errs++;
                 }
         }
 
-        else if (rank == 1) { /*target*/
+        else if (rank == 1) {   /*target */
             MPI_Win_free(&win);
 
-            for (i=0; i<SIZE1; i++) {
+            for (i = 0; i < SIZE1; i++) {
                 if (B[i] != i) {
                     printf("Put Error: B[%d] is %d, should be %d\n", i, B[i], i);
                     errs++;
index bae541f..9374980 100644 (file)
@@ -3,13 +3,13 @@
  *  (C) 2010 by Argonne National Laboratory.
  *      See COPYRIGHT in top-level directory.
  */
-#include "mpi.h" 
+#include "mpi.h"
 #include "stdio.h"
 #include "stdlib.h"
 #include "mpitest.h"
 
-/* 
- * Tests for lock contention, including special cases within the MPICH code 
+/*
+ * Tests for lock contention, including special cases within the MPICH code
  * (any MPI implementation should pass these tests; in the MPICH case, our
  * coverage analysis showed that the lockcontention.c test was not covering
  * all cases, and in fact, this test revealed a bug in the code).
 #define NBLOCK 10
 #define MAX_ERRS_REPORT 10
 
-/* 
+/*
  *  Each process writes data into the rmabuf on the process with target rank
  *  trank.  The final result in rmabuf are the consecutive integers starting
- *  from 0.  Each process, however, does not write a consecutive block.  
+ *  from 0.  Each process, however, does not write a consecutive block.
  *  Instead, they write these locations:
  *
  *  for i=0,...,NELM-1
  *     for j=0,...,NBLOCK-1
  *         j + NBLOCK * (rank + i * wsize)
- *  
+ *
  * The value written is the location.
  *
  * In many cases, multiple RMA operations are needed.  Where these must not
  * overlap, the above pattern is replicated at NBLOCK*NELM*wsize.
- * (NBLOCK is either 1 or NBLOCK in the code below, depending on use) 
+ * (NBLOCK is either 1 or NBLOCK in the code below, depending on use)
  */
 
 static int toterrs = 0;
 
-int testValues( int, int, int, int *, const char * );
+int testValues(int, int, int, int *, const char *);
 
-int main(int argc, char *argv[]) 
-{ 
+int main(int argc, char *argv[])
+{
     int rank, wsize, i, j, cnt;
     int *rmabuf, *localbuf, *localbuf2, *vals;
     MPI_Win win;
     int trank = 0;
     int windowsize;
 
-    MTest_Init(&argc,&argv); 
-    MPI_Comm_size(MPI_COMM_WORLD,&wsize); 
-    MPI_Comm_rank(MPI_COMM_WORLD,&rank); 
+    MTest_Init(&argc, &argv);
+    MPI_Comm_size(MPI_COMM_WORLD, &wsize);
+    MPI_Comm_rank(MPI_COMM_WORLD, &rank);
 
     if (wsize < 2) {
         fprintf(stderr, "Run this program with at least 2 processes\n");
-        MPI_Abort(MPI_COMM_WORLD,1);
+        MPI_Abort(MPI_COMM_WORLD, 1);
     }
 
-    windowsize = (2*NBLOCK + 2) * NELM * wsize;
-    rmabuf     = (int *)malloc( windowsize * sizeof(int) );
-    localbuf   = (int *)malloc( NELM * sizeof(int) );
-    localbuf2  = (int *)malloc( NELM * NBLOCK * sizeof(int) );
-    vals       = (int *)malloc( NELM*sizeof(int) );
+    windowsize = (2 * NBLOCK + 2) * NELM * wsize;
+    rmabuf = (int *) malloc(windowsize * sizeof(int));
+    localbuf = (int *) malloc(NELM * sizeof(int));
+    localbuf2 = (int *) malloc(NELM * NBLOCK * sizeof(int));
+    vals = (int *) malloc(NELM * sizeof(int));
 
-    /* 
+    /*
      * Initialize the buffers
      */
-    for (i=0; i<NELM; i++) {
-      localbuf[i] = rank + i*wsize;
+    for (i = 0; i < NELM; i++) {
+        localbuf[i] = rank + i * wsize;
     }
     cnt = 0;
-    for (i=0; i<NELM; i++) {
-       for (j=0; j<NBLOCK; j++) {
-           localbuf2[cnt++] = j + NBLOCK * (rank + i*wsize);
-       }
+    for (i = 0; i < NELM; i++) {
+        for (j = 0; j < NBLOCK; j++) {
+            localbuf2[cnt++] = j + NBLOCK * (rank + i * wsize);
+        }
     }
-    for (i=0; i<windowsize; i++) {
-      rmabuf[i] = -1;
+    for (i = 0; i < windowsize; i++) {
+        rmabuf[i] = -1;
     }
 
     /* Create the window */
-    MPI_Win_create(rmabuf, windowsize*sizeof(int), sizeof(int), MPI_INFO_NULL, 
-                  MPI_COMM_WORLD, &win); 
+    MPI_Win_create(rmabuf, windowsize * sizeof(int), sizeof(int), MPI_INFO_NULL,
+                   MPI_COMM_WORLD, &win);
 
     /* Multiple puts, with contention at trank */
-    MPI_Barrier( MPI_COMM_WORLD );
-    for (i=0; i<NELM; i++) {
-       MPI_Win_lock( MPI_LOCK_EXCLUSIVE, trank, 0, win );
-       MPI_Put( &localbuf[i], 1, MPI_INT, trank, 
-                rank + i*wsize, 1, MPI_INT, win );
-       MPI_Put( &localbuf[i], 1, MPI_INT, trank, 
-                rank + (i+NELM)*wsize, 1, MPI_INT, win );
-       MPI_Win_unlock( trank, win );
+    MPI_Barrier(MPI_COMM_WORLD);
+    for (i = 0; i < NELM; i++) {
+        MPI_Win_lock(MPI_LOCK_EXCLUSIVE, trank, 0, win);
+        MPI_Put(&localbuf[i], 1, MPI_INT, trank, rank + i * wsize, 1, MPI_INT, win);
+        MPI_Put(&localbuf[i], 1, MPI_INT, trank, rank + (i + NELM) * wsize, 1, MPI_INT, win);
+        MPI_Win_unlock(trank, win);
     }
-    MPI_Barrier( MPI_COMM_WORLD );
+    MPI_Barrier(MPI_COMM_WORLD);
     if (rank == trank) {
-       MPI_Win_lock( MPI_LOCK_EXCLUSIVE, trank, 0, win );
-       toterrs += testValues( 1, NELM, wsize, rmabuf, "Multiple puts (1)" );
-       toterrs += testValues( 1, NELM, wsize, rmabuf + wsize*NELM,
-                              "Multiple puts (2)" );
-       MPI_Win_unlock( trank, win );
+        MPI_Win_lock(MPI_LOCK_EXCLUSIVE, trank, 0, win);
+        toterrs += testValues(1, NELM, wsize, rmabuf, "Multiple puts (1)");
+        toterrs += testValues(1, NELM, wsize, rmabuf + wsize * NELM, "Multiple puts (2)");
+        MPI_Win_unlock(trank, win);
     }
-    MPI_Barrier( MPI_COMM_WORLD );
+    MPI_Barrier(MPI_COMM_WORLD);
     /* Reinit the rmabuf */
-    for (i=0; i<windowsize; i++) {
-      rmabuf[i] = -1;
+    for (i = 0; i < windowsize; i++) {
+        rmabuf[i] = -1;
     }
-    MPI_Barrier( MPI_COMM_WORLD );
+    MPI_Barrier(MPI_COMM_WORLD);
 
     /* Single put with contention */
     trank = 0;
-    for (i=0; i<NELM; i++) {
-       MPI_Win_lock( MPI_LOCK_EXCLUSIVE, trank, 0, win );
-       MPI_Put( &localbuf[i], 1, MPI_INT, trank, rank + i*wsize, 1, MPI_INT, 
-                win );
-       MPI_Win_unlock( trank, win );
+    for (i = 0; i < NELM; i++) {
+        MPI_Win_lock(MPI_LOCK_EXCLUSIVE, trank, 0, win);
+        MPI_Put(&localbuf[i], 1, MPI_INT, trank, rank + i * wsize, 1, MPI_INT, win);
+        MPI_Win_unlock(trank, win);
     }
-    MPI_Barrier( MPI_COMM_WORLD );
+    MPI_Barrier(MPI_COMM_WORLD);
     if (rank == trank) {
-       MPI_Win_lock( MPI_LOCK_EXCLUSIVE, trank, 0, win );
-       toterrs += testValues( 1, NELM, wsize, rmabuf, "Single put" );
-       MPI_Win_unlock( trank, win );
+        MPI_Win_lock(MPI_LOCK_EXCLUSIVE, trank, 0, win);
+        toterrs += testValues(1, NELM, wsize, rmabuf, "Single put");
+        MPI_Win_unlock(trank, win);
     }
 
     /* Reinit the rmabuf */
-    for (i=0; i<windowsize; i++) {
-       rmabuf[i] = -1;
+    for (i = 0; i < windowsize; i++) {
+        rmabuf[i] = -1;
     }
     /* Longer puts with contention at trank */
-    MPI_Barrier( MPI_COMM_WORLD );
-    for (i=0; i<NELM; i++) {
-       MPI_Win_lock( MPI_LOCK_EXCLUSIVE, trank, 0, win );
-       if (rank != trank) {
-           MPI_Put( &localbuf2[i*NBLOCK], NBLOCK, MPI_INT, trank, 
-                    NELM * wsize + NBLOCK*(rank+i*wsize), NBLOCK, 
-                    MPI_INT, win );
-           MPI_Put( &localbuf2[i*NBLOCK], NBLOCK, MPI_INT, trank, 
-                    NELM * wsize + NBLOCK*(rank+(i+NELM)*wsize), NBLOCK, 
-                    MPI_INT, win );
-       }
-       MPI_Put( &localbuf[i], 1, MPI_INT, trank, rank+i*wsize, 1, MPI_INT, 
-                win );
-       MPI_Win_unlock( trank, win );
+    MPI_Barrier(MPI_COMM_WORLD);
+    for (i = 0; i < NELM; i++) {
+        MPI_Win_lock(MPI_LOCK_EXCLUSIVE, trank, 0, win);
+        if (rank != trank) {
+            MPI_Put(&localbuf2[i * NBLOCK], NBLOCK, MPI_INT, trank,
+                    NELM * wsize + NBLOCK * (rank + i * wsize), NBLOCK, MPI_INT, win);
+            MPI_Put(&localbuf2[i * NBLOCK], NBLOCK, MPI_INT, trank,
+                    NELM * wsize + NBLOCK * (rank + (i + NELM) * wsize), NBLOCK, MPI_INT, win);
+        }
+        MPI_Put(&localbuf[i], 1, MPI_INT, trank, rank + i * wsize, 1, MPI_INT, win);
+        MPI_Win_unlock(trank, win);
     }
-    MPI_Barrier( MPI_COMM_WORLD );
+    MPI_Barrier(MPI_COMM_WORLD);
     if (rank == trank) {
-       /* For simplicity in testing, set the values that rank==trank
-          would have set. */
-       for (i=0; i<NELM; i++) {
-           for (j=0; j<NBLOCK; j++) {
-               rmabuf[NELM*wsize + NBLOCK*(trank+i*wsize) + j] = 
-                   j + NBLOCK*(trank +i*wsize);
-               rmabuf[NELM*wsize + NBLOCK*(trank+(i+NELM)*wsize) + j] = 
-                   j + NBLOCK*(trank + i*wsize);
-           }
-       }
-       MPI_Win_lock( MPI_LOCK_EXCLUSIVE, trank, 0, win );
-       toterrs += testValues( 1, NELM, wsize, rmabuf, "Long puts (1)" );
-       toterrs += testValues( NBLOCK, NELM, wsize, rmabuf + NELM * wsize,
-                              "Long puts(2)" );
-       toterrs += testValues( NBLOCK, NELM, wsize, 
-                              rmabuf + NELM * wsize * (1 + NBLOCK),
-                              "Long puts(3)" );
-       MPI_Win_unlock( trank, win );
+        /* For simplicity in testing, set the values that rank==trank
+         * would have set. */
+        for (i = 0; i < NELM; i++) {
+            for (j = 0; j < NBLOCK; j++) {
+                rmabuf[NELM * wsize + NBLOCK * (trank + i * wsize) + j] =
+                    j + NBLOCK * (trank + i * wsize);
+                rmabuf[NELM * wsize + NBLOCK * (trank + (i + NELM) * wsize) + j] =
+                    j + NBLOCK * (trank + i * wsize);
+            }
+        }
+        MPI_Win_lock(MPI_LOCK_EXCLUSIVE, trank, 0, win);
+        toterrs += testValues(1, NELM, wsize, rmabuf, "Long puts (1)");
+        toterrs += testValues(NBLOCK, NELM, wsize, rmabuf + NELM * wsize, "Long puts(2)");
+        toterrs += testValues(NBLOCK, NELM, wsize,
+                              rmabuf + NELM * wsize * (1 + NBLOCK), "Long puts(3)");
+        MPI_Win_unlock(trank, win);
     }
-    
+
     /* Reinit the rmabuf */
-    for (i=0; i<windowsize; i++) {
-       rmabuf[i] = -1;
+    for (i = 0; i < windowsize; i++) {
+        rmabuf[i] = -1;
     }
-    for (i=0; i< NELM; i++) 
-       vals[i] = -2;
-    
+    for (i = 0; i < NELM; i++)
+        vals[i] = -2;
+
     /* Put mixed with Get */
-    MPI_Barrier( MPI_COMM_WORLD );
-    for (i=0; i<NELM; i++) {
-       MPI_Win_lock( MPI_LOCK_EXCLUSIVE, trank, 0, win );
-       if (rank != trank) {
-           MPI_Put( &localbuf2[i], NBLOCK, MPI_INT, trank, 
-                    NELM*wsize + NBLOCK*(rank + i*wsize), NBLOCK, MPI_INT, 
-                    win );
-           MPI_Put( &localbuf[i], 1, MPI_INT, trank, 
-                    rank + i*wsize, 1, MPI_INT, win );
-       }
-       else {
-           MPI_Get( &vals[i], 1, MPI_INT, trank, i, 1, MPI_INT, win );
-       }
-       MPI_Win_unlock( trank, win );
+    MPI_Barrier(MPI_COMM_WORLD);
+    for (i = 0; i < NELM; i++) {
+        MPI_Win_lock(MPI_LOCK_EXCLUSIVE, trank, 0, win);
+        if (rank != trank) {
+            MPI_Put(&localbuf2[i], NBLOCK, MPI_INT, trank,
+                    NELM * wsize + NBLOCK * (rank + i * wsize), NBLOCK, MPI_INT, win);
+            MPI_Put(&localbuf[i], 1, MPI_INT, trank, rank + i * wsize, 1, MPI_INT, win);
+        }
+        else {
+            MPI_Get(&vals[i], 1, MPI_INT, trank, i, 1, MPI_INT, win);
+        }
+        MPI_Win_unlock(trank, win);
     }
-    MPI_Barrier( MPI_COMM_WORLD );
+    MPI_Barrier(MPI_COMM_WORLD);
     if (rank == trank) {
-       /* Just test the Get */
-       for (i=0; i<wsize; i++) {
-           if (i == trank) {
-               if (vals[i] != -1) {
-                   toterrs++;
-                   if (toterrs < MAX_ERRS_REPORT) {
-                       printf( "put/get: vals[%d] = %d, expected -1\n",
-                               i, vals[i] );
-                   }
-               }
-           }
-           else if (vals[i] != i && vals[i] != -1) {
-               toterrs++;
-               if (toterrs < MAX_ERRS_REPORT) {
-                   printf( "put/get: vals[%d] = %d, expected -1 or %d\n",
-                           i, vals[i], i );
-               }
-           }
-       }
+        /* Just test the Get */
+        for (i = 0; i < wsize; i++) {
+            if (i == trank) {
+                if (vals[i] != -1) {
+                    toterrs++;
+                    if (toterrs < MAX_ERRS_REPORT) {
+                        printf("put/get: vals[%d] = %d, expected -1\n", i, vals[i]);
+                    }
+                }
+            }
+            else if (vals[i] != i && vals[i] != -1) {
+                toterrs++;
+                if (toterrs < MAX_ERRS_REPORT) {
+                    printf("put/get: vals[%d] = %d, expected -1 or %d\n", i, vals[i], i);
+                }
+            }
+        }
     }
 
     /* Contention only with get */
-    for (i=0; i<windowsize; i++) {
-       rmabuf[i] = -i;
+    for (i = 0; i < windowsize; i++) {
+        rmabuf[i] = -i;
     }
-    for (i=0; i<NELM; i++)
-       vals[i] = -2;
+    for (i = 0; i < NELM; i++)
+        vals[i] = -2;
 
-    MPI_Barrier( MPI_COMM_WORLD );
-    for (i=0; i<NELM; i++) {
-       MPI_Win_lock( MPI_LOCK_EXCLUSIVE, trank, 0, win );
-       MPI_Get( &vals[i], 1, MPI_INT, trank, i, 1, MPI_INT, win );
-       MPI_Win_unlock( trank, win );
+    MPI_Barrier(MPI_COMM_WORLD);
+    for (i = 0; i < NELM; i++) {
+        MPI_Win_lock(MPI_LOCK_EXCLUSIVE, trank, 0, win);
+        MPI_Get(&vals[i], 1, MPI_INT, trank, i, 1, MPI_INT, win);
+        MPI_Win_unlock(trank, win);
     }
-    MPI_Barrier( MPI_COMM_WORLD );
+    MPI_Barrier(MPI_COMM_WORLD);
     if (rank == trank) {
-       for (i=0; i<NELM; i++) {
-           if (vals[i] != -i) {
-               toterrs++;
-               if (toterrs < MAX_ERRS_REPORT) {
-                   printf( "single get: vals[%d] = %d, expected %d\n",
-                           i, vals[i], -i );
-               }
-           }
-       }
+        for (i = 0; i < NELM; i++) {
+            if (vals[i] != -i) {
+                toterrs++;
+                if (toterrs < MAX_ERRS_REPORT) {
+                    printf("single get: vals[%d] = %d, expected %d\n", i, vals[i], -i);
+                }
+            }
+        }
     }
 
     /* Contention with accumulate */
-    MPI_Barrier( MPI_COMM_WORLD );
-    for (i=0; i<NELM*wsize; i++) {
-       rmabuf[i] = 0;
+    MPI_Barrier(MPI_COMM_WORLD);
+    for (i = 0; i < NELM * wsize; i++) {
+        rmabuf[i] = 0;
     }
-    MPI_Barrier( MPI_COMM_WORLD );
-    for (i=0; i<NELM; i++) {
-       MPI_Win_lock( MPI_LOCK_EXCLUSIVE, trank, 0, win );
-       MPI_Accumulate( &localbuf[i], 1, MPI_INT, trank, rank+i*wsize, 
-                       1, MPI_INT, MPI_SUM, win );
-       MPI_Accumulate( &localbuf[i], 1, MPI_INT, trank, rank+i*wsize, 
-                       1, MPI_INT, MPI_SUM, win );
-       MPI_Win_unlock( trank, win );
+    MPI_Barrier(MPI_COMM_WORLD);
+    for (i = 0; i < NELM; i++) {
+        MPI_Win_lock(MPI_LOCK_EXCLUSIVE, trank, 0, win);
+        MPI_Accumulate(&localbuf[i], 1, MPI_INT, trank, rank + i * wsize, 1, MPI_INT, MPI_SUM, win);
+        MPI_Accumulate(&localbuf[i], 1, MPI_INT, trank, rank + i * wsize, 1, MPI_INT, MPI_SUM, win);
+        MPI_Win_unlock(trank, win);
     }
-    MPI_Barrier( MPI_COMM_WORLD );
+    MPI_Barrier(MPI_COMM_WORLD);
     if (rank == trank) {
-       MPI_Win_lock( MPI_LOCK_EXCLUSIVE, trank, 0, win );
-       for (i=0; i<NELM * wsize; i++) {
-           if (rmabuf[i] != 2*i) {
-               toterrs++;
-               if (toterrs < MAX_ERRS_REPORT) {
-                   printf( "2 accumulate: rmabuf[%d] = %d, expected %d\n",
-                           i, rmabuf[i], 2*i );
-               }
-           }
-       }
-       MPI_Win_unlock( trank, win );
+        MPI_Win_lock(MPI_LOCK_EXCLUSIVE, trank, 0, win);
+        for (i = 0; i < NELM * wsize; i++) {
+            if (rmabuf[i] != 2 * i) {
+                toterrs++;
+                if (toterrs < MAX_ERRS_REPORT) {
+                    printf("2 accumulate: rmabuf[%d] = %d, expected %d\n", i, rmabuf[i], 2 * i);
+                }
+            }
+        }
+        MPI_Win_unlock(trank, win);
     }
 
-    MPI_Win_free( &win );
+    MPI_Win_free(&win);
+
+    free(rmabuf);
+    free(localbuf);
+    free(localbuf2);
+    free(vals);
 
-    free( rmabuf );
-    free( localbuf );
-    free( localbuf2 );
-    free( vals );
-   
     MTest_Finalize(toterrs);
-    MPI_Finalize(); 
-    return 0; 
-} 
+    MPI_Finalize();
+    return 0;
+}
 
-/* Test the values in the rmabuf against the expected values.  Return the 
+/* Test the values in the rmabuf against the expected values.  Return the
    number of errors */
-int testValues( int nb, int nelm, int wsize, int *rmabuf, const char *msg )
+int testValues(int nb, int nelm, int wsize, int *rmabuf, const char *msg)
 {
     int i, errs = 0;
-               
-    for (i=0; i<nb * nelm * wsize; i++) {
-       if (rmabuf[i] != i) {
-           if (toterrs + errs < MAX_ERRS_REPORT) {
-               printf( "%s:rmabuf[%d] = %d expected %d\n", 
-                       msg, i, rmabuf[i], i );
-           }
-           errs++;
-       }
+
+    for (i = 0; i < nb * nelm * wsize; i++) {
+        if (rmabuf[i] != i) {
+            if (toterrs + errs < MAX_ERRS_REPORT) {
+                printf("%s:rmabuf[%d] = %d expected %d\n", msg, i, rmabuf[i], i);
+            }
+            errs++;
+        }
     }
 
     return errs;
index d70e26c..8be8a50 100644 (file)
@@ -3,7 +3,7 @@
  *  (C) 2012 by Argonne National Laboratory.
  *      See COPYRIGHT in top-level directory.
  */
-#include "mpi.h" 
+#include "mpi.h"
 #include "stdio.h"
 #include "stdlib.h"
 #include "mpitest.h"
@@ -19,7 +19,7 @@
 #define PUT_VAL 0xdcba97
 #define ACC_VAL 10771134
 
-/* 
+/*
  * Additional tests for lock contention.  These are designed to exercise
  * some of the optimizations within MPICH, but all are valid MPI programs.
  * Tests structure includes
@@ -36,9 +36,9 @@
  *                                  lock         // Note: this may block
  *                                     rma operations (see below)
  *                                  unlock
- *    
+ *
  *    unlock                        send back to partner
- *    receive from partner 
+ *    receive from partner
  *    check for correct data
  *
  * The delay may be implemented as a ring of message communication; this
  */
 
 /* Define a datatype to be used with */
-int stride    = 11;
-int veccount  = 7;
-MPI_Datatype  vectype;
+int stride = 11;
+int veccount = 7;
+MPI_Datatype vectype;
 /* Define long RMA ops size */
 int longcount = 512;
-int medcount  = 127;
-int mednum    = 4;
+int medcount = 127;
+int mednum = 4;
 
-void RMATest( int i, MPI_Win win, int master, int *srcbuf, int srcbufsize, int *getbuf, int getbufsize );
-int  RMACheck( int i, int *buf, MPI_Aint bufsize );
-int  RMACheckGet( int i, MPI_Win win, int *getbuf, MPI_Aint getsize);
-void RMATestInit( int i, int *buf, MPI_Aint bufsize );
+void RMATest(int i, MPI_Win win, int master, int *srcbuf, int srcbufsize, int *getbuf,
+             int getbufsize);
+int RMACheck(int i, int *buf, MPI_Aint bufsize);
+int RMACheckGet(int i, MPI_Win win, int *getbuf, MPI_Aint getsize);
+void RMATestInit(int i, int *buf, MPI_Aint bufsize);
 
-int main( int argc, char *argv[] )
+int main(int argc, char *argv[])
 {
-    int      errs = 0;
-    MPI_Win  win;
-    int  *rmabuffer=0, *getbuf=0;
-    MPI_Aint bufsize=0, getbufsize=0;
-    int      master, partner, next, wrank, wsize, i;
-    int      ntest = LAST_TEST;
+    int errs = 0;
+    MPI_Win win;
+    int *rmabuffer = 0, *getbuf = 0;
+    MPI_Aint bufsize = 0, getbufsize = 0;
+    int master, partner, next, wrank, wsize, i;
+    int ntest = LAST_TEST;
     int *srcbuf;
 
-    MTest_Init( &argc, &argv );
+    MTest_Init(&argc, &argv);
 
     /* Determine who is responsible for each part of the test */
-    MPI_Comm_rank( MPI_COMM_WORLD, &wrank );
-    MPI_Comm_size( MPI_COMM_WORLD, &wsize );
+    MPI_Comm_rank(MPI_COMM_WORLD, &wrank);
+    MPI_Comm_size(MPI_COMM_WORLD, &wsize);
     if (wsize < 3) {
-       fprintf( stderr, "This test requires at least 3 processes\n" );
-       MPI_Abort( MPI_COMM_WORLD, 1 );
+        fprintf(stderr, "This test requires at least 3 processes\n");
+        MPI_Abort(MPI_COMM_WORLD, 1);
     }
 
-    master  = 0;
+    master = 0;
     partner = 1;
     next = wrank + 1;
-    if (next == partner) next++;
+    if (next == partner)
+        next++;
     if (next >= wsize) {
-       next = 0;
-       if (next == partner) next++;
+        next = 0;
+        if (next == partner)
+            next++;
     }
 
     /* Determine the last test to run (by default, run them all) */
-    for (i=1; i<argc; i++) {
-       if (strcmp( "-ntest", argv[i] ) == 0) { 
-           i++;
-           if (i < argc) {
-               ntest = atoi( argv[i] );
-           }
-           else {
-               fprintf( stderr, "Missing value for -ntest\n" );
-               MPI_Abort( MPI_COMM_WORLD, 1 );
-           }
-       }
+    for (i = 1; i < argc; i++) {
+        if (strcmp("-ntest", argv[i]) == 0) {
+            i++;
+            if (i < argc) {
+                ntest = atoi(argv[i]);
+            }
+            else {
+                fprintf(stderr, "Missing value for -ntest\n");
+                MPI_Abort(MPI_COMM_WORLD, 1);
+            }
+        }
     }
 
-    MPI_Type_vector( veccount, 1, stride, MPI_INT, &vectype );
-    MPI_Type_commit( &vectype );
+    MPI_Type_vector(veccount, 1, stride, MPI_INT, &vectype);
+    MPI_Type_commit(&vectype);
 
     /* Create the RMA window */
     bufsize = 0;
     if (wrank == master) {
-       bufsize = RMA_SIZE;
-       MPI_Alloc_mem( bufsize*sizeof(int), MPI_INFO_NULL, &rmabuffer );
+        bufsize = RMA_SIZE;
+        MPI_Alloc_mem(bufsize * sizeof(int), MPI_INFO_NULL, &rmabuffer);
     }
     else if (wrank == partner) {
-       getbufsize = RMA_SIZE;
-       getbuf = (int *)malloc( getbufsize*sizeof(int) );
-       if (!getbuf) {
-           fprintf( stderr, "Unable to allocated %d bytes for getbuf\n", 
-                   (int)getbufsize );
-           MPI_Abort( MPI_COMM_WORLD, 1 );
-       }
+        getbufsize = RMA_SIZE;
+        getbuf = (int *) malloc(getbufsize * sizeof(int));
+        if (!getbuf) {
+            fprintf(stderr, "Unable to allocated %d bytes for getbuf\n", (int) getbufsize);
+            MPI_Abort(MPI_COMM_WORLD, 1);
+        }
     }
-    srcbuf = malloc(RMA_SIZE*sizeof(*srcbuf));
+    srcbuf = malloc(RMA_SIZE * sizeof(*srcbuf));
     assert(srcbuf);
 
-    MPI_Win_create( rmabuffer, bufsize, sizeof(int), MPI_INFO_NULL,
-                   MPI_COMM_WORLD, &win );
-    
+    MPI_Win_create(rmabuffer, bufsize * sizeof(int), sizeof(int), MPI_INFO_NULL,
+                   MPI_COMM_WORLD, &win);
+
     /* Run a sequence of tests */
-    for (i=0; i<=ntest; i++) {
-       if (wrank == master) {
-           MTestPrintfMsg( 0, "Test %d\n", i );
-           /* Because this lock is local, it must return only when the
-            lock is acquired */
-           MPI_Win_lock( MPI_LOCK_EXCLUSIVE, 0, master, win );
-           RMATestInit( i, rmabuffer, bufsize );
-           MPI_Send( MPI_BOTTOM, 0, MPI_INT, partner, i, MPI_COMM_WORLD );
-           MPI_Send( MPI_BOTTOM, 0, MPI_INT, next, i, MPI_COMM_WORLD );
-           MPI_Recv( MPI_BOTTOM, 0, MPI_INT, MPI_ANY_SOURCE, i, 
-                     MPI_COMM_WORLD, MPI_STATUS_IGNORE );
-           MPI_Win_unlock( master, win );
-           MPI_Recv( MPI_BOTTOM, 0, MPI_INT, partner, i, MPI_COMM_WORLD, 
-                     MPI_STATUS_IGNORE );
-           errs += RMACheck( i, rmabuffer, bufsize );
-       }
-       else if (wrank == partner) {
-           MPI_Recv( MPI_BOTTOM, 0, MPI_INT, master, i, MPI_COMM_WORLD,
-                     MPI_STATUS_IGNORE );
-           MPI_Win_lock( MPI_LOCK_EXCLUSIVE, 0, master, win );
-           RMATest( i, win, master, srcbuf, RMA_SIZE, getbuf, getbufsize );
-           MPI_Win_unlock( master, win );
-           errs += RMACheckGet( i, win, getbuf, getbufsize );
-           MPI_Send( MPI_BOTTOM, 0, MPI_INT, master, i, MPI_COMM_WORLD );
-       }
-       else {
-           MPI_Recv( MPI_BOTTOM, 0, MPI_INT, MPI_ANY_SOURCE, i, 
-                     MPI_COMM_WORLD, MPI_STATUS_IGNORE );
-           MPI_Send( MPI_BOTTOM, 0, MPI_INT, next, i, MPI_COMM_WORLD );
-       }
+    for (i = 0; i <= ntest; i++) {
+        if (wrank == master) {
+            MTestPrintfMsg(0, "Test %d\n", i);
+            /* Because this lock is local, it must return only when the
+             * lock is acquired */
+            MPI_Win_lock(MPI_LOCK_EXCLUSIVE, 0, master, win);
+            RMATestInit(i, rmabuffer, bufsize);
+            MPI_Send(MPI_BOTTOM, 0, MPI_INT, partner, i, MPI_COMM_WORLD);
+            MPI_Send(MPI_BOTTOM, 0, MPI_INT, next, i, MPI_COMM_WORLD);
+            MPI_Recv(MPI_BOTTOM, 0, MPI_INT, MPI_ANY_SOURCE, i, MPI_COMM_WORLD, MPI_STATUS_IGNORE);
+            MPI_Win_unlock(master, win);
+            MPI_Recv(MPI_BOTTOM, 0, MPI_INT, partner, i, MPI_COMM_WORLD, MPI_STATUS_IGNORE);
+            errs += RMACheck(i, rmabuffer, bufsize);
+        }
+        else if (wrank == partner) {
+            MPI_Recv(MPI_BOTTOM, 0, MPI_INT, master, i, MPI_COMM_WORLD, MPI_STATUS_IGNORE);
+            MPI_Win_lock(MPI_LOCK_EXCLUSIVE, 0, master, win);
+            RMATest(i, win, master, srcbuf, RMA_SIZE, getbuf, getbufsize);
+            MPI_Win_unlock(master, win);
+            errs += RMACheckGet(i, win, getbuf, getbufsize);
+            MPI_Send(MPI_BOTTOM, 0, MPI_INT, master, i, MPI_COMM_WORLD);
+        }
+        else {
+            MPI_Recv(MPI_BOTTOM, 0, MPI_INT, MPI_ANY_SOURCE, i, MPI_COMM_WORLD, MPI_STATUS_IGNORE);
+            MPI_Send(MPI_BOTTOM, 0, MPI_INT, next, i, MPI_COMM_WORLD);
+        }
     }
 
     if (rmabuffer) {
-       MPI_Free_mem( rmabuffer );
+        MPI_Free_mem(rmabuffer);
     }
     if (getbuf) {
-       free( getbuf );
+        free(getbuf);
     }
-    MPI_Win_free( &win );
-    MPI_Type_free( &vectype );
+    free(srcbuf);
+    MPI_Win_free(&win);
+    MPI_Type_free(&vectype);
 
-    MTest_Finalize( errs );
+    MTest_Finalize(errs);
     MPI_Finalize();
-    return MTestReturnValue( errs );
+    return MTestReturnValue(errs);
 }
 
 /* Perform the tests.
  *
  * The srcbuf must be passed in because the buffer must remain valid
  * until the subsequent unlock call. */
-void RMATest( int i, MPI_Win win, int master, int *srcbuf, int srcbufsize, int *getbuf, int getbufsize )
+void RMATest(int i, MPI_Win win, int master, int *srcbuf, int srcbufsize, int *getbuf,
+             int getbufsize)
 {
     int j, k;
     int *source = srcbuf;
     assert(srcbufsize == RMA_SIZE);
 
-    for (j=0; j<srcbufsize; j++) source[j] = -j;
+    for (j = 0; j < srcbufsize; j++)
+        source[j] = -j;
 
     switch (i) {
-    case 0: /* Single short put (1 word at OFFSET_1) */
-       source[0] = PUT_VAL;
-       MPI_Put( source, 1, MPI_INT, master, OFFSET_1, 1, MPI_INT, win );
-       break;
-    case 1: /* Single short accumulate (1 word of value 17 at OFFSET_2) */
-       source[0] = ACC_VAL;
-       MPI_Accumulate( source, 1, MPI_INT, master, 
-                       OFFSET_2, 1, MPI_INT, MPI_SUM, win );
-       break;
-    case 2: /* Single short get (1 word at OFFSET_3) */
-       getbuf[0] = -1;
-       MPI_Get( getbuf, 1, MPI_INT, master, OFFSET_3, 1, MPI_INT, win );
-       break;
-    case 3: /* Datatype single put (strided put) */
-       for (j=0; j<veccount; j++) {
-           source[j*stride] = PUT_VAL + j;
-       }
-       MPI_Put( source, 1, vectype, master, OFFSET_1, 1, vectype, win );
-       break;
-    case 4: /* Datatype single accumulate (strided acc) */
-       for (j=0; j<veccount; j++) {
-           source[j*stride] = ACC_VAL + j;
-       }
-       MPI_Accumulate( source, 1, vectype, master, 
-                       OFFSET_2, 1, vectype, MPI_SUM, win );
-       break;
-    case 5: /* Datatype single get (strided get) */
-       for (j=0; j<veccount; j++) {
-           getbuf[j] = -j;
-       }
-       MPI_Get( getbuf, 1, vectype, master,
-                OFFSET_3, 1, vectype, win );
-       break;
-    case 6: /* a few small puts (like strided put, but 1 word at a time) */
-       for (j=0; j<veccount; j++) {
-           source[j*stride] = PUT_VAL + j;
-       }
-       for (j=0; j<veccount; j++) {
-           MPI_Put( source + j*stride, 1, MPI_INT, master, 
-                    OFFSET_1+j*stride, 1, MPI_INT, win );
-       }
-       break;
-    case 7: /* a few small accumulates (like strided acc, but 1 word at a time )*/
-       for (j=0; j<veccount; j++) {
-           source[j*stride] = ACC_VAL + j;
-       }
-       for (j=0; j<veccount; j++) {
-           MPI_Accumulate( source + j*stride, 1, MPI_INT, master, 
-                           OFFSET_2+j*stride, 1, MPI_INT, MPI_SUM, win );
-       }
-       break;
-    case 8: /* a few small gets (like strided get, but 1 word at a time) */
-       for (j=0; j<veccount; j++) {
-           getbuf[j*stride] = -j;
-       }
-       for (j=0; j<veccount; j++) {
-           MPI_Get( getbuf + j*stride, 1, MPI_INT, master, 
-                    OFFSET_3+j*stride, 1, MPI_INT, win );
-       }
-       break;
-    case 9: /* Single long put (OFFSET_1) */
-       for (j=0; j<longcount; j++) source[j] = j;
-       MPI_Put( source, longcount, MPI_INT, master,
-                OFFSET_1, longcount, MPI_INT, win ); 
-       break;
-    case 10: /* Single long accumulate (OFFSET_2) */
-       for (j=0; j<longcount; j++) source[j] = j;
-       MPI_Accumulate( source, longcount, MPI_INT, master, 
-                       OFFSET_2, longcount, MPI_INT, MPI_SUM, win );
-       break;
-    case 11: /* Single long get (OFFSET_3) */
-       for (j=0; j<longcount; j++) getbuf[j] = -j;
-       MPI_Get( getbuf, longcount, MPI_INT, master,
-                OFFSET_3, longcount, MPI_INT, win ); 
-       break;
-    case 12: /* a few long puts (start at OFFSET_1, medcount ) */
-       for (j=0; j<mednum; j++) {
-           for (k=0; k<medcount; k++) {
-               source[j*medcount+k] = j*2*medcount+k;
-           }
-           MPI_Put( source + j*medcount, medcount, MPI_INT, master,
-                    OFFSET_1 + j*2*medcount, medcount, MPI_INT, win );
-       }
-       break;
-    case 13: /* a few long accumulates (start at OFFSET_2, medcount) */
-       for (j=0; j<mednum; j++) {
-           for (k=0; k<medcount; k++) {
-               source[j*medcount+k] = ACC_VAL + j*2*medcount+k;
-           }
-           MPI_Accumulate( source + j*medcount, medcount, MPI_INT, master,
-                           OFFSET_2 + j*2*medcount, medcount, MPI_INT, 
-                           MPI_SUM, win );
-       }
-       break;
-    case 14: /* a few long gets (start at OFFSET_3, medcount) */
-       for (j=0; j<mednum; j++) {
-           for (k=0; k<medcount; k++) {
-               getbuf[j*medcount+k] = -(j*medcount+k);
-           }
-           MPI_Get( getbuf + j*medcount, medcount, MPI_INT, master,
-                           OFFSET_3 + j*2*medcount, medcount, MPI_INT, win );
-       }
-       break;
+    case 0:    /* Single short put (1 word at OFFSET_1) */
+        source[0] = PUT_VAL;
+        MPI_Put(source, 1, MPI_INT, master, OFFSET_1, 1, MPI_INT, win);
+        break;
+    case 1:    /* Single short accumulate (1 word of value 17 at OFFSET_2) */
+        source[0] = ACC_VAL;
+        MPI_Accumulate(source, 1, MPI_INT, master, OFFSET_2, 1, MPI_INT, MPI_SUM, win);
+        break;
+    case 2:    /* Single short get (1 word at OFFSET_3) */
+        getbuf[0] = -1;
+        MPI_Get(getbuf, 1, MPI_INT, master, OFFSET_3, 1, MPI_INT, win);
+        break;
+    case 3:    /* Datatype single put (strided put) */
+        for (j = 0; j < veccount; j++) {
+            source[j * stride] = PUT_VAL + j;
+        }
+        MPI_Put(source, 1, vectype, master, OFFSET_1, 1, vectype, win);
+        break;
+    case 4:    /* Datatype single accumulate (strided acc) */
+        for (j = 0; j < veccount; j++) {
+            source[j * stride] = ACC_VAL + j;
+        }
+        MPI_Accumulate(source, 1, vectype, master, OFFSET_2, 1, vectype, MPI_SUM, win);
+        break;
+    case 5:    /* Datatype single get (strided get) */
+        for (j = 0; j < veccount; j++) {
+            getbuf[j] = -j;
+        }
+        MPI_Get(getbuf, 1, vectype, master, OFFSET_3, 1, vectype, win);
+        break;
+    case 6:    /* a few small puts (like strided put, but 1 word at a time) */
+        for (j = 0; j < veccount; j++) {
+            source[j * stride] = PUT_VAL + j;
+        }
+        for (j = 0; j < veccount; j++) {
+            MPI_Put(source + j * stride, 1, MPI_INT, master,
+                    OFFSET_1 + j * stride, 1, MPI_INT, win);
+        }
+        break;
+    case 7:    /* a few small accumulates (like strided acc, but 1 word at a time) */
+        for (j = 0; j < veccount; j++) {
+            source[j * stride] = ACC_VAL + j;
+        }
+        for (j = 0; j < veccount; j++) {
+            MPI_Accumulate(source + j * stride, 1, MPI_INT, master,
+                           OFFSET_2 + j * stride, 1, MPI_INT, MPI_SUM, win);
+        }
+        break;
+    case 8:    /* a few small gets (like strided get, but 1 word at a time) */
+        for (j = 0; j < veccount; j++) {
+            getbuf[j * stride] = -j;
+        }
+        for (j = 0; j < veccount; j++) {
+            MPI_Get(getbuf + j * stride, 1, MPI_INT, master,
+                    OFFSET_3 + j * stride, 1, MPI_INT, win);
+        }
+        break;
+    case 9:    /* Single long put (OFFSET_1) */
+        for (j = 0; j < longcount; j++)
+            source[j] = j;
+        MPI_Put(source, longcount, MPI_INT, master, OFFSET_1, longcount, MPI_INT, win);
+        break;
+    case 10:   /* Single long accumulate (OFFSET_2) */
+        for (j = 0; j < longcount; j++)
+            source[j] = j;
+        MPI_Accumulate(source, longcount, MPI_INT, master,
+                       OFFSET_2, longcount, MPI_INT, MPI_SUM, win);
+        break;
+    case 11:   /* Single long get (OFFSET_3) */
+        for (j = 0; j < longcount; j++)
+            getbuf[j] = -j;
+        MPI_Get(getbuf, longcount, MPI_INT, master, OFFSET_3, longcount, MPI_INT, win);
+        break;
+    case 12:   /* a few long puts (start at OFFSET_1, medcount) */
+        for (j = 0; j < mednum; j++) {
+            for (k = 0; k < medcount; k++) {
+                source[j * medcount + k] = j * 2 * medcount + k;
+            }
+            MPI_Put(source + j * medcount, medcount, MPI_INT, master,
+                    OFFSET_1 + j * 2 * medcount, medcount, MPI_INT, win);
+        }
+        break;
+    case 13:   /* a few long accumulates (start at OFFSET_2, medcount) */
+        for (j = 0; j < mednum; j++) {
+            for (k = 0; k < medcount; k++) {
+                source[j * medcount + k] = ACC_VAL + j * 2 * medcount + k;
+            }
+            MPI_Accumulate(source + j * medcount, medcount, MPI_INT, master,
+                           OFFSET_2 + j * 2 * medcount, medcount, MPI_INT, MPI_SUM, win);
+        }
+        break;
+    case 14:   /* a few long gets (start at OFFSET_3, medcount) */
+        for (j = 0; j < mednum; j++) {
+            for (k = 0; k < medcount; k++) {
+                getbuf[j * medcount + k] = -(j * medcount + k);
+            }
+            MPI_Get(getbuf + j * medcount, medcount, MPI_INT, master,
+                    OFFSET_3 + j * 2 * medcount, medcount, MPI_INT, win);
+        }
+        break;
     }
 }
 
-int RMACheck( int i, int *buf, MPI_Aint bufsize )
+int RMACheck(int i, int *buf, MPI_Aint bufsize)
 {
     int j, k;
     int errs = 0;
 
     switch (i) {
-    case 0: /* Single short put (1 word at OFFSET_1) */
-       if (buf[OFFSET_1] != PUT_VAL) {
-           errs++;
-           printf( "case 0: value is %d should be %d\n", 
-                   buf[OFFSET_1], PUT_VAL );
-       }
-       break;
-    case 1: /* Single short accumulate (1 word of value 17 at OFFSET_2) */
-       if (buf[OFFSET_2] != ACC_VAL + OFFSET_2) {
-           errs++;
-           printf( "case 1: value is %d should be %d\n", 
-                   buf[OFFSET_2], ACC_VAL + OFFSET_2 );
-       }
-       break;
-    case 2: /* Single short get (1 word at OFFSET_3) */
-       /* See RMACheckGet */
-       break;
-    case 3: /* Datatype single put (strided put) */
-    case 6: /* a few small puts (like strided put, but 1 word at a time) */
+    case 0:    /* Single short put (1 word at OFFSET_1) */
+        if (buf[OFFSET_1] != PUT_VAL) {
+            errs++;
+            printf("case 0: value is %d should be %d\n", buf[OFFSET_1], PUT_VAL);
+        }
+        break;
+    case 1:    /* Single short accumulate (1 word of value 17 at OFFSET_2) */
+        if (buf[OFFSET_2] != ACC_VAL + OFFSET_2) {
+            errs++;
+            printf("case 1: value is %d should be %d\n", buf[OFFSET_2], ACC_VAL + OFFSET_2);
+        }
+        break;
+    case 2:    /* Single short get (1 word at OFFSET_3) */
+        /* See RMACheckGet */
+        break;
+    case 3:    /* Datatype single put (strided put) */
+    case 6:    /* a few small puts (like strided put, but 1 word at a time) */
         /* FIXME: The conditional and increment are reversed below.  This looks
          * like a bug, and currently prevents the following test from running. */
-       for (j=0; j++; j<veccount) {
-           if (buf[j*stride] != PUT_VAL + j) {
-               errs++;
-               printf( "case %d: value is %d should be %d\n", i,
-                       buf[j*stride], PUT_VAL+j );
-           }
-       }
-       break;
-    case 4: /* Datatype single accumulate (strided acc) */
-    case 7: /* a few small accumulates (like strided acc, but 1 word at a time )*/
+        for (j = 0; j++; j < veccount) {
+            if (buf[j * stride] != PUT_VAL + j) {
+                errs++;
+                printf("case %d: value is %d should be %d\n", i, buf[j * stride], PUT_VAL + j);
+            }
+        }
+        break;
+    case 4:    /* Datatype single accumulate (strided acc) */
+    case 7:    /* a few small accumulates (like strided acc, but 1 word at a time) */
         /* FIXME: The conditional and increment are reversed below.  This looks
          * like a bug, and currently prevents the following test from running. */
-       for (j=0; j++; j<veccount) {
-           if (buf[j*stride] != ACC_VAL + j + OFFSET_2 + j*stride) {
-               errs++;
-               printf( "case %d: value is %d should be %d\n", i,
-                       buf[j*stride], ACC_VAL+j+OFFSET_2+j*stride );
-           }
-       }
-       break;
-    case 5: /* Datatype single get (strided get) */
-    case 8: /* a few small gets (like strided get, but 1 word at a time) */
-       /* See RMACheckGet */
-       break;
-    case 9: /* Single long put (OFFSET_1) */
-       for (j=0; j<longcount; j++) {
-           if (buf[OFFSET_1+j] != j) {
-               errs++;
-               printf( "case 9: value is %d should be %d\n",
-                       buf[OFFSET_1+j], OFFSET_1 + j );
-           }
-       }
-       break;
-    case 10: /* Single long accumulate (OFFSET_2) */
-       for (j=0; j<longcount; j++) {
-           if (buf[OFFSET_2+j] != OFFSET_2 + j + j) {
-               errs++;
-               printf( "case 10: value is %d should be %d\n", 
-                       buf[OFFSET_2+j], OFFSET_2 + j + j );
-           }
-       }
-       break;
-    case 11: /* Single long get (OFFSET_3) */
-       /* See RMACheckGet */
-       break;
-    case 12: /* a few long puts (start at OFFSET_1, medcount ) */
-       for (j=0; j<mednum; j++) {
-           for (k=0; k<medcount; k++) {
-               if (buf[OFFSET_1 + j*2*medcount + k] != 
-                   j*2*medcount+k ) {
-                   errs++;
-                   printf( "case 12: value is %d should be %d\n", 
-                           buf[OFFSET_1+j*2*medcount + k], j*2*medcount + k );
-               }
-           }
-       }
-       break;
-    case 13: /* a few long accumulates (start at OFFSET_2, medcount) */
-       for (j=0; j<mednum; j++) {
-           for (k=0; k<medcount; k++) {
-               if (buf[OFFSET_2 + j*2*medcount + k] != 
-                   OFFSET_2 + 2*j*2*medcount+2*k + ACC_VAL ) {
-                   errs++;
-                   printf( "case 13: value is %d should be %d\n", 
-                           buf[OFFSET_2+j*2*medcount + k], 
-                           OFFSET_2 + 2*j*2*medcount + k +ACC_VAL);
-               }
-           }
-       }
-       break;
-    case 14: /* a few long gets (start at OFFSET_3, medcount) */
-       /* See RMACheckGet */
-       break;
+        for (j = 0; j++; j < veccount) {
+            if (buf[j * stride] != ACC_VAL + j + OFFSET_2 + j * stride) {
+                errs++;
+                printf("case %d: value is %d should be %d\n", i,
+                       buf[j * stride], ACC_VAL + j + OFFSET_2 + j * stride);
+            }
+        }
+        break;
+    case 5:    /* Datatype single get (strided get) */
+    case 8:    /* a few small gets (like strided get, but 1 word at a time) */
+        /* See RMACheckGet */
+        break;
+    case 9:    /* Single long put (OFFSET_1) */
+        for (j = 0; j < longcount; j++) {
+            if (buf[OFFSET_1 + j] != j) {
+                errs++;
+                printf("case 9: value is %d should be %d\n", buf[OFFSET_1 + j], OFFSET_1 + j);
+            }
+        }
+        break;
+    case 10:   /* Single long accumulate (OFFSET_2) */
+        for (j = 0; j < longcount; j++) {
+            if (buf[OFFSET_2 + j] != OFFSET_2 + j + j) {
+                errs++;
+                printf("case 10: value is %d should be %d\n", buf[OFFSET_2 + j], OFFSET_2 + j + j);
+            }
+        }
+        break;
+    case 11:   /* Single long get (OFFSET_3) */
+        /* See RMACheckGet */
+        break;
+    case 12:   /* a few long puts (start at OFFSET_1, medcount) */
+        for (j = 0; j < mednum; j++) {
+            for (k = 0; k < medcount; k++) {
+                if (buf[OFFSET_1 + j * 2 * medcount + k] != j * 2 * medcount + k) {
+                    errs++;
+                    printf("case 12: value is %d should be %d\n",
+                           buf[OFFSET_1 + j * 2 * medcount + k], j * 2 * medcount + k);
+                }
+            }
+        }
+        break;
+    case 13:   /* a few long accumulates (start at OFFSET_2, medcount) */
+        for (j = 0; j < mednum; j++) {
+            for (k = 0; k < medcount; k++) {
+                if (buf[OFFSET_2 + j * 2 * medcount + k] !=
+                    OFFSET_2 + 2 * j * 2 * medcount + 2 * k + ACC_VAL) {
+                    errs++;
+                    printf("case 13: value is %d should be %d\n",
+                           buf[OFFSET_2 + j * 2 * medcount + k],
+                           OFFSET_2 + 2 * j * 2 * medcount + k + ACC_VAL);
+                }
+            }
+        }
+        break;
+    case 14:   /* a few long gets (start at OFFSET_3, medcount) */
+        /* See RMACheckGet */
+        break;
     default:
-       fprintf( stderr, "Unrecognized case %d\n", i );
-       errs++;
-       break;
+        fprintf(stderr, "Unrecognized case %d\n", i);
+        errs++;
+        break;
     }
     return errs;
 }
 
-int RMACheckGet( int i, MPI_Win win, int *getbuf, MPI_Aint getsize)
+int RMACheckGet(int i, MPI_Win win, int *getbuf, MPI_Aint getsize)
 {
     int errs = 0;
     int j, k;
 
     /* */
     switch (i) {
-    case 0: /* Single short put (1 word at OFFSET_1) */
-       break;
-    case 1: /* Single short accumulate (1 word of value 17 at OFFSET_2) */
-       break;
-    case 2: /* Single short get (1 word at OFFSET_3) */
-       if (getbuf[0] != OFFSET_3) {
-           errs++;
-           printf( "case 2: value is %d should be %d\n", 
-                   getbuf[0], OFFSET_3 );
-       }
-       break;
-    case 3: /* Datatype single put (strided put) */
-       break;
-    case 4: /* Datatype single accumulate (strided acc) */
-       break;
-    case 5: /* Datatype single get (strided get) */
-    case 8: /* a few small gets (like strided get, but 1 word at a time) */
-       for (j=0; j<veccount; j++) {
-           if (getbuf[j*stride] != OFFSET_3 + j*stride) {
-               errs++;
-               printf( "case %d: value is %d should be %d\n", i,
-                       getbuf[j*stride], OFFSET_3 + j*stride );
-           }
-       }
-       
-       break;
-    case 6: /* a few small puts (like strided put, but 1 word at a time) */
-       break;
-    case 7: /* a few small accumulates (like strided acc, but 1 word at a time )*/
-       break;
-    case 9: /* Single long put (OFFSET_1) */
-       break;
-    case 10: /* Single long accumulate (OFFSET_2) */
-       break;
-    case 11: /* Single long get (OFFSET_3) */
-       for (j=0; j<longcount; j++) {
-           if (getbuf[j] != OFFSET_3 + j) {
-               errs++;
-               printf( "case 11: value is %d should be %d\n",
-                       getbuf[j], OFFSET_3 + j );
-           }
-       }
-       break;
-    case 12: /* a few long puts (start at OFFSET_1, medcount ) */
-       break;
-    case 13: /* a few long accumulates (start at OFFSET_2, medcount) */
-       break;
-    case 14: /* a few long gets (start at OFFSET_3, medcount) */
-       for (j=0; j<mednum; j++) {
-           for (k=0; k<medcount; k++) {
-               if (getbuf[j*medcount + k] != 
-                   OFFSET_3 + j*2*medcount+k ) {
-                   errs++;
-                   printf( "case 14: buf[%d] value is %d should be %d\n", 
-                           j*medcount + k,
-                           getbuf[j*medcount + k], 
-                           OFFSET_3 + j*2*medcount + k );
-               }
-           }
-       }
-       break;
+    case 0:    /* Single short put (1 word at OFFSET_1) */
+        break;
+    case 1:    /* Single short accumulate (1 word of value 17 at OFFSET_2) */
+        break;
+    case 2:    /* Single short get (1 word at OFFSET_3) */
+        if (getbuf[0] != OFFSET_3) {
+            errs++;
+            printf("case 2: value is %d should be %d\n", getbuf[0], OFFSET_3);
+        }
+        break;
+    case 3:    /* Datatype single put (strided put) */
+        break;
+    case 4:    /* Datatype single accumulate (strided acc) */
+        break;
+    case 5:    /* Datatype single get (strided get) */
+    case 8:    /* a few small gets (like strided get, but 1 word at a time) */
+        for (j = 0; j < veccount; j++) {
+            if (getbuf[j * stride] != OFFSET_3 + j * stride) {
+                errs++;
+                printf("case %d: value is %d should be %d\n", i,
+                       getbuf[j * stride], OFFSET_3 + j * stride);
+            }
+        }
+
+        break;
+    case 6:    /* a few small puts (like strided put, but 1 word at a time) */
+        break;
+    case 7:    /* a few small accumulates (like strided acc, but 1 word at a time) */
+        break;
+    case 9:    /* Single long put (OFFSET_1) */
+        break;
+    case 10:   /* Single long accumulate (OFFSET_2) */
+        break;
+    case 11:   /* Single long get (OFFSET_3) */
+        for (j = 0; j < longcount; j++) {
+            if (getbuf[j] != OFFSET_3 + j) {
+                errs++;
+                printf("case 11: value is %d should be %d\n", getbuf[j], OFFSET_3 + j);
+            }
+        }
+        break;
+    case 12:   /* a few long puts (start at OFFSET_1, medcount) */
+        break;
+    case 13:   /* a few long accumulates (start at OFFSET_2, medcount) */
+        break;
+    case 14:   /* a few long gets (start at OFFSET_3, medcount) */
+        for (j = 0; j < mednum; j++) {
+            for (k = 0; k < medcount; k++) {
+                if (getbuf[j * medcount + k] != OFFSET_3 + j * 2 * medcount + k) {
+                    errs++;
+                    printf("case 14: buf[%d] value is %d should be %d\n",
+                           j * medcount + k,
+                           getbuf[j * medcount + k], OFFSET_3 + j * 2 * medcount + k);
+                }
+            }
+        }
+        break;
     default:
-       fprintf( stderr, "Unrecognized case %d\n", i );
-       errs++;
-       break;
+        fprintf(stderr, "Unrecognized case %d\n", i);
+        errs++;
+        break;
     }
     return errs;
 }
 
 
-void RMATestInit( int i, int *buf, MPI_Aint bufsize )
+void RMATestInit(int i, int *buf, MPI_Aint bufsize)
 {
     int j;
-    for (j=0; j<bufsize; j++) {
-       buf[j] = j;
+    for (j = 0; j < bufsize; j++) {
+        buf[j] = j;
     }
 }
-
index 8b04ce6..bf79d0c 100644 (file)
 static char MTEST_Descrip[] = "Locks with no RMA operations";
 */
 
-int main( int argc, char *argv[] )
+int main(int argc, char *argv[])
 {
     int errs = 0;
     int rank, size, i;
-    MPI_Comm      comm;
-    MPI_Win       win;
-    int           *winbuf, count;
+    MPI_Comm comm;
+    MPI_Win win;
+    int *winbuf, count;
 
-    MTest_Init( &argc, &argv );
+    MTest_Init(&argc, &argv);
 
     comm = MPI_COMM_WORLD;
 
-    MPI_Comm_rank( comm, &rank );
-    MPI_Comm_size( comm, &size );
+    MPI_Comm_rank(comm, &rank);
+    MPI_Comm_size(comm, &size);
 
     /* Allocate and initialize buf */
-    count  = 1000;
+    count = 1000;
 
-    MPI_Alloc_mem( count*sizeof(int), MPI_INFO_NULL, &winbuf );
+    MPI_Alloc_mem(count * sizeof(int), MPI_INFO_NULL, &winbuf);
 
-    MPI_Win_create( winbuf, count * sizeof(int), sizeof(int), MPI_INFO_NULL, 
-                   comm, &win );
+    MPI_Win_create(winbuf, count * sizeof(int), sizeof(int), MPI_INFO_NULL, comm, &win);
 
     /* Clear winbuf */
-    memset( winbuf, 0, count*sizeof(int) );
+    memset(winbuf, 0, count * sizeof(int));
 
-    /* Note that for i == rank, this is a useful operation - it allows 
-       the programmer to use direct loads and stores, rather than 
-       put/get/accumulate, to access the local memory window. */
-    for (i=0; i<size; i++) {
-       MPI_Win_lock( MPI_LOCK_EXCLUSIVE, i, 0, win );
-       MPI_Win_unlock( i, win );
+    /* Note that for i == rank, this is a useful operation - it allows
+     * the programmer to use direct loads and stores, rather than
+     * put/get/accumulate, to access the local memory window. */
+    for (i = 0; i < size; i++) {
+        MPI_Win_lock(MPI_LOCK_EXCLUSIVE, i, 0, win);
+        MPI_Win_unlock(i, win);
     }
 
-    for (i=0; i<size; i++) {
-       MPI_Win_lock( MPI_LOCK_SHARED, i, 0, win );
-       MPI_Win_unlock( i, win );
+    for (i = 0; i < size; i++) {
+        MPI_Win_lock(MPI_LOCK_SHARED, i, 0, win);
+        MPI_Win_unlock(i, win);
     }
 
-    MPI_Win_free( &win );
-    MPI_Free_mem( winbuf );
+    MPI_Win_free(&win);
+    MPI_Free_mem(winbuf);
 
     /* If this test completes, no error has been found */
     /* A more complete test may ensure that local locks in fact block
-       remote, exclusive locks */
-    MTest_Finalize( errs );
+     * remote, exclusive locks */
+    MTest_Finalize(errs);
 
     MPI_Finalize();
     return 0;
index 6f962e3..2259505 100644 (file)
@@ -3,28 +3,28 @@
  *  (C) 2012 by Argonne National Laboratory.
  *      See COPYRIGHT in top-level directory.
  */
-#include "mpi.h" 
+#include "mpi.h"
 #include "stdio.h"
 #include "stdlib.h"
 #include "mpitest.h"
 
-/* tests passive target RMA on 2 processes. tests the lock-single_op-unlock 
+/* tests passive target RMA on 2 processes. tests the lock-single_op-unlock
    optimization for less common cases:
 
    origin datatype derived, target datatype predefined
 
 */
-int main(int argc, char *argv[]) 
-{ 
-    int          wrank, nprocs, *srcbuf, *rmabuf, i;
-    int          memsize;
+int main(int argc, char *argv[])
+{
+    int wrank, nprocs, *srcbuf, *rmabuf, i;
+    int memsize;
     MPI_Datatype vectype;
-    MPI_Win      win;
-    int          errs = 0;
+    MPI_Win win;
+    int errs = 0;
 
-    MTest_Init(&argc,&argv); 
-    MPI_Comm_size(MPI_COMM_WORLD,&nprocs); 
-    MPI_Comm_rank(MPI_COMM_WORLD,&wrank); 
+    MTest_Init(&argc, &argv);
+    MPI_Comm_size(MPI_COMM_WORLD, &nprocs);
+    MPI_Comm_rank(MPI_COMM_WORLD, &wrank);
 
     if (nprocs < 2) {
         printf("Run this program with 2 or more processes\n");
@@ -33,179 +33,169 @@ int main(int argc, char *argv[])
 
     memsize = 10 * 4 * nprocs;
     /* Create and initialize data areas */
-    srcbuf = (int *)malloc( sizeof(int) * memsize );
-    MPI_Alloc_mem( sizeof(int) * memsize, MPI_INFO_NULL, &rmabuf );
+    srcbuf = (int *) malloc(sizeof(int) * memsize);
+    MPI_Alloc_mem(sizeof(int) * memsize, MPI_INFO_NULL, &rmabuf);
     if (!srcbuf || !rmabuf) {
-       printf( "Unable to allocate srcbuf and rmabuf of size %d\n", memsize );
-       MPI_Abort( MPI_COMM_WORLD, 1 );
+        printf("Unable to allocate srcbuf and rmabuf of size %d\n", memsize);
+        MPI_Abort(MPI_COMM_WORLD, 1);
     }
-    for (i=0; i<memsize; i++) {
-      rmabuf[i] = -i;
-      srcbuf[i] = i;
+    for (i = 0; i < memsize; i++) {
+        rmabuf[i] = -i;
+        srcbuf[i] = i;
     }
 
-    MPI_Win_create( rmabuf, memsize*sizeof(int), sizeof(int), MPI_INFO_NULL, 
-                   MPI_COMM_WORLD, &win );
+    MPI_Win_create(rmabuf, memsize * sizeof(int), sizeof(int), MPI_INFO_NULL, MPI_COMM_WORLD, &win);
 
     /* Vector of 10 elements, separated by 4 */
-    MPI_Type_vector( 10, 1, 4, MPI_INT, &vectype );
-    MPI_Type_commit( &vectype );
+    MPI_Type_vector(10, 1, 4, MPI_INT, &vectype);
+    MPI_Type_commit(&vectype);
 
-    /* Accumulate with a derived origin type and target predefined type*/
+    /* Accumulate with a derived origin type and target predefined type */
     if (wrank == 0) {
-       MPI_Barrier( MPI_COMM_WORLD );
-       MPI_Win_lock( MPI_LOCK_EXCLUSIVE, 0, 0, win );
-       for (i=0; i<10; i++) {
-           if (rmabuf[i] != -i + 4*i) {
-               errs++;
-               printf( "Acc: expected rmabuf[%d] = %d but saw %d\n", 
-                       i, -i + 4*i, rmabuf[i] );
-           }
-           rmabuf[i] = -i;
-       }
-       for (i=10; i<memsize; i++) {
-           if (rmabuf[i] != -i) {
-               errs++;
-               printf( "Acc: expected rmabuf[%d] = %d but saw %d\n", 
-                       i, -i, rmabuf[i] );
-               rmabuf[i] = -i;
-           }
-       }
-       MPI_Win_unlock( 0, win );
+        MPI_Barrier(MPI_COMM_WORLD);
+        MPI_Win_lock(MPI_LOCK_EXCLUSIVE, 0, 0, win);
+        for (i = 0; i < 10; i++) {
+            if (rmabuf[i] != -i + 4 * i) {
+                errs++;
+                printf("Acc: expected rmabuf[%d] = %d but saw %d\n", i, -i + 4 * i, rmabuf[i]);
+            }
+            rmabuf[i] = -i;
+        }
+        for (i = 10; i < memsize; i++) {
+            if (rmabuf[i] != -i) {
+                errs++;
+                printf("Acc: expected rmabuf[%d] = %d but saw %d\n", i, -i, rmabuf[i]);
+                rmabuf[i] = -i;
+            }
+        }
+        MPI_Win_unlock(0, win);
     }
     else if (wrank == 1) {
-       MPI_Win_lock( MPI_LOCK_SHARED, 0, 0, win );
-       MPI_Accumulate( srcbuf, 1, vectype, 0, 0, 10, MPI_INT, MPI_SUM, win );
-       MPI_Win_unlock( 0, win );
-       MPI_Barrier( MPI_COMM_WORLD );
+        MPI_Win_lock(MPI_LOCK_SHARED, 0, 0, win);
+        MPI_Accumulate(srcbuf, 1, vectype, 0, 0, 10, MPI_INT, MPI_SUM, win);
+        MPI_Win_unlock(0, win);
+        MPI_Barrier(MPI_COMM_WORLD);
     }
     else {
-       MPI_Barrier( MPI_COMM_WORLD );
+        MPI_Barrier(MPI_COMM_WORLD);
     }
 
     MPI_Barrier(MPI_COMM_WORLD);
 
-    /* Put with a derived origin type and target predefined type*/
+    /* Put with a derived origin type and target predefined type */
     if (wrank == 0) {
-       MPI_Barrier( MPI_COMM_WORLD );
-       MPI_Win_lock( MPI_LOCK_EXCLUSIVE, 0, 0, win );
-       for (i=0; i<10; i++) {
-           if (rmabuf[i] != 4*i) {
-               errs++;
-               printf( "Put: expected rmabuf[%d] = %d but saw %d\n", 
-                       i, 4*i, rmabuf[i] );
-           }
-           rmabuf[i] = -i;
-       }
-       for (i=10; i<memsize; i++) {
-           if (rmabuf[i] != -i) {
-               errs++;
-               printf( "Put: expected rmabuf[%d] = %d but saw %d\n", 
-                       i, -i, rmabuf[i] );
-               rmabuf[i] = -i;
-           }
-       }
-       MPI_Win_unlock( 0, win );
+        MPI_Barrier(MPI_COMM_WORLD);
+        MPI_Win_lock(MPI_LOCK_EXCLUSIVE, 0, 0, win);
+        for (i = 0; i < 10; i++) {
+            if (rmabuf[i] != 4 * i) {
+                errs++;
+                printf("Put: expected rmabuf[%d] = %d but saw %d\n", i, 4 * i, rmabuf[i]);
+            }
+            rmabuf[i] = -i;
+        }
+        for (i = 10; i < memsize; i++) {
+            if (rmabuf[i] != -i) {
+                errs++;
+                printf("Put: expected rmabuf[%d] = %d but saw %d\n", i, -i, rmabuf[i]);
+                rmabuf[i] = -i;
+            }
+        }
+        MPI_Win_unlock(0, win);
     }
     else if (wrank == 1) {
-       MPI_Win_lock( MPI_LOCK_SHARED, 0, 0, win );
-       MPI_Put( srcbuf, 1, vectype, 0, 0, 10, MPI_INT, win );
-       MPI_Win_unlock( 0, win );
-       MPI_Barrier( MPI_COMM_WORLD );
+        MPI_Win_lock(MPI_LOCK_SHARED, 0, 0, win);
+        MPI_Put(srcbuf, 1, vectype, 0, 0, 10, MPI_INT, win);
+        MPI_Win_unlock(0, win);
+        MPI_Barrier(MPI_COMM_WORLD);
     }
     else {
-       MPI_Barrier( MPI_COMM_WORLD );
+        MPI_Barrier(MPI_COMM_WORLD);
     }
 
     MPI_Barrier(MPI_COMM_WORLD);
 
-    /* Put with a derived origin type and target predefined type, with 
-       a get (see the move-to-end optimization) */
+    /* Put with a derived origin type and target predefined type, with
+     * a get (see the move-to-end optimization) */
     if (wrank == 0) {
-       MPI_Barrier( MPI_COMM_WORLD );
-       MPI_Win_lock( MPI_LOCK_EXCLUSIVE, 0, 0, win );
-       for (i=0; i<10; i++) {
-           if (rmabuf[i] != 4*i) {
-               errs++;
-               printf( "Put: expected rmabuf[%d] = %d but saw %d\n", 
-                       i, 4*i, rmabuf[i] );
-           }
-           rmabuf[i] = -i;
-       }
-       for (i=10; i<memsize; i++) {
-           if (rmabuf[i] != -i) {
-               errs++;
-               printf( "Put: expected rmabuf[%d] = %d but saw %d\n", 
-                       i, -i, rmabuf[i] );
-               rmabuf[i] = -i;
-           }
-       }
-       MPI_Win_unlock( 0, win );
+        MPI_Barrier(MPI_COMM_WORLD);
+        MPI_Win_lock(MPI_LOCK_EXCLUSIVE, 0, 0, win);
+        for (i = 0; i < 10; i++) {
+            if (rmabuf[i] != 4 * i) {
+                errs++;
+                printf("Put: expected rmabuf[%d] = %d but saw %d\n", i, 4 * i, rmabuf[i]);
+            }
+            rmabuf[i] = -i;
+        }
+        for (i = 10; i < memsize; i++) {
+            if (rmabuf[i] != -i) {
+                errs++;
+                printf("Put: expected rmabuf[%d] = %d but saw %d\n", i, -i, rmabuf[i]);
+                rmabuf[i] = -i;
+            }
+        }
+        MPI_Win_unlock(0, win);
     }
     else if (wrank == 1) {
-       int val;
-       MPI_Win_lock( MPI_LOCK_SHARED, 0, 0, win );
-       MPI_Get( &val, 1, MPI_INT, 0, 10, 1, MPI_INT, win );
-       MPI_Put( srcbuf, 1, vectype, 0, 0, 10, MPI_INT, win );
-       MPI_Win_unlock( 0, win );
-       MPI_Barrier( MPI_COMM_WORLD );
-       if (val != -10) {
-           errs++;
-           printf( "Get: Expected -10, got %d\n", val );
-       }
+        int val;
+        MPI_Win_lock(MPI_LOCK_SHARED, 0, 0, win);
+        MPI_Get(&val, 1, MPI_INT, 0, 10, 1, MPI_INT, win);
+        MPI_Put(srcbuf, 1, vectype, 0, 0, 10, MPI_INT, win);
+        MPI_Win_unlock(0, win);
+        MPI_Barrier(MPI_COMM_WORLD);
+        if (val != -10) {
+            errs++;
+            printf("Get: Expected -10, got %d\n", val);
+        }
     }
     else {
-       MPI_Barrier( MPI_COMM_WORLD );
+        MPI_Barrier(MPI_COMM_WORLD);
     }
 
     MPI_Barrier(MPI_COMM_WORLD);
 
-    /* Put with a derived origin type and target predefined type, with 
-       a get already at the end (see the move-to-end optimization) */
+    /* Put with a derived origin type and target predefined type, with
+     * a get already at the end (see the move-to-end optimization) */
     if (wrank == 0) {
-       MPI_Barrier( MPI_COMM_WORLD );
-       MPI_Win_lock( MPI_LOCK_EXCLUSIVE, 0, 0, win );
-       for (i=0; i<10; i++) {
-           if (rmabuf[i] != 4*i) {
-               errs++;
-               printf( "Put: expected rmabuf[%d] = %d but saw %d\n", 
-                       i, 4*i, rmabuf[i] );
-           }
-           rmabuf[i] = -i;
-       }
-       for (i=10; i<memsize; i++) {
-           if (rmabuf[i] != -i) {
-               errs++;
-               printf( "Put: expected rmabuf[%d] = %d but saw %d\n", 
-                       i, -i, rmabuf[i] );
-               rmabuf[i] = -i;
-           }
-       }
-       MPI_Win_unlock( 0, win );
+        MPI_Barrier(MPI_COMM_WORLD);
+        MPI_Win_lock(MPI_LOCK_EXCLUSIVE, 0, 0, win);
+        for (i = 0; i < 10; i++) {
+            if (rmabuf[i] != 4 * i) {
+                errs++;
+                printf("Put: expected rmabuf[%d] = %d but saw %d\n", i, 4 * i, rmabuf[i]);
+            }
+            rmabuf[i] = -i;
+        }
+        for (i = 10; i < memsize; i++) {
+            if (rmabuf[i] != -i) {
+                errs++;
+                printf("Put: expected rmabuf[%d] = %d but saw %d\n", i, -i, rmabuf[i]);
+                rmabuf[i] = -i;
+            }
+        }
+        MPI_Win_unlock(0, win);
     }
     else if (wrank == 1) {
-       int val;
-       MPI_Win_lock( MPI_LOCK_SHARED, 0, 0, win );
-       MPI_Put( srcbuf, 1, vectype, 0, 0, 10, MPI_INT, win );
-       MPI_Get( &val, 1, MPI_INT, 0, 10, 1, MPI_INT, win );
-       MPI_Win_unlock( 0, win );
-       MPI_Barrier( MPI_COMM_WORLD );
-       if (val != -10) {
-           errs++;
-           printf( "Get: Expected -10, got %d\n", val );
-       }
+        int val;
+        MPI_Win_lock(MPI_LOCK_SHARED, 0, 0, win);
+        MPI_Put(srcbuf, 1, vectype, 0, 0, 10, MPI_INT, win);
+        MPI_Get(&val, 1, MPI_INT, 0, 10, 1, MPI_INT, win);
+        MPI_Win_unlock(0, win);
+        MPI_Barrier(MPI_COMM_WORLD);
+        if (val != -10) {
+            errs++;
+            printf("Get: Expected -10, got %d\n", val);
+        }
     }
     else {
-       MPI_Barrier( MPI_COMM_WORLD );
+        MPI_Barrier(MPI_COMM_WORLD);
     }
 
-    MPI_Win_free( &win );
-    MPI_Free_mem( rmabuf );
-    free( srcbuf );
-    MPI_Type_free( &vectype );
+    MPI_Win_free(&win);
+    MPI_Free_mem(rmabuf);
+    free(srcbuf);
+    MPI_Type_free(&vectype);
 
     MTest_Finalize(errs);
-    MPI_Finalize(); 
-    return 0; 
-} 
-
+    MPI_Finalize();
+    return 0;
+}
diff --git a/teshsuite/smpi/mpich3-test/rma/manyget.c b/teshsuite/smpi/mpich3-test/rma/manyget.c
new file mode 100644 (file)
index 0000000..2db4db0
--- /dev/null
@@ -0,0 +1,60 @@
+/* -*- Mode: C; c-basic-offset:4 ; indent-tabs-mode:nil ; -*- */
+/*
+ *  (C) 2015 by Argonne National Laboratory.
+ *      See COPYRIGHT in top-level directory.
+ */
+
+/* This test triggers a limitation in the Portals4 netmod where
+ * too many large messages can overflow the available ME entries
+ * (PTL_NO_SPACE). Our approach is to queue the entire send message
+ * in the Rportals layer until we know there is ME space available.
+ */
+#include <stdlib.h>
+#include <stdio.h>
+#include <mpi.h>
+#include "mpitest.h"
+
+#define BUFSIZE (32*1024)
+
+int main(int argc, char *argv[])
+{
+    int i, rank, size;
+    int *buf;
+    MPI_Win win;
+
+    MPI_Init(&argc, &argv);
+
+    buf = malloc(BUFSIZE);
+    MTEST_VG_MEM_INIT(buf, BUFSIZE);
+
+    MPI_Comm_rank(MPI_COMM_WORLD, &rank);
+    MPI_Comm_size(MPI_COMM_WORLD, &size);
+
+    if (size != 2) {
+        printf("test must be run with 2 processes!\n");
+        MPI_Abort(MPI_COMM_WORLD, 1);
+    }
+
+    if (rank == 0)
+        MPI_Win_create(buf, BUFSIZE, sizeof(int), MPI_INFO_NULL, MPI_COMM_WORLD, &win);
+    else
+        MPI_Win_create(MPI_BOTTOM, 0, 1, MPI_INFO_NULL, MPI_COMM_WORLD, &win);
+
+    MPI_Win_fence(0, win);
+
+    if (rank == 1) {
+        for (i = 0; i < 1000; i++)
+            MPI_Get(buf, BUFSIZE / sizeof(int), MPI_INT, 0, 0, BUFSIZE / sizeof(int), MPI_INT, win);
+    }
+
+    MPI_Win_fence(0, win);
+    MPI_Win_free(&win);
+
+    if (rank == 0)
+        printf(" No Errors\n");
+
+    free(buf);
+    MPI_Finalize();
+
+    return 0;
+}
index 571d29e..6773919 100644 (file)
@@ -17,7 +17,7 @@
 
 #define MAX_COUNT 65536*4/16
 #define MAX_RMA_SIZE 2  /* 16 in manyrma performance test */
-#define MAX_RUNS 10
+#define MAX_RUNS 8
 #define MAX_ITER_TIME  5.0      /* seconds */
 
 typedef enum { SYNC_NONE = 0,
@@ -112,6 +112,14 @@ int main(int argc, char *argv[])
     MPI_Group_free(&wgroup);
 
     arraysize = maxSz * MAX_COUNT;
+#ifdef USE_WIN_ALLOCATE
+    MPI_Win_allocate(arraysize * sizeof(int), (int) sizeof(int), MPI_INFO_NULL,
+                     MPI_COMM_WORLD, &arraybuffer, &win);
+    if (!arraybuffer) {
+        fprintf(stderr, "Unable to allocate %d words\n", arraysize);
+        MPI_Abort(MPI_COMM_WORLD, 1);
+    }
+#else
     arraybuffer = (int *) malloc(arraysize * sizeof(int));
     if (!arraybuffer) {
         fprintf(stderr, "Unable to allocate %d words\n", arraysize);
@@ -120,6 +128,7 @@ int main(int argc, char *argv[])
 
     MPI_Win_create(arraybuffer, arraysize * sizeof(int), (int) sizeof(int),
                    MPI_INFO_NULL, MPI_COMM_WORLD, &win);
+#endif
 
     if (maxCount > MAX_COUNT) {
         fprintf(stderr, "MaxCount must not exceed %d\n", MAX_COUNT);
@@ -212,6 +221,10 @@ int main(int argc, char *argv[])
 
     MPI_Win_free(&win);
 
+#ifndef USE_WIN_ALLOCATE
+    free(arraybuffer);
+#endif
+
     MPI_Group_free(&accessGroup);
     MPI_Group_free(&exposureGroup);
 
index 52a3bbf..a972a55 100644 (file)
@@ -39,7 +39,7 @@ int MCS_Mutex_create(int tail_rank, MPI_Comm comm, MCS_Mutex * hdl_out)
     hdl->tail_rank = tail_rank;
 
 #ifdef USE_WIN_SHARED
-    MPI_Win_allocate_shared(2*sizeof(int), sizeof(int), MPI_INFO_NULL,
+    MPI_Win_allocate_shared(2 * sizeof(int), sizeof(int), MPI_INFO_NULL,
                             hdl->comm, &hdl->base, &hdl->window);
 #else
 #ifdef USE_WIN_ALLOC_SHM
@@ -49,7 +49,7 @@ int MCS_Mutex_create(int tail_rank, MPI_Comm comm, MCS_Mutex * hdl_out)
     MPI_Info_create(&hdl->win_info);
     MPI_Info_set(hdl->win_info, "alloc_shm", "false");
 #endif
-    MPI_Win_allocate(2*sizeof(int), sizeof(int), hdl->win_info, hdl->comm,
+    MPI_Win_allocate(2 * sizeof(int), sizeof(int), hdl->win_info, hdl->comm,
                      &hdl->base, &hdl->window);
 #endif
 
@@ -119,7 +119,8 @@ int MCS_Mutex_lock(MCS_Mutex hdl)
         /* Wait for notification */
         MPI_Status status;
 
-        MPI_Accumulate(&rank, 1, MPI_INT, prev, MCS_MTX_ELEM_DISP, 1, MPI_INT, MPI_REPLACE, hdl->window);
+        MPI_Accumulate(&rank, 1, MPI_INT, prev, MCS_MTX_ELEM_DISP, 1, MPI_INT, MPI_REPLACE,
+                       hdl->window);
         MPI_Win_flush(prev, hdl->window);
 
         debug_print("%2d: LOCK   - waiting for notification from %d\n", rank, prev);
@@ -181,11 +182,10 @@ int MCS_Mutex_unlock(MCS_Mutex hdl)
 
     /* Read my next pointer.  FOP is used since another process may write to
      * this location concurrent with this read. */
-    MPI_Fetch_and_op(NULL, &next, MPI_INT, rank, MCS_MTX_ELEM_DISP, MPI_NO_OP,
-                     hdl->window);
+    MPI_Fetch_and_op(NULL, &next, MPI_INT, rank, MCS_MTX_ELEM_DISP, MPI_NO_OP, hdl->window);
     MPI_Win_flush(rank, hdl->window);
 
-    if ( next == MPI_PROC_NULL) {
+    if (next == MPI_PROC_NULL) {
         int tail;
         int nil = MPI_PROC_NULL;
 
@@ -206,10 +206,10 @@ int MCS_Mutex_unlock(MCS_Mutex hdl)
                                  MPI_NO_OP, hdl->window);
 
                 MPI_Win_flush(rank, hdl->window);
-                if (next != MPI_PROC_NULL) break;
+                if (next != MPI_PROC_NULL)
+                    break;
 
-                MPI_Iprobe(MPI_ANY_SOURCE, MPI_ANY_TAG, MPI_COMM_WORLD, &flag,
-                           MPI_STATUS_IGNORE);
+                MPI_Iprobe(MPI_ANY_SOURCE, MPI_ANY_TAG, MPI_COMM_WORLD, &flag, MPI_STATUS_IGNORE);
             }
         }
     }
index c558516..0bf63c3 100644 (file)
 static char MTEST_Descrip[] = "Mix synchronization types";
 */
 
-void delay( double time );
-void delay( double time )
+void delay(double time);
+void delay(double time)
 {
     double t1;
     t1 = MPI_Wtime();
-    while (MPI_Wtime() - t1 < time) ;
+    while (MPI_Wtime() - t1 < time);
 }
 
-int main( int argc, char *argv[] )
+int main(int argc, char *argv[])
 {
-    int      errs = 0;
-    int      crank, csize, source, dest, loop;
-    int      *buf0, *buf1, *buf2, *inbuf2, count0, count1, count2, count, i;
+    int errs = 0;
+    int crank, csize, source, dest, loop;
+    int *buf0, *buf1, *buf2, *inbuf2, count0, count1, count2, count, i;
     MPI_Comm comm;
-    MPI_Win  win;
-    int      *winbuf;
+    MPI_Win win;
+    int *winbuf;
 
-    MTest_Init( &argc, &argv );
+    MTest_Init(&argc, &argv);
 
     comm = MPI_COMM_WORLD;
 
@@ -40,205 +40,189 @@ int main( int argc, char *argv[] )
     count2 = 100;
 
     count = count0 + count1 + count2 + 2;
-    
+
     /* Allocate and initialize the local buffers */
-    buf0   = (int *)malloc( count0 * sizeof(int) );
-    buf1   = (int *)malloc( count1 * sizeof(int) );
-    buf2   = (int *)malloc( count2 * sizeof(int) );
-    inbuf2 = (int *)malloc( count2 * sizeof(int) );
+    buf0 = (int *) malloc(count0 * sizeof(int));
+    buf1 = (int *) malloc(count1 * sizeof(int));
+    buf2 = (int *) malloc(count2 * sizeof(int));
+    inbuf2 = (int *) malloc(count2 * sizeof(int));
     if (!buf0 || !buf1 || !buf2 || !inbuf2) {
-       fprintf( stderr, "Unable to allocated buf0-2\n" );
-       MPI_Abort( MPI_COMM_WORLD, 1 );
+        fprintf(stderr, "Unable to allocated buf0-2\n");
+        MPI_Abort(MPI_COMM_WORLD, 1);
     }
-    for (i=0; i<count0; i++) buf0[i] = i;
-    for (i=0; i<count1; i++) buf1[i] = i + count0;
-    for (i=0; i<count2; i++) buf2[i] = i + count0 + count1;
+    for (i = 0; i < count0; i++)
+        buf0[i] = i;
+    for (i = 0; i < count1; i++)
+        buf1[i] = i + count0;
+    for (i = 0; i < count2; i++)
+        buf2[i] = i + count0 + count1;
 
     /* Allocate the window buffer and create the memory window. */
-    MPI_Alloc_mem( count*sizeof(int), MPI_INFO_NULL, &winbuf );
+    MPI_Alloc_mem(count * sizeof(int), MPI_INFO_NULL, &winbuf);
     if (!winbuf) {
-       fprintf( stderr, "Unable to allocate %d words\n", count );
-       MPI_Abort( MPI_COMM_WORLD, 0 );
+        fprintf(stderr, "Unable to allocate %d words\n", count);
+        MPI_Abort(MPI_COMM_WORLD, 0);
     }
-    MPI_Win_create( winbuf, count*sizeof(int), sizeof(int), MPI_INFO_NULL, 
-                   comm, &win );
+    MPI_Win_create(winbuf, count * sizeof(int), sizeof(int), MPI_INFO_NULL, comm, &win);
 
-    MPI_Comm_size( comm, &csize );
-    MPI_Comm_rank( comm, &crank );
-    dest   = 0;
+    MPI_Comm_size(comm, &csize);
+    MPI_Comm_rank(comm, &crank);
+    dest = 0;
     source = 1;
 
-    for (loop=0; loop<2; loop++) {
-       /* Perform several communication operations, mixing synchronization
-          types.  Use multiple communication to avoid the single-operation
-          optimization that may be present. */
-       MTestPrintfMsg( 3, "Beginning loop %d of mixed sync put operations\n", 
-                       loop ); 
-       MPI_Barrier( comm );
-       if (crank == source) {
-           MTestPrintfMsg( 3, "About to perform exclusive lock\n" );
-           MPI_Win_lock( MPI_LOCK_EXCLUSIVE, dest, 0, win );
-           MPI_Put( buf0, count0, MPI_INT, dest, 0, count0, MPI_INT, win );
-           MPI_Put( buf1, count1, MPI_INT, dest, count0, count1, MPI_INT, 
-                    win );
-           MPI_Put( buf2, count2, MPI_INT, dest, count0+count1, count2, 
-                    MPI_INT, win );
-           MPI_Win_unlock( dest, win );
-           MTestPrintfMsg( 3, "Released exclusive lock\n" );
-       }
-       else if (crank == dest) {
-           /* Just delay a bit */
-           delay( 0.0001 );
-       }
-
-       /* The synchronization mode can only be changed when the process 
-          memory and public copy are guaranteed to have the same values 
-          (See 11.7, Semantics and Correctness). This barrier ensures that 
-          the lock/unlock completes before the fence call.  */
-       MPI_Barrier( comm );
-
-       MTestPrintfMsg( 3, "About to start fence\n" );
-       MPI_Win_fence( 0, win );
-       if (crank == source) {
-           MPI_Put( buf0, count0, MPI_INT, dest, 1, count0, MPI_INT, win );
-           MPI_Put( buf1, count1, MPI_INT, dest, 1+count0, count1, MPI_INT, 
-                    win );
-           MPI_Put( buf2, count2, MPI_INT, dest, 1+count0+count1, count2, 
-                    MPI_INT, win );
-       }
-       MPI_Win_fence( 0, win );
-       MTestPrintfMsg( 3, "Finished with fence sync\n" );
-
-       /* Check results */
-       if (crank == dest) {
-           for (i=0; i<count0+count1+count2; i++) {
-               if (winbuf[1+i] != i) {
-                   errs++;
-                   if (errs < 10) {
-                       fprintf( stderr, "winbuf[%d] = %d, expected %d\n",
-                                1+i, winbuf[1+i], i ); fflush(stderr);
-                   }
-               }
-           }
-       }
-       
-       /* End of test loop */
+    for (loop = 0; loop < 2; loop++) {
+        /* Perform several communication operations, mixing synchronization
+         * types.  Use multiple communication to avoid the single-operation
+         * optimization that may be present. */
+        MTestPrintfMsg(3, "Beginning loop %d of mixed sync put operations\n", loop);
+        MPI_Barrier(comm);
+        if (crank == source) {
+            MTestPrintfMsg(3, "About to perform exclusive lock\n");
+            MPI_Win_lock(MPI_LOCK_EXCLUSIVE, dest, 0, win);
+            MPI_Put(buf0, count0, MPI_INT, dest, 0, count0, MPI_INT, win);
+            MPI_Put(buf1, count1, MPI_INT, dest, count0, count1, MPI_INT, win);
+            MPI_Put(buf2, count2, MPI_INT, dest, count0 + count1, count2, MPI_INT, win);
+            MPI_Win_unlock(dest, win);
+            MTestPrintfMsg(3, "Released exclusive lock\n");
+        }
+        else if (crank == dest) {
+            /* Just delay a bit */
+            delay(0.0001);
+        }
+
+        /* The synchronization mode can only be changed when the process
+         * memory and public copy are guaranteed to have the same values
+         * (See 11.7, Semantics and Correctness). This barrier ensures that
+         * the lock/unlock completes before the fence call.  */
+        MPI_Barrier(comm);
+
+        MTestPrintfMsg(3, "About to start fence\n");
+        MPI_Win_fence(0, win);
+        if (crank == source) {
+            MPI_Put(buf0, count0, MPI_INT, dest, 1, count0, MPI_INT, win);
+            MPI_Put(buf1, count1, MPI_INT, dest, 1 + count0, count1, MPI_INT, win);
+            MPI_Put(buf2, count2, MPI_INT, dest, 1 + count0 + count1, count2, MPI_INT, win);
+        }
+        MPI_Win_fence(0, win);
+        MTestPrintfMsg(3, "Finished with fence sync\n");
+
+        /* Check results */
+        if (crank == dest) {
+            for (i = 0; i < count0 + count1 + count2; i++) {
+                if (winbuf[1 + i] != i) {
+                    errs++;
+                    if (errs < 10) {
+                        fprintf(stderr, "winbuf[%d] = %d, expected %d\n", 1 + i, winbuf[1 + i], i);
+                        fflush(stderr);
+                    }
+                }
+            }
+        }
+
+        /* End of test loop */
     }
 
     /* Use mixed put and accumulate */
-    for (loop=0; loop<2; loop++) {
-       /* Perform several communication operations, mixing synchronization
-          types.  Use multiple communication to avoid the single-operation
-          optimization that may be present. */
-       MTestPrintfMsg( 3, "Begining loop %d of mixed sync put/acc operations\n", 
-                       loop ); 
-       memset( winbuf, 0, count*sizeof(int) );
-       MPI_Barrier( comm );
-       if (crank == source) {
-           MPI_Win_lock( MPI_LOCK_EXCLUSIVE, dest, 0, win );
-           MPI_Accumulate( buf0, count0, MPI_INT, dest, 0, count0, MPI_INT, 
-                           MPI_SUM, win );
-           MPI_Accumulate( buf1, count1, MPI_INT, dest, count0, count1, 
-                           MPI_INT, MPI_SUM, win );
-           MPI_Put( buf2, count2, MPI_INT, dest, count0+count1, count2, 
-                    MPI_INT, win );
-           MPI_Win_unlock( dest, win );
-       }
-       else if (crank == dest) {
-           /* Just delay a bit */
-           delay( 0.0001 );
-       }
-       /* See above - the fence should not start until the unlock completes */
-       MPI_Barrier( comm );
-       MPI_Win_fence( 0, win );
-       if (crank == source) {
-           MPI_Accumulate( buf0, count0, MPI_INT, dest, 1, count0, MPI_INT, 
-                           MPI_REPLACE, win );
-           MPI_Accumulate( buf1, count1, MPI_INT, dest, 1+count0, count1, 
-                           MPI_INT, MPI_REPLACE, win );
-           MPI_Put( buf2, count2, MPI_INT, dest, 1+count0+count1, count2, 
-                    MPI_INT, win );
-       }
-       MPI_Win_fence( 0, win );
-
-       /* Check results */
-       if (crank == dest) {
-           for (i=0; i<count0+count1+count2; i++) {
-               if (winbuf[1+i] != i) {
-                   errs++;
-                   if (errs < 10) {
-                       fprintf( stderr, "winbuf[%d] = %d, expected %d\n",
-                                1+i, winbuf[1+i], i ); fflush(stderr);
-                   }
-               }
-           }
-       }
-       
-       /* End of test loop */
+    for (loop = 0; loop < 2; loop++) {
+        /* Perform several communication operations, mixing synchronization
+         * types.  Use multiple communication to avoid the single-operation
+         * optimization that may be present. */
+        MTestPrintfMsg(3, "Begining loop %d of mixed sync put/acc operations\n", loop);
+        memset(winbuf, 0, count * sizeof(int));
+        MPI_Barrier(comm);
+        if (crank == source) {
+            MPI_Win_lock(MPI_LOCK_EXCLUSIVE, dest, 0, win);
+            MPI_Accumulate(buf0, count0, MPI_INT, dest, 0, count0, MPI_INT, MPI_SUM, win);
+            MPI_Accumulate(buf1, count1, MPI_INT, dest, count0, count1, MPI_INT, MPI_SUM, win);
+            MPI_Put(buf2, count2, MPI_INT, dest, count0 + count1, count2, MPI_INT, win);
+            MPI_Win_unlock(dest, win);
+        }
+        else if (crank == dest) {
+            /* Just delay a bit */
+            delay(0.0001);
+        }
+        /* See above - the fence should not start until the unlock completes */
+        MPI_Barrier(comm);
+        MPI_Win_fence(0, win);
+        if (crank == source) {
+            MPI_Accumulate(buf0, count0, MPI_INT, dest, 1, count0, MPI_INT, MPI_REPLACE, win);
+            MPI_Accumulate(buf1, count1, MPI_INT, dest, 1 + count0, count1,
+                           MPI_INT, MPI_REPLACE, win);
+            MPI_Put(buf2, count2, MPI_INT, dest, 1 + count0 + count1, count2, MPI_INT, win);
+        }
+        MPI_Win_fence(0, win);
+
+        /* Check results */
+        if (crank == dest) {
+            for (i = 0; i < count0 + count1 + count2; i++) {
+                if (winbuf[1 + i] != i) {
+                    errs++;
+                    if (errs < 10) {
+                        fprintf(stderr, "winbuf[%d] = %d, expected %d\n", 1 + i, winbuf[1 + i], i);
+                        fflush(stderr);
+                    }
+                }
+            }
+        }
+
+        /* End of test loop */
     }
 
     /* Use mixed accumulate and get */
-    for (loop=0; loop<2; loop++) {
-       /* Perform several communication operations, mixing synchronization
-          types.  Use multiple communication to avoid the single-operation
-          optimization that may be present. */
-       MTestPrintfMsg( 3, "Begining loop %d of mixed sync put/get/acc operations\n", 
-                       loop ); 
-       MPI_Barrier( comm );
-       if (crank == source) {
-           MPI_Win_lock( MPI_LOCK_EXCLUSIVE, dest, 0, win );
-           MPI_Accumulate( buf0, count0, MPI_INT, dest, 0, count0, MPI_INT, 
-                           MPI_REPLACE, win );
-           MPI_Put( buf1, count1, MPI_INT, dest, count0, count1, MPI_INT, 
-                    win );
-           MPI_Get( inbuf2, count2, MPI_INT, dest, count0+count1, count2, 
-                    MPI_INT, win );
-           MPI_Win_unlock( dest, win );
-       }
-       else if (crank == dest) {
-           /* Just delay a bit */
-           delay( 0.0001 );
-       }
-       /* See above - the fence should not start until the unlock completes */
-       MPI_Barrier( comm );
-       MPI_Win_fence( 0, win );
-       if (crank == source) {
-           MPI_Accumulate( buf0, count0, MPI_INT, dest, 1, count0, MPI_INT, 
-                           MPI_REPLACE, win );
-           MPI_Put( buf1, count1, MPI_INT, dest, 1+count0, count1, MPI_INT, 
-                    win );
-           MPI_Get( inbuf2, count2, MPI_INT, dest, 1+count0+count1, count2, 
-                    MPI_INT, win );
-       }
-       MPI_Win_fence( 0, win );
-
-       /* Check results */
-       if (crank == dest) {
-           /* Do the put/accumulate parts */
-           for (i=0; i<count0+count1; i++) {
-               if (winbuf[1+i] != i) {
-                   errs++;
-                   if (errs < 10) {
-                       fprintf( stderr, "winbuf[%d] = %d, expected %d\n",
-                                1+i, winbuf[1+i], i ); fflush(stderr);
-                   }
-               }
-           }
-       }
-       
-       /* End of test loop */
+    for (loop = 0; loop < 2; loop++) {
+        /* Perform several communication operations, mixing synchronization
+         * types.  Use multiple communication to avoid the single-operation
+         * optimization that may be present. */
+        MTestPrintfMsg(3, "Begining loop %d of mixed sync put/get/acc operations\n", loop);
+        MPI_Barrier(comm);
+        if (crank == source) {
+            MPI_Win_lock(MPI_LOCK_EXCLUSIVE, dest, 0, win);
+            MPI_Accumulate(buf0, count0, MPI_INT, dest, 0, count0, MPI_INT, MPI_REPLACE, win);
+            MPI_Put(buf1, count1, MPI_INT, dest, count0, count1, MPI_INT, win);
+            MPI_Get(inbuf2, count2, MPI_INT, dest, count0 + count1, count2, MPI_INT, win);
+            MPI_Win_unlock(dest, win);
+        }
+        else if (crank == dest) {
+            /* Just delay a bit */
+            delay(0.0001);
+        }
+        /* See above - the fence should not start until the unlock completes */
+        MPI_Barrier(comm);
+        MPI_Win_fence(0, win);
+        if (crank == source) {
+            MPI_Accumulate(buf0, count0, MPI_INT, dest, 1, count0, MPI_INT, MPI_REPLACE, win);
+            MPI_Put(buf1, count1, MPI_INT, dest, 1 + count0, count1, MPI_INT, win);
+            MPI_Get(inbuf2, count2, MPI_INT, dest, 1 + count0 + count1, count2, MPI_INT, win);
+        }
+        MPI_Win_fence(0, win);
+
+        /* Check results */
+        if (crank == dest) {
+            /* Do the put/accumulate parts */
+            for (i = 0; i < count0 + count1; i++) {
+                if (winbuf[1 + i] != i) {
+                    errs++;
+                    if (errs < 10) {
+                        fprintf(stderr, "winbuf[%d] = %d, expected %d\n", 1 + i, winbuf[1 + i], i);
+                        fflush(stderr);
+                    }
+                }
+            }
+        }
+
+        /* End of test loop */
     }
 
-    MTestPrintfMsg( 3, "Freeing the window\n" );
-    MPI_Barrier( comm );
-    MPI_Win_free( &win );
-    MPI_Free_mem( winbuf );
-    free( buf0 );
-    free( buf1 );
-    free( buf2 );
-    free( inbuf2 );
+    MTestPrintfMsg(3, "Freeing the window\n");
+    MPI_Barrier(comm);
+    MPI_Win_free(&win);
+    MPI_Free_mem(winbuf);
+    free(buf0);
+    free(buf1);
+    free(buf2);
+    free(inbuf2);
 
-    MTest_Finalize( errs );
+    MTest_Finalize(errs);
 
     MPI_Finalize();
     return 0;
index 4eeaba5..a5cf508 100644 (file)
@@ -5,11 +5,6 @@
  *      See COPYRIGHT in top-level directory.
  */
 
-/** MPI Mutex test -- James Dinan <dinan@mcs.anl.gov>
-  *
-  * All processes create a mutex then lock+unlock it N times.
-  */
-
 #include <stdio.h>
 #include <stdlib.h>
 #include <assert.h>
 const int verbose = 0;
 double delay_ctr = 0.0;
 
-int main(int argc, char ** argv) {
-  int rank, nproc, i;
-  double t_mpix_mtx, t_mcs_mtx;
-  MPI_Comm mtx_comm;
-  MCS_Mutex mcs_mtx;
+int main(int argc, char **argv)
+{
+    int rank, nproc, i;
+    double t_mcs_mtx;
+    MPI_Comm mtx_comm;
+    MCS_Mutex mcs_mtx;
 
-  MPI_Init(&argc, &argv);
+    MPI_Init(&argc, &argv);
 
-  MPI_Comm_rank(MPI_COMM_WORLD, &rank);
-  MPI_Comm_size(MPI_COMM_WORLD, &nproc);
+    MPI_Comm_rank(MPI_COMM_WORLD, &rank);
+    MPI_Comm_size(MPI_COMM_WORLD, &nproc);
 
 #ifdef USE_WIN_SHARED
-  MPI_Comm_split_type(MPI_COMM_WORLD, MPI_COMM_TYPE_SHARED, rank,
-                      MPI_INFO_NULL, &mtx_comm);
+    MPI_Comm_split_type(MPI_COMM_WORLD, MPI_COMM_TYPE_SHARED, rank, MPI_INFO_NULL, &mtx_comm);
 #else
-  mtx_comm = MPI_COMM_WORLD;
+    mtx_comm = MPI_COMM_WORLD;
 #endif
 
-  MCS_Mutex_create(0, mtx_comm, &mcs_mtx);
+    MCS_Mutex_create(0, mtx_comm, &mcs_mtx);
 
-  MPI_Barrier(MPI_COMM_WORLD);
-  t_mcs_mtx = MPI_Wtime();
+    MPI_Barrier(MPI_COMM_WORLD);
+    t_mcs_mtx = MPI_Wtime();
 
-  for (i = 0; i < NUM_ITER; i++) {
-    /* Combining trylock and lock here is helpful for testing because it makes
-     * CAS and Fetch-and-op contend for the tail pointer. */
-    if (rank % 2) {
-      int success = 0;
-      while (!success) {
-        MCS_Mutex_trylock(mcs_mtx, &success);
-      }
-    }
-    else {
-        MCS_Mutex_lock(mcs_mtx);
+    for (i = 0; i < NUM_ITER; i++) {
+        /* Combining trylock and lock here is helpful for testing because it makes
+         * CAS and Fetch-and-op contend for the tail pointer. */
+#ifdef USE_CONTIGUOUS_RANK
+        if (rank < nproc / 2) {
+#else
+        if (rank % 2) {
+#endif
+            int success = 0;
+            while (!success) {
+                MCS_Mutex_trylock(mcs_mtx, &success);
+            }
+        }
+        else {
+            MCS_Mutex_lock(mcs_mtx);
+        }
+        MCS_Mutex_unlock(mcs_mtx);
     }
-    MCS_Mutex_unlock(mcs_mtx);
-  }
 
-  MPI_Barrier(MPI_COMM_WORLD);
-  t_mcs_mtx = MPI_Wtime() - t_mcs_mtx;
+    MPI_Barrier(MPI_COMM_WORLD);
+    t_mcs_mtx = MPI_Wtime() - t_mcs_mtx;
 
-  MCS_Mutex_free(&mcs_mtx);
+    MCS_Mutex_free(&mcs_mtx);
 
-  if (rank == 0) {
-      if (verbose) {
-          printf("Nproc %d, MCS Mtx = %f us\n", nproc, t_mcs_mtx/NUM_ITER*1.0e6);
-      }
-  }
+    if (rank == 0) {
+        if (verbose) {
+            printf("Nproc %d, MCS Mtx = %f us\n", nproc, t_mcs_mtx / NUM_ITER * 1.0e6);
+        }
+    }
 
-  if (mtx_comm != MPI_COMM_WORLD)
-      MPI_Comm_free(&mtx_comm);
+    if (mtx_comm != MPI_COMM_WORLD)
+        MPI_Comm_free(&mtx_comm);
 
-  MTest_Finalize(0);
-  MPI_Finalize();
+    MTest_Finalize(0);
+    MPI_Finalize();
 
-  return 0;
+    return 0;
 }
diff --git a/teshsuite/smpi/mpich3-test/rma/nb_test.c b/teshsuite/smpi/mpich3-test/rma/nb_test.c
new file mode 100644 (file)
index 0000000..5cebc68
--- /dev/null
@@ -0,0 +1,42 @@
+/* -*- Mode: C; c-basic-offset:4 ; indent-tabs-mode:nil ; -*- */
+/*
+ *  (C) 2001 by Argonne National Laboratory.
+ *      See COPYRIGHT in top-level directory.
+ */
+#include <stdio.h>
+#include <mpi.h>
+#include <mpitest.h>
+
+int main(int argc, char *argv[])
+{
+    MPI_Win win;
+    int flag, tmp, rank;
+    int base[1024], errs = 0;
+    MPI_Request req;
+
+    MTest_Init(&argc, &argv);
+    MPI_Comm_rank(MPI_COMM_WORLD, &rank);
+
+    MPI_Win_create(base, 1024 * sizeof(int), sizeof(int), MPI_INFO_NULL, MPI_COMM_WORLD, &win);
+
+    if (rank == 0) {
+        MPI_Win_lock(MPI_LOCK_EXCLUSIVE, 0, 0, win);
+        MPI_Barrier(MPI_COMM_WORLD);
+        MPI_Barrier(MPI_COMM_WORLD);
+        MPI_Win_unlock(0, win);
+    }
+    else {
+        MPI_Barrier(MPI_COMM_WORLD);
+        MPI_Win_lock(MPI_LOCK_EXCLUSIVE, 0, 0, win);
+        MPI_Rput(&tmp, 1, MPI_INT, 0, 0, 1, MPI_INT, win, &req);
+        MPI_Test(&req, &flag, MPI_STATUS_IGNORE);
+        MPI_Barrier(MPI_COMM_WORLD);
+        MPI_Win_unlock(0, win);
+    }
+
+    MPI_Win_free(&win);
+
+    MTest_Finalize(errs);
+    MPI_Finalize();
+    return 0;
+}
index c5b1342..fa87000 100644 (file)
@@ -7,28 +7,33 @@
 #include <mpi.h>
 #include "mpitest.h"
 
-int main(int argc, charargv[])
+int main(int argc, char *argv[])
 {
-  MPI_Win win;
-  MPI_Group group;
-  int errs = 0;
-
-  MTest_Init(&argc,&argv); 
-
-  MPI_Win_create(NULL, 0, 1, MPI_INFO_NULL, MPI_COMM_WORLD, &win);
-  MPI_Win_get_group(win, &group);
-  
-  MPI_Win_post(group, 0, win);
-  MPI_Win_start(group, 0, win);
-  
-  MPI_Win_complete(win);
-  
-  MPI_Win_wait(win);
-
-  MPI_Group_free( &group );
-  MPI_Win_free(&win); 
-
-  MTest_Finalize(errs);
-  MPI_Finalize();
-  return 0;
+    MPI_Win win;
+    MPI_Group group;
+    int errs = 0;
+
+    MTest_Init(&argc, &argv);
+
+#ifdef USE_WIN_ALLOCATE
+    char *baseptr;
+    MPI_Win_allocate(0, 1, MPI_INFO_NULL, MPI_COMM_WORLD, &baseptr, &win);
+#else
+    MPI_Win_create(NULL, 0, 1, MPI_INFO_NULL, MPI_COMM_WORLD, &win);
+#endif
+    MPI_Win_get_group(win, &group);
+
+    MPI_Win_post(group, 0, win);
+    MPI_Win_start(group, 0, win);
+
+    MPI_Win_complete(win);
+
+    MPI_Win_wait(win);
+
+    MPI_Group_free(&group);
+    MPI_Win_free(&win);
+
+    MTest_Finalize(errs);
+    MPI_Finalize();
+    return 0;
 }
diff --git a/teshsuite/smpi/mpich3-test/rma/overlap_wins_rma.c b/teshsuite/smpi/mpich3-test/rma/overlap_wins_rma.c
new file mode 100644 (file)
index 0000000..9ccdeef
--- /dev/null
@@ -0,0 +1,304 @@
+/* -*- Mode: C; c-basic-offset:4 ; indent-tabs-mode:nil ; -*- */
+/*
+ *
+ *  (C) 2016 by Argonne National Laboratory.
+ *      See COPYRIGHT in top-level directory.
+ */
+
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+#include <mpi.h>
+
+/* This test checks the remote completion of flush with RMA write-like operations
+ * (PUT, ACC, GET_ACC, FOP, CAS) concurrently issued from different origin processes
+ * to the same target over overlapping windows (i.e., two windows exposing the same
+ * memory region)
+ * 1. The first [nprocs-1] processes perform as origin, and the last process
+ *    performs as target.
+ * 2. Everyone allocates a buffer and creates [nprocs-1] windows over the same buffer.
+ * 3. Every origin P[i] issues RMA operations and flush to target through
+ *    wins[i] respectively, to different location winbuf[i] on target.
+ * 4. Finally, every origin P[i] issues GET and flush to obtain winbuf[i] on
+ *    target and checks the correctness. */
+
+#define ITER 10
+#define BUF_CNT 2
+
+#if defined(TEST_CAS)
+#define MPI_DATATYPE MPI_INT
+#define DATATYPE int
+#define DATATYPE_FORMAT "%d"
+#else
+#define MPI_DATATYPE MPI_DOUBLE
+#define DATATYPE double
+#define DATATYPE_FORMAT "%.1f"
+#endif
+
+DATATYPE local_buf[BUF_CNT], result_buf[BUF_CNT], compare_buf[BUF_CNT];
+DATATYPE exp_target_val = 0.0;
+
+const int verbose = 0;
+
+int rank = -1, nprocs = 0;
+int norigins, target;
+MPI_Win *wins;
+int win_size = 0, win_cnt = 0;
+
+DATATYPE *winbuf = NULL, *my_base = NULL;
+
+#define verbose_print(str,...) {                        \
+            if (verbose) {                               \
+                fprintf(stdout, str, ## __VA_ARGS__);   \
+                fflush(stdout);                         \
+            }                                           \
+        }
+#define error_print(str,...) {                        \
+            fprintf(stderr, str, ## __VA_ARGS__);   \
+            fflush(stderr);                         \
+        }
+
+/* Define operation name for error message */
+#ifdef TEST_PUT
+const char *rma_name = "Put";
+#elif defined(TEST_ACC)
+const char *rma_name = "Accumulate";
+#elif defined(TEST_GACC)
+const char *rma_name = "Get_accumulate";
+#elif defined(TEST_FOP)
+const char *rma_name = "Fetch_and_op";
+#elif defined(TEST_CAS)
+const char *rma_name = "Compare_and_swap";
+#else
+const char *rma_name = "None";
+#endif
+
+/* Issue functions for different RMA operations */
+#ifdef TEST_PUT
+static inline void issue_rma_op(DATATYPE * origin_addr, DATATYPE * result_addr /* NULL */ ,
+                                DATATYPE * compare_addr /* NULL */ , int dst, MPI_Aint target_disp,
+                                MPI_Win win)
+{
+    MPI_Put(origin_addr, 1, MPI_DATATYPE, dst, target_disp, 1, MPI_DATATYPE, win);
+}
+#elif defined(TEST_ACC)
+static inline void issue_rma_op(DATATYPE * origin_addr, DATATYPE * result_addr /* NULL */ ,
+                                DATATYPE * compare_addr /* NULL */ , int dst, MPI_Aint target_disp,
+                                MPI_Win win)
+{
+    MPI_Accumulate(origin_addr, 1, MPI_DATATYPE, dst, target_disp, 1, MPI_DATATYPE, MPI_SUM, win);
+}
+#elif defined(TEST_GACC)
+static inline void issue_rma_op(DATATYPE * origin_addr, DATATYPE * result_addr,
+                                DATATYPE * compare_addr /* NULL */ , int dst, MPI_Aint target_disp,
+                                MPI_Win win)
+{
+    MPI_Get_accumulate(origin_addr, 1, MPI_DATATYPE, result_addr, 1, MPI_DATATYPE, dst, target_disp,
+                       1, MPI_DATATYPE, MPI_SUM, win);
+}
+#elif defined(TEST_FOP)
+static inline void issue_rma_op(DATATYPE * origin_addr, DATATYPE * result_addr,
+                                DATATYPE * compare_addr /* NULL */ , int dst, MPI_Aint target_disp,
+                                MPI_Win win)
+{
+    MPI_Fetch_and_op(origin_addr, result_addr, MPI_DATATYPE, dst, target_disp, MPI_SUM, win);
+}
+#elif defined(TEST_CAS)
+static inline void issue_rma_op(DATATYPE * origin_addr, DATATYPE * result_addr,
+                                DATATYPE * compare_addr, int dst, MPI_Aint target_disp, MPI_Win win)
+{
+    MPI_Compare_and_swap(origin_addr, compare_addr, result_addr, MPI_DATATYPE, dst, target_disp,
+                         win);
+}
+#else
+#define issue_rma_op(loc_addr, result_addr, compare_addr, dst, target_disp, win)
+#endif
+
+static inline void set_iteration_data(int x)
+{
+    int i;
+
+#if defined(TEST_CAS)
+    for (i = 0; i < BUF_CNT; i++)
+        compare_buf[i] = local_buf[i];  /* always equal, thus swap happens */
+#endif
+
+    for (i = 0; i < BUF_CNT; i++) {
+        local_buf[i] = rank + i + x;
+
+#if defined(TEST_CAS) || defined(TEST_PUT)
+        exp_target_val = local_buf[i];  /* swap */
+#else
+        exp_target_val += local_buf[i]; /* sum */
+#endif
+    }
+}
+
+static void print_origin_data(void)
+{
+    int i;
+
+    printf("[%d] local_buf: ", rank);
+    for (i = 0; i < BUF_CNT; i++)
+        printf(DATATYPE_FORMAT " ", local_buf[i]);
+    printf("\n");
+
+    printf("[%d] result_buf: ", rank);
+    for (i = 0; i < BUF_CNT; i++)
+        printf(DATATYPE_FORMAT " ", result_buf[i]);
+    printf("\n");
+}
+
+static void print_target_data(void)
+{
+    int i;
+    printf("[%d] winbuf: ", rank);
+    for (i = 0; i < win_cnt; i++)
+        printf(DATATYPE_FORMAT " ", winbuf[i]);
+    printf("\n");
+    fflush(stdout);
+}
+
+static int run_test()
+{
+    int errors = 0;
+    int i, x;
+    int dst = 0, target_disp = 0;
+    MPI_Win win = MPI_WIN_NULL;
+    DATATYPE target_val = 0.0;
+
+    /* 1. Specify working window and displacement.
+     *  - Target:  no RMA issued, always check results on wins[0].
+     *  - Origins: issue RMA on different window and different memory location */
+    if (rank == target) {
+        win = wins[0];
+    }
+    else {
+        win = wins[rank];
+        target_disp = rank;
+    }
+    dst = target;
+
+    /* 2. Every one resets local data */
+    memset(local_buf, 0, sizeof(local_buf));
+    memset(result_buf, 0, sizeof(result_buf));
+    memset(compare_buf, 0, sizeof(compare_buf));
+
+    MPI_Barrier(MPI_COMM_WORLD);
+
+    if (rank != target) {
+
+        /* 3. Origins issue RMA to target over its working window */
+        MPI_Win_lock(MPI_LOCK_SHARED, dst, 0, win);
+        verbose_print("[%d] RMA start, test %s (dst=%d, target_disp=%d, win 0x%x) - flush\n",
+                      rank, rma_name, dst, target_disp, win);
+
+        for (x = 0; x < ITER; x++) {
+            /* update local buffers and expected value in every iteration */
+            set_iteration_data(x);
+
+            for (i = 0; i < BUF_CNT; i++)
+                issue_rma_op(&local_buf[i], &result_buf[i], &compare_buf[i], dst, target_disp, win);
+            MPI_Win_flush(dst, win);
+
+            if (verbose)
+                print_origin_data();
+        }
+
+        /* 4. Check correctness of final target value */
+        MPI_Get(&target_val, 1, MPI_DATATYPE, dst, target_disp, 1, MPI_DATATYPE, win);
+        MPI_Win_flush(dst, win);
+        if (target_val != exp_target_val) {
+            error_print("rank %d (iter %d) - check %s, got target_val = "
+                        DATATYPE_FORMAT ", expected " DATATYPE_FORMAT "\n", rank, x,
+                        rma_name, target_val, exp_target_val);
+            errors++;
+        }
+
+        MPI_Win_unlock(dst, win);
+    }
+
+    MPI_Barrier(MPI_COMM_WORLD);
+
+    /* 5. Every one prints window buffer */
+    if (verbose && rank == target) {
+        MPI_Win_lock(MPI_LOCK_SHARED, rank, 0, win);
+        print_target_data();
+        MPI_Win_unlock(rank, win);
+    }
+
+    return errors;
+}
+
+static void init_windows(void)
+{
+    int i = 0;
+
+    /* Everyone creates norigins overlapping windows. */
+    winbuf = malloc(win_size);
+    memset(winbuf, 0, win_size);
+
+    wins = malloc(norigins * sizeof(MPI_Win));
+    for (i = 0; i < norigins; i++) {
+        wins[i] = MPI_WIN_NULL;
+        MPI_Win_create(winbuf, win_size, sizeof(DATATYPE), MPI_INFO_NULL, MPI_COMM_WORLD, &wins[i]);
+    }
+}
+
+static void destroy_windows(void)
+{
+    int i = 0;
+    for (i = 0; i < norigins; i++) {
+        if (wins[i] != MPI_WIN_NULL)
+            MPI_Win_free(&wins[i]);
+    }
+    free(wins);
+    free(winbuf);
+}
+
+int main(int argc, char *argv[])
+{
+    int errors = 0, all_errors = 0;
+
+    MPI_Init(&argc, &argv);
+    MPI_Comm_rank(MPI_COMM_WORLD, &rank);
+    MPI_Comm_size(MPI_COMM_WORLD, &nprocs);
+
+    if (nprocs < 3) {
+        if (rank == 0) {
+            error_print("Error: must use at least 3 processes\n");
+        }
+        MPI_Barrier(MPI_COMM_WORLD);
+        MPI_Abort(MPI_COMM_WORLD, 1);
+    }
+
+    /* The last rank performs as target, all others are origin.
+     * Every origin accesses to a different memory location on the target. */
+    target = nprocs - 1;
+    norigins = nprocs - 1;
+    win_cnt = nprocs - 1;
+    win_size = sizeof(DATATYPE) * win_cnt;
+
+    if (rank == 0) {
+        verbose_print("[%d] %d origins, target rank = %d\n", rank, norigins, target);
+    }
+
+    init_windows();
+    MPI_Barrier(MPI_COMM_WORLD);
+
+    /* start test */
+    errors = run_test();
+
+    MPI_Barrier(MPI_COMM_WORLD);
+    MPI_Reduce(&errors, &all_errors, 1, MPI_INT, MPI_SUM, 0, MPI_COMM_WORLD);
+
+    if (rank == 0 && all_errors == 0) {
+        fprintf(stdout, " No Errors\n");
+        fflush(stdout);
+    }
+
+    destroy_windows();
+    MPI_Finalize();
+
+    return 0;
+}
index 9cb1cee..5df4126 100644 (file)
@@ -18,7 +18,8 @@
 #include "mpitest.h"
 #include "squelch.h"
 
-int main(int argc, char **argv) {
+int main(int argc, char **argv)
+{
     int i, rank, nproc, errors = 0;
 
     int *win_buf;
@@ -42,16 +43,16 @@ int main(int argc, char **argv) {
     /* Set up odd/even groups and buffers */
 
     odd_nproc = nproc / 2;
-    even_nproc  = nproc / 2 + ( (nproc % 2 == 0) ? 0 : 1 );
+    even_nproc = nproc / 2 + ((nproc % 2 == 0) ? 0 : 1);
 
     odd_ranks = malloc(sizeof(int) * odd_nproc);
     even_ranks = malloc(sizeof(int) * even_nproc);
 
     for (i = 0; i < even_nproc; i++)
-        even_ranks[i] = i*2;
+        even_ranks[i] = i * 2;
 
     for (i = 0; i < odd_nproc; i++)
-        odd_ranks[i] = i*2+1;
+        odd_ranks[i] = i * 2 + 1;
 
     MPI_Comm_group(MPI_COMM_WORLD, &world_group);
     MPI_Group_incl(world_group, odd_nproc, odd_ranks, &odd_group);
@@ -59,27 +60,31 @@ int main(int argc, char **argv) {
 
     /* Create the window */
 
-    MPI_Alloc_mem(nproc*sizeof(int), MPI_INFO_NULL, &win_buf);
-
+#ifdef USE_WIN_ALLOCATE
+    MPI_Win_allocate(nproc * sizeof(int), sizeof(int), MPI_INFO_NULL,
+                     MPI_COMM_WORLD, &win_buf, &win);
+#else
+    MPI_Alloc_mem(nproc * sizeof(int), MPI_INFO_NULL, &win_buf);
+    MPI_Win_create(win_buf, nproc * sizeof(int), sizeof(int), MPI_INFO_NULL, MPI_COMM_WORLD, &win);
+#endif
+    MPI_Win_lock(MPI_LOCK_SHARED, rank, 0, win);
     for (i = 0; i < nproc; i++)
         win_buf[i] = -1;
-
-    MPI_Win_create(win_buf, nproc*sizeof(int), sizeof(int), MPI_INFO_NULL,
-                   MPI_COMM_WORLD, &win);
+    MPI_Win_unlock(rank, win);
 
     /* Perform PSCW communication: Odd/even matchup */
 
     if (rank % 2 == 0) {
-        MPI_Win_start(odd_group, 0, win);  /* Even-numbered procs target odd procs */
-        MPI_Win_post(odd_group, 0, win);   /* Even procs are targeted by odd procs */
+        MPI_Win_start(odd_group, 0, win);       /* Even-numbered procs target odd procs */
+        MPI_Win_post(odd_group, 0, win);        /* Even procs are targeted by odd procs */
 
         /* Write to my slot at each target */
         for (i = 0; i < odd_nproc; i++)
             MPI_Put(&rank, 1, MPI_INT, odd_ranks[i], rank, 1, MPI_INT, win);
     }
     else {
-        MPI_Win_post(even_group, 0, win);  /* Odd procs are targeted by even procs */
-        MPI_Win_start(even_group, 0, win); /* Odd-numbered procs target even procs */
+        MPI_Win_post(even_group, 0, win);       /* Odd procs are targeted by even procs */
+        MPI_Win_start(even_group, 0, win);      /* Odd-numbered procs target even procs */
 
         /* Write to my slot at each target */
         for (i = 0; i < even_nproc; i++)
@@ -93,16 +98,16 @@ int main(int argc, char **argv) {
     /* Perform PSCW communication: Odd/odd and even/even matchup */
 
     if (rank % 2 == 0) {
-        MPI_Win_post(even_group, 0, win);  /* Even procs are targeted by even procs */
-        MPI_Win_start(even_group, 0, win); /* Even-numbered procs target even procs */
+        MPI_Win_post(even_group, 0, win);       /* Even procs are targeted by even procs */
+        MPI_Win_start(even_group, 0, win);      /* Even-numbered procs target even procs */
 
         /* Write to my slot at each target */
         for (i = 0; i < even_nproc; i++)
             MPI_Put(&rank, 1, MPI_INT, even_ranks[i], rank, 1, MPI_INT, win);
     }
     else {
-        MPI_Win_post(odd_group, 0, win);   /* Odd procs are targeted by odd procs */
-        MPI_Win_start(odd_group, 0, win);  /* Odd-numbered procs target odd procs */
+        MPI_Win_post(odd_group, 0, win);        /* Odd procs are targeted by odd procs */
+        MPI_Win_start(odd_group, 0, win);       /* Odd-numbered procs target odd procs */
 
         /* Write to my slot at each target */
         for (i = 0; i < odd_nproc; i++)
@@ -117,14 +122,15 @@ int main(int argc, char **argv) {
         if (win_buf[i] != i) {
             errors++;
 
-            SQUELCH( printf("%d: Error -- win_buf[%d] = %d, expected %d\n",
-                            rank, i, win_buf[i], i);
-                   );
+            SQUELCH(printf("%d: Error -- win_buf[%d] = %d, expected %d\n", rank, i, win_buf[i], i);
+);
         }
     }
 
     MPI_Win_free(&win);
+#ifndef USE_WIN_ALLOCATE
     MPI_Free_mem(win_buf);
+#endif
 
     MPI_Group_free(&world_group);
     MPI_Group_free(&odd_group);
@@ -133,7 +139,7 @@ int main(int argc, char **argv) {
     free(odd_ranks);
     free(even_ranks);
 
-    MTest_Finalize( errors );
+    MTest_Finalize(errors);
     MPI_Finalize();
-    return MTestReturnValue( errors );
+    return MTestReturnValue(errors);
 }
index ba95a1c..1c5c3d5 100644 (file)
@@ -6,7 +6,7 @@
 
 /* One-Sided MPI 2-D Strided Put Test
  *
- * Author: James Dinan <dinan@mcs.anl.gov> 
+ * Author: James Dinan <dinan@mcs.anl.gov>
  * Date  : March, 2011
  *
  * This code performs N strided put operations into a 2d patch of a shared
 #define SUB_YDIM 1024
 #define ITERATIONS 10
 
-int main(int argc, char **argv) {
+int main(int argc, char **argv)
+{
     int i, j, rank, nranks, peer, bufsize, errors;
-    double  *win_buf, *src_buf, *dst_buf;
+    double *win_buf, *src_buf, *dst_buf;
     MPI_Win buf_win;
 
     MTest_Init(&argc, &argv);
@@ -44,52 +45,53 @@ int main(int argc, char **argv) {
 
     bufsize = XDIM * YDIM * sizeof(double);
     MPI_Alloc_mem(bufsize, MPI_INFO_NULL, &win_buf);
-    /* Alloc_mem is not required for the origin buffers for RMA operations - 
-       just for the Win_create memory */
+    /* Alloc_mem is not required for the origin buffers for RMA operations -
+     * just for the Win_create memory */
     MPI_Alloc_mem(bufsize, MPI_INFO_NULL, &src_buf);
     MPI_Alloc_mem(bufsize, MPI_INFO_NULL, &dst_buf);
 
-    for (i = 0; i < XDIM*YDIM; i++) {
-        *(win_buf  + i) = 1.0 + rank;
+    for (i = 0; i < XDIM * YDIM; i++) {
+        *(win_buf + i) = 1.0 + rank;
         *(src_buf + i) = 1.0 + rank;
     }
 
     MPI_Win_create(win_buf, bufsize, 1, MPI_INFO_NULL, MPI_COMM_WORLD, &buf_win);
 
-    peer = (rank+1) % nranks;
+    peer = (rank + 1) % nranks;
 
     /* Perform ITERATIONS strided put operations */
 
     for (i = 0; i < ITERATIONS; i++) {
-      MPI_Aint idx_loc[SUB_YDIM];
-      int idx_rem[SUB_YDIM];
-      int blk_len[SUB_YDIM];
-      MPI_Datatype src_type, dst_type;
+        MPI_Aint idx_loc[SUB_YDIM];
+        int idx_rem[SUB_YDIM];
+        int blk_len[SUB_YDIM];
+        MPI_Datatype src_type, dst_type;
 
-      void *base_ptr = dst_buf;
-      MPI_Aint base_int;
+        void *base_ptr = dst_buf;
+        MPI_Aint base_int;
 
-      MPI_Get_address(base_ptr, &base_int);
+        MPI_Get_address(base_ptr, &base_int);
 
-      for (j = 0; j < SUB_YDIM; j++) {
-        MPI_Get_address(&src_buf[j*XDIM], &idx_loc[j]);
-        idx_loc[j] = idx_loc[j] - base_int;
-        idx_rem[j] = j*XDIM*sizeof(double);
-        blk_len[j] = SUB_XDIM*sizeof(double);
-      }
+        for (j = 0; j < SUB_YDIM; j++) {
+            MPI_Get_address(&src_buf[j * XDIM], &idx_loc[j]);
+            idx_loc[j] = idx_loc[j] - base_int;
+            idx_rem[j] = j * XDIM * sizeof(double);
+            blk_len[j] = SUB_XDIM * sizeof(double);
+        }
 
-      MPI_Type_create_hindexed(SUB_YDIM, blk_len, idx_loc, MPI_BYTE, &src_type);
-      MPI_Type_create_indexed_block(SUB_YDIM, SUB_XDIM*sizeof(double), idx_rem, MPI_BYTE, &dst_type);
+        MPI_Type_create_hindexed(SUB_YDIM, blk_len, idx_loc, MPI_BYTE, &src_type);
+        MPI_Type_create_indexed_block(SUB_YDIM, SUB_XDIM * sizeof(double), idx_rem, MPI_BYTE,
+                                      &dst_type);
 
-      MPI_Type_commit(&src_type);
-      MPI_Type_commit(&dst_type);
+        MPI_Type_commit(&src_type);
+        MPI_Type_commit(&dst_type);
 
-      MPI_Win_lock(MPI_LOCK_EXCLUSIVE, peer, 0, buf_win);
-      MPI_Put(base_ptr, 1, src_type, peer, 0, 1, dst_type, buf_win);
-      MPI_Win_unlock(peer, buf_win);
+        MPI_Win_lock(MPI_LOCK_EXCLUSIVE, peer, 0, buf_win);
+        MPI_Put(base_ptr, 1, src_type, peer, 0, 1, dst_type, buf_win);
+        MPI_Win_unlock(peer, buf_win);
 
-      MPI_Type_free(&src_type);
-      MPI_Type_free(&dst_type);
+        MPI_Type_free(&src_type);
+        MPI_Type_free(&dst_type);
     }
 
     MPI_Barrier(MPI_COMM_WORLD);
@@ -99,40 +101,40 @@ int main(int argc, char **argv) {
     MPI_Win_lock(MPI_LOCK_EXCLUSIVE, rank, 0, buf_win);
     errors = 0;
     for (i = 0; i < SUB_XDIM; i++) {
-      for (j = 0; j < SUB_YDIM; j++) {
-        const double actual   = *(win_buf + i + j*XDIM);
-        const double expected = (1.0 + ((rank+nranks-1)%nranks));
-        if (actual - expected > 1e-10) {
-          SQUELCH( printf("%d: Data validation failed at [%d, %d] expected=%f actual=%f\n",
-              rank, j, i, expected, actual); );
-          errors++;
-          fflush(stdout);
+        for (j = 0; j < SUB_YDIM; j++) {
+            const double actual = *(win_buf + i + j * XDIM);
+            const double expected = (1.0 + ((rank + nranks - 1) % nranks));
+            if (actual - expected > 1e-10) {
+                SQUELCH(printf("%d: Data validation failed at [%d, %d] expected=%f actual=%f\n",
+                               rank, j, i, expected, actual););
+                errors++;
+                fflush(stdout);
+            }
         }
-      }
     }
     for (i = SUB_XDIM; i < XDIM; i++) {
-      for (j = 0; j < SUB_YDIM; j++) {
-        const double actual   = *(win_buf + i + j*XDIM);
-        const double expected = 1.0 + rank;
-        if (actual - expected > 1e-10) {
-          SQUELCH( printf("%d: Data validation failed at [%d, %d] expected=%f actual=%f\n",
-              rank, j, i, expected, actual); );
-          errors++;
-          fflush(stdout);
+        for (j = 0; j < SUB_YDIM; j++) {
+            const double actual = *(win_buf + i + j * XDIM);
+            const double expected = 1.0 + rank;
+            if (actual - expected > 1e-10) {
+                SQUELCH(printf("%d: Data validation failed at [%d, %d] expected=%f actual=%f\n",
+                               rank, j, i, expected, actual););
+                errors++;
+                fflush(stdout);
+            }
         }
-      }
     }
     for (i = 0; i < XDIM; i++) {
-      for (j = SUB_YDIM; j < YDIM; j++) {
-        const double actual   = *(win_buf + i + j*XDIM);
-        const double expected = 1.0 + rank;
-        if (actual - expected > 1e-10) {
-          SQUELCH( printf("%d: Data validation failed at [%d, %d] expected=%f actual=%f\n",
-              rank, j, i, expected, actual); );
-          errors++;
-          fflush(stdout);
+        for (j = SUB_YDIM; j < YDIM; j++) {
+            const double actual = *(win_buf + i + j * XDIM);
+            const double expected = 1.0 + rank;
+            if (actual - expected > 1e-10) {
+                SQUELCH(printf("%d: Data validation failed at [%d, %d] expected=%f actual=%f\n",
+                               rank, j, i, expected, actual););
+                errors++;
+                fflush(stdout);
+            }
         }
-      }
     }
     MPI_Win_unlock(rank, buf_win);
 
@@ -141,7 +143,7 @@ int main(int argc, char **argv) {
     MPI_Free_mem(src_buf);
     MPI_Free_mem(dst_buf);
 
-    MTest_Finalize( errors );
+    MTest_Finalize(errors);
     MPI_Finalize();
 
     return 0;
index 6634ea0..7d67bfd 100644 (file)
@@ -6,7 +6,7 @@
 
 /* One-Sided MPI 2-D Strided Put Test
  *
- * Author: James Dinan <dinan@mcs.anl.gov> 
+ * Author: James Dinan <dinan@mcs.anl.gov>
  * Date  : March, 2011
  *
  * This code performs N strided put operations into a 2d patch of a shared
@@ -30,7 +30,8 @@
 #define SUB_YDIM 1024
 #define ITERATIONS 10
 
-int main(int argc, char **argv) {
+int main(int argc, char **argv)
+{
     int i, j, rank, nranks, peer, bufsize, errors;
     double *win_buf, *src_buf, *dst_buf;
     MPI_Win buf_win;
@@ -45,41 +46,42 @@ int main(int argc, char **argv) {
     MPI_Alloc_mem(bufsize, MPI_INFO_NULL, &src_buf);
     MPI_Alloc_mem(bufsize, MPI_INFO_NULL, &dst_buf);
 
-    for (i = 0; i < XDIM*YDIM; i++) {
-        *(win_buf  + i) = 1.0 + rank;
+    for (i = 0; i < XDIM * YDIM; i++) {
+        *(win_buf + i) = 1.0 + rank;
         *(src_buf + i) = 1.0 + rank;
     }
 
     MPI_Win_create(win_buf, bufsize, 1, MPI_INFO_NULL, MPI_COMM_WORLD, &buf_win);
 
-    peer = (rank+1) % nranks;
+    peer = (rank + 1) % nranks;
 
     /* Perform ITERATIONS strided put operations */
 
     for (i = 0; i < ITERATIONS; i++) {
-      MPI_Aint idx_loc[SUB_YDIM];
-      int idx_rem[SUB_YDIM];
-      int blk_len[SUB_YDIM];
-      MPI_Datatype src_type, dst_type;
-
-      for (j = 0; j < SUB_YDIM; j++) {
-        MPI_Get_address(&src_buf[j*XDIM], &idx_loc[j]);
-        idx_rem[j] = j*XDIM*sizeof(double);
-        blk_len[j] = SUB_XDIM*sizeof(double);
-      }
+        MPI_Aint idx_loc[SUB_YDIM];
+        int idx_rem[SUB_YDIM];
+        int blk_len[SUB_YDIM];
+        MPI_Datatype src_type, dst_type;
+
+        for (j = 0; j < SUB_YDIM; j++) {
+            MPI_Get_address(&src_buf[j * XDIM], &idx_loc[j]);
+            idx_rem[j] = j * XDIM * sizeof(double);
+            blk_len[j] = SUB_XDIM * sizeof(double);
+        }
 
-      MPI_Type_create_hindexed(SUB_YDIM, blk_len, idx_loc, MPI_BYTE, &src_type);
-      MPI_Type_create_indexed_block(SUB_YDIM, SUB_XDIM*sizeof(double), idx_rem, MPI_BYTE, &dst_type);
+        MPI_Type_create_hindexed(SUB_YDIM, blk_len, idx_loc, MPI_BYTE, &src_type);
+        MPI_Type_create_indexed_block(SUB_YDIM, SUB_XDIM * sizeof(double), idx_rem, MPI_BYTE,
+                                      &dst_type);
 
-      MPI_Type_commit(&src_type);
-      MPI_Type_commit(&dst_type);
+        MPI_Type_commit(&src_type);
+        MPI_Type_commit(&dst_type);
 
-      MPI_Win_lock(MPI_LOCK_EXCLUSIVE, peer, 0, buf_win);
-      MPI_Put(MPI_BOTTOM, 1, src_type, peer, 0, 1, dst_type, buf_win);
-      MPI_Win_unlock(peer, buf_win);
+        MPI_Win_lock(MPI_LOCK_EXCLUSIVE, peer, 0, buf_win);
+        MPI_Put(MPI_BOTTOM, 1, src_type, peer, 0, 1, dst_type, buf_win);
+        MPI_Win_unlock(peer, buf_win);
 
-      MPI_Type_free(&src_type);
-      MPI_Type_free(&dst_type);
+        MPI_Type_free(&src_type);
+        MPI_Type_free(&dst_type);
     }
 
     MPI_Barrier(MPI_COMM_WORLD);
@@ -89,40 +91,40 @@ int main(int argc, char **argv) {
     MPI_Win_lock(MPI_LOCK_EXCLUSIVE, rank, 0, buf_win);
     errors = 0;
     for (i = 0; i < SUB_XDIM; i++) {
-      for (j = 0; j < SUB_YDIM; j++) {
-        const double actual   = *(win_buf + i + j*XDIM);
-        const double expected = (1.0 + ((rank+nranks-1)%nranks));
-        if (actual - expected > 1e-10) {
-          SQUELCH( printf("%d: Data validation failed at [%d, %d] expected=%f actual=%f\n",
-              rank, j, i, expected, actual); );
-          errors++;
-          fflush(stdout);
+        for (j = 0; j < SUB_YDIM; j++) {
+            const double actual = *(win_buf + i + j * XDIM);
+            const double expected = (1.0 + ((rank + nranks - 1) % nranks));
+            if (actual - expected > 1e-10) {
+                SQUELCH(printf("%d: Data validation failed at [%d, %d] expected=%f actual=%f\n",
+                               rank, j, i, expected, actual););
+                errors++;
+                fflush(stdout);
+            }
         }
-      }
     }
     for (i = SUB_XDIM; i < XDIM; i++) {
-      for (j = 0; j < SUB_YDIM; j++) {
-        const double actual   = *(win_buf + i + j*XDIM);
-        const double expected = 1.0 + rank;
-        if (actual - expected > 1e-10) {
-          SQUELCH( printf("%d: Data validation failed at [%d, %d] expected=%f actual=%f\n",
-              rank, j, i, expected, actual); );
-          errors++;
-          fflush(stdout);
+        for (j = 0; j < SUB_YDIM; j++) {
+            const double actual = *(win_buf + i + j * XDIM);
+            const double expected = 1.0 + rank;
+            if (actual - expected > 1e-10) {
+                SQUELCH(printf("%d: Data validation failed at [%d, %d] expected=%f actual=%f\n",
+                               rank, j, i, expected, actual););
+                errors++;
+                fflush(stdout);
+            }
         }
-      }
     }
     for (i = 0; i < XDIM; i++) {
-      for (j = SUB_YDIM; j < YDIM; j++) {
-        const double actual   = *(win_buf + i + j*XDIM);
-        const double expected = 1.0 + rank;
-        if (actual - expected > 1e-10) {
-          SQUELCH( printf("%d: Data validation failed at [%d, %d] expected=%f actual=%f\n",
-              rank, j, i, expected, actual); );
-          errors++;
-          fflush(stdout);
+        for (j = SUB_YDIM; j < YDIM; j++) {
+            const double actual = *(win_buf + i + j * XDIM);
+            const double expected = 1.0 + rank;
+            if (actual - expected > 1e-10) {
+                SQUELCH(printf("%d: Data validation failed at [%d, %d] expected=%f actual=%f\n",
+                               rank, j, i, expected, actual););
+                errors++;
+                fflush(stdout);
+            }
         }
-      }
     }
     MPI_Win_unlock(rank, buf_win);
 
@@ -131,7 +133,7 @@ int main(int argc, char **argv) {
     MPI_Free_mem(src_buf);
     MPI_Free_mem(dst_buf);
 
-    MTest_Finalize( errors );
+    MTest_Finalize(errors);
     MPI_Finalize();
 
     return 0;
index 1020063..4f49bea 100644 (file)
  */
 #include "mpi.h"
 #include <stdio.h>
+#include <string.h>
 #include "mpitest.h"
 
+/* These counts allow reasonable sizes for the large tests */
+#define LARGE_CNT_CONTIG    5500000
+#define LARGE_CNT_NONCONTIG 1500000
+
 /*
 static char MTEST_Descrip[] = "Put with Fence";
 */
 
-int main( int argc, char *argv[] )
+static inline int test(MPI_Comm comm, int rank, int source, int dest,
+                       MTestDatatype * sendtype, MTestDatatype * recvtype)
 {
     int errs = 0, err;
+    MPI_Aint extent, lb;
+    MPI_Win win;
+
+    MTestPrintfMsg(1,
+                   "Putting count = %ld of sendtype %s - count = %ld receive type %s\n",
+                   sendtype->count, MTestGetDatatypeName(sendtype), recvtype->count,
+                   MTestGetDatatypeName(recvtype));
+
+    /* Make sure that everyone has a recv buffer */
+    recvtype->InitBuf(recvtype);
+    MPI_Type_extent(recvtype->datatype, &extent);
+    MPI_Type_lb(recvtype->datatype, &lb);
+    MPI_Win_create(recvtype->buf, recvtype->count * extent + lb, extent, MPI_INFO_NULL, comm, &win);
+    MPI_Win_fence(0, win);
+    if (rank == source) {
+        /* To improve reporting of problems about operations, we
+         * change the error handler to errors return */
+        MPI_Win_set_errhandler(win, MPI_ERRORS_RETURN);
+
+        sendtype->InitBuf(sendtype);
+
+        err = MPI_Put(sendtype->buf, sendtype->count,
+                      sendtype->datatype, dest, 0, recvtype->count, recvtype->datatype, win);
+        if (err) {
+            errs++;
+            if (errs < 10) {
+                MTestPrintError(err);
+            }
+        }
+        err = MPI_Win_fence(0, win);
+        if (err) {
+            errs++;
+            if (errs < 10) {
+                MTestPrintError(err);
+            }
+        }
+    }
+    else if (rank == dest) {
+        MPI_Win_fence(0, win);
+        /* This should have the same effect, in terms of
+         * transfering data, as a send/recv pair */
+        err = MTestCheckRecv(0, recvtype);
+        if (err) {
+            if (errs < 10) {
+                printf
+                    ("Data in target buffer did not match for destination datatype %s (put with source datatype %s)\n",
+                     MTestGetDatatypeName(recvtype), MTestGetDatatypeName(sendtype));
+                /* Redo the test, with the errors printed */
+                recvtype->printErrors = 1;
+                (void) MTestCheckRecv(0, recvtype);
+            }
+            errs += err;
+        }
+    }
+    else {
+        MPI_Win_fence(0, win);
+    }
+    MPI_Win_free(&win);
+
+    return errs;
+}
+
+
+int main(int argc, char *argv[])
+{
+    int errs = 0;
     int rank, size, source, dest;
-    int minsize = 2, count; 
-    MPI_Comm      comm;
-    MPI_Win       win;
-    MPI_Aint      extent;
+    int minsize = 2, count;
+    MPI_Comm comm;
     MTestDatatype sendtype, recvtype;
 
-    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;
-       /* Determine the sender and receiver */
-       MPI_Comm_rank( comm, &rank );
-       MPI_Comm_size( comm, &size );
-       source = 0;
-       dest   = size - 1;
-       
-       for (count = 1; count < 65000; count = count * 2) {
-           while (MTestGetDatatypes( &sendtype, &recvtype, count )) {
-
-               MTestPrintfMsg( 1, 
-                      "Putting count = %d of sendtype %s receive type %s\n", 
-                               count, MTestGetDatatypeName( &sendtype ),
-                               MTestGetDatatypeName( &recvtype ) );
-
-               /* Make sure that everyone has a recv buffer */
-               recvtype.InitBuf( &recvtype );
-
-               MPI_Type_extent( recvtype.datatype, &extent );
-               MPI_Win_create( recvtype.buf, recvtype.count * extent, 
-                               extent, MPI_INFO_NULL, comm, &win );
-               MPI_Win_fence( 0, win );
-               if (rank == source) {
-                   /* To improve reporting of problems about operations, we
-                      change the error handler to errors return */
-                   MPI_Win_set_errhandler( win, MPI_ERRORS_RETURN );
-
-                   sendtype.InitBuf( &sendtype );
-                   
-                   err = MPI_Put( sendtype.buf, sendtype.count, 
-                                  sendtype.datatype, dest, 0, 
-                                  recvtype.count, recvtype.datatype, win );
-                   if (err) {
-                       errs++;
-                       if (errs < 10) {
-                           MTestPrintError( err );
-                       }
-                   }
-                   err = MPI_Win_fence( 0, win );
-                   if (err) {
-                       errs++;
-                       if (errs < 10) {
-                           MTestPrintError( err );
-                       }
-                   }
-               }
-               else if (rank == dest) {
-                   MPI_Win_fence( 0, win );
-                   /* This should have the same effect, in terms of
-                      transfering data, as a send/recv pair */
-                   err = MTestCheckRecv( 0, &recvtype );
-                   if (err) {
-                       if (errs < 10) {
-                           printf( "Data in target buffer did not match for destination datatype %s (put with source datatype %s)\n", 
-                                   MTestGetDatatypeName( &recvtype ),
-                                   MTestGetDatatypeName( &sendtype ) );
-                           /* Redo the test, with the errors printed */
-                           recvtype.printErrors = 1;
-                           (void)MTestCheckRecv( 0, &recvtype );
-                       }
-                       errs += err;
-                   }
-               }
-               else {
-                   MPI_Win_fence( 0, win );
-               }
-               MPI_Win_free( &win );
-               MTestFreeDatatype( &sendtype );
-               MTestFreeDatatype( &recvtype );
-           }
-       }
+    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;
+        /* Determine the sender and receiver */
+        MPI_Comm_rank(comm, &rank);
+        MPI_Comm_size(comm, &size);
+        source = 0;
+        dest = size - 1;
+
+        MTEST_DATATYPE_FOR_EACH_COUNT(count) {
+            while (MTestGetDatatypes(&sendtype, &recvtype, count)) {
+                errs += test(comm, rank, source, dest, &sendtype, &recvtype);
+                MTestFreeDatatype(&sendtype);
+                MTestFreeDatatype(&recvtype);
+            }
+        }
         MTestFreeComm(&comm);
     }
 
-    MTest_Finalize( errs );
+    /* Part #2: simple large size test - contiguous and noncontiguous */
+    if (sizeof(void *) > 4) {   /* Only if > 32-bit architecture */
+        MPI_Comm_rank(MPI_COMM_WORLD, &rank);
+        MPI_Comm_size(MPI_COMM_WORLD, &size);
+        source = 0;
+        dest = size - 1;
+
+        MTestGetDatatypes(&sendtype, &recvtype, LARGE_CNT_CONTIG);
+        errs += test(MPI_COMM_WORLD, rank, source, dest, &sendtype, &recvtype);
+
+        do {
+            MTestFreeDatatype(&sendtype);
+            MTestFreeDatatype(&recvtype);
+            MTestGetDatatypes(&sendtype, &recvtype, LARGE_CNT_NONCONTIG);
+        } while (strstr(MTestGetDatatypeName(&sendtype), "vector") == NULL);
+        errs += test(MPI_COMM_WORLD, rank, source, dest, &sendtype, &recvtype);
+        MTestFreeDatatype(&sendtype);
+        MTestFreeDatatype(&recvtype);
+    }
+
+    MTest_Finalize(errs);
     MPI_Finalize();
     return 0;
 }
index 6a23eb2..8064d4a 100644 (file)
 static char MTEST_Descrip[] = "Put with Fence for an indexed datatype";
 */
 
-int CheckMPIErr( int err );
+int CheckMPIErr(int err);
 
-int main( int argc, char *argv[] )
+int main(int argc, char *argv[])
 {
-    int           errs = 0, err;
-    int           i, rank, size, source, dest;
-    int           blksize, totsize;
-    int           *recvBuf = 0, *srcBuf = 0;
-    MPI_Comm      comm;
-    MPI_Win       win;
-    MPI_Aint      extent;
-    MPI_Datatype  originType;
-    int           counts[2];
-    int           displs[2];
-
-    MTest_Init( &argc, &argv );
+    int errs = 0, err;
+    int i, rank, size, source, dest;
+    int blksize, totsize;
+    int *recvBuf = 0, *srcBuf = 0;
+    MPI_Comm comm;
+    MPI_Win win;
+    MPI_Aint extent;
+    MPI_Datatype originType;
+    int counts[2];
+    int displs[2];
+
+    MTest_Init(&argc, &argv);
 
     /* Select the communicator and datatypes */
     comm = MPI_COMM_WORLD;
 
     /* Create the datatype */
-    /* One MPI Implementation fails this test with sufficiently large 
-       values of blksize - it appears to convert this type to an 
-       incorrect contiguous move */
+    /* One MPI Implementation fails this test with sufficiently large
+     * values of blksize - it appears to convert this type to an
+     * incorrect contiguous move */
     blksize = 2048;
     counts[0] = blksize;
     counts[1] = blksize;
     displs[0] = 0;
     displs[1] = blksize + 1;
-    MPI_Type_indexed( 2, counts, displs, MPI_INT, &originType );
-    MPI_Type_commit( &originType );
+    MPI_Type_indexed(2, counts, displs, MPI_INT, &originType);
+    MPI_Type_commit(&originType);
 
     totsize = 2 * blksize;
 
     /* Determine the sender and receiver */
-    MPI_Comm_rank( comm, &rank );
-    MPI_Comm_size( comm, &size );
+    MPI_Comm_rank(comm, &rank);
+    MPI_Comm_size(comm, &size);
     source = 0;
-    dest   = size - 1;
-       
-    recvBuf = (int *) malloc( totsize * sizeof(int) );
-    srcBuf  = (int *) malloc( (totsize + 1) * sizeof(int) ) ;
-    
+    dest = size - 1;
+
+    recvBuf = (int *) malloc(totsize * sizeof(int));
+    srcBuf = (int *) malloc((totsize + 1) * sizeof(int));
+
     if (!recvBuf || !srcBuf) {
-       fprintf( stderr, "Could not allocate buffers\n" );
-       MPI_Abort( MPI_COMM_WORLD, 1 );
+        fprintf(stderr, "Could not allocate buffers\n");
+        MPI_Abort(MPI_COMM_WORLD, 1);
     }
-    
+
     /* Initialize the send and recv buffers */
-    for (i=0; i<totsize; i++) {
-       recvBuf[i] = -1;
+    for (i = 0; i < totsize; i++) {
+        recvBuf[i] = -1;
     }
-    for (i=0; i<blksize; i++) {
-       srcBuf[i] = i;
-       srcBuf[blksize+1+i] = blksize+i;
+    for (i = 0; i < blksize; i++) {
+        srcBuf[i] = i;
+        srcBuf[blksize + 1 + i] = blksize + i;
     }
     srcBuf[blksize] = -1;
 
-    MPI_Type_extent( MPI_INT, &extent );
-    MPI_Win_create( recvBuf, totsize * extent, extent, 
-                   MPI_INFO_NULL, comm, &win );
-    MPI_Win_fence( 0, win );
+    MPI_Type_extent(MPI_INT, &extent);
+    MPI_Win_create(recvBuf, totsize * extent, extent, MPI_INFO_NULL, comm, &win);
+    MPI_Win_fence(0, win);
     if (rank == source) {
-       /* To improve reporting of problems about operations, we
-          change the error handler to errors return */
-       MPI_Win_set_errhandler( win, MPI_ERRORS_RETURN );
-
-       err = MPI_Put( srcBuf, 1, originType, dest, 0, 
-                      totsize, MPI_INT, win );
-       errs += CheckMPIErr( err );
-       err = MPI_Win_fence( 0, win );
-       errs += CheckMPIErr( err );
+        /* To improve reporting of problems about operations, we
+         * change the error handler to errors return */
+        MPI_Win_set_errhandler(win, MPI_ERRORS_RETURN);
+
+        err = MPI_Put(srcBuf, 1, originType, dest, 0, totsize, MPI_INT, win);
+        errs += CheckMPIErr(err);
+        err = MPI_Win_fence(0, win);
+        errs += CheckMPIErr(err);
     }
     else if (rank == dest) {
-       MPI_Win_fence( 0, win );
-       for (i=0; i<totsize; i++) {
-           if (recvBuf[i] != i) {
-               errs++;
-               if (errs < 10) {
-                   printf( "recvBuf[%d] = %d should = %d\n", 
-                           i, recvBuf[i], i );
-               }
-           }
-       }
+        MPI_Win_fence(0, win);
+        for (i = 0; i < totsize; i++) {
+            if (recvBuf[i] != i) {
+                errs++;
+                if (errs < 10) {
+                    printf("recvBuf[%d] = %d should = %d\n", i, recvBuf[i], i);
+                }
+            }
+        }
     }
     else {
-       MPI_Win_fence( 0, win );
+        MPI_Win_fence(0, win);
     }
-    
-    MPI_Type_free( &originType );
-    MPI_Win_free( &win );
-    free( recvBuf );
-    free( srcBuf );
 
-    MTest_Finalize( errs );
+    MPI_Type_free(&originType);
+    MPI_Win_free(&win);
+    free(recvBuf);
+    free(srcBuf);
+
+    MTest_Finalize(errs);
     MPI_Finalize();
     return 0;
 }
 
-int CheckMPIErr( int err )
+int CheckMPIErr(int err)
 {
     int rc = 0;
-    if (err != MPI_SUCCESS) { 
-       MTestPrintError( err );
-       rc = 1;
+    if (err != MPI_SUCCESS) {
+        MTestPrintError(err);
+        rc = 1;
     }
     return rc;
 }
index ff18f4c..d46c8f9 100644 (file)
 static char MTEST_Descrip[] = "Put with Post/Start/Complete/Wait";
 */
 
-int main( int argc, char *argv[] )
+int main(int argc, char *argv[])
 {
     int errs = 0, err;
     int rank, size, source, dest;
-    int minsize = 2, count; 
-    MPI_Comm      comm;
-    MPI_Win       win;
-    MPI_Aint      extent;
-    MPI_Group     wingroup, neighbors;
+    int minsize = 2, count;
+    MPI_Comm comm;
+    MPI_Win win;
+    MPI_Aint extent, lb;
+    MPI_Group wingroup, neighbors;
     MTestDatatype sendtype, recvtype;
 
-    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;
-       /* Determine the sender and receiver */
-       MPI_Comm_rank( comm, &rank );
-       MPI_Comm_size( comm, &size );
-       source = 0;
-       dest   = size - 1;
-       
-       for (count = 1; count < 65000; count = count * 2) {
-           while (MTestGetDatatypes( &sendtype, &recvtype, count )) {
-               /* Make sure that everyone has a recv buffer */
-               recvtype.InitBuf( &recvtype );
+    /* 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;
+        /* Determine the sender and receiver */
+        MPI_Comm_rank(comm, &rank);
+        MPI_Comm_size(comm, &size);
+        source = 0;
+        dest = size - 1;
 
-               MPI_Type_extent( recvtype.datatype, &extent );
-               MPI_Win_create( recvtype.buf, recvtype.count * extent, 
-                               (int)extent, MPI_INFO_NULL, comm, &win );
-               MPI_Win_get_group( win, &wingroup );
-               if (rank == source) {
-                   /* To improve reporting of problems about operations, we
-                      change the error handler to errors return */
-                   MPI_Win_set_errhandler( win, MPI_ERRORS_RETURN );
-                   sendtype.InitBuf( &sendtype );
-                   
-                   /* Neighbor is dest only */
-                   MPI_Group_incl( wingroup, 1, &dest, &neighbors );
-                   err = MPI_Win_start( neighbors, 0, win );
-                   if (err) {
-                       errs++;
-                       if (errs < 10) {
-                           MTestPrintError( err );
-                       }
-                   }
-                   MPI_Group_free( &neighbors );
-                   err = MPI_Put( sendtype.buf, sendtype.count, 
-                                   sendtype.datatype, dest, 0, 
-                                  recvtype.count, recvtype.datatype, win );
-                   if (err) {
-                       errs++;
-                       MTestPrintError( err );
-                   }
-                   err = MPI_Win_complete( win );
-                   if (err) {
-                       errs++;
-                       if (errs < 10) {
-                           MTestPrintError( err );
-                       }
-                   }
-               }
-               else if (rank == dest) {
-                   MPI_Group_incl( wingroup, 1, &source, &neighbors );
-                   MPI_Win_post( neighbors, 0, win );
-                   MPI_Group_free( &neighbors );
-                   MPI_Win_wait( win );
-                   /* This should have the same effect, in terms of
-                      transfering data, as a send/recv pair */
-                   err = MTestCheckRecv( 0, &recvtype );
-                   if (err) {
-                       errs += errs;
-                   }
-               }
-               else {
-                   /* Nothing; the other processes need not call any 
-                      MPI routines */
-                   ;
-               }
-               MPI_Win_free( &win );
-               MTestFreeDatatype( &sendtype );
-               MTestFreeDatatype( &recvtype );
-               MPI_Group_free( &wingroup );
-           }
-       }
-       MTestFreeComm( &comm );
+        MTEST_DATATYPE_FOR_EACH_COUNT(count) {
+            while (MTestGetDatatypes(&sendtype, &recvtype, count)) {
+                /* Make sure that everyone has a recv buffer */
+                recvtype.InitBuf(&recvtype);
+
+                MPI_Type_extent(recvtype.datatype, &extent);
+                MPI_Type_lb(recvtype.datatype, &lb);
+                MPI_Win_create(recvtype.buf, recvtype.count * extent + lb,
+                               (int) extent, MPI_INFO_NULL, comm, &win);
+                MPI_Win_get_group(win, &wingroup);
+                if (rank == source) {
+                    /* To improve reporting of problems about operations, we
+                     * change the error handler to errors return */
+                    MPI_Win_set_errhandler(win, MPI_ERRORS_RETURN);
+                    sendtype.InitBuf(&sendtype);
+
+                    /* Neighbor is dest only */
+                    MPI_Group_incl(wingroup, 1, &dest, &neighbors);
+                    err = MPI_Win_start(neighbors, 0, win);
+                    if (err) {
+                        errs++;
+                        if (errs < 10) {
+                            MTestPrintError(err);
+                        }
+                    }
+                    MPI_Group_free(&neighbors);
+                    err = MPI_Put(sendtype.buf, sendtype.count,
+                                  sendtype.datatype, dest, 0,
+                                  recvtype.count, recvtype.datatype, win);
+                    if (err) {
+                        errs++;
+                        MTestPrintError(err);
+                    }
+                    err = MPI_Win_complete(win);
+                    if (err) {
+                        errs++;
+                        if (errs < 10) {
+                            MTestPrintError(err);
+                        }
+                    }
+                }
+                else if (rank == dest) {
+                    MPI_Group_incl(wingroup, 1, &source, &neighbors);
+                    MPI_Win_post(neighbors, 0, win);
+                    MPI_Group_free(&neighbors);
+                    MPI_Win_wait(win);
+                    /* This should have the same effect, in terms of
+                     * transfering data, as a send/recv pair */
+                    err = MTestCheckRecv(0, &recvtype);
+                    if (err) {
+                        errs += errs;
+                    }
+                }
+                else {
+                    /* Nothing; the other processes need not call any
+                     * MPI routines */
+                    ;
+                }
+                MPI_Win_free(&win);
+                MTestFreeDatatype(&sendtype);
+                MTestFreeDatatype(&recvtype);
+                MPI_Group_free(&wingroup);
+            }
+        }
+        MTestFreeComm(&comm);
     }
 
-    MTest_Finalize( errs );
+    MTest_Finalize(errs);
     MPI_Finalize();
     return 0;
 }
diff --git a/teshsuite/smpi/mpich3-test/rma/racc_local_comp.c b/teshsuite/smpi/mpich3-test/rma/racc_local_comp.c
new file mode 100644 (file)
index 0000000..ea9e57c
--- /dev/null
@@ -0,0 +1,132 @@
+/* -*- Mode: C; c-basic-offset:4 ; indent-tabs-mode:nil ; -*- */
+/*
+ *
+ *  (C) 2014 by Argonne National Laboratory.
+ *      See COPYRIGHT in top-level directory.
+ */
+#include <mpi.h>
+#include <stdio.h>
+#include <assert.h>
+#include "mpitest.h"
+
+#define ITER 100
+#define MAX_SIZE 65536
+
+int main(int argc, char *argv[])
+{
+    int rank, nproc, i;
+    int errors = 0, all_errors = 0;
+    int *buf = NULL, *winbuf = NULL;
+    MPI_Win window;
+
+    MPI_Init(&argc, &argv);
+    MPI_Comm_rank(MPI_COMM_WORLD, &rank);
+    MPI_Comm_size(MPI_COMM_WORLD, &nproc);
+
+    if (nproc < 2) {
+        if (rank == 0)
+            printf("Error: must be run with two or more processes\n");
+        MPI_Abort(MPI_COMM_WORLD, 1);
+    }
+
+    MPI_Alloc_mem(MAX_SIZE * sizeof(int), MPI_INFO_NULL, &buf);
+    MPI_Alloc_mem(MAX_SIZE * sizeof(int), MPI_INFO_NULL, &winbuf);
+    MPI_Win_create(winbuf, MAX_SIZE * sizeof(int), sizeof(int), MPI_INFO_NULL,
+                   MPI_COMM_WORLD, &window);
+
+    MPI_Win_lock_all(0, window);
+
+    /* Test Raccumulate local completion with small data.
+     * Small data is always copied to header packet as immediate data. */
+    if (rank == 1) {
+        for (i = 0; i < ITER; i++) {
+            MPI_Request acc_req;
+            int val = -1;
+
+            buf[0] = rank * i;
+            MPI_Raccumulate(&buf[0], 1, MPI_INT, 0, 0, 1, MPI_INT, MPI_MAX, window, &acc_req);
+            MPI_Wait(&acc_req, MPI_STATUS_IGNORE);
+
+            /* reset local buffer to check local completion */
+            buf[0] = 0;
+            MPI_Win_flush(0, window);
+
+            MPI_Get(&val, 1, MPI_INT, 0, 0, 1, MPI_INT, window);
+            MPI_Win_flush(0, window);
+
+            if (val != rank * i) {
+                printf("%d - Got %d in small Raccumulate test, expected %d (%d * %d)\n", rank, val,
+                       rank * i, rank, i);
+                errors++;
+            }
+        }
+    }
+
+    MPI_Barrier(MPI_COMM_WORLD);
+
+    /* Test Raccumulate local completion with large data .
+     * Large data is not suitable for 1-copy optimization, and always sent out
+     * from user buffer. */
+    if (rank == 1) {
+        for (i = 0; i < ITER; i++) {
+            MPI_Request acc_req;
+            int val0 = -1, val1 = -1, val2 = -1;
+            int j;
+
+            /* initialize data */
+            for (j = 0; j < MAX_SIZE; j++) {
+                buf[j] = rank + j + i;
+            }
+
+            MPI_Raccumulate(buf, MAX_SIZE, MPI_INT, 0, 0, MAX_SIZE, MPI_INT, MPI_REPLACE, window,
+                            &acc_req);
+            MPI_Wait(&acc_req, MPI_STATUS_IGNORE);
+
+            /* reset local buffer to check local completion */
+            buf[0] = 0;
+            buf[MAX_SIZE - 1] = 0;
+            buf[MAX_SIZE / 2] = 0;
+            MPI_Win_flush(0, window);
+
+            /* get remote values which are modified in local buffer after wait */
+            MPI_Get(&val0, 1, MPI_INT, 0, 0, 1, MPI_INT, window);
+            MPI_Get(&val1, 1, MPI_INT, 0, MAX_SIZE - 1, 1, MPI_INT, window);
+            MPI_Get(&val2, 1, MPI_INT, 0, MAX_SIZE / 2, 1, MPI_INT, window);
+            MPI_Win_flush(0, window);
+
+            if (val0 != rank + i) {
+                printf("%d - Got %d in large Raccumulate test, expected %d\n", rank,
+                       val0, rank + i);
+                errors++;
+            }
+            if (val1 != rank + MAX_SIZE - 1 + i) {
+                printf("%d - Got %d in large Raccumulate test, expected %d\n", rank,
+                       val1, rank + MAX_SIZE - 1 + i);
+                errors++;
+            }
+            if (val2 != rank + MAX_SIZE / 2 + i) {
+                printf("%d - Got %d in large Raccumulate test, expected %d\n", rank,
+                       val2, rank + MAX_SIZE / 2 + i);
+                errors++;
+            }
+        }
+    }
+
+    MPI_Win_unlock_all(window);
+    MPI_Barrier(MPI_COMM_WORLD);
+
+    MPI_Win_free(&window);
+    if (buf)
+        MPI_Free_mem(buf);
+    if (winbuf)
+        MPI_Free_mem(winbuf);
+
+    MPI_Reduce(&errors, &all_errors, 1, MPI_INT, MPI_SUM, 0, MPI_COMM_WORLD);
+
+    if (rank == 0 && all_errors == 0)
+        printf(" No Errors\n");
+
+    MPI_Finalize();
+
+    return 0;
+}
index 5788972..38549fd 100644 (file)
  * function. */
 double junk = 0.0;
 
-void compute(int step, double *data) {
+void compute(int step, double *data)
+{
     int i;
 
     for (i = 0; i < N; i++)
         junk += data[i] * (double) step;
 }
 
-int main( int argc, char *argv[] )
+int main(int argc, char *argv[])
 {
     int i, rank, nproc;
     int errors = 0, all_errors = 0;
@@ -41,7 +42,7 @@ int main( int argc, char *argv[] )
     MPI_Request put_req[M] = { MPI_REQUEST_NULL };
     MPI_Request get_req;
     double *baseptr;
-    double data[M][N]; /* M buffers of length N */
+    double data[M][N];          /* M buffers of length N */
     MPI_Info win_info;
 
     MPI_Init(&argc, &argv);
@@ -58,29 +59,28 @@ int main( int argc, char *argv[] )
     MPI_Info_set(win_info, "alloc_shm", "false");
 #endif
 
-    MPI_Win_allocate(NSTEPS*N*sizeof(double), sizeof(double), win_info,
+    MPI_Win_allocate(NSTEPS * N * sizeof(double), sizeof(double), win_info,
                      MPI_COMM_WORLD, &baseptr, &win);
 
     MPI_Win_lock_all(0, win);
 
     for (i = 0; i < NSTEPS; i++) {
-        int target = (rank+1) % nproc;
+        int target = (rank + 1) % nproc;
         int j;
 
         /* Find a free put request */
         if (i < M) {
             j = i;
-        } else {
+        }
+        else {
             MPI_Waitany(M, put_req, &j, MPI_STATUS_IGNORE);
         }
 
-        MPI_Rget(data[j], N, MPI_DOUBLE, target, i*N, N, MPI_DOUBLE, win,
-                 &get_req);
-        MPI_Wait(&get_req,MPI_STATUS_IGNORE);
+        MPI_Rget(data[j], N, MPI_DOUBLE, target, i * N, N, MPI_DOUBLE, win, &get_req);
+        MPI_Wait(&get_req, MPI_STATUS_IGNORE);
 
         compute(i, data[j]);
-        MPI_Rput(data[j], N, MPI_DOUBLE, target, i*N, N, MPI_DOUBLE, win,
-                 &put_req[j]);
+        MPI_Rput(data[j], N, MPI_DOUBLE, target, i * N, N, MPI_DOUBLE, win, &put_req[j]);
 
     }
 
index ef2636f..c24af56 100644 (file)
@@ -11,7 +11,7 @@
 
 #define ITER 100
 
-int main( int argc, char *argv[] )
+int main(int argc, char *argv[])
 {
     int rank, nproc, i;
     int errors = 0, all_errors = 0;
@@ -23,19 +23,22 @@ int main( int argc, char *argv[] )
     MPI_Comm_size(MPI_COMM_WORLD, &nproc);
 
     if (nproc < 2) {
-        if (rank == 0) printf("Error: must be run with two or more processes\n");
+        if (rank == 0)
+            printf("Error: must be run with two or more processes\n");
         MPI_Abort(MPI_COMM_WORLD, 1);
     }
 
     /** Create using MPI_Win_create() **/
 
     if (rank == 0) {
-      MPI_Alloc_mem(4*sizeof(int), MPI_INFO_NULL, &buf);
-      *buf = nproc-1;
-    } else
-      buf = NULL;
+        MPI_Alloc_mem(4 * sizeof(int), MPI_INFO_NULL, &buf);
+        *buf = nproc - 1;
+    }
+    else
+        buf = NULL;
 
-    MPI_Win_create(buf, 4*sizeof(int)*(rank == 0), 1, MPI_INFO_NULL, MPI_COMM_WORLD, &window);
+    MPI_Win_create(buf, 4 * sizeof(int) * (rank == 0), sizeof(int),
+                   MPI_INFO_NULL, MPI_COMM_WORLD, &window);
 
     /* PROC_NULL Communication */
     {
@@ -44,10 +47,12 @@ int main( int argc, char *argv[] )
 
         MPI_Win_lock_all(0, window);
 
-        MPI_Rget_accumulate(&val[0], 1, MPI_INT, &res, 1, MPI_INT, MPI_PROC_NULL, 0, 1, MPI_INT, MPI_REPLACE, window, &pn_req[0]);
+        MPI_Rget_accumulate(&val[0], 1, MPI_INT, &res, 1, MPI_INT, MPI_PROC_NULL, 0, 1, MPI_INT,
+                            MPI_REPLACE, window, &pn_req[0]);
         MPI_Rget(&val[1], 1, MPI_INT, MPI_PROC_NULL, 1, 1, MPI_INT, window, &pn_req[1]);
         MPI_Rput(&val[2], 1, MPI_INT, MPI_PROC_NULL, 2, 1, MPI_INT, window, &pn_req[2]);
-        MPI_Raccumulate(&val[3], 1, MPI_INT, MPI_PROC_NULL, 3, 1, MPI_INT, MPI_REPLACE, window, &pn_req[3]);
+        MPI_Raccumulate(&val[3], 1, MPI_INT, MPI_PROC_NULL, 3, 1, MPI_INT, MPI_REPLACE, window,
+                        &pn_req[3]);
 
         assert(pn_req[0] != MPI_REQUEST_NULL);
         assert(pn_req[1] != MPI_REQUEST_NULL);
@@ -72,22 +77,23 @@ int main( int argc, char *argv[] )
          * to the right.  Each process, in turn, performs third-party
          * communication via process 0's window. */
         if (rank > 0) {
-            MPI_Recv(NULL, 0, MPI_BYTE, rank-1, 0, MPI_COMM_WORLD, MPI_STATUS_IGNORE);
+            MPI_Recv(NULL, 0, MPI_BYTE, rank - 1, 0, MPI_COMM_WORLD, MPI_STATUS_IGNORE);
         }
 
-        MPI_Rget_accumulate(&rank, 1, MPI_INT, &val, 1, MPI_INT, 0, 0, 1, MPI_INT, MPI_REPLACE, window, &gacc_req);
+        MPI_Rget_accumulate(&rank, 1, MPI_INT, &val, 1, MPI_INT, 0, 0, 1, MPI_INT, MPI_REPLACE,
+                            window, &gacc_req);
         assert(gacc_req != MPI_REQUEST_NULL);
         MPI_Wait(&gacc_req, MPI_STATUS_IGNORE);
 
-        exp = (rank + nproc-1) % nproc;
+        exp = (rank + nproc - 1) % nproc;
 
         if (val != exp) {
             printf("%d - Got %d, expected %d\n", rank, val, exp);
             errors++;
         }
 
-        if (rank < nproc-1) {
-            MPI_Send(NULL, 0, MPI_BYTE, rank+1, 0, MPI_COMM_WORLD);
+        if (rank < nproc - 1) {
+            MPI_Send(NULL, 0, MPI_BYTE, rank + 1, 0, MPI_COMM_WORLD);
         }
 
         MPI_Barrier(MPI_COMM_WORLD);
@@ -95,7 +101,8 @@ int main( int argc, char *argv[] )
 
     MPI_Barrier(MPI_COMM_WORLD);
 
-    if (rank == 0) *buf = nproc-1;
+    if (rank == 0)
+        *buf = nproc - 1;
     MPI_Win_sync(window);
 
     /* GET+PUT: Test third-party communication, through rank 0. */
@@ -107,26 +114,26 @@ int main( int argc, char *argv[] )
          * to the right.  Each process, in turn, performs third-party
          * communication via process 0's window. */
         if (rank > 0) {
-            MPI_Recv(NULL, 0, MPI_BYTE, rank-1, 0, MPI_COMM_WORLD, MPI_STATUS_IGNORE);
+            MPI_Recv(NULL, 0, MPI_BYTE, rank - 1, 0, MPI_COMM_WORLD, MPI_STATUS_IGNORE);
         }
 
         MPI_Rget(&val, 1, MPI_INT, 0, 0, 1, MPI_INT, window, &req);
         assert(req != MPI_REQUEST_NULL);
         MPI_Wait(&req, MPI_STATUS_IGNORE);
 
-        MPI_Rput(&rank, 1, MPI_INT, 0, 0, 1, MPI_INT, window, &req);
-        assert(req != MPI_REQUEST_NULL);
-        MPI_Wait(&req, MPI_STATUS_IGNORE);
+        /* Use flush to guarantee remote completion */
+        MPI_Put(&rank, 1, MPI_INT, 0, 0, 1, MPI_INT, window);
+        MPI_Win_flush(0, window);
 
-        exp = (rank + nproc-1) % nproc;
+        exp = (rank + nproc - 1) % nproc;
 
         if (val != exp) {
             printf("%d - Got %d, expected %d\n", rank, val, exp);
             errors++;
         }
 
-        if (rank < nproc-1) {
-            MPI_Send(NULL, 0, MPI_BYTE, rank+1, 0, MPI_COMM_WORLD);
+        if (rank < nproc - 1) {
+            MPI_Send(NULL, 0, MPI_BYTE, rank + 1, 0, MPI_COMM_WORLD);
         }
 
         MPI_Barrier(MPI_COMM_WORLD);
@@ -134,7 +141,8 @@ int main( int argc, char *argv[] )
 
     MPI_Barrier(MPI_COMM_WORLD);
 
-    if (rank == 0) *buf = nproc-1;
+    if (rank == 0)
+        *buf = nproc - 1;
     MPI_Win_sync(window);
 
     /* GET+ACC: Test third-party communication, through rank 0. */
@@ -146,26 +154,26 @@ int main( int argc, char *argv[] )
          * to the right.  Each process, in turn, performs third-party
          * communication via process 0's window. */
         if (rank > 0) {
-            MPI_Recv(NULL, 0, MPI_BYTE, rank-1, 0, MPI_COMM_WORLD, MPI_STATUS_IGNORE);
+            MPI_Recv(NULL, 0, MPI_BYTE, rank - 1, 0, MPI_COMM_WORLD, MPI_STATUS_IGNORE);
         }
 
         MPI_Rget(&val, 1, MPI_INT, 0, 0, 1, MPI_INT, window, &req);
         assert(req != MPI_REQUEST_NULL);
         MPI_Wait(&req, MPI_STATUS_IGNORE);
 
-        MPI_Raccumulate(&rank, 1, MPI_INT, 0, 0, 1, MPI_INT, MPI_REPLACE, window, &req);
-        assert(req != MPI_REQUEST_NULL);
-        MPI_Wait(&req, MPI_STATUS_IGNORE);
+        /* Use flush to guarantee remote completion */
+        MPI_Accumulate(&rank, 1, MPI_INT, 0, 0, 1, MPI_INT, MPI_REPLACE, window);
+        MPI_Win_flush(0, window);
 
-        exp = (rank + nproc-1) % nproc;
+        exp = (rank + nproc - 1) % nproc;
 
         if (val != exp) {
             printf("%d - Got %d, expected %d\n", rank, val, exp);
             errors++;
         }
 
-        if (rank < nproc-1) {
-            MPI_Send(NULL, 0, MPI_BYTE, rank+1, 0, MPI_COMM_WORLD);
+        if (rank < nproc - 1) {
+            MPI_Send(NULL, 0, MPI_BYTE, rank + 1, 0, MPI_COMM_WORLD);
         }
 
         MPI_Barrier(MPI_COMM_WORLD);
@@ -182,10 +190,12 @@ int main( int argc, char *argv[] )
 
         MPI_Win_lock_all(0, window);
 
-        MPI_Rget_accumulate(&val[0], 1, MPI_INT, &res, 1, MPI_INT, target, 0, 1, MPI_INT, MPI_REPLACE, window, &pn_req[0]);
+        MPI_Rget_accumulate(&val[0], 1, MPI_INT, &res, 1, MPI_INT, target, 0, 1, MPI_INT,
+                            MPI_REPLACE, window, &pn_req[0]);
         MPI_Rget(&val[1], 1, MPI_INT, target, 1, 1, MPI_INT, window, &pn_req[1]);
         MPI_Rput(&val[2], 1, MPI_INT, target, 2, 1, MPI_INT, window, &pn_req[2]);
-        MPI_Raccumulate(&val[3], 1, MPI_INT, target, 3, 1, MPI_INT, MPI_REPLACE, window, &pn_req[3]);
+        MPI_Raccumulate(&val[3], 1, MPI_INT, target, 3, 1, MPI_INT, MPI_REPLACE, window,
+                        &pn_req[3]);
 
         assert(pn_req[0] != MPI_REQUEST_NULL);
         assert(pn_req[1] != MPI_REQUEST_NULL);
@@ -207,10 +217,12 @@ int main( int argc, char *argv[] )
 
         MPI_Win_lock_all(0, window);
 
-        MPI_Rget_accumulate(&val[0], 1, MPI_INT, &res, 1, MPI_INT, target, 0, 1, MPI_INT, MPI_REPLACE, window, &pn_req[0]);
+        MPI_Rget_accumulate(&val[0], 1, MPI_INT, &res, 1, MPI_INT, target, 0, 1, MPI_INT,
+                            MPI_REPLACE, window, &pn_req[0]);
         MPI_Rget(&val[1], 1, MPI_INT, target, 1, 1, MPI_INT, window, &pn_req[1]);
         MPI_Rput(&val[2], 1, MPI_INT, target, 2, 1, MPI_INT, window, &pn_req[2]);
-        MPI_Raccumulate(&val[3], 1, MPI_INT, target, 3, 1, MPI_INT, MPI_REPLACE, window, &pn_req[3]);
+        MPI_Raccumulate(&val[3], 1, MPI_INT, target, 3, 1, MPI_INT, MPI_REPLACE, window,
+                        &pn_req[3]);
 
         assert(pn_req[0] != MPI_REQUEST_NULL);
         assert(pn_req[1] != MPI_REQUEST_NULL);
@@ -230,10 +242,12 @@ int main( int argc, char *argv[] )
 
         MPI_Win_lock_all(0, window);
 
-        MPI_Rget_accumulate(&val[0], 1, MPI_INT, &res, 1, MPI_INT, target, 0, 1, MPI_INT, MPI_REPLACE, window, &pn_req[0]);
+        MPI_Rget_accumulate(&val[0], 1, MPI_INT, &res, 1, MPI_INT, target, 0, 1, MPI_INT,
+                            MPI_REPLACE, window, &pn_req[0]);
         MPI_Rget(&val[1], 1, MPI_INT, target, 1, 1, MPI_INT, window, &pn_req[1]);
         MPI_Rput(&val[2], 1, MPI_INT, target, 2, 1, MPI_INT, window, &pn_req[2]);
-        MPI_Raccumulate(&val[3], 1, MPI_INT, target, 3, 1, MPI_INT, MPI_REPLACE, window, &pn_req[3]);
+        MPI_Raccumulate(&val[3], 1, MPI_INT, target, 3, 1, MPI_INT, MPI_REPLACE, window,
+                        &pn_req[3]);
 
         assert(pn_req[0] != MPI_REQUEST_NULL);
         assert(pn_req[1] != MPI_REQUEST_NULL);
@@ -255,10 +269,12 @@ int main( int argc, char *argv[] )
 
         MPI_Win_lock_all(0, window);
 
-        MPI_Rget_accumulate(&val[0], 1, MPI_INT, &res, 1, MPI_INT, target, 0, 1, MPI_INT, MPI_REPLACE, window, &pn_req[0]);
+        MPI_Rget_accumulate(&val[0], 1, MPI_INT, &res, 1, MPI_INT, target, 0, 1, MPI_INT,
+                            MPI_REPLACE, window, &pn_req[0]);
         MPI_Rget(&val[1], 1, MPI_INT, target, 1, 1, MPI_INT, window, &pn_req[1]);
         MPI_Rput(&val[2], 1, MPI_INT, target, 2, 1, MPI_INT, window, &pn_req[2]);
-        MPI_Raccumulate(&val[3], 1, MPI_INT, target, 3, 1, MPI_INT, MPI_REPLACE, window, &pn_req[3]);
+        MPI_Raccumulate(&val[3], 1, MPI_INT, target, 3, 1, MPI_INT, MPI_REPLACE, window,
+                        &pn_req[3]);
 
         assert(pn_req[0] != MPI_REQUEST_NULL);
         assert(pn_req[1] != MPI_REQUEST_NULL);
@@ -273,7 +289,8 @@ int main( int argc, char *argv[] )
     }
 
     MPI_Win_free(&window);
-    if (buf) MPI_Free_mem(buf);
+    if (buf)
+        MPI_Free_mem(buf);
 
     MPI_Reduce(&errors, &all_errors, 1, MPI_INT, MPI_SUM, 0, MPI_COMM_WORLD);
 
diff --git a/teshsuite/smpi/mpich3-test/rma/rget-unlock.c b/teshsuite/smpi/mpich3-test/rma/rget-unlock.c
new file mode 100644 (file)
index 0000000..4c854df
--- /dev/null
@@ -0,0 +1,87 @@
+/*
+ *  (C) 2016 by Argonne National Laboratory.
+ *      See COPYRIGHT in top-level directory.
+ *
+ *  Portions of this code were written by Intel Corporation.
+ *  Copyright (C) 2011-2016 Intel Corporation.  Intel provides this material
+ *  to Argonne National Laboratory subject to Software Grant and Corporate
+ *  Contributor License Agreement dated February 8, 2012.
+ *
+ *
+ *  This is a test case to make sure synchronization in unlock works correctly.
+ *
+ *  Essentially this program does the following:
+ *
+ *  lock_all
+ *  req=rget(buf)
+ *  unlock_all
+ *  re-use buf
+ *  wait(req)
+ *
+ *  This program is valid but if unlock_all does not implement the synchronization
+ *  semantics correctly reusing the buffer would race with outstanding rgets.
+ *
+ */
+
+#include <stdio.h>
+#include <stdlib.h>
+#include <memory.h>
+#include <mpi.h>
+
+#define N_ELMS (128)
+#define BLOCKSIZE (1)
+#define N_BLOCKS (N_ELMS/BLOCKSIZE)
+
+int main(int argc, char *argv[])
+{
+    MPI_Win win;
+    int i;
+    int *rbuf, *lbuf;
+    int rank, size, trg;
+    MPI_Request *reqs;
+    int n_errors = 0;
+
+    MPI_Init(&argc, &argv);
+
+    MPI_Comm_rank(MPI_COMM_WORLD, &rank);
+    MPI_Comm_size(MPI_COMM_WORLD, &size);
+
+    trg = (rank + 1) % size;
+
+    rbuf = malloc(sizeof(int) * N_ELMS);
+    for (i = 0; i < N_ELMS; i++)
+        rbuf[i] = rank;
+
+    lbuf = malloc(sizeof(int) * N_ELMS);
+    memset(lbuf, -1, sizeof(int) * N_ELMS);
+
+    reqs = malloc(sizeof(MPI_Request) * N_BLOCKS);
+
+    MPI_Win_create(rbuf, sizeof(int) * N_ELMS, sizeof(int), MPI_INFO_NULL, MPI_COMM_WORLD, &win);
+    MPI_Win_lock_all(MPI_MODE_NOCHECK, win);
+    for (i = 0; i < N_BLOCKS; i++)
+        MPI_Rget(lbuf+i*BLOCKSIZE, BLOCKSIZE, MPI_INT, trg, i*BLOCKSIZE, BLOCKSIZE, MPI_INT, win, &reqs[i]);
+    MPI_Win_unlock_all(win);
+    for (i = 0; i < N_ELMS; i++)
+        lbuf[i] = -2;
+
+    MPI_Waitall(N_BLOCKS, reqs, MPI_STATUSES_IGNORE);
+    for (i = 0; i < N_ELMS; i++) {
+        int v = lbuf[i];
+        if (v != -2) {
+            printf("lbuf[%d]=%d, expected -2\n", i, v);
+            n_errors++;
+        }
+    }
+    MPI_Win_free(&win);
+
+    free(reqs);
+    free(lbuf);
+    free(rbuf);
+
+    if (rank == 0 && n_errors == 0)
+        printf(" No Errors\n");
+
+    MPI_Finalize();
+    return 0;
+}
index cb228f3..70d092a 100644 (file)
         if (err) {                                                      \
             errs++;                                                     \
             if (errs < 10) {                                            \
-                MTestPrintErrorMsg( "PROC_NULL to " op_name_, err );    \
+                MTestPrintErrorMsg("PROC_NULL to " op_name_, err);    \
             }                                                           \
         }                                                               \
-        err = MPI_Win_fence( 0, win );                                  \
+        err = MPI_Win_fence(0, win);                                  \
         if (err) {                                                      \
             errs++;                                                     \
             if (errs < 10) {                                            \
-                MTestPrintErrorMsg( "Fence after " op_name_, err );     \
+                MTestPrintErrorMsg("Fence after " op_name_, err);     \
             }                                                           \
         }                                                               \
     } while (0)
         if (err) {                                                      \
             errs++;                                                     \
             if (errs < 10) {                                            \
-                MTestPrintErrorMsg( "Lock before" op_name_, err );      \
+                MTestPrintErrorMsg("Lock before" op_name_, err);      \
             }                                                           \
         }                                                               \
         err = fcn_call_                                                 \
         if (err) {                                                      \
             errs++;                                                     \
             if (errs < 10) {                                            \
-                MTestPrintErrorMsg( "PROC_NULL to " op_name_, err );    \
+                MTestPrintErrorMsg("PROC_NULL to " op_name_, err);    \
             }                                                           \
         }                                                               \
-        err = MPI_Win_unlock( MPI_PROC_NULL, win );                     \
+        err = MPI_Win_unlock(MPI_PROC_NULL, win);                     \
         if (err) {                                                      \
             errs++;                                                     \
             if (errs < 10) {                                            \
-                MTestPrintErrorMsg( "Unlock after " op_name_, err );    \
+                MTestPrintErrorMsg("Unlock after " op_name_, err);    \
             }                                                           \
         }                                                               \
     } while (0)
         if (err) {                                                      \
             errs++;                                                     \
             if (errs < 10) {                                            \
-                MTestPrintErrorMsg( "Lock before" op_name_, err );      \
+                MTestPrintErrorMsg("Lock before" op_name_, err);      \
             }                                                           \
         }                                                               \
         err = fcn_call_                                                 \
         if (err) {                                                      \
             errs++;                                                     \
             if (errs < 10) {                                            \
-                MTestPrintErrorMsg( "PROC_NULL to " op_name_, err );    \
+                MTestPrintErrorMsg("PROC_NULL to " op_name_, err);    \
             }                                                           \
         }                                                               \
-        err = MPI_Win_unlock( MPI_PROC_NULL, win );                     \
+        err = MPI_Win_unlock(MPI_PROC_NULL, win);                     \
         if (err) {                                                      \
             errs++;                                                     \
             if (errs < 10) {                                            \
-                MTestPrintErrorMsg( "Unlock after " op_name_, err );    \
+                MTestPrintErrorMsg("Unlock after " op_name_, err);    \
             }                                                           \
         }                                                               \
-        err = MPI_Wait( &req_, MPI_STATUS_IGNORE );                     \
+        err = MPI_Wait(&req_, MPI_STATUS_IGNORE);                     \
         if (err) {                                                      \
             errs++;                                                     \
             if (errs < 10) {                                            \
-                MTestPrintErrorMsg( "Wait after " op_name_, err );      \
+                MTestPrintErrorMsg("Wait after " op_name_, err);      \
             }                                                           \
         }                                                               \
     } while (0)
 static char MTEST_Descrip[] = "Test the MPI_PROC_NULL is a valid target";
 */
 
-int main( int argc, char *argv[] )
+int main(int argc, char *argv[])
 {
-    int           errs = 0, err;
-    int           rank, size;
-    int           *buf, bufsize;
-    int           *result;
-    int           *rmabuf, rsize, rcount;
-    MPI_Comm      comm;
-    MPI_Win       win;
-    MPI_Request   req;
+    int errs = 0, err;
+    int rank, size;
+    int *buf, bufsize;
+    int *result;
+    int *rmabuf, rsize, rcount;
+    MPI_Comm comm;
+    MPI_Win win;
+    MPI_Request req;
 
-    MTest_Init( &argc, &argv );
+    MTest_Init(&argc, &argv);
 
     bufsize = 256 * sizeof(int);
-    buf     = (int *)malloc( bufsize );
+    buf = (int *) malloc(bufsize);
     if (!buf) {
-       fprintf( stderr, "Unable to allocated %d bytes\n", bufsize );
-       MPI_Abort( MPI_COMM_WORLD, 1 );
+        fprintf(stderr, "Unable to allocated %d bytes\n", bufsize);
+        MPI_Abort(MPI_COMM_WORLD, 1);
     }
-    result  = (int *)malloc( bufsize );
+    result = (int *) malloc(bufsize);
     if (!result) {
-        fprintf( stderr, "Unable to allocated %d bytes\n", bufsize );
-        MPI_Abort( MPI_COMM_WORLD, 1 );
+        fprintf(stderr, "Unable to allocated %d bytes\n", bufsize);
+        MPI_Abort(MPI_COMM_WORLD, 1);
     }
-    rcount   = 16;
-    rsize    = rcount * sizeof(int);
-    rmabuf   = (int *)malloc( rsize );
+    rcount = 16;
+    rsize = rcount * sizeof(int);
+    rmabuf = (int *) malloc(rsize);
     if (!rmabuf) {
-       fprintf( stderr, "Unable to allocated %d bytes\n", rsize );
-       MPI_Abort( MPI_COMM_WORLD, 1 );
+        fprintf(stderr, "Unable to allocated %d bytes\n", rsize);
+        MPI_Abort(MPI_COMM_WORLD, 1);
     }
-       
-    /* 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, 1, 1 )) {
-       if (comm == MPI_COMM_NULL) continue;
-       /* Determine the sender and receiver */
-       MPI_Comm_rank( comm, &rank );
-       MPI_Comm_size( comm, &size );
-       
-       MPI_Win_create( buf, bufsize, sizeof(int), MPI_INFO_NULL, comm, &win );
-       /* To improve reporting of problems about operations, we
-          change the error handler to errors return */
-       MPI_Win_set_errhandler( win, MPI_ERRORS_RETURN );
+
+    /* 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, 1, 1)) {
+        if (comm == MPI_COMM_NULL)
+            continue;
+        /* Determine the sender and receiver */
+        MPI_Comm_rank(comm, &rank);
+        MPI_Comm_size(comm, &size);
+
+        MPI_Win_create(buf, bufsize, sizeof(int), MPI_INFO_NULL, comm, &win);
+        /* To improve reporting of problems about operations, we
+         * change the error handler to errors return */
+        MPI_Win_set_errhandler(win, MPI_ERRORS_RETURN);
 
         /** TEST OPERATIONS USING ACTIVE TARGET (FENCE) SYNCHRONIZATION **/
-        MPI_Win_fence( 0, win );
+        MPI_Win_fence(0, win);
 
         TEST_FENCE_OP("Put",
-                      MPI_Put( rmabuf, rcount, MPI_INT, MPI_PROC_NULL, 0,
-                               rcount, MPI_INT, win );
-                     );
+                      MPI_Put(rmabuf, rcount, MPI_INT, MPI_PROC_NULL, 0, rcount, MPI_INT, win);
+);
 
         TEST_FENCE_OP("Get",
-                      MPI_Get( rmabuf, rcount, MPI_INT, MPI_PROC_NULL, 0,
-                               rcount, MPI_INT, win );
-                     );
+                      MPI_Get(rmabuf, rcount, MPI_INT, MPI_PROC_NULL, 0, rcount, MPI_INT, win);
+);
         TEST_FENCE_OP("Accumulate",
-                      MPI_Accumulate( rmabuf, rcount, MPI_INT, MPI_PROC_NULL,
-                                      0, rcount, MPI_INT, MPI_SUM, win );
-                     );
+                      MPI_Accumulate(rmabuf, rcount, MPI_INT, MPI_PROC_NULL,
+                                     0, rcount, MPI_INT, MPI_SUM, win);
+);
         TEST_FENCE_OP("Get accumulate",
-                      MPI_Get_accumulate( rmabuf, rcount, MPI_INT, result,
-                                          rcount, MPI_INT, MPI_PROC_NULL, 0,
-                                          rcount, MPI_INT, MPI_SUM, win );
-                     );
+                      MPI_Get_accumulate(rmabuf, rcount, MPI_INT, result,
+                                         rcount, MPI_INT, MPI_PROC_NULL, 0,
+                                         rcount, MPI_INT, MPI_SUM, win);
+);
         TEST_FENCE_OP("Fetch and op",
-                      MPI_Fetch_and_op( rmabuf, result, MPI_INT, MPI_PROC_NULL,
-                                        0, MPI_SUM, win );
-                     );
+                      MPI_Fetch_and_op(rmabuf, result, MPI_INT, MPI_PROC_NULL, 0, MPI_SUM, win);
+);
         TEST_FENCE_OP("Compare and swap",
-                      MPI_Compare_and_swap( rmabuf, &rank, result, MPI_INT,
-                                            MPI_PROC_NULL, 0, win );
-                     );
+                      MPI_Compare_and_swap(rmabuf, &rank, result, MPI_INT, MPI_PROC_NULL, 0, win);
+);
 
         /** TEST OPERATIONS USING PASSIVE TARGET SYNCHRONIZATION **/
 
-        TEST_PT_OP("Put",
-                   MPI_Put( rmabuf, rcount, MPI_INT, MPI_PROC_NULL, 0, rcount,
-                            MPI_INT, win );
-                   );
-        TEST_PT_OP("Get",
-                   MPI_Get( rmabuf, rcount, MPI_INT, MPI_PROC_NULL, 0, rcount,
-                            MPI_INT, win );
-                   );
+        TEST_PT_OP("Put", MPI_Put(rmabuf, rcount, MPI_INT, MPI_PROC_NULL, 0, rcount, MPI_INT, win);
+);
+        TEST_PT_OP("Get", MPI_Get(rmabuf, rcount, MPI_INT, MPI_PROC_NULL, 0, rcount, MPI_INT, win);
+);
         TEST_PT_OP("Accumulate",
-                   MPI_Accumulate( rmabuf, rcount, MPI_INT, MPI_PROC_NULL, 0,
-                                   rcount, MPI_INT, MPI_SUM, win );
-                   );
+                   MPI_Accumulate(rmabuf, rcount, MPI_INT, MPI_PROC_NULL, 0,
+                                  rcount, MPI_INT, MPI_SUM, win);
+);
         TEST_PT_OP("Get accumulate",
-                   MPI_Get_accumulate( rmabuf, rcount, MPI_INT, result, rcount,
-                                       MPI_INT, MPI_PROC_NULL, 0, rcount,
-                                       MPI_INT, MPI_SUM, win );
-                   );
+                   MPI_Get_accumulate(rmabuf, rcount, MPI_INT, result, rcount,
+                                      MPI_INT, MPI_PROC_NULL, 0, rcount, MPI_INT, MPI_SUM, win);
+);
         TEST_PT_OP("Fetch and op",
-                   MPI_Fetch_and_op( rmabuf, result, MPI_INT, MPI_PROC_NULL, 0,
-                                     MPI_SUM, win );
-                   );
+                   MPI_Fetch_and_op(rmabuf, result, MPI_INT, MPI_PROC_NULL, 0, MPI_SUM, win);
+);
         TEST_PT_OP("Compare and swap",
-                   MPI_Compare_and_swap( rmabuf, &rank, result, MPI_INT,
-                                         MPI_PROC_NULL, 0, win );
-                   );
+                   MPI_Compare_and_swap(rmabuf, &rank, result, MPI_INT, MPI_PROC_NULL, 0, win);
+);
 
         /** TEST REQUEST-BASED OPERATIONS (PASSIVE TARGET ONLY) **/
 
         TEST_REQ_OP("Rput", req,
-                    MPI_Rput( rmabuf, rcount, MPI_INT, MPI_PROC_NULL, 0, rcount,
-                              MPI_INT, win, &req );
-                   );
+                    MPI_Rput(rmabuf, rcount, MPI_INT, MPI_PROC_NULL, 0, rcount, MPI_INT, win, &req);
+);
         TEST_REQ_OP("Rget", req,
-                    MPI_Rget( rmabuf, rcount, MPI_INT, MPI_PROC_NULL, 0, rcount,
-                              MPI_INT, win, &req );
-                   );
+                    MPI_Rget(rmabuf, rcount, MPI_INT, MPI_PROC_NULL, 0, rcount, MPI_INT, win, &req);
+);
         TEST_REQ_OP("Raccumulate", req,
-                    MPI_Raccumulate( rmabuf, rcount, MPI_INT, MPI_PROC_NULL, 0,
-                                     rcount, MPI_INT, MPI_SUM, win, &req );
-                   );
+                    MPI_Raccumulate(rmabuf, rcount, MPI_INT, MPI_PROC_NULL, 0,
+                                    rcount, MPI_INT, MPI_SUM, win, &req);
+);
         TEST_REQ_OP("Rget_accumulate", req,
-                    MPI_Rget_accumulate( rmabuf, rcount, MPI_INT, result,
-                                         rcount, MPI_INT, MPI_PROC_NULL, 0,
-                                         rcount, MPI_INT, MPI_SUM, win, &req );
-                   );
+                    MPI_Rget_accumulate(rmabuf, rcount, MPI_INT, result,
+                                        rcount, MPI_INT, MPI_PROC_NULL, 0,
+                                        rcount, MPI_INT, MPI_SUM, win, &req);
+);
 
-       MPI_Win_free( &win );
+        MPI_Win_free(&win);
         MTestFreeComm(&comm);
     }
 
-    free( result );
-    free( buf );
-    free( rmabuf );
-    MTest_Finalize( errs );
+    free(result);
+    free(buf);
+    free(rmabuf);
+    MTest_Finalize(errs);
     MPI_Finalize();
     return 0;
 }
index 9e27b77..78bbbe3 100644 (file)
         if (err) {                                                      \
             errs++;                                                     \
             if (errs < 10) {                                            \
-                MTestPrintErrorMsg( "Zero-byte op " op_name_, err );    \
+                MTestPrintErrorMsg("Zero-byte op " op_name_, err);    \
             }                                                           \
         }                                                               \
-        err = MPI_Win_fence( 0, win );                                  \
+        err = MPI_Win_fence(0, win);                                  \
         if (err) {                                                      \
             errs++;                                                     \
             if (errs < 10) {                                            \
-                MTestPrintErrorMsg( "Fence after " op_name_, err );     \
+                MTestPrintErrorMsg("Fence after " op_name_, err);     \
             }                                                           \
         }                                                               \
     } while (0)
         if (err) {                                                      \
             errs++;                                                     \
             if (errs < 10) {                                            \
-                MTestPrintErrorMsg( "Lock before" op_name_, err );      \
+                MTestPrintErrorMsg("Lock before" op_name_, err);      \
             }                                                           \
         }                                                               \
         err = fcn_call_                                                 \
         if (err) {                                                      \
             errs++;                                                     \
             if (errs < 10) {                                            \
-                MTestPrintErrorMsg( "Zero-byte op " op_name_, err );    \
+                MTestPrintErrorMsg("Zero-byte op " op_name_, err);    \
             }                                                           \
         }                                                               \
-        err = MPI_Win_unlock( TARGET, win );                            \
+        err = MPI_Win_unlock(TARGET, win);                            \
         if (err) {                                                      \
             errs++;                                                     \
             if (errs < 10) {                                            \
-                MTestPrintErrorMsg( "Unlock after " op_name_, err );    \
+                MTestPrintErrorMsg("Unlock after " op_name_, err);    \
             }                                                           \
         }                                                               \
     } while (0)
         if (err) {                                                      \
             errs++;                                                     \
             if (errs < 10) {                                            \
-                MTestPrintErrorMsg( "Lock before" op_name_, err );      \
+                MTestPrintErrorMsg("Lock before" op_name_, err);      \
             }                                                           \
         }                                                               \
         err = fcn_call_                                                 \
         if (err) {                                                      \
             errs++;                                                     \
             if (errs < 10) {                                            \
-                MTestPrintErrorMsg( "Zero-byte op " op_name_, err );    \
+                MTestPrintErrorMsg("Zero-byte op " op_name_, err);    \
             }                                                           \
         }                                                               \
-        err = MPI_Win_unlock( TARGET, win );                            \
+        err = MPI_Win_unlock(TARGET, win);                            \
         if (err) {                                                      \
             errs++;                                                     \
             if (errs < 10) {                                            \
-                MTestPrintErrorMsg( "Unlock after " op_name_, err );    \
+                MTestPrintErrorMsg("Unlock after " op_name_, err);    \
             }                                                           \
         }                                                               \
-        err = MPI_Wait( &req_, MPI_STATUS_IGNORE );                     \
+        err = MPI_Wait(&req_, MPI_STATUS_IGNORE);                     \
         if (err) {                                                      \
             errs++;                                                     \
             if (errs < 10) {                                            \
-                MTestPrintErrorMsg( "Wait after " op_name_, err );      \
+                MTestPrintErrorMsg("Wait after " op_name_, err);      \
             }                                                           \
         }                                                               \
     } while (0)
 static char MTEST_Descrip[] = "Test handling of zero-byte transfers";
 */
 
-int main( int argc, char *argv[] )
+int main(int argc, char *argv[])
 {
-    int           errs = 0, err;
-    int           rank, size;
-    int           *buf, bufsize;
-    int           *result;
-    int           *rmabuf, rsize, rcount;
-    MPI_Comm      comm;
-    MPI_Win       win;
-    MPI_Request   req;
-    MPI_Datatype  derived_dtp;
-
-    MTest_Init( &argc, &argv );
+    int errs = 0, err;
+    int rank, size;
+    int *buf, bufsize;
+    int *result;
+    int *rmabuf, rsize, rcount;
+    MPI_Comm comm;
+    MPI_Win win;
+    MPI_Request req;
+    MPI_Datatype derived_dtp;
+
+    MTest_Init(&argc, &argv);
 
     bufsize = 256 * sizeof(int);
-    buf     = (int *)malloc( bufsize );
+    buf = (int *) malloc(bufsize);
     if (!buf) {
-        fprintf( stderr, "Unable to allocated %d bytes\n", bufsize );
-        MPI_Abort( MPI_COMM_WORLD, 1 );
+        fprintf(stderr, "Unable to allocated %d bytes\n", bufsize);
+        MPI_Abort(MPI_COMM_WORLD, 1);
     }
-    result  = (int *)malloc( bufsize );
+    result = (int *) malloc(bufsize);
     if (!result) {
-        fprintf( stderr, "Unable to allocated %d bytes\n", bufsize );
-        MPI_Abort( MPI_COMM_WORLD, 1 );
+        fprintf(stderr, "Unable to allocated %d bytes\n", bufsize);
+        MPI_Abort(MPI_COMM_WORLD, 1);
     }
-    rcount   = 16;
-    rsize    = rcount * sizeof(int);
-    rmabuf   = (int *)malloc( rsize );
+    rcount = 16;
+    rsize = rcount * sizeof(int);
+    rmabuf = (int *) malloc(rsize);
     if (!rmabuf) {
-        fprintf( stderr, "Unable to allocated %d bytes\n", rsize );
-        MPI_Abort( MPI_COMM_WORLD, 1 );
+        fprintf(stderr, "Unable to allocated %d bytes\n", rsize);
+        MPI_Abort(MPI_COMM_WORLD, 1);
     }
 
     MPI_Type_contiguous(2, MPI_INT, &derived_dtp);
@@ -133,106 +133,94 @@ int main( int argc, char *argv[] )
 
     /* The following loop is used to run through a series of communicators
      * that are subsets of MPI_COMM_WORLD, of size 1 or greater. */
-    while (MTestGetIntracommGeneral( &comm, 1, 1 )) {
+    while (MTestGetIntracommGeneral(&comm, 1, 1)) {
         int count = 0;
 
-        if (comm == MPI_COMM_NULL) continue;
+        if (comm == MPI_COMM_NULL)
+            continue;
         /* Determine the sender and receiver */
-        MPI_Comm_rank( comm, &rank );
-        MPI_Comm_size( comm, &size );
+        MPI_Comm_rank(comm, &rank);
+        MPI_Comm_size(comm, &size);
 
-        MPI_Win_create( buf, bufsize, 2*sizeof(int), MPI_INFO_NULL, comm, &win );
+        MPI_Win_create(buf, bufsize, 2 * sizeof(int), MPI_INFO_NULL, comm, &win);
         /* To improve reporting of problems about operations, we
-           change the error handler to errors return */
-        MPI_Win_set_errhandler( win, MPI_ERRORS_RETURN );
+         * change the error handler to errors return */
+        MPI_Win_set_errhandler(win, MPI_ERRORS_RETURN);
 
         /** TEST OPERATIONS USING ACTIVE TARGET (FENCE) SYNCHRONIZATION **/
-        MPI_Win_fence( 0, win );
+        MPI_Win_fence(0, win);
 
-        TEST_FENCE_OP("Put",
-                      MPI_Put( rmabuf, count, MPI_INT, TARGET, 0,
-                               count, MPI_INT, win );
-                     );
+        TEST_FENCE_OP("Put", MPI_Put(rmabuf, count, MPI_INT, TARGET, 0, count, MPI_INT, win);
+);
 
-        TEST_FENCE_OP("Get",
-                      MPI_Get( rmabuf, count, MPI_INT, TARGET, 0,
-                               count, MPI_INT, win );
-                     );
+        TEST_FENCE_OP("Get", MPI_Get(rmabuf, count, MPI_INT, TARGET, 0, count, MPI_INT, win);
+);
         TEST_FENCE_OP("Accumulate",
-                      MPI_Accumulate( rmabuf, count, MPI_INT, TARGET,
-                                      0, count, MPI_INT, MPI_SUM, win );
-                     );
+                      MPI_Accumulate(rmabuf, count, MPI_INT, TARGET,
+                                     0, count, MPI_INT, MPI_SUM, win);
+);
         TEST_FENCE_OP("Accumulate_derived",
-                      MPI_Accumulate( rmabuf, count, derived_dtp, TARGET,
-                                      0, count, derived_dtp, MPI_SUM, win );
-                     );
+                      MPI_Accumulate(rmabuf, count, derived_dtp, TARGET,
+                                     0, count, derived_dtp, MPI_SUM, win);
+);
         TEST_FENCE_OP("Get accumulate",
-                      MPI_Get_accumulate( rmabuf, count, MPI_INT, result,
-                                          count, MPI_INT, TARGET, 0,
-                                          count, MPI_INT, MPI_SUM, win );
-                     );
+                      MPI_Get_accumulate(rmabuf, count, MPI_INT, result,
+                                         count, MPI_INT, TARGET, 0, count, MPI_INT, MPI_SUM, win);
+);
         /* Note: It's not possible to generate a zero-byte FOP or CAS */
 
         /** TEST OPERATIONS USING PASSIVE TARGET SYNCHRONIZATION **/
 
-        TEST_PT_OP("Put",
-                   MPI_Put( rmabuf, count, MPI_INT, TARGET, 0, count,
-                            MPI_INT, win );
-                   );
-        TEST_PT_OP("Get",
-                   MPI_Get( rmabuf, count, MPI_INT, TARGET, 0, count,
-                            MPI_INT, win );
-                   );
+        TEST_PT_OP("Put", MPI_Put(rmabuf, count, MPI_INT, TARGET, 0, count, MPI_INT, win);
+);
+        TEST_PT_OP("Get", MPI_Get(rmabuf, count, MPI_INT, TARGET, 0, count, MPI_INT, win);
+);
         TEST_PT_OP("Accumulate",
-                   MPI_Accumulate( rmabuf, count, MPI_INT, TARGET, 0,
-                                   count, MPI_INT, MPI_SUM, win );
-                   );
+                   MPI_Accumulate(rmabuf, count, MPI_INT, TARGET, 0, count, MPI_INT, MPI_SUM, win);
+);
         TEST_PT_OP("Accumulate_derived",
-                   MPI_Accumulate( rmabuf, count, derived_dtp, TARGET, 0,
-                                   count, derived_dtp, MPI_SUM, win );
-                   );
+                   MPI_Accumulate(rmabuf, count, derived_dtp, TARGET, 0,
+                                  count, derived_dtp, MPI_SUM, win);
+);
         TEST_PT_OP("Get accumulate",
-                   MPI_Get_accumulate( rmabuf, count, MPI_INT, result, count,
-                                       MPI_INT, TARGET, 0, count,
-                                       MPI_INT, MPI_SUM, win );
-                   );
+                   MPI_Get_accumulate(rmabuf, count, MPI_INT, result, count,
+                                      MPI_INT, TARGET, 0, count, MPI_INT, MPI_SUM, win);
+);
 
         /* Note: It's not possible to generate a zero-byte FOP or CAS */
 
         /** TEST REQUEST-BASED OPERATIONS (PASSIVE TARGET ONLY) **/
 
         TEST_REQ_OP("Rput", req,
-                    MPI_Rput( rmabuf, count, MPI_INT, TARGET, 0, count,
-                              MPI_INT, win, &req );
-                   );
+                    MPI_Rput(rmabuf, count, MPI_INT, TARGET, 0, count, MPI_INT, win, &req);
+);
         TEST_REQ_OP("Rget", req,
-                    MPI_Rget( rmabuf, count, MPI_INT, TARGET, 0, count,
-                              MPI_INT, win, &req );
-                   );
+                    MPI_Rget(rmabuf, count, MPI_INT, TARGET, 0, count, MPI_INT, win, &req);
+);
         TEST_REQ_OP("Raccumulate", req,
-                    MPI_Raccumulate( rmabuf, count, MPI_INT, TARGET, 0,
-                                     count, MPI_INT, MPI_SUM, win, &req );
-                   );
+                    MPI_Raccumulate(rmabuf, count, MPI_INT, TARGET, 0,
+                                    count, MPI_INT, MPI_SUM, win, &req);
+);
         TEST_REQ_OP("Raccumulate_derived", req,
-                    MPI_Raccumulate( rmabuf, count, derived_dtp, TARGET, 0,
-                                     count, derived_dtp, MPI_SUM, win, &req );
-                   );
+                    MPI_Raccumulate(rmabuf, count, derived_dtp, TARGET, 0,
+                                    count, derived_dtp, MPI_SUM, win, &req);
+);
         TEST_REQ_OP("Rget_accumulate", req,
-                    MPI_Rget_accumulate( rmabuf, count, MPI_INT, result,
-                                         count, MPI_INT, TARGET, 0,
-                                         count, MPI_INT, MPI_SUM, win, &req );
-                   );
+                    MPI_Rget_accumulate(rmabuf, count, MPI_INT, result,
+                                        count, MPI_INT, TARGET, 0,
+                                        count, MPI_INT, MPI_SUM, win, &req);
+);
 
-        MPI_Win_free( &win );
+        MPI_Win_free(&win);
         MTestFreeComm(&comm);
     }
 
     MPI_Type_free(&derived_dtp);
 
-    free( result );
-    free( buf );
-    free( rmabuf );
-    MTest_Finalize( errs );
+    free(result);
+    free(buf);
+    free(rmabuf);
+    MTest_Finalize(errs);
     MPI_Finalize();
     return 0;
 }
diff --git a/teshsuite/smpi/mpich3-test/rma/rput_local_comp.c b/teshsuite/smpi/mpich3-test/rma/rput_local_comp.c
new file mode 100644 (file)
index 0000000..0d1f682
--- /dev/null
@@ -0,0 +1,129 @@
+/* -*- Mode: C; c-basic-offset:4 ; indent-tabs-mode:nil ; -*- */
+/*
+ *
+ *  (C) 2014 by Argonne National Laboratory.
+ *      See COPYRIGHT in top-level directory.
+ */
+#include <mpi.h>
+#include <stdio.h>
+#include <assert.h>
+#include "mpitest.h"
+
+#define ITER 100
+#define MAX_SIZE 65536
+
+int main(int argc, char *argv[])
+{
+    int rank, nproc, i;
+    int errors = 0, all_errors = 0;
+    int *buf = NULL, *winbuf = NULL;
+    MPI_Win window;
+
+    MPI_Init(&argc, &argv);
+    MPI_Comm_rank(MPI_COMM_WORLD, &rank);
+    MPI_Comm_size(MPI_COMM_WORLD, &nproc);
+
+    if (nproc < 2) {
+        if (rank == 0)
+            printf("Error: must be run with two or more processes\n");
+        MPI_Abort(MPI_COMM_WORLD, 1);
+    }
+
+    MPI_Alloc_mem(MAX_SIZE * sizeof(int), MPI_INFO_NULL, &buf);
+    MPI_Alloc_mem(MAX_SIZE * sizeof(int), MPI_INFO_NULL, &winbuf);
+    MPI_Win_create(winbuf, MAX_SIZE * sizeof(int), sizeof(int), MPI_INFO_NULL,
+                   MPI_COMM_WORLD, &window);
+
+    MPI_Win_lock_all(0, window);
+
+    /* Test Rput local completion with small data.
+     * Small data is always copied to header packet as immediate data. */
+    if (rank == 1) {
+        for (i = 0; i < ITER; i++) {
+            MPI_Request put_req;
+            int val = -1;
+
+            buf[0] = rank;
+            MPI_Rput(&buf[0], 1, MPI_INT, 0, 0, 1, MPI_INT, window, &put_req);
+            MPI_Wait(&put_req, MPI_STATUS_IGNORE);
+
+            /* reset local buffer to check local completion */
+            buf[0] = 0;
+            MPI_Win_flush(0, window);
+
+            MPI_Get(&val, 1, MPI_INT, 0, 0, 1, MPI_INT, window);
+            MPI_Win_flush(0, window);
+
+            if (val != rank) {
+                printf("%d - Got %d in small Rput test, expected %d\n", rank, val, rank);
+                errors++;
+            }
+        }
+    }
+
+    MPI_Barrier(MPI_COMM_WORLD);
+
+    /* Test Rput local completion with large data .
+     * Large data is not suitable for 1-copy optimization, and always sent out
+     * from user buffer. */
+    if (rank == 1) {
+        for (i = 0; i < ITER; i++) {
+            MPI_Request put_req;
+            int val0 = -1, val1 = -1, val2 = -1;
+            int j;
+
+            /* initialize data */
+            for (j = 0; j < MAX_SIZE; j++) {
+                buf[j] = rank + j + i;
+            }
+
+            MPI_Rput(buf, MAX_SIZE, MPI_INT, 0, 0, MAX_SIZE, MPI_INT, window, &put_req);
+            MPI_Wait(&put_req, MPI_STATUS_IGNORE);
+
+            /* reset local buffer to check local completion */
+            buf[0] = 0;
+            buf[MAX_SIZE - 1] = 0;
+            buf[MAX_SIZE / 2] = 0;
+            MPI_Win_flush(0, window);
+
+            /* get remote values which are modified in local buffer after wait */
+            MPI_Get(&val0, 1, MPI_INT, 0, 0, 1, MPI_INT, window);
+            MPI_Get(&val1, 1, MPI_INT, 0, MAX_SIZE - 1, 1, MPI_INT, window);
+            MPI_Get(&val2, 1, MPI_INT, 0, MAX_SIZE / 2, 1, MPI_INT, window);
+            MPI_Win_flush(0, window);
+
+            if (val0 != rank + i) {
+                printf("%d - Got %d in large Rput test, expected %d\n", rank, val0, rank + i);
+                errors++;
+            }
+            if (val1 != rank + MAX_SIZE - 1 + i) {
+                printf("%d - Got %d in large Rput test, expected %d\n", rank, val1,
+                       rank + MAX_SIZE - 1 + i);
+                errors++;
+            }
+            if (val2 != rank + MAX_SIZE / 2 + i) {
+                printf("%d - Got %d in large Rput test, expected %d\n", rank, val2,
+                       rank + MAX_SIZE / 2 + i);
+                errors++;
+            }
+        }
+    }
+
+    MPI_Win_unlock_all(window);
+    MPI_Barrier(MPI_COMM_WORLD);
+
+    MPI_Win_free(&window);
+    if (buf)
+        MPI_Free_mem(buf);
+    if (winbuf)
+        MPI_Free_mem(winbuf);
+
+    MPI_Reduce(&errors, &all_errors, 1, MPI_INT, MPI_SUM, 0, MPI_COMM_WORLD);
+
+    if (rank == 0 && all_errors == 0)
+        printf(" No Errors\n");
+
+    MPI_Finalize();
+
+    return 0;
+}
index ca8ae4b..6a8b4f0 100644 (file)
 static char MTEST_Descrip[] = "RMA to self";
 */
 
-int main( int argc, char *argv[] )
+int main(int argc, char *argv[])
 {
     int errs = 0;
     int rank, size, i, j;
-    MPI_Comm      comm;
-    MPI_Win       win;
-    int           *winbuf, count;
-    int           *sbuf, scount, vcount;
-    MPI_Datatype  vectype;
+    MPI_Comm comm;
+    MPI_Win win;
+    int *winbuf, count;
+    int *sbuf, scount, vcount;
+    MPI_Datatype vectype;
 
-    MTest_Init( &argc, &argv );
+    MTest_Init(&argc, &argv);
 
     comm = MPI_COMM_WORLD;
 
-    MPI_Comm_rank( comm, &rank );
-    MPI_Comm_size( comm, &size );
+    MPI_Comm_rank(comm, &rank);
+    MPI_Comm_size(comm, &size);
 
     /* Allocate and initialize sbuf */
     scount = 1000;
-    count  = 1000;
-    sbuf   = (int *)malloc( scount * sizeof(int) );
+    count = 1000;
+    sbuf = (int *) malloc(scount * sizeof(int));
     if (!sbuf) {
-       fprintf( stderr, "Could not allocate send buffer f size %d\n", 
-                scount );
-       MPI_Abort( MPI_COMM_WORLD, 0 );
+        fprintf(stderr, "Could not allocate send buffer f size %d\n", scount);
+        MPI_Abort(MPI_COMM_WORLD, 0);
     }
-    for (i=0; i<scount; i++) sbuf[i] = i;
+    for (i = 0; i < scount; i++)
+        sbuf[i] = i;
 
-    MPI_Alloc_mem( count*sizeof(int), MPI_INFO_NULL, &winbuf );
+    MPI_Alloc_mem(count * sizeof(int), MPI_INFO_NULL, &winbuf);
 
     /* This is a simple vector type */
     vcount = count / 4;
-    MPI_Type_vector( vcount, 1, 2, MPI_INT, &vectype );
-    MPI_Type_commit( &vectype );
-    MPI_Win_create( winbuf, count * sizeof(int), sizeof(int), MPI_INFO_NULL, 
-                   comm, &win );
+    MPI_Type_vector(vcount, 1, 2, MPI_INT, &vectype);
+    MPI_Type_commit(&vectype);
+    MPI_Win_create(winbuf, count * sizeof(int), sizeof(int), MPI_INFO_NULL, comm, &win);
+
+    /* Check with different combination of types, including non-contig on
+     * both sides */
 
-    /* Check with different combination of types, including non-contig on 
-       both sides */
-    
     /* Clear winbuf */
-    memset( winbuf, 0, count*sizeof(int) );
-    MPI_Win_lock( MPI_LOCK_EXCLUSIVE, rank, 0, win );
-    MPI_Put( sbuf, 1, vectype, rank, 0, 1, vectype, win );
-    MPI_Win_unlock( rank, win );
+    memset(winbuf, 0, count * sizeof(int));
+    MPI_Win_lock(MPI_LOCK_EXCLUSIVE, rank, 0, win);
+    MPI_Put(sbuf, 1, vectype, rank, 0, 1, vectype, win);
+    MPI_Win_unlock(rank, win);
     /* Check results */
     j = 0;
-    for (i=0; i<vcount; i++) {
-       if (winbuf[j] != sbuf[j]) {
-           errs ++;
-           fprintf( stderr, "VecPut: winbuf[%d] = %d, should = %d\n", 
-                    winbuf[j], j, sbuf[j] );
-       }
-       j += 2;
+    for (i = 0; i < vcount; i++) {
+        if (winbuf[j] != sbuf[j]) {
+            errs++;
+            fprintf(stderr, "VecPut: winbuf[%d] = %d, should = %d\n", j, winbuf[j], sbuf[j]);
+        }
+        j += 2;
     }
 
-    memset( winbuf, 0, count*sizeof(int) );
-    MPI_Win_lock( MPI_LOCK_SHARED, rank, 0, win );
-    MPI_Accumulate( sbuf, 1, vectype, rank, 0, 1, vectype, MPI_SUM, win );
-    MPI_Win_unlock( rank, win );
+    memset(winbuf, 0, count * sizeof(int));
+    MPI_Win_lock(MPI_LOCK_SHARED, rank, 0, win);
+    MPI_Accumulate(sbuf, 1, vectype, rank, 0, 1, vectype, MPI_SUM, win);
+    MPI_Win_unlock(rank, win);
     /* Check results */
     j = 0;
-    for (i=0; i<vcount; i++) {
-       if (winbuf[j] != sbuf[j]) {
-           errs ++;
-           fprintf( stderr, "VecAcc: winbuf[%d] = %d, should = %d\n", 
-                    winbuf[j], j, sbuf[j] );
-       }
-       j += 2;
+    for (i = 0; i < vcount; i++) {
+        if (winbuf[j] != sbuf[j]) {
+            errs++;
+            fprintf(stderr, "VecAcc: winbuf[%d] = %d, should = %d\n", j, winbuf[j], sbuf[j]);
+        }
+        j += 2;
     }
 
     /* Now, use get to fetch back the results that we just wrote */
-    memset( sbuf, 0, count*sizeof(int) );
-    MPI_Win_lock( MPI_LOCK_SHARED, rank, 0, win );
-    MPI_Get( sbuf, 1, vectype, rank, 0, 1, vectype, win );
-    MPI_Win_unlock( rank, win );
+    memset(sbuf, 0, count * sizeof(int));
+    MPI_Win_lock(MPI_LOCK_SHARED, rank, 0, win);
+    MPI_Get(sbuf, 1, vectype, rank, 0, 1, vectype, win);
+    MPI_Win_unlock(rank, win);
     /* Check results */
     j = 0;
-    for (i=0; i<vcount; i++) {
-       if (winbuf[j] != sbuf[j]) {
-           errs ++;
-           fprintf( stderr, "VecAcc: winbuf[%d] = %d, should = %d\n", 
-                    winbuf[j], j, sbuf[j] );
-       }
-       j += 2;
+    for (i = 0; i < vcount; i++) {
+        if (winbuf[j] != sbuf[j]) {
+            errs++;
+            fprintf(stderr, "VecAcc: winbuf[%d] = %d, should = %d\n", j, winbuf[j], sbuf[j]);
+        }
+        j += 2;
     }
 
-    MPI_Win_free( &win );
-    MPI_Free_mem( winbuf );
-    free( sbuf );
-    MPI_Type_free( &vectype );
+    MPI_Win_free(&win);
+    MPI_Free_mem(winbuf);
+    free(sbuf);
+    MPI_Type_free(&vectype);
 
-    MTest_Finalize( errs );
+    MTest_Finalize(errs);
 
     MPI_Finalize();
     return 0;
index ac54f52..e16ac1f 100644 (file)
@@ -6,7 +6,7 @@
 
 /* One-Sided MPI 2-D Strided Accumulate Test
  *
- * Author: James Dinan <dinan@mcs.anl.gov> 
+ * Author: James Dinan <dinan@mcs.anl.gov>
  * Date  : December, 2010
  *
  * This code performs N accumulates into a 2d patch of a shared array.  The
@@ -28,7 +28,8 @@
 #define SUB_YDIM 8
 #define ITERATIONS 1
 
-int main(int argc, char **argv) {
+int main(int argc, char **argv)
+{
     int itr, i, j, rank, nranks, peer, bufsize, errors;
     double *win_buf, *src_buf;
     MPI_Win buf_win;
@@ -42,51 +43,51 @@ int main(int argc, char **argv) {
     MPI_Alloc_mem(bufsize, MPI_INFO_NULL, &win_buf);
     MPI_Alloc_mem(bufsize, MPI_INFO_NULL, &src_buf);
 
-    for (i = 0; i < XDIM*YDIM; i++) {
+    for (i = 0; i < XDIM * YDIM; i++) {
         *(win_buf + i) = -1.0;
         *(src_buf + i) = 1.0 + rank;
     }
 
     MPI_Win_create(win_buf, bufsize, 1, MPI_INFO_NULL, MPI_COMM_WORLD, &buf_win);
 
-    peer = (rank+1) % nranks;
+    peer = (rank + 1) % nranks;
 
     /* Perform ITERATIONS strided accumulate operations */
 
     for (itr = 0; itr < ITERATIONS; itr++) {
-      MPI_Aint idx_loc[SUB_YDIM];
-      int idx_rem[SUB_YDIM];
-      int blk_len[SUB_YDIM];
-      MPI_Datatype src_type, dst_type;
-
-      for (i = 0; i < SUB_YDIM; i++) {
-        MPI_Get_address(&src_buf[i*XDIM], &idx_loc[i]);
-        idx_rem[i] = i*XDIM;
-        blk_len[i] = SUB_XDIM;
-      }
+        MPI_Aint idx_loc[SUB_YDIM];
+        int idx_rem[SUB_YDIM];
+        int blk_len[SUB_YDIM];
+        MPI_Datatype src_type, dst_type;
+
+        for (i = 0; i < SUB_YDIM; i++) {
+            MPI_Get_address(&src_buf[i * XDIM], &idx_loc[i]);
+            idx_rem[i] = i * XDIM;
+            blk_len[i] = SUB_XDIM;
+        }
 
 #ifdef ABSOLUTE
-      MPI_Type_hindexed(SUB_YDIM, blk_len, idx_loc, MPI_DOUBLE, &src_type);
+        MPI_Type_hindexed(SUB_YDIM, blk_len, idx_loc, MPI_DOUBLE, &src_type);
 #else
-      MPI_Type_indexed(SUB_YDIM, blk_len, idx_rem, MPI_DOUBLE, &src_type);
+        MPI_Type_indexed(SUB_YDIM, blk_len, idx_rem, MPI_DOUBLE, &src_type);
 #endif
-      MPI_Type_indexed(SUB_YDIM, blk_len, idx_rem, MPI_DOUBLE, &dst_type);
+        MPI_Type_indexed(SUB_YDIM, blk_len, idx_rem, MPI_DOUBLE, &dst_type);
 
-      MPI_Type_commit(&src_type);
-      MPI_Type_commit(&dst_type);
+        MPI_Type_commit(&src_type);
+        MPI_Type_commit(&dst_type);
 
-      MPI_Win_lock(MPI_LOCK_EXCLUSIVE, peer, 0, buf_win);
+        MPI_Win_lock(MPI_LOCK_EXCLUSIVE, peer, 0, buf_win);
 
 #ifdef ABSOLUTE
-      MPI_Accumulate(MPI_BOTTOM, 1, src_type, peer, 0, 1, dst_type, MPI_SUM, buf_win);
+        MPI_Accumulate(MPI_BOTTOM, 1, src_type, peer, 0, 1, dst_type, MPI_SUM, buf_win);
 #else
-      MPI_Accumulate(src_buf, 1, src_type, peer, 0, 1, dst_type, MPI_SUM, buf_win);
+        MPI_Accumulate(src_buf, 1, src_type, peer, 0, 1, dst_type, MPI_SUM, buf_win);
 #endif
 
-      MPI_Win_unlock(peer, buf_win);
+        MPI_Win_unlock(peer, buf_win);
 
-      MPI_Type_free(&src_type);
-      MPI_Type_free(&dst_type);
+        MPI_Type_free(&src_type);
+        MPI_Type_free(&dst_type);
     }
 
     MPI_Barrier(MPI_COMM_WORLD);
@@ -96,40 +97,40 @@ int main(int argc, char **argv) {
     MPI_Win_lock(MPI_LOCK_EXCLUSIVE, rank, 0, buf_win);
     errors = 0;
     for (i = 0; i < SUB_XDIM; i++) {
-      for (j = 0; j < SUB_YDIM; j++) {
-        const double actual   = *(win_buf + i + j*XDIM);
-        const double expected = -1.0 + (1.0 + ((rank+nranks-1)%nranks)) * (ITERATIONS);
-        if (fabs(actual - expected) > 1.0e-10) {
-          SQUELCH( printf("%d: Data validation failed at [%d, %d] expected=%f actual=%f\n",
-              rank, j, i, expected, actual); );
-          errors++;
-          fflush(stdout);
+        for (j = 0; j < SUB_YDIM; j++) {
+            const double actual = *(win_buf + i + j * XDIM);
+            const double expected = -1.0 + (1.0 + ((rank + nranks - 1) % nranks)) * (ITERATIONS);
+            if (fabs(actual - expected) > 1.0e-10) {
+                SQUELCH(printf("%d: Data validation failed at [%d, %d] expected=%f actual=%f\n",
+                               rank, j, i, expected, actual););
+                errors++;
+                fflush(stdout);
+            }
         }
-      }
     }
     for (i = SUB_XDIM; i < XDIM; i++) {
-      for (j = 0; j < SUB_YDIM; j++) {
-        const double actual   = *(win_buf + i + j*XDIM);
-        const double expected = -1.0;
-        if (fabs(actual - expected) > 1.0e-10) {
-          SQUELCH( printf("%d: Data validation failed at [%d, %d] expected=%f actual=%f\n",
-              rank, j, i, expected, actual); );
-          errors++;
-          fflush(stdout);
+        for (j = 0; j < SUB_YDIM; j++) {
+            const double actual = *(win_buf + i + j * XDIM);
+            const double expected = -1.0;
+            if (fabs(actual - expected) > 1.0e-10) {
+                SQUELCH(printf("%d: Data validation failed at [%d, %d] expected=%f actual=%f\n",
+                               rank, j, i, expected, actual););
+                errors++;
+                fflush(stdout);
+            }
         }
-      }
     }
     for (i = 0; i < XDIM; i++) {
-      for (j = SUB_YDIM; j < YDIM; j++) {
-        const double actual   = *(win_buf + i + j*XDIM);
-        const double expected = -1.0;
-        if (fabs(actual - expected) > 1.0e-10) {
-          SQUELCH( printf("%d: Data validation failed at [%d, %d] expected=%f actual=%f\n",
-              rank, j, i, expected, actual); );
-          errors++;
-          fflush(stdout);
+        for (j = SUB_YDIM; j < YDIM; j++) {
+            const double actual = *(win_buf + i + j * XDIM);
+            const double expected = -1.0;
+            if (fabs(actual - expected) > 1.0e-10) {
+                SQUELCH(printf("%d: Data validation failed at [%d, %d] expected=%f actual=%f\n",
+                               rank, j, i, expected, actual););
+                errors++;
+                fflush(stdout);
+            }
         }
-      }
     }
     MPI_Win_unlock(rank, buf_win);
 
@@ -137,7 +138,7 @@ int main(int argc, char **argv) {
     MPI_Free_mem(win_buf);
     MPI_Free_mem(src_buf);
 
-    MTest_Finalize( errors );
+    MTest_Finalize(errors);
     MPI_Finalize();
-    return MTestReturnValue( errors );
+    return MTestReturnValue(errors);
 }
index 55ecde2..529d628 100644 (file)
@@ -6,7 +6,7 @@
 
 /* One-Sided MPI 2-D Strided Accumulate Test
  *
- * Author: James Dinan <dinan@mcs.anl.gov> 
+ * Author: James Dinan <dinan@mcs.anl.gov>
  * Date  : December, 2010
  *
  * This code performs one-sided accumulate into a 2d patch of a shared array.
 #include "mpitest.h"
 #include "squelch.h"
 
-#define XDIM 1024 
+#define XDIM 1024
 #define YDIM 1024
 #define ITERATIONS 10
 
-int main(int argc, char **argv) {
+int main(int argc, char **argv)
+{
     int i, j, rank, nranks, peer, bufsize, errors;
     double *buffer, *src_buf;
     MPI_Win buf_win;
@@ -37,41 +38,42 @@ int main(int argc, char **argv) {
     MPI_Alloc_mem(bufsize, MPI_INFO_NULL, &buffer);
     MPI_Alloc_mem(bufsize, MPI_INFO_NULL, &src_buf);
 
-    for (i = 0; i < XDIM*YDIM; i++) {
-        *(buffer  + i) = 1.0 + rank;
+    for (i = 0; i < XDIM * YDIM; i++) {
+        *(buffer + i) = 1.0 + rank;
         *(src_buf + i) = 1.0 + rank;
     }
 
     MPI_Win_create(buffer, bufsize, 1, MPI_INFO_NULL, MPI_COMM_WORLD, &buf_win);
 
-    peer = (rank+1) % nranks;
+    peer = (rank + 1) % nranks;
 
     for (i = 0; i < ITERATIONS; i++) {
 
-      MPI_Win_lock(MPI_LOCK_EXCLUSIVE, peer, 0, buf_win);
+        MPI_Win_lock(MPI_LOCK_EXCLUSIVE, peer, 0, buf_win);
 
-      for (j = 0; j < YDIM; j++) {
-        MPI_Accumulate(src_buf + j*XDIM, XDIM, MPI_DOUBLE, peer,
-                       j*XDIM*sizeof(double), XDIM, MPI_DOUBLE, MPI_SUM, buf_win);
-      }
+        for (j = 0; j < YDIM; j++) {
+            MPI_Accumulate(src_buf + j * XDIM, XDIM, MPI_DOUBLE, peer,
+                           j * XDIM * sizeof(double), XDIM, MPI_DOUBLE, MPI_SUM, buf_win);
+        }
 
-      MPI_Win_unlock(peer, buf_win);
+        MPI_Win_unlock(peer, buf_win);
     }
 
     MPI_Barrier(MPI_COMM_WORLD);
 
     MPI_Win_lock(MPI_LOCK_EXCLUSIVE, rank, 0, buf_win);
     for (i = errors = 0; i < XDIM; i++) {
-      for (j = 0; j < YDIM; j++) {
-        const double actual   = *(buffer + i + j*XDIM);
-        const double expected = (1.0 + rank) + (1.0 + ((rank+nranks-1)%nranks)) * (ITERATIONS);
-        if (fabs(actual - expected) > 1.0e-10) {
-          SQUELCH( printf("%d: Data validation failed at [%d, %d] expected=%f actual=%f\n",
-              rank, j, i, expected, actual); );
-          errors++;
-          fflush(stdout);
+        for (j = 0; j < YDIM; j++) {
+            const double actual = *(buffer + i + j * XDIM);
+            const double expected =
+                (1.0 + rank) + (1.0 + ((rank + nranks - 1) % nranks)) * (ITERATIONS);
+            if (fabs(actual - expected) > 1.0e-10) {
+                SQUELCH(printf("%d: Data validation failed at [%d, %d] expected=%f actual=%f\n",
+                               rank, j, i, expected, actual););
+                errors++;
+                fflush(stdout);
+            }
         }
-      }
     }
     MPI_Win_unlock(rank, buf_win);
 
@@ -79,7 +81,7 @@ int main(int argc, char **argv) {
     MPI_Free_mem(buffer);
     MPI_Free_mem(src_buf);
 
-    MTest_Finalize( errors );
+    MTest_Finalize(errors);
     MPI_Finalize();
-    return MTestReturnValue( errors );
+    return MTestReturnValue(errors);
 }
index c8f850c..b1c667c 100644 (file)
@@ -6,7 +6,7 @@
 
 /* One-Sided MPI 2-D Strided Accumulate Test
  *
- * Author: James Dinan <dinan@mcs.anl.gov> 
+ * Author: James Dinan <dinan@mcs.anl.gov>
  * Date  : December, 2010
  *
  * This code performs N accumulates into a 2d patch of a shared array.  The
 #include "mpitest.h"
 #include "squelch.h"
 
-#define XDIM 1024 
+#define XDIM 1024
 #define YDIM 1024
 #define SUB_XDIM 512
 #define SUB_YDIM 512
 #define ITERATIONS 10
 
-int main(int argc, char **argv) {
+int main(int argc, char **argv)
+{
     int i, j, rank, nranks, peer, bufsize, errors;
     double *win_buf, *src_buf;
     MPI_Win buf_win;
@@ -42,44 +43,44 @@ int main(int argc, char **argv) {
     MPI_Alloc_mem(bufsize, MPI_INFO_NULL, &win_buf);
     MPI_Alloc_mem(bufsize, MPI_INFO_NULL, &src_buf);
 
-    for (i = 0; i < XDIM*YDIM; i++) {
+    for (i = 0; i < XDIM * YDIM; i++) {
         *(win_buf + i) = -1.0;
         *(src_buf + i) = 1.0 + rank;
     }
 
     MPI_Win_create(win_buf, bufsize, 1, MPI_INFO_NULL, MPI_COMM_WORLD, &buf_win);
 
-    peer = (rank+1) % nranks;
+    peer = (rank + 1) % nranks;
 
     /* Perform ITERATIONS strided accumulate operations */
 
     for (i = 0; i < ITERATIONS; i++) {
-      int ndims               = 2;
-      int src_arr_sizes[2]    = { XDIM, YDIM };
-      int src_arr_subsizes[2] = { SUB_XDIM, SUB_YDIM };
-      int src_arr_starts[2]   = {    0,    0 };
-      int dst_arr_sizes[2]    = { XDIM, YDIM };
-      int dst_arr_subsizes[2] = { SUB_XDIM, SUB_YDIM };
-      int dst_arr_starts[2]   = {    0,    0 };
-      MPI_Datatype src_type, dst_type;
+        int ndims = 2;
+        int src_arr_sizes[2] = { XDIM, YDIM };
+        int src_arr_subsizes[2] = { SUB_XDIM, SUB_YDIM };
+        int src_arr_starts[2] = { 0, 0 };
+        int dst_arr_sizes[2] = { XDIM, YDIM };
+        int dst_arr_subsizes[2] = { SUB_XDIM, SUB_YDIM };
+        int dst_arr_starts[2] = { 0, 0 };
+        MPI_Datatype src_type, dst_type;
 
-      MPI_Type_create_subarray(ndims, src_arr_sizes, src_arr_subsizes, src_arr_starts,
-          MPI_ORDER_C, MPI_DOUBLE, &src_type);
+        MPI_Type_create_subarray(ndims, src_arr_sizes, src_arr_subsizes, src_arr_starts,
+                                 MPI_ORDER_C, MPI_DOUBLE, &src_type);
 
-      MPI_Type_create_subarray(ndims, dst_arr_sizes, dst_arr_subsizes, dst_arr_starts,
-          MPI_ORDER_C, MPI_DOUBLE, &dst_type);
+        MPI_Type_create_subarray(ndims, dst_arr_sizes, dst_arr_subsizes, dst_arr_starts,
+                                 MPI_ORDER_C, MPI_DOUBLE, &dst_type);
 
-      MPI_Type_commit(&src_type);
-      MPI_Type_commit(&dst_type);
+        MPI_Type_commit(&src_type);
+        MPI_Type_commit(&dst_type);
 
-      MPI_Win_lock(MPI_LOCK_EXCLUSIVE, peer, 0, buf_win);
+        MPI_Win_lock(MPI_LOCK_EXCLUSIVE, peer, 0, buf_win);
 
-      MPI_Accumulate(src_buf, 1, src_type, peer, 0, 1, dst_type, MPI_SUM, buf_win);
+        MPI_Accumulate(src_buf, 1, src_type, peer, 0, 1, dst_type, MPI_SUM, buf_win);
 
-      MPI_Win_unlock(peer, buf_win);
+        MPI_Win_unlock(peer, buf_win);
 
-      MPI_Type_free(&src_type);
-      MPI_Type_free(&dst_type);
+        MPI_Type_free(&src_type);
+        MPI_Type_free(&dst_type);
     }
 
     MPI_Barrier(MPI_COMM_WORLD);
@@ -89,40 +90,40 @@ int main(int argc, char **argv) {
     MPI_Win_lock(MPI_LOCK_EXCLUSIVE, rank, 0, buf_win);
     errors = 0;
     for (i = 0; i < SUB_XDIM; i++) {
-      for (j = 0; j < SUB_YDIM; j++) {
-        const double actual   = *(win_buf + i + j*XDIM);
-        const double expected = -1.0 + (1.0 + ((rank+nranks-1)%nranks)) * (ITERATIONS);
-        if (fabs(actual - expected) > 1.0e-10) {
-          SQUELCH( printf("%d: Data validation failed at [%d, %d] expected=%f actual=%f\n",
-              rank, j, i, expected, actual); );
-          errors++;
-          fflush(stdout);
+        for (j = 0; j < SUB_YDIM; j++) {
+            const double actual = *(win_buf + i + j * XDIM);
+            const double expected = -1.0 + (1.0 + ((rank + nranks - 1) % nranks)) * (ITERATIONS);
+            if (fabs(actual - expected) > 1.0e-10) {
+                SQUELCH(printf("%d: Data validation failed at [%d, %d] expected=%f actual=%f\n",
+                               rank, j, i, expected, actual););
+                errors++;
+                fflush(stdout);
+            }
         }
-      }
     }
     for (i = SUB_XDIM; i < XDIM; i++) {
-      for (j = 0; j < SUB_YDIM; j++) {
-        const double actual   = *(win_buf + i + j*XDIM);
-        const double expected = -1.0;
-        if (fabs(actual - expected) > 1.0e-10) {
-          SQUELCH( printf("%d: Data validation failed at [%d, %d] expected=%f actual=%f\n",
-              rank, j, i, expected, actual); );
-          errors++;
-          fflush(stdout);
+        for (j = 0; j < SUB_YDIM; j++) {
+            const double actual = *(win_buf + i + j * XDIM);
+            const double expected = -1.0;
+            if (fabs(actual - expected) > 1.0e-10) {
+                SQUELCH(printf("%d: Data validation failed at [%d, %d] expected=%f actual=%f\n",
+                               rank, j, i, expected, actual););
+                errors++;
+                fflush(stdout);
+            }
         }
-      }
     }
     for (i = 0; i < XDIM; i++) {
-      for (j = SUB_YDIM; j < YDIM; j++) {
-        const double actual   = *(win_buf + i + j*XDIM);
-        const double expected = -1.0;
-        if (fabs(actual - expected) > 1.0e-10) {
-          SQUELCH( printf("%d: Data validation failed at [%d, %d] expected=%f actual=%f\n",
-              rank, j, i, expected, actual); );
-          errors++;
-          fflush(stdout);
+        for (j = SUB_YDIM; j < YDIM; j++) {
+            const double actual = *(win_buf + i + j * XDIM);
+            const double expected = -1.0;
+            if (fabs(actual - expected) > 1.0e-10) {
+                SQUELCH(printf("%d: Data validation failed at [%d, %d] expected=%f actual=%f\n",
+                               rank, j, i, expected, actual););
+                errors++;
+                fflush(stdout);
+            }
         }
-      }
     }
     MPI_Win_unlock(rank, buf_win);
 
@@ -130,7 +131,7 @@ int main(int argc, char **argv) {
     MPI_Free_mem(win_buf);
     MPI_Free_mem(src_buf);
 
-    MTest_Finalize( errors );
+    MTest_Finalize(errors);
     MPI_Finalize();
-    return MTestReturnValue( errors );
+    return MTestReturnValue(errors);
 }
index 3a98d29..c0c1406 100644 (file)
@@ -6,7 +6,7 @@
 
 /* One-Sided MPI 2-D Strided Get Test
  *
- * Author: James Dinan <dinan@mcs.anl.gov> 
+ * Author: James Dinan <dinan@mcs.anl.gov>
  * Date  : December, 2010
  *
  * This code performs N strided get operations from a 2d patch of a shared
@@ -27,7 +27,8 @@
 #define SUB_XDIM 8
 #define SUB_YDIM 256
 
-int main(int argc, char **argv) {
+int main(int argc, char **argv)
+{
     int i, j, rank, nranks, peer, bufsize, errors;
     double *win_buf, *loc_buf;
     MPI_Win buf_win;
@@ -45,20 +46,20 @@ int main(int argc, char **argv) {
     MPI_Alloc_mem(bufsize, MPI_INFO_NULL, &win_buf);
     MPI_Alloc_mem(bufsize, MPI_INFO_NULL, &loc_buf);
 
-    for (i = 0; i < XDIM*YDIM; i++) {
-        *(win_buf + i) =  1.0 + rank;
+    for (i = 0; i < XDIM * YDIM; i++) {
+        *(win_buf + i) = 1.0 + rank;
         *(loc_buf + i) = -1.0;
     }
 
     MPI_Win_create(win_buf, bufsize, 1, MPI_INFO_NULL, MPI_COMM_WORLD, &buf_win);
 
-    peer = (rank+1) % nranks;
+    peer = (rank + 1) % nranks;
 
     /* Build the datatype */
 
     for (i = 0; i < SUB_YDIM; i++) {
-      idx_rem[i] = i*XDIM;
-      blk_len[i] = SUB_XDIM;
+        idx_rem[i] = i * XDIM;
+        blk_len[i] = SUB_XDIM;
     }
 
     MPI_Type_indexed(SUB_YDIM, blk_len, idx_rem, MPI_DOUBLE, &loc_type);
@@ -87,47 +88,47 @@ int main(int argc, char **argv) {
 
     errors = 0;
     for (i = 0; i < SUB_XDIM; i++) {
-      for (j = 0; j < SUB_YDIM; j++) {
-        const double actual   = *(loc_buf + i + j*XDIM);
-        const double expected = (1.0 + peer);
-        if (fabs(actual - expected) > 1.0e-10) {
-          SQUELCH( printf("%d: Data validation failed at [%d, %d] expected=%f actual=%f\n",
-              rank, j, i, expected, actual); );
-          errors++;
-          fflush(stdout);
+        for (j = 0; j < SUB_YDIM; j++) {
+            const double actual = *(loc_buf + i + j * XDIM);
+            const double expected = (1.0 + peer);
+            if (fabs(actual - expected) > 1.0e-10) {
+                SQUELCH(printf("%d: Data validation failed at [%d, %d] expected=%f actual=%f\n",
+                               rank, j, i, expected, actual););
+                errors++;
+                fflush(stdout);
+            }
         }
-      }
     }
     for (i = SUB_XDIM; i < XDIM; i++) {
-      for (j = 0; j < SUB_YDIM; j++) {
-        const double actual   = *(loc_buf + i + j*XDIM);
-        const double expected = -1.0;
-        if (fabs(actual - expected) > 1.0e-10) {
-          SQUELCH( printf("%d: Data validation failed at [%d, %d] expected=%f actual=%f\n",
-              rank, j, i, expected, actual); );
-          errors++;
-          fflush(stdout);
+        for (j = 0; j < SUB_YDIM; j++) {
+            const double actual = *(loc_buf + i + j * XDIM);
+            const double expected = -1.0;
+            if (fabs(actual - expected) > 1.0e-10) {
+                SQUELCH(printf("%d: Data validation failed at [%d, %d] expected=%f actual=%f\n",
+                               rank, j, i, expected, actual););
+                errors++;
+                fflush(stdout);
+            }
         }
-      }
     }
     for (i = 0; i < XDIM; i++) {
-      for (j = SUB_YDIM; j < YDIM; j++) {
-        const double actual   = *(loc_buf + i + j*XDIM);
-        const double expected = -1.0;
-        if (fabs(actual - expected) > 1.0e-10) {
-          SQUELCH( printf("%d: Data validation failed at [%d, %d] expected=%f actual=%f\n",
-              rank, j, i, expected, actual); );
-          errors++;
-          fflush(stdout);
+        for (j = SUB_YDIM; j < YDIM; j++) {
+            const double actual = *(loc_buf + i + j * XDIM);
+            const double expected = -1.0;
+            if (fabs(actual - expected) > 1.0e-10) {
+                SQUELCH(printf("%d: Data validation failed at [%d, %d] expected=%f actual=%f\n",
+                               rank, j, i, expected, actual););
+                errors++;
+                fflush(stdout);
+            }
         }
-      }
     }
 
     MPI_Win_free(&buf_win);
     MPI_Free_mem(win_buf);
     MPI_Free_mem(loc_buf);
 
-    MTest_Finalize( errors );
+    MTest_Finalize(errors);
     MPI_Finalize();
-    return MTestReturnValue( errors );
+    return MTestReturnValue(errors);
 }
index e3293a1..88a08ad 100644 (file)
@@ -6,7 +6,7 @@
 
 /* One-Sided MPI 2-D Strided Accumulate Test
  *
- * Author: James Dinan <dinan@mcs.anl.gov> 
+ * Author: James Dinan <dinan@mcs.anl.gov>
  * Date  : December, 2010
  *
  * This code performs N strided put operations followed by get operations into
@@ -28,7 +28,8 @@
 #define SUB_YDIM 2
 #define ITERATIONS 10
 
-int main(int argc, char **argv) {
+int main(int argc, char **argv)
+{
     int i, j, rank, nranks, peer, bufsize, errors;
     double *win_buf, *src_buf, *dst_buf;
     MPI_Win buf_win;
@@ -43,47 +44,47 @@ int main(int argc, char **argv) {
     MPI_Alloc_mem(bufsize, MPI_INFO_NULL, &src_buf);
     MPI_Alloc_mem(bufsize, MPI_INFO_NULL, &dst_buf);
 
-    for (i = 0; i < XDIM*YDIM; i++) {
+    for (i = 0; i < XDIM * YDIM; i++) {
         *(win_buf + i) = -1.0;
-        *(src_buf + i) =  1.0 + rank;
+        *(src_buf + i) = 1.0 + rank;
     }
 
     MPI_Win_create(win_buf, bufsize, 1, MPI_INFO_NULL, MPI_COMM_WORLD, &buf_win);
 
-    peer = (rank+1) % nranks;
+    peer = (rank + 1) % nranks;
 
     /* Perform ITERATIONS strided accumulate operations */
 
     for (i = 0; i < ITERATIONS; i++) {
-      int idx_rem[SUB_YDIM];
-      int blk_len[SUB_YDIM];
-      MPI_Datatype src_type, dst_type;
-
-      for (j = 0; j < SUB_YDIM; j++) {
-        idx_rem[j] = j*XDIM;
-        blk_len[j] = SUB_XDIM;
-      }
-
-      MPI_Type_indexed(SUB_YDIM, blk_len, idx_rem, MPI_DOUBLE, &src_type);
-      MPI_Type_indexed(SUB_YDIM, blk_len, idx_rem, MPI_DOUBLE, &dst_type);
-
-      MPI_Type_commit(&src_type);
-      MPI_Type_commit(&dst_type);
-
-      /* PUT */
-      MPI_Win_lock(MPI_LOCK_EXCLUSIVE, peer, 0, buf_win);
-      MPI_Get_accumulate(src_buf, 1, src_type, dst_buf, 1, src_type, peer, 0,
-                          1, dst_type, MPI_REPLACE, buf_win);
-      MPI_Win_unlock(peer, buf_win);
-
-      /* GET */
-      MPI_Win_lock(MPI_LOCK_EXCLUSIVE, peer, 0, buf_win);
-      MPI_Get_accumulate(src_buf, 1, src_type, dst_buf, 1, src_type, peer, 0,
-                          1, dst_type, MPI_NO_OP, buf_win);
-      MPI_Win_unlock(peer, buf_win);
-
-      MPI_Type_free(&src_type);
-      MPI_Type_free(&dst_type);
+        int idx_rem[SUB_YDIM];
+        int blk_len[SUB_YDIM];
+        MPI_Datatype src_type, dst_type;
+
+        for (j = 0; j < SUB_YDIM; j++) {
+            idx_rem[j] = j * XDIM;
+            blk_len[j] = SUB_XDIM;
+        }
+
+        MPI_Type_indexed(SUB_YDIM, blk_len, idx_rem, MPI_DOUBLE, &src_type);
+        MPI_Type_indexed(SUB_YDIM, blk_len, idx_rem, MPI_DOUBLE, &dst_type);
+
+        MPI_Type_commit(&src_type);
+        MPI_Type_commit(&dst_type);
+
+        /* PUT */
+        MPI_Win_lock(MPI_LOCK_EXCLUSIVE, peer, 0, buf_win);
+        MPI_Get_accumulate(src_buf, 1, src_type, dst_buf, 1, src_type, peer, 0,
+                           1, dst_type, MPI_REPLACE, buf_win);
+        MPI_Win_unlock(peer, buf_win);
+
+        /* GET */
+        MPI_Win_lock(MPI_LOCK_EXCLUSIVE, peer, 0, buf_win);
+        MPI_Get_accumulate(src_buf, 1, src_type, dst_buf, 1, src_type, peer, 0,
+                           1, dst_type, MPI_NO_OP, buf_win);
+        MPI_Win_unlock(peer, buf_win);
+
+        MPI_Type_free(&src_type);
+        MPI_Type_free(&dst_type);
     }
 
     MPI_Barrier(MPI_COMM_WORLD);
@@ -93,40 +94,40 @@ int main(int argc, char **argv) {
     MPI_Win_lock(MPI_LOCK_EXCLUSIVE, rank, 0, buf_win);
     errors = 0;
     for (i = 0; i < SUB_XDIM; i++) {
-      for (j = 0; j < SUB_YDIM; j++) {
-        const double actual   = *(win_buf + i + j*XDIM);
-        const double expected = (1.0 + ((rank+nranks-1)%nranks));
-        if (fabs(actual - expected) > 1.0e-10) {
-          SQUELCH( printf("%d: Data validation failed at [%d, %d] expected=%f actual=%f\n",
-              rank, j, i, expected, actual); );
-          errors++;
-          fflush(stdout);
+        for (j = 0; j < SUB_YDIM; j++) {
+            const double actual = *(win_buf + i + j * XDIM);
+            const double expected = (1.0 + ((rank + nranks - 1) % nranks));
+            if (fabs(actual - expected) > 1.0e-10) {
+                SQUELCH(printf("%d: Data validation failed at [%d, %d] expected=%f actual=%f\n",
+                               rank, j, i, expected, actual););
+                errors++;
+                fflush(stdout);
+            }
         }
-      }
     }
     for (i = SUB_XDIM; i < XDIM; i++) {
-      for (j = 0; j < SUB_YDIM; j++) {
-        const double actual   = *(win_buf + i + j*XDIM);
-        const double expected = -1.0;
-        if (fabs(actual - expected) > 1.0e-10) {
-          SQUELCH( printf("%d: Data validation failed at [%d, %d] expected=%f actual=%f\n",
-              rank, j, i, expected, actual); );
-          errors++;
-          fflush(stdout);
+        for (j = 0; j < SUB_YDIM; j++) {
+            const double actual = *(win_buf + i + j * XDIM);
+            const double expected = -1.0;
+            if (fabs(actual - expected) > 1.0e-10) {
+                SQUELCH(printf("%d: Data validation failed at [%d, %d] expected=%f actual=%f\n",
+                               rank, j, i, expected, actual););
+                errors++;
+                fflush(stdout);
+            }
         }
-      }
     }
     for (i = 0; i < XDIM; i++) {
-      for (j = SUB_YDIM; j < YDIM; j++) {
-        const double actual   = *(win_buf + i + j*XDIM);
-        const double expected = -1.0;
-        if (fabs(actual - expected) > 1.0e-10) {
-          SQUELCH( printf("%d: Data validation failed at [%d, %d] expected=%f actual=%f\n",
-              rank, j, i, expected, actual); );
-          errors++;
-          fflush(stdout);
+        for (j = SUB_YDIM; j < YDIM; j++) {
+            const double actual = *(win_buf + i + j * XDIM);
+            const double expected = -1.0;
+            if (fabs(actual - expected) > 1.0e-10) {
+                SQUELCH(printf("%d: Data validation failed at [%d, %d] expected=%f actual=%f\n",
+                               rank, j, i, expected, actual););
+                errors++;
+                fflush(stdout);
+            }
         }
-      }
     }
     MPI_Win_unlock(rank, buf_win);
 
@@ -135,7 +136,7 @@ int main(int argc, char **argv) {
     MPI_Free_mem(src_buf);
     MPI_Free_mem(dst_buf);
 
-    MTest_Finalize( errors );
+    MTest_Finalize(errors);
     MPI_Finalize();
-    return MTestReturnValue( errors );
+    return MTestReturnValue(errors);
 }
index e1c8169..6a36196 100644 (file)
@@ -28,7 +28,8 @@
 #define SUB_YDIM 2
 #define ITERATIONS 10
 
-int main(int argc, char **argv) {
+int main(int argc, char **argv)
+{
     int rank, nranks, rank_world, nranks_world;
     int i, j, peer, bufsize, errors;
     double *win_buf, *src_buf, *dst_buf;
@@ -40,7 +41,7 @@ int main(int argc, char **argv) {
     MPI_Comm_rank(MPI_COMM_WORLD, &rank_world);
     MPI_Comm_size(MPI_COMM_WORLD, &nranks_world);
 
-    MPI_Comm_split_type(MPI_COMM_WORLD, MPI_COMM_TYPE_SHARED, rank, MPI_INFO_NULL, &shr_comm);
+    MPI_Comm_split_type(MPI_COMM_WORLD, MPI_COMM_TYPE_SHARED, rank_world, MPI_INFO_NULL, &shr_comm);
 
     MPI_Comm_rank(shr_comm, &rank);
     MPI_Comm_size(shr_comm, &nranks);
@@ -53,47 +54,47 @@ int main(int argc, char **argv) {
 
     MPI_Win_fence(0, buf_win);
 
-    for (i = 0; i < XDIM*YDIM; i++) {
+    for (i = 0; i < XDIM * YDIM; i++) {
         *(win_buf + i) = -1.0;
-        *(src_buf + i) =  1.0 + rank;
+        *(src_buf + i) = 1.0 + rank;
     }
 
     MPI_Win_fence(0, buf_win);
 
-    peer = (rank+1) % nranks;
+    peer = (rank + 1) % nranks;
 
     /* Perform ITERATIONS strided accumulate operations */
 
     for (i = 0; i < ITERATIONS; i++) {
-      int idx_rem[SUB_YDIM];
-      int blk_len[SUB_YDIM];
-      MPI_Datatype src_type, dst_type;
-
-      for (j = 0; j < SUB_YDIM; j++) {
-        idx_rem[j] = j*XDIM;
-        blk_len[j] = SUB_XDIM;
-      }
-
-      MPI_Type_indexed(SUB_YDIM, blk_len, idx_rem, MPI_DOUBLE, &src_type);
-      MPI_Type_indexed(SUB_YDIM, blk_len, idx_rem, MPI_DOUBLE, &dst_type);
-
-      MPI_Type_commit(&src_type);
-      MPI_Type_commit(&dst_type);
-
-      /* PUT */
-      MPI_Win_lock(MPI_LOCK_EXCLUSIVE, peer, 0, buf_win);
-      MPI_Get_accumulate(src_buf, 1, src_type, dst_buf, 1, src_type, peer, 0,
-                          1, dst_type, MPI_REPLACE, buf_win);
-      MPI_Win_unlock(peer, buf_win);
-
-      /* GET */
-      MPI_Win_lock(MPI_LOCK_EXCLUSIVE, peer, 0, buf_win);
-      MPI_Get_accumulate(src_buf, 1, src_type, dst_buf, 1, src_type, peer, 0,
-                          1, dst_type, MPI_NO_OP, buf_win);
-      MPI_Win_unlock(peer, buf_win);
-
-      MPI_Type_free(&src_type);
-      MPI_Type_free(&dst_type);
+        int idx_rem[SUB_YDIM];
+        int blk_len[SUB_YDIM];
+        MPI_Datatype src_type, dst_type;
+
+        for (j = 0; j < SUB_YDIM; j++) {
+            idx_rem[j] = j * XDIM;
+            blk_len[j] = SUB_XDIM;
+        }
+
+        MPI_Type_indexed(SUB_YDIM, blk_len, idx_rem, MPI_DOUBLE, &src_type);
+        MPI_Type_indexed(SUB_YDIM, blk_len, idx_rem, MPI_DOUBLE, &dst_type);
+
+        MPI_Type_commit(&src_type);
+        MPI_Type_commit(&dst_type);
+
+        /* PUT */
+        MPI_Win_lock(MPI_LOCK_EXCLUSIVE, peer, 0, buf_win);
+        MPI_Get_accumulate(src_buf, 1, src_type, dst_buf, 1, src_type, peer, 0,
+                           1, dst_type, MPI_REPLACE, buf_win);
+        MPI_Win_unlock(peer, buf_win);
+
+        /* GET */
+        MPI_Win_lock(MPI_LOCK_EXCLUSIVE, peer, 0, buf_win);
+        MPI_Get_accumulate(src_buf, 1, src_type, dst_buf, 1, src_type, peer, 0,
+                           1, dst_type, MPI_NO_OP, buf_win);
+        MPI_Win_unlock(peer, buf_win);
+
+        MPI_Type_free(&src_type);
+        MPI_Type_free(&dst_type);
     }
 
     MPI_Barrier(MPI_COMM_WORLD);
@@ -103,40 +104,40 @@ int main(int argc, char **argv) {
     MPI_Win_lock(MPI_LOCK_EXCLUSIVE, rank, 0, buf_win);
     errors = 0;
     for (i = 0; i < SUB_XDIM; i++) {
-      for (j = 0; j < SUB_YDIM; j++) {
-        const double actual   = *(win_buf + i + j*XDIM);
-        const double expected = (1.0 + ((rank+nranks-1)%nranks));
-        if (fabs(actual - expected) > 1.0e-10) {
-          SQUELCH( printf("%d: Data validation failed at [%d, %d] expected=%f actual=%f\n",
-              rank, j, i, expected, actual); );
-          errors++;
-          fflush(stdout);
+        for (j = 0; j < SUB_YDIM; j++) {
+            const double actual = *(win_buf + i + j * XDIM);
+            const double expected = (1.0 + ((rank + nranks - 1) % nranks));
+            if (fabs(actual - expected) > 1.0e-10) {
+                SQUELCH(printf("%d: Data validation failed at [%d, %d] expected=%f actual=%f\n",
+                               rank, j, i, expected, actual););
+                errors++;
+                fflush(stdout);
+            }
         }
-      }
     }
     for (i = SUB_XDIM; i < XDIM; i++) {
-      for (j = 0; j < SUB_YDIM; j++) {
-        const double actual   = *(win_buf + i + j*XDIM);
-        const double expected = -1.0;
-        if (fabs(actual - expected) > 1.0e-10) {
-          SQUELCH( printf("%d: Data validation failed at [%d, %d] expected=%f actual=%f\n",
-              rank, j, i, expected, actual); );
-          errors++;
-          fflush(stdout);
+        for (j = 0; j < SUB_YDIM; j++) {
+            const double actual = *(win_buf + i + j * XDIM);
+            const double expected = -1.0;
+            if (fabs(actual - expected) > 1.0e-10) {
+                SQUELCH(printf("%d: Data validation failed at [%d, %d] expected=%f actual=%f\n",
+                               rank, j, i, expected, actual););
+                errors++;
+                fflush(stdout);
+            }
         }
-      }
     }
     for (i = 0; i < XDIM; i++) {
-      for (j = SUB_YDIM; j < YDIM; j++) {
-        const double actual   = *(win_buf + i + j*XDIM);
-        const double expected = -1.0;
-        if (fabs(actual - expected) > 1.0e-10) {
-          SQUELCH( printf("%d: Data validation failed at [%d, %d] expected=%f actual=%f\n",
-              rank, j, i, expected, actual); );
-          errors++;
-          fflush(stdout);
+        for (j = SUB_YDIM; j < YDIM; j++) {
+            const double actual = *(win_buf + i + j * XDIM);
+            const double expected = -1.0;
+            if (fabs(actual - expected) > 1.0e-10) {
+                SQUELCH(printf("%d: Data validation failed at [%d, %d] expected=%f actual=%f\n",
+                               rank, j, i, expected, actual););
+                errors++;
+                fflush(stdout);
+            }
         }
-      }
     }
     MPI_Win_unlock(rank, buf_win);
 
@@ -145,7 +146,7 @@ int main(int argc, char **argv) {
     MPI_Free_mem(dst_buf);
     MPI_Comm_free(&shr_comm);
 
-    MTest_Finalize( errors );
+    MTest_Finalize(errors);
     MPI_Finalize();
-    return MTestReturnValue( errors );
+    return MTestReturnValue(errors);
 }
index 09f17ae..0b6c8c4 100644 (file)
@@ -6,7 +6,7 @@
 
 /* One-Sided MPI 2-D Strided Accumulate Test
  *
- * Author: James Dinan <dinan@mcs.anl.gov> 
+ * Author: James Dinan <dinan@mcs.anl.gov>
  * Date  : December, 2010
  *
  * This code performs N strided put operations followed by get operations into
@@ -28,7 +28,8 @@
 #define SUB_YDIM 255
 #define ITERATIONS 10
 
-int main(int argc, char **argv) {
+int main(int argc, char **argv)
+{
     int i, j, rank, nranks, peer, bufsize, errors;
     double *win_buf, *src_buf, *dst_buf;
     MPI_Win buf_win;
@@ -43,43 +44,43 @@ int main(int argc, char **argv) {
     MPI_Alloc_mem(bufsize, MPI_INFO_NULL, &src_buf);
     MPI_Alloc_mem(bufsize, MPI_INFO_NULL, &dst_buf);
 
-    for (i = 0; i < XDIM*YDIM; i++) {
+    for (i = 0; i < XDIM * YDIM; i++) {
         *(win_buf + i) = -1.0;
-        *(src_buf + i) =  1.0 + rank;
+        *(src_buf + i) = 1.0 + rank;
     }
 
     MPI_Win_create(win_buf, bufsize, 1, MPI_INFO_NULL, MPI_COMM_WORLD, &buf_win);
 
-    peer = (rank+1) % nranks;
+    peer = (rank + 1) % nranks;
 
     /* Perform ITERATIONS strided accumulate operations */
 
     for (i = 0; i < ITERATIONS; i++) {
-      int idx_rem[SUB_YDIM];
-      int blk_len[SUB_YDIM];
-      MPI_Datatype src_type, dst_type;
+        int idx_rem[SUB_YDIM];
+        int blk_len[SUB_YDIM];
+        MPI_Datatype src_type, dst_type;
 
-      for (j = 0; j < SUB_YDIM; j++) {
-        idx_rem[j] = j*XDIM;
-        blk_len[j] = SUB_XDIM;
-      }
+        for (j = 0; j < SUB_YDIM; j++) {
+            idx_rem[j] = j * XDIM;
+            blk_len[j] = SUB_XDIM;
+        }
 
-      MPI_Type_indexed(SUB_YDIM, blk_len, idx_rem, MPI_DOUBLE, &src_type);
-      MPI_Type_indexed(SUB_YDIM, blk_len, idx_rem, MPI_DOUBLE, &dst_type);
+        MPI_Type_indexed(SUB_YDIM, blk_len, idx_rem, MPI_DOUBLE, &src_type);
+        MPI_Type_indexed(SUB_YDIM, blk_len, idx_rem, MPI_DOUBLE, &dst_type);
 
-      MPI_Type_commit(&src_type);
-      MPI_Type_commit(&dst_type);
+        MPI_Type_commit(&src_type);
+        MPI_Type_commit(&dst_type);
 
-      MPI_Win_lock(MPI_LOCK_EXCLUSIVE, peer, 0, buf_win);
-      MPI_Put(src_buf, 1, src_type, peer, 0, 1, dst_type, buf_win);
-      MPI_Win_unlock(peer, buf_win);
+        MPI_Win_lock(MPI_LOCK_EXCLUSIVE, peer, 0, buf_win);
+        MPI_Put(src_buf, 1, src_type, peer, 0, 1, dst_type, buf_win);
+        MPI_Win_unlock(peer, buf_win);
 
-      MPI_Win_lock(MPI_LOCK_EXCLUSIVE, peer, 0, buf_win);
-      MPI_Get(dst_buf, 1, src_type, peer, 0, 1, dst_type, buf_win);
-      MPI_Win_unlock(peer, buf_win);
+        MPI_Win_lock(MPI_LOCK_EXCLUSIVE, peer, 0, buf_win);
+        MPI_Get(dst_buf, 1, src_type, peer, 0, 1, dst_type, buf_win);
+        MPI_Win_unlock(peer, buf_win);
 
-      MPI_Type_free(&src_type);
-      MPI_Type_free(&dst_type);
+        MPI_Type_free(&src_type);
+        MPI_Type_free(&dst_type);
     }
 
     MPI_Barrier(MPI_COMM_WORLD);
@@ -89,40 +90,40 @@ int main(int argc, char **argv) {
     MPI_Win_lock(MPI_LOCK_EXCLUSIVE, rank, 0, buf_win);
     errors = 0;
     for (i = 0; i < SUB_XDIM; i++) {
-      for (j = 0; j < SUB_YDIM; j++) {
-        const double actual   = *(win_buf + i + j*XDIM);
-        const double expected = (1.0 + ((rank+nranks-1)%nranks));
-        if (fabs(actual - expected) > 1.0e-10) {
-          SQUELCH( printf("%d: Data validation failed at [%d, %d] expected=%f actual=%f\n",
-              rank, j, i, expected, actual); );
-          errors++;
-          fflush(stdout);
+        for (j = 0; j < SUB_YDIM; j++) {
+            const double actual = *(win_buf + i + j * XDIM);
+            const double expected = (1.0 + ((rank + nranks - 1) % nranks));
+            if (fabs(actual - expected) > 1.0e-10) {
+                SQUELCH(printf("%d: Data validation failed at [%d, %d] expected=%f actual=%f\n",
+                               rank, j, i, expected, actual););
+                errors++;
+                fflush(stdout);
+            }
         }
-      }
     }
     for (i = SUB_XDIM; i < XDIM; i++) {
-      for (j = 0; j < SUB_YDIM; j++) {
-        const double actual   = *(win_buf + i + j*XDIM);
-        const double expected = -1.0;
-        if (fabs(actual - expected) > 1.0e-10) {
-          SQUELCH( printf("%d: Data validation failed at [%d, %d] expected=%f actual=%f\n",
-              rank, j, i, expected, actual); );
-          errors++;
-          fflush(stdout);
+        for (j = 0; j < SUB_YDIM; j++) {
+            const double actual = *(win_buf + i + j * XDIM);
+            const double expected = -1.0;
+            if (fabs(actual - expected) > 1.0e-10) {
+                SQUELCH(printf("%d: Data validation failed at [%d, %d] expected=%f actual=%f\n",
+                               rank, j, i, expected, actual););
+                errors++;
+                fflush(stdout);
+            }
         }
-      }
     }
     for (i = 0; i < XDIM; i++) {
-      for (j = SUB_YDIM; j < YDIM; j++) {
-        const double actual   = *(win_buf + i + j*XDIM);
-        const double expected = -1.0;
-        if (fabs(actual - expected) > 1.0e-10) {
-          SQUELCH( printf("%d: Data validation failed at [%d, %d] expected=%f actual=%f\n",
-              rank, j, i, expected, actual); );
-          errors++;
-          fflush(stdout);
+        for (j = SUB_YDIM; j < YDIM; j++) {
+            const double actual = *(win_buf + i + j * XDIM);
+            const double expected = -1.0;
+            if (fabs(actual - expected) > 1.0e-10) {
+                SQUELCH(printf("%d: Data validation failed at [%d, %d] expected=%f actual=%f\n",
+                               rank, j, i, expected, actual););
+                errors++;
+                fflush(stdout);
+            }
         }
-      }
     }
     MPI_Win_unlock(rank, buf_win);
 
@@ -131,7 +132,7 @@ int main(int argc, char **argv) {
     MPI_Free_mem(src_buf);
     MPI_Free_mem(dst_buf);
 
-    MTest_Finalize( errors );
+    MTest_Finalize(errors);
     MPI_Finalize();
-    return MTestReturnValue( errors );
+    return MTestReturnValue(errors);
 }
index 1e65f2a..b6f2bfa 100644 (file)
@@ -28,7 +28,8 @@
 #define SUB_YDIM 255
 #define ITERATIONS 10
 
-int main(int argc, char **argv) {
+int main(int argc, char **argv)
+{
     int rank, nranks, rank_world, nranks_world;
     int i, j, peer, bufsize, errors;
     double *win_buf, *src_buf, *dst_buf;
@@ -40,7 +41,7 @@ int main(int argc, char **argv) {
     MPI_Comm_rank(MPI_COMM_WORLD, &rank_world);
     MPI_Comm_size(MPI_COMM_WORLD, &nranks_world);
 
-    MPI_Comm_split_type(MPI_COMM_WORLD, MPI_COMM_TYPE_SHARED, rank, MPI_INFO_NULL, &shr_comm);
+    MPI_Comm_split_type(MPI_COMM_WORLD, MPI_COMM_TYPE_SHARED, rank_world, MPI_INFO_NULL, &shr_comm);
 
     MPI_Comm_rank(shr_comm, &rank);
     MPI_Comm_size(shr_comm, &nranks);
@@ -53,43 +54,43 @@ int main(int argc, char **argv) {
 
     MPI_Win_fence(0, buf_win);
 
-    for (i = 0; i < XDIM*YDIM; i++) {
+    for (i = 0; i < XDIM * YDIM; i++) {
         *(win_buf + i) = -1.0;
-        *(src_buf + i) =  1.0 + rank;
+        *(src_buf + i) = 1.0 + rank;
     }
 
     MPI_Win_fence(0, buf_win);
 
-    peer = (rank+1) % nranks;
+    peer = (rank + 1) % nranks;
 
     /* Perform ITERATIONS strided accumulate operations */
 
     for (i = 0; i < ITERATIONS; i++) {
-      int idx_rem[SUB_YDIM];
-      int blk_len[SUB_YDIM];
-      MPI_Datatype src_type, dst_type;
+        int idx_rem[SUB_YDIM];
+        int blk_len[SUB_YDIM];
+        MPI_Datatype src_type, dst_type;
 
-      for (j = 0; j < SUB_YDIM; j++) {
-        idx_rem[j] = j*XDIM;
-        blk_len[j] = SUB_XDIM;
-      }
+        for (j = 0; j < SUB_YDIM; j++) {
+            idx_rem[j] = j * XDIM;
+            blk_len[j] = SUB_XDIM;
+        }
 
-      MPI_Type_indexed(SUB_YDIM, blk_len, idx_rem, MPI_DOUBLE, &src_type);
-      MPI_Type_indexed(SUB_YDIM, blk_len, idx_rem, MPI_DOUBLE, &dst_type);
+        MPI_Type_indexed(SUB_YDIM, blk_len, idx_rem, MPI_DOUBLE, &src_type);
+        MPI_Type_indexed(SUB_YDIM, blk_len, idx_rem, MPI_DOUBLE, &dst_type);
 
-      MPI_Type_commit(&src_type);
-      MPI_Type_commit(&dst_type);
+        MPI_Type_commit(&src_type);
+        MPI_Type_commit(&dst_type);
 
-      MPI_Win_lock(MPI_LOCK_EXCLUSIVE, peer, 0, buf_win);
-      MPI_Put(src_buf, 1, src_type, peer, 0, 1, dst_type, buf_win);
-      MPI_Win_unlock(peer, buf_win);
+        MPI_Win_lock(MPI_LOCK_EXCLUSIVE, peer, 0, buf_win);
+        MPI_Put(src_buf, 1, src_type, peer, 0, 1, dst_type, buf_win);
+        MPI_Win_unlock(peer, buf_win);
 
-      MPI_Win_lock(MPI_LOCK_EXCLUSIVE, peer, 0, buf_win);
-      MPI_Get(dst_buf, 1, src_type, peer, 0, 1, dst_type, buf_win);
-      MPI_Win_unlock(peer, buf_win);
+        MPI_Win_lock(MPI_LOCK_EXCLUSIVE, peer, 0, buf_win);
+        MPI_Get(dst_buf, 1, src_type, peer, 0, 1, dst_type, buf_win);
+        MPI_Win_unlock(peer, buf_win);
 
-      MPI_Type_free(&src_type);
-      MPI_Type_free(&dst_type);
+        MPI_Type_free(&src_type);
+        MPI_Type_free(&dst_type);
     }
 
     MPI_Barrier(shr_comm);
@@ -99,40 +100,40 @@ int main(int argc, char **argv) {
     MPI_Win_lock(MPI_LOCK_EXCLUSIVE, rank, 0, buf_win);
     errors = 0;
     for (i = 0; i < SUB_XDIM; i++) {
-      for (j = 0; j < SUB_YDIM; j++) {
-        const double actual   = *(win_buf + i + j*XDIM);
-        const double expected = (1.0 + ((rank+nranks-1)%nranks));
-        if (fabs(actual - expected) > 1.0e-10) {
-          SQUELCH( printf("%d: Data validation failed at [%d, %d] expected=%f actual=%f\n",
-              rank, j, i, expected, actual); );
-          errors++;
-          fflush(stdout);
+        for (j = 0; j < SUB_YDIM; j++) {
+            const double actual = *(win_buf + i + j * XDIM);
+            const double expected = (1.0 + ((rank + nranks - 1) % nranks));
+            if (fabs(actual - expected) > 1.0e-10) {
+                SQUELCH(printf("%d: Data validation failed at [%d, %d] expected=%f actual=%f\n",
+                               rank, j, i, expected, actual););
+                errors++;
+                fflush(stdout);
+            }
         }
-      }
     }
     for (i = SUB_XDIM; i < XDIM; i++) {
-      for (j = 0; j < SUB_YDIM; j++) {
-        const double actual   = *(win_buf + i + j*XDIM);
-        const double expected = -1.0;
-        if (fabs(actual - expected) > 1.0e-10) {
-          SQUELCH( printf("%d: Data validation failed at [%d, %d] expected=%f actual=%f\n",
-              rank, j, i, expected, actual); );
-          errors++;
-          fflush(stdout);
+        for (j = 0; j < SUB_YDIM; j++) {
+            const double actual = *(win_buf + i + j * XDIM);
+            const double expected = -1.0;
+            if (fabs(actual - expected) > 1.0e-10) {
+                SQUELCH(printf("%d: Data validation failed at [%d, %d] expected=%f actual=%f\n",
+                               rank, j, i, expected, actual););
+                errors++;
+                fflush(stdout);
+            }
         }
-      }
     }
     for (i = 0; i < XDIM; i++) {
-      for (j = SUB_YDIM; j < YDIM; j++) {
-        const double actual   = *(win_buf + i + j*XDIM);
-        const double expected = -1.0;
-        if (fabs(actual - expected) > 1.0e-10) {
-          SQUELCH( printf("%d: Data validation failed at [%d, %d] expected=%f actual=%f\n",
-              rank, j, i, expected, actual); );
-          errors++;
-          fflush(stdout);
+        for (j = SUB_YDIM; j < YDIM; j++) {
+            const double actual = *(win_buf + i + j * XDIM);
+            const double expected = -1.0;
+            if (fabs(actual - expected) > 1.0e-10) {
+                SQUELCH(printf("%d: Data validation failed at [%d, %d] expected=%f actual=%f\n",
+                               rank, j, i, expected, actual););
+                errors++;
+                fflush(stdout);
+            }
         }
-      }
     }
     MPI_Win_unlock(rank, buf_win);
 
@@ -141,7 +142,7 @@ int main(int argc, char **argv) {
     MPI_Free_mem(dst_buf);
     MPI_Comm_free(&shr_comm);
 
-    MTest_Finalize( errors );
+    MTest_Finalize(errors);
     MPI_Finalize();
-    return MTestReturnValue( errors );
+    return MTestReturnValue(errors);
 }
index b11995b..eb2d1a1 100644 (file)
@@ -3,7 +3,7 @@
  *  (C) 2001 by Argonne National Laboratory.
  *      See COPYRIGHT in top-level directory.
  */
-#include "mpi.h" 
+#include "mpi.h"
 #include "stdio.h"
 #include "mpitest.h"
 #include "squelch.h"
 
 #define SIZE 100
 
-int main(int argc, char *argv[]) 
-{ 
+int main(int argc, char *argv[])
+{
     int rank, nprocs, A[SIZE], B[SIZE], i;
     MPI_Comm CommDeuce;
     MPI_Win win;
     int errs = 0;
-    MTest_Init(&argc,&argv); 
-    MPI_Comm_size(MPI_COMM_WORLD,&nprocs); 
-    MPI_Comm_rank(MPI_COMM_WORLD,&rank); 
+
+    MTest_Init(&argc, &argv);
+    MPI_Comm_size(MPI_COMM_WORLD, &nprocs);
+    MPI_Comm_rank(MPI_COMM_WORLD, &rank);
 
     if (nprocs < 2) {
         printf("Run this program with 2 or more processes\n");
@@ -32,50 +32,52 @@ int main(int argc, char *argv[])
 
     if (rank < 2) {
         if (rank == 0) {
-            for (i=0; i<SIZE; i++)
+            for (i = 0; i < SIZE; i++)
                 A[i] = B[i] = i;
         }
         else {
-            for (i=0; i<SIZE; i++) {
-                A[i] = (-3)*i;
-                B[i] = (-4)*i;
+            for (i = 0; i < SIZE; i++) {
+                A[i] = (-3) * i;
+                B[i] = (-4) * i;
             }
         }
-        MPI_Win_create(B, SIZE*sizeof(int), sizeof(int), MPI_INFO_NULL, CommDeuce, &win); 
-        MPI_Win_fence(0, win); 
+
+        MPI_Win_create(B, SIZE * sizeof(int), sizeof(int), MPI_INFO_NULL, CommDeuce, &win);
+
+        MPI_Win_fence(0, win);
+
         if (rank == 0) {
-            for (i=0; i<SIZE-1; i++)
-                MPI_Put(A+i, 1, MPI_INT, 1, i, 1, MPI_INT, win);
-        }        
+            for (i = 0; i < SIZE - 1; i++)
+                MPI_Put(A + i, 1, MPI_INT, 1, i, 1, MPI_INT, win);
+        }
         else {
-            for (i=0; i<SIZE-1; i++)
-                MPI_Get(A+i, 1, MPI_INT, 0, i, 1, MPI_INT, win);
-            MPI_Accumulate(A+i, 1, MPI_INT, 0, i, 1, MPI_INT, MPI_SUM, win);
+            for (i = 0; i < SIZE - 1; i++)
+                MPI_Get(A + i, 1, MPI_INT, 0, i, 1, MPI_INT, win);
+
+            MPI_Accumulate(A + i, 1, MPI_INT, 0, i, 1, MPI_INT, MPI_SUM, win);
         }
-        MPI_Win_fence(0, win); 
+        MPI_Win_fence(0, win);
+
         if (rank == 1) {
-            for (i=0; i<SIZE-1; i++) {
+            for (i = 0; i < SIZE - 1; i++) {
                 if (A[i] != B[i]) {
-                    SQUELCH( printf("Put/Get Error: A[i]=%d, B[i]=%d\n", A[i], B[i]); );
+                    SQUELCH(printf("Put/Get Error: A[i]=%d, B[i]=%d\n", A[i], B[i]););
                     errs++;
-                   }
+                }
             }
         }
         else {
-            if (B[SIZE-1] != SIZE - 1 - 3*(SIZE-1)) {
-                SQUELCH( printf("Accumulate Error: B[SIZE-1] is %d, should be %d\n", B[SIZE-1], SIZE - 1 - 3*(SIZE-1)); );
+            if (B[SIZE - 1] != SIZE - 1 - 3 * (SIZE - 1)) {
+                SQUELCH(printf
+                        ("Accumulate Error: B[SIZE-1] is %d, should be %d\n", B[SIZE - 1],
+                         SIZE - 1 - 3 * (SIZE - 1)););
                 errs++;
             }
-          }
-       MPI_Win_free(&win); 
+        }
+        MPI_Win_free(&win);
     }
     MPI_Comm_free(&CommDeuce);
     MTest_Finalize(errs);
-    MPI_Finalize(); 
-    return 0; 
-} 
+    MPI_Finalize();
+    return 0;
+}
index 9ceedfd..2c88cb8 100644 (file)
@@ -3,7 +3,7 @@
  *  (C) 2001 by Argonne National Laboratory.
  *      See COPYRIGHT in top-level directory.
  */
-#include "mpi.h" 
+#include "mpi.h"
 #include "stdio.h"
 #include "mpitest.h"
 #include "squelch.h"
 
 #define SIZE 100
 
-int main(int argc, char *argv[]) 
-{ 
+int main(int argc, char *argv[])
+{
     int rank, nprocs, i;
     MPI_Comm CommDeuce;
     int *A, *B;
 
     MPI_Win win;
     int errs = 0;
-    MTest_Init(&argc,&argv); 
-    MPI_Comm_size(MPI_COMM_WORLD,&nprocs); 
-    MPI_Comm_rank(MPI_COMM_WORLD,&rank); 
+
+    MTest_Init(&argc, &argv);
+    MPI_Comm_size(MPI_COMM_WORLD, &nprocs);
+    MPI_Comm_rank(MPI_COMM_WORLD, &rank);
 
     if (nprocs < 2) {
         printf("Run this program with 2 or more processes\n");
@@ -45,49 +45,51 @@ int main(int argc, char *argv[])
             printf("Can't allocate memory in test program\n");
             MPI_Abort(MPI_COMM_WORLD, 1);
         }
-        
+
         if (rank == 0) {
-            for (i=0; i<SIZE; i++)
+            for (i = 0; i < SIZE; i++)
                 A[i] = B[i] = i;
         }
         else {
-            for (i=0; i<SIZE; i++) {
-                A[i] = (-3)*i;
-                B[i] = (-4)*i;
+            for (i = 0; i < SIZE; i++) {
+                A[i] = (-3) * i;
+                B[i] = (-4) * i;
             }
         }
 
-        MPI_Win_create(B, SIZE*sizeof(int), sizeof(int), MPI_INFO_NULL, CommDeuce, &win);
+        MPI_Win_create(B, SIZE * sizeof(int), sizeof(int), MPI_INFO_NULL, CommDeuce, &win);
+
+        MPI_Win_fence(0, win);
 
-        MPI_Win_fence(0, win); 
         if (rank == 0) {
-            for (i=0; i<SIZE-1; i++)
-                MPI_Put(A+i, 1, MPI_INT, 1, i, 1, MPI_INT, win);
-        }        
+            for (i = 0; i < SIZE - 1; i++)
+                MPI_Put(A + i, 1, MPI_INT, 1, i, 1, MPI_INT, win);
+        }
         else {
-            for (i=0; i<SIZE-1; i++)
-                MPI_Get(A+i, 1, MPI_INT, 0, i, 1, MPI_INT, win);
-            MPI_Accumulate(A+i, 1, MPI_INT, 0, i, 1, MPI_INT, MPI_SUM, win);
+            for (i = 0; i < SIZE - 1; i++)
+                MPI_Get(A + i, 1, MPI_INT, 0, i, 1, MPI_INT, win);
+
+            MPI_Accumulate(A + i, 1, MPI_INT, 0, i, 1, MPI_INT, MPI_SUM, win);
         }
-        MPI_Win_fence(0, win); 
+        MPI_Win_fence(0, win);
+
         if (rank == 1) {
-            for (i=0; i<SIZE-1; i++) {
+            for (i = 0; i < SIZE - 1; i++) {
                 if (A[i] != B[i]) {
-                    SQUELCH( printf("Put/Get Error: A[i]=%d, B[i]=%d\n", A[i], B[i]); );
+                    SQUELCH(printf("Put/Get Error: A[i]=%d, B[i]=%d\n", A[i], B[i]););
                     errs++;
-              }
+                }
             }
         }
         else {
-            if (B[SIZE-1] != SIZE - 1 - 3*(SIZE-1)) {
-                SQUELCH( printf("Accumulate Error: B[SIZE-1] is %d, should be %d\n", B[SIZE-1], SIZE - 1 - 3*(SIZE-1)); );
+            if (B[SIZE - 1] != SIZE - 1 - 3 * (SIZE - 1)) {
+                SQUELCH(printf
+                        ("Accumulate Error: B[SIZE-1] is %d, should be %d\n", B[SIZE - 1],
+                         SIZE - 1 - 3 * (SIZE - 1)););
                 errs++;
             }
-           }
-        MPI_Win_free(&win); 
+        }
+        MPI_Win_free(&win);
 
         MPI_Free_mem(A);
         MPI_Free_mem(B);
@@ -95,6 +97,6 @@ int main(int argc, char *argv[])
     MPI_Comm_free(&CommDeuce);
 
     MTest_Finalize(errs);
-    MPI_Finalize(); 
-    return 0; 
-} 
+    MPI_Finalize();
+    return 0;
+}
index 072c184..68bec22 100644 (file)
@@ -3,7 +3,7 @@
  *  (C) 2001 by Argonne National Laboratory.
  *      See COPYRIGHT in top-level directory.
  */
-#include "mpi.h" 
+#include "mpi.h"
 #include "stdio.h"
 #include "mpitest.h"
 #include "squelch.h"
 
 #define SIZE 100
 
-int main(int argc, char *argv[]) 
-{ 
+int main(int argc, char *argv[])
+{
     int rank, nprocs, A[SIZE], B[SIZE], i;
     MPI_Comm CommDeuce;
     MPI_Win win;
     MPI_Datatype contig_2ints;
     int errs = 0;
 
-    MTest_Init(&argc,&argv); 
-    MPI_Comm_size(MPI_COMM_WORLD,&nprocs); 
-    MPI_Comm_rank(MPI_COMM_WORLD,&rank); 
+    MTest_Init(&argc, &argv);
+    MPI_Comm_size(MPI_COMM_WORLD, &nprocs);
+    MPI_Comm_rank(MPI_COMM_WORLD, &rank);
 
     if (nprocs < 2) {
         printf("Run this program with 2 or more processes\n");
@@ -35,46 +35,48 @@ int main(int argc, char *argv[])
     if (rank < 2) {
 
         if (rank == 0) {
-            for (i=0; i<SIZE; i++)
+            for (i = 0; i < SIZE; i++)
                 A[i] = B[i] = i;
         }
         else {
-            for (i=0; i<SIZE; i++) {
-                A[i] = (-3)*i;
-                B[i] = (-4)*i;
+            for (i = 0; i < SIZE; i++) {
+                A[i] = (-3) * i;
+                B[i] = (-4) * i;
             }
         }
 
         MPI_Type_contiguous(2, MPI_INT, &contig_2ints);
         MPI_Type_commit(&contig_2ints);
 
-        MPI_Win_create(B, SIZE*sizeof(int), sizeof(int), MPI_INFO_NULL, CommDeuce, &win);
+        MPI_Win_create(B, SIZE * sizeof(int), sizeof(int), MPI_INFO_NULL, CommDeuce, &win);
 
         MPI_Win_fence(0, win);
 
         if (rank == 0) {
-            for (i=0; i<SIZE-2; i+=2)
-                MPI_Put(A+i, 2, MPI_INT, 1, i, 1, contig_2ints, win);
+            for (i = 0; i < SIZE - 2; i += 2)
+                MPI_Put(A + i, 2, MPI_INT, 1, i, 1, contig_2ints, win);
         }
         else {
-            for (i=0; i<SIZE-2; i+=2)
-                MPI_Get(A+i, 2, MPI_INT, 0, i, 1, contig_2ints, win);
+            for (i = 0; i < SIZE - 2; i += 2)
+                MPI_Get(A + i, 2, MPI_INT, 0, i, 1, contig_2ints, win);
 
-            MPI_Accumulate(A+SIZE-2, 2, MPI_INT, 0, SIZE-2, 1, contig_2ints, MPI_SUM, win);
+            MPI_Accumulate(A + SIZE - 2, 2, MPI_INT, 0, SIZE - 2, 1, contig_2ints, MPI_SUM, win);
         }
         MPI_Win_fence(0, win);
 
         if (rank == 1) {
-            for (i=0; i<SIZE-2; i++) {
+            for (i = 0; i < SIZE - 2; i++) {
                 if (A[i] != B[i]) {
-                    SQUELCH( printf("Put/Get Error: A[i]=%d, B[i]=%d\n", A[i], B[i]); );
+                    SQUELCH(printf("Put/Get Error: A[i]=%d, B[i]=%d\n", A[i], B[i]););
                     errs++;
                 }
             }
         }
         else {
-            if (B[SIZE-1] != SIZE - 1 - 3*(SIZE-1)) {
-                SQUELCH( printf("Accumulate Error: B[SIZE-1] is %d, should be %d\n", B[SIZE-1], SIZE - 1 - 3*(SIZE-1)); );
+            if (B[SIZE - 1] != SIZE - 1 - 3 * (SIZE - 1)) {
+                SQUELCH(printf
+                        ("Accumulate Error: B[SIZE-1] is %d, should be %d\n", B[SIZE - 1],
+                         SIZE - 1 - 3 * (SIZE - 1)););
                 errs++;
             }
         }
@@ -84,6 +86,6 @@ int main(int argc, char *argv[])
     }
     MPI_Comm_free(&CommDeuce);
     MTest_Finalize(errs);
-    MPI_Finalize(); 
-    return 0; 
-} 
+    MPI_Finalize();
+    return 0;
+}
index f4399ea..b41c56c 100644 (file)
@@ -3,7 +3,7 @@
  *  (C) 2001 by Argonne National Laboratory.
  *      See COPYRIGHT in top-level directory.
  */
-#include "mpi.h" 
+#include "mpi.h"
 #include "stdio.h"
 #include "mpitest.h"
 #include "squelch.h"
 #define SIZE1 100
 #define SIZE2 200
 
-int main(int argc, char *argv[]) 
-{ 
-    int rank, destrank, nprocs, A[SIZE2], B[SIZE2], i;
+int main(int argc, char *argv[])
+{
+    int rank, destrank, nprocs, A[SIZE2], i;
     MPI_Comm CommDeuce;
     MPI_Group comm_group, group;
     MPI_Win win;
     int errs = 0;
 
-    MTest_Init(&argc,&argv); 
-    MPI_Comm_size(MPI_COMM_WORLD,&nprocs); 
-    MPI_Comm_rank(MPI_COMM_WORLD,&rank); 
+    MTest_Init(&argc, &argv);
+    MPI_Comm_size(MPI_COMM_WORLD, &nprocs);
+    MPI_Comm_rank(MPI_COMM_WORLD, &rank);
 
     if (nprocs < 2) {
         printf("Run this program with 2 or more processes\n");
@@ -32,40 +32,57 @@ int main(int argc, char *argv[])
 
     MPI_Comm_split(MPI_COMM_WORLD, (rank < 2), rank, &CommDeuce);
 
-    if (rank < 2)
-    {
+    if (rank < 2) {
         MPI_Comm_group(CommDeuce, &comm_group);
 
         if (rank == 0) {
-            for (i=0; i<SIZE2; i++) A[i] = B[i] = i;
+            int B[SIZE2];
+            for (i = 0; i < SIZE2; i++)
+                A[i] = B[i] = i;
+#ifdef USE_WIN_ALLOCATE
+            char *base_ptr;
+            MPI_Win_allocate(0, 1, MPI_INFO_NULL, CommDeuce, &base_ptr, &win);
+#else
             MPI_Win_create(NULL, 0, 1, MPI_INFO_NULL, CommDeuce, &win);
+#endif
             destrank = 1;
             MPI_Group_incl(comm_group, 1, &destrank, &group);
             MPI_Win_start(group, 0, win);
-            for (i=0; i<SIZE1; i++)
-                MPI_Put(A+i, 1, MPI_INT, 1, i, 1, MPI_INT, win);
-            for (i=0; i<SIZE1; i++)
-                MPI_Get(B+i, 1, MPI_INT, 1, SIZE1+i, 1, MPI_INT, win);
+            for (i = 0; i < SIZE1; i++)
+                MPI_Put(A + i, 1, MPI_INT, 1, i, 1, MPI_INT, win);
+            for (i = 0; i < SIZE1; i++)
+                MPI_Get(B + i, 1, MPI_INT, 1, SIZE1 + i, 1, MPI_INT, win);
 
             MPI_Win_complete(win);
 
-            for (i=0; i<SIZE1; i++)
-                if (B[i] != (-4)*(i+SIZE1)) {
-                    SQUELCH( printf("Get Error: B[i] is %d, should be %d\n", B[i], (-4)*(i+SIZE1)); );
+            for (i = 0; i < SIZE1; i++)
+                if (B[i] != (-4) * (i + SIZE1)) {
+                    SQUELCH(printf
+                            ("Get Error: B[i] is %d, should be %d\n", B[i], (-4) * (i + SIZE1)););
                     errs++;
                 }
         }
         else if (rank == 1) {
-            for (i=0; i<SIZE2; i++) B[i] = (-4)*i;
-            MPI_Win_create(B, SIZE2*sizeof(int), sizeof(int), MPI_INFO_NULL, CommDeuce, &win);
+#ifdef USE_WIN_ALLOCATE
+            int *B;
+            MPI_Win_allocate(SIZE2 * sizeof(int), sizeof(int), MPI_INFO_NULL, CommDeuce, &B, &win);
+#else
+            int B[SIZE2];
+            MPI_Win_create(B, SIZE2 * sizeof(int), sizeof(int), MPI_INFO_NULL, CommDeuce, &win);
+#endif
+            MPI_Win_lock(MPI_LOCK_SHARED, rank, 0, win);
+            for (i = 0; i < SIZE2; i++)
+                B[i] = (-4) * i;
+            MPI_Win_unlock(rank, win);
+
             destrank = 0;
             MPI_Group_incl(comm_group, 1, &destrank, &group);
             MPI_Win_post(group, 0, win);
             MPI_Win_wait(win);
 
-            for (i=0; i<SIZE1; i++) {
+            for (i = 0; i < SIZE1; i++) {
                 if (B[i] != i) {
-                    SQUELCH( printf("Put Error: B[i] is %d, should be %d\n", B[i], i); );
+                    SQUELCH(printf("Put Error: B[i] is %d, should be %d\n", B[i], i););
                     errs++;
                 }
             }
@@ -78,5 +95,5 @@ int main(int argc, char *argv[])
     MPI_Comm_free(&CommDeuce);
     MTest_Finalize(errs);
     MPI_Finalize();
-    return 0; 
-} 
+    return 0;
+}
index 53780d5..c3fb529 100644 (file)
@@ -3,7 +3,7 @@
  *  (C) 2001 by Argonne National Laboratory.
  *      See COPYRIGHT in top-level directory.
  */
-#include "mpi.h" 
+#include "mpi.h"
 #include "stdio.h"
 #include "mpitest.h"
 #include "squelch.h"
 #define SIZE1 100
 #define SIZE2 200
 
-int main(int argc, char *argv[]) 
-{ 
+int main(int argc, char *argv[])
+{
     int rank, destrank, nprocs, *A, *B, i;
     MPI_Comm CommDeuce;
     MPI_Group comm_group, group;
     MPI_Win win;
     int errs = 0;
 
-    MTest_Init(&argc,&argv); 
-    MPI_Comm_size(MPI_COMM_WORLD,&nprocs); 
-    MPI_Comm_rank(MPI_COMM_WORLD,&rank); 
+    MTest_Init(&argc, &argv);
+    MPI_Comm_size(MPI_COMM_WORLD, &nprocs);
+    MPI_Comm_rank(MPI_COMM_WORLD, &rank);
 
     if (nprocs < 2) {
         printf("Run this program with 2 or more processes\n");
@@ -34,66 +34,90 @@ int main(int argc, char *argv[])
 
     MPI_Comm_split(MPI_COMM_WORLD, (rank < 2), rank, &CommDeuce);
 
-    if (rank < 2)
-    {
+    if (rank < 2) {
 
         i = MPI_Alloc_mem(SIZE2 * sizeof(int), MPI_INFO_NULL, &A);
         if (i) {
             printf("Can't allocate memory in test program\n");
             MPI_Abort(MPI_COMM_WORLD, 1);
         }
-        i = MPI_Alloc_mem(SIZE2 * sizeof(int), MPI_INFO_NULL, &B);
-        if (i) {
-            printf("Can't allocate memory in test program\n");
-            MPI_Abort(MPI_COMM_WORLD, 1);
-        }
 
         MPI_Comm_group(CommDeuce, &comm_group);
 
         if (rank == 0) {
-            for (i=0; i<SIZE2; i++) A[i] = B[i] = i;
+            i = MPI_Alloc_mem(SIZE2 * sizeof(int), MPI_INFO_NULL, &B);
+            if (i) {
+                printf("Can't allocate memory in test program\n");
+                MPI_Abort(MPI_COMM_WORLD, 1);
+            }
+
+            for (i = 0; i < SIZE2; i++)
+                A[i] = B[i] = i;
+#ifdef USE_WIN_ALLOCATE
+            char *base_ptr;
+            MPI_Win_allocate(0, 1, MPI_INFO_NULL, CommDeuce, &base_ptr, &win);
+#else
             MPI_Win_create(NULL, 0, 1, MPI_INFO_NULL, CommDeuce, &win);
+#endif
             destrank = 1;
             MPI_Group_incl(comm_group, 1, &destrank, &group);
             MPI_Win_start(group, 0, win);
-            for (i=0; i<SIZE1; i++)
-                MPI_Put(A+i, 1, MPI_INT, 1, i, 1, MPI_INT, win);
-            for (i=0; i<SIZE1; i++)
-                MPI_Get(B+i, 1, MPI_INT, 1, SIZE1+i, 1, MPI_INT, win);
+            for (i = 0; i < SIZE1; i++)
+                MPI_Put(A + i, 1, MPI_INT, 1, i, 1, MPI_INT, win);
+            for (i = 0; i < SIZE1; i++)
+                MPI_Get(B + i, 1, MPI_INT, 1, SIZE1 + i, 1, MPI_INT, win);
 
             MPI_Win_complete(win);
 
-            for (i=0; i<SIZE1; i++)
-                if (B[i] != (-4)*(i+SIZE1)) {
-                    SQUELCH( printf("Get Error: B[i] is %d, should be %d\n", B[i], (-4)*(i+SIZE1)); );
+            for (i = 0; i < SIZE1; i++)
+                if (B[i] != (-4) * (i + SIZE1)) {
+                    SQUELCH(printf
+                            ("Get Error: B[i] is %d, should be %d\n", B[i], (-4) * (i + SIZE1)););
                     errs++;
                 }
+
+            MPI_Free_mem(B);
         }
         else if (rank == 1) {
-            for (i=0; i<SIZE2; i++) B[i] = (-4)*i;
-            MPI_Win_create(B, SIZE2*sizeof(int), sizeof(int), MPI_INFO_NULL, CommDeuce, &win);
+#ifdef USE_WIN_ALLOCATE
+            MPI_Win_allocate(SIZE2 * sizeof(int), sizeof(int), MPI_INFO_NULL, CommDeuce, &B, &win);
+#else
+            i = MPI_Alloc_mem(SIZE2 * sizeof(int), MPI_INFO_NULL, &B);
+            if (i) {
+                printf("Can't allocate memory in test program\n");
+                MPI_Abort(MPI_COMM_WORLD, 1);
+            }
+            MPI_Win_create(B, SIZE2 * sizeof(int), sizeof(int), MPI_INFO_NULL, CommDeuce, &win);
+#endif
+            MPI_Win_lock(MPI_LOCK_SHARED, rank, 0, win);
+            for (i = 0; i < SIZE2; i++)
+                B[i] = (-4) * i;
+            MPI_Win_unlock(rank, win);
+
             destrank = 0;
             MPI_Group_incl(comm_group, 1, &destrank, &group);
             MPI_Win_post(group, 0, win);
             MPI_Win_wait(win);
 
-            for (i=0; i<SIZE1; i++) {
+            for (i = 0; i < SIZE1; i++) {
                 if (B[i] != i) {
-                    SQUELCH( printf("Put Error: B[i] is %d, should be %d\n", B[i], i); );
+                    SQUELCH(printf("Put Error: B[i] is %d, should be %d\n", B[i], i););
                     errs++;
                 }
             }
+#ifndef USE_WIN_ALLOCATE
+            MPI_Free_mem(B);
+#endif
         }
 
         MPI_Group_free(&group);
         MPI_Group_free(&comm_group);
         MPI_Win_free(&win);
         MPI_Free_mem(A);
-        MPI_Free_mem(B);
     }
 
     MPI_Comm_free(&CommDeuce);
     MTest_Finalize(errs);
     MPI_Finalize();
-    return 0; 
-} 
+    return 0;
+}
index 06dd53b..fcff72b 100644 (file)
@@ -3,7 +3,7 @@
  *  (C) 2001 by Argonne National Laboratory.
  *      See COPYRIGHT in top-level directory.
  */
-#include "mpi.h" 
+#include "mpi.h"
 #include "stdio.h"
 #include "stdlib.h"
 #include "mpitest.h"
 
 #define SIZE 1048576
 
-int main(int argc, char *argv[]) 
-{ 
+int main(int argc, char *argv[])
+{
     int rank, destrank, nprocs, *A, *B, i;
     MPI_Comm CommDeuce;
     MPI_Group comm_group, group;
     MPI_Win win;
     int errs = 0;
 
-    MTest_Init(&argc,&argv); 
-    MPI_Comm_size(MPI_COMM_WORLD,&nprocs); 
-    MPI_Comm_rank(MPI_COMM_WORLD,&rank); 
+    MTest_Init(&argc, &argv);
+    MPI_Comm_size(MPI_COMM_WORLD, &nprocs);
+    MPI_Comm_rank(MPI_COMM_WORLD, &rank);
 
     if (nprocs < 2) {
         printf("Run this program with 2 or more processes\n");
@@ -37,64 +37,88 @@ int main(int argc, char *argv[])
 
     MPI_Comm_split(MPI_COMM_WORLD, (rank < 2), rank, &CommDeuce);
 
-    if (rank < 2)
-    {
+    if (rank < 2) {
         A = (int *) malloc(SIZE * sizeof(int));
         if (!A) {
             printf("Can't allocate memory in test program\n");
             MPI_Abort(MPI_COMM_WORLD, 1);
         }
-        B = (int *) malloc(SIZE * sizeof(int));
-        if (!B) {
-            printf("Can't allocate memory in test program\n");
-            MPI_Abort(MPI_COMM_WORLD, 1);
-        }
 
         MPI_Comm_group(CommDeuce, &comm_group);
 
         if (rank == 0) {
-            for (i=0; i<SIZE; i++) {
+            B = (int *) malloc(SIZE * sizeof(int));
+            if (!B) {
+                printf("Can't allocate memory in test program\n");
+                MPI_Abort(MPI_COMM_WORLD, 1);
+            }
+
+            for (i = 0; i < SIZE; i++) {
                 A[i] = i;
                 B[i] = SIZE + i;
             }
+#ifdef USE_WIN_ALLOCATE
+            char *base_ptr;
+            MPI_Win_allocate(0, 1, MPI_INFO_NULL, CommDeuce, &base_ptr, &win);
+#else
             MPI_Win_create(NULL, 0, 1, MPI_INFO_NULL, CommDeuce, &win);
+#endif
             destrank = 1;
             MPI_Group_incl(comm_group, 1, &destrank, &group);
             MPI_Win_start(group, 0, win);
             MPI_Put(A, SIZE, MPI_INT, 1, 0, SIZE, MPI_INT, win);
             MPI_Win_complete(win);
             MPI_Send(B, SIZE, MPI_INT, 1, 100, MPI_COMM_WORLD);
+
+            free(B);
         }
 
         else if (rank == 1) {
-            for (i=0; i<SIZE; i++) A[i] = B[i] = (-4)*i;
-            MPI_Win_create(B, SIZE*sizeof(int), sizeof(int), MPI_INFO_NULL, CommDeuce, &win);
+#ifdef USE_WIN_ALLOCATE
+            MPI_Win_allocate(SIZE * sizeof(int), sizeof(int), MPI_INFO_NULL, CommDeuce, &B, &win);
+#else
+            B = (int *) malloc(SIZE * sizeof(int));
+            if (!B) {
+                printf("Can't allocate memory in test program\n");
+                MPI_Abort(MPI_COMM_WORLD, 1);
+            }
+            MPI_Win_create(B, SIZE * sizeof(int), sizeof(int), MPI_INFO_NULL, CommDeuce, &win);
+#endif
+            MPI_Win_lock(MPI_LOCK_SHARED, rank, 0, win);
+            for (i = 0; i < SIZE; i++)
+                A[i] = B[i] = (-4) * i;
+            MPI_Win_unlock(rank, win);
+
             destrank = 0;
             MPI_Group_incl(comm_group, 1, &destrank, &group);
             MPI_Win_post(group, 0, win);
             MPI_Recv(A, SIZE, MPI_INT, 0, 100, MPI_COMM_WORLD, MPI_STATUS_IGNORE);
             MPI_Win_wait(win);
 
-            for (i=0; i<SIZE; i++) {
+            for (i = 0; i < SIZE; i++) {
                 if (B[i] != i) {
-                    SQUELCH( printf("Rank 1: Put Error: B[i] is %d, should be %d\n", B[i], i); );
+                    SQUELCH(printf("Rank 1: Put Error: B[i] is %d, should be %d\n", B[i], i););
                     errs++;
                 }
                 if (A[i] != SIZE + i) {
-                    SQUELCH( printf("Rank 1: Send/Recv Error: A[i] is %d, should be %d\n", A[i], SIZE+i); );
+                    SQUELCH(printf
+                            ("Rank 1: Send/Recv Error: A[i] is %d, should be %d\n", A[i],
+                             SIZE + i););
                     errs++;
                 }
             }
+#ifndef USE_WIN_ALLOCATE
+            free(B);
+#endif
         }
 
         MPI_Group_free(&group);
         MPI_Group_free(&comm_group);
         MPI_Win_free(&win);
         free(A);
-        free(B);
     }
     MPI_Comm_free(&CommDeuce);
     MTest_Finalize(errs);
-    MPI_Finalize(); 
-    return 0; 
-} 
+    MPI_Finalize();
+    return 0;
+}
index dc10c31..5ff0bfc 100644 (file)
@@ -3,7 +3,7 @@
  *  (C) 2001 by Argonne National Laboratory.
  *      See COPYRIGHT in top-level directory.
  */
-#include "mpi.h" 
+#include "mpi.h"
 #include "stdio.h"
 #include "stdlib.h"
 #include "mpitest.h"
 
 #define SIZE 1048576
 
-int main(int argc, char *argv[]) 
-{ 
+int main(int argc, char *argv[])
+{
     int rank, destrank, nprocs, *A, *B, i;
     MPI_Comm CommDeuce;
     MPI_Group comm_group, group;
     MPI_Win win;
     int errs = 0;
 
-    MTest_Init(&argc,&argv); 
-    MPI_Comm_size(MPI_COMM_WORLD,&nprocs); 
-    MPI_Comm_rank(MPI_COMM_WORLD,&rank); 
+    MTest_Init(&argc, &argv);
+    MPI_Comm_size(MPI_COMM_WORLD, &nprocs);
+    MPI_Comm_rank(MPI_COMM_WORLD, &rank);
 
     if (nprocs < 2) {
         printf("Run this program with 2 or more processes\n");
@@ -45,56 +45,82 @@ int main(int argc, char *argv[])
             printf("Can't allocate memory in test program\n");
             MPI_Abort(MPI_COMM_WORLD, 1);
         }
-        i = MPI_Alloc_mem(SIZE * sizeof(int), MPI_INFO_NULL, &B);
-        if (i) {
-            printf("Can't allocate memory in test program\n");
-            MPI_Abort(MPI_COMM_WORLD, 1);
-        }
 
         MPI_Comm_group(CommDeuce, &comm_group);
 
         if (rank == 0) {
-            for (i=0; i<SIZE; i++) {
+            i = MPI_Alloc_mem(SIZE * sizeof(int), MPI_INFO_NULL, &B);
+            if (i) {
+                printf("Can't allocate memory in test program\n");
+                MPI_Abort(MPI_COMM_WORLD, 1);
+            }
+
+            for (i = 0; i < SIZE; i++) {
                 A[i] = i;
                 B[i] = SIZE + i;
             }
+#ifdef USE_WIN_ALLOCATE
+            char *base_ptr;
+            MPI_Win_allocate(0, 1, MPI_INFO_NULL, CommDeuce, &base_ptr, &win);
+#else
             MPI_Win_create(NULL, 0, 1, MPI_INFO_NULL, CommDeuce, &win);
+#endif
             destrank = 1;
             MPI_Group_incl(comm_group, 1, &destrank, &group);
             MPI_Win_start(group, 0, win);
             MPI_Put(A, SIZE, MPI_INT, 1, 0, SIZE, MPI_INT, win);
             MPI_Win_complete(win);
             MPI_Send(B, SIZE, MPI_INT, 1, 100, MPI_COMM_WORLD);
+
+            MPI_Free_mem(B);
         }
         else {  /* rank=1 */
-            for (i=0; i<SIZE; i++) A[i] = B[i] = (-4)*i;
-            MPI_Win_create(B, SIZE*sizeof(int), sizeof(int), MPI_INFO_NULL, CommDeuce, &win);
+#ifdef USE_WIN_ALLOCATE
+            MPI_Win_allocate(SIZE * sizeof(int), sizeof(int), MPI_INFO_NULL, CommDeuce, &B, &win);
+#else
+            i = MPI_Alloc_mem(SIZE * sizeof(int), MPI_INFO_NULL, &B);
+            if (i) {
+                printf("Can't allocate memory in test program\n");
+                MPI_Abort(MPI_COMM_WORLD, 1);
+            }
+            MPI_Win_create(B, SIZE * sizeof(int), sizeof(int), MPI_INFO_NULL, CommDeuce, &win);
+#endif
+            MPI_Win_lock(MPI_LOCK_SHARED, rank, 0, win);
+            for (i = 0; i < SIZE; i++)
+                A[i] = B[i] = (-4) * i;
+            MPI_Win_unlock(rank, win);
+
             destrank = 0;
             MPI_Group_incl(comm_group, 1, &destrank, &group);
             MPI_Win_post(group, 0, win);
             MPI_Recv(A, SIZE, MPI_INT, 0, 100, MPI_COMM_WORLD, MPI_STATUS_IGNORE);
             MPI_Win_wait(win);
 
-            for (i=0; i<SIZE; i++) {
+            for (i = 0; i < SIZE; i++) {
                 if (B[i] != i) {
-                    SQUELCH( printf("Rank 1: Put Error: B[i] is %d, should be %d\n", B[i], i); );
+                    SQUELCH(printf("Rank 1: Put Error: B[i] is %d, should be %d\n", B[i], i););
                     errs++;
                 }
                 if (A[i] != SIZE + i) {
-                    SQUELCH( printf("Rank 1: Send/Recv Error: A[i] is %d, should be %d\n", A[i], SIZE+i); );
+                    SQUELCH(printf
+                            ("Rank 1: Send/Recv Error: A[i] is %d, should be %d\n", A[i],
+                             SIZE + i););
                     errs++;
                 }
             }
+
+#ifndef USE_WIN_ALLOCATE
+            MPI_Free_mem(B);
+#endif
         }
 
         MPI_Group_free(&group);
         MPI_Group_free(&comm_group);
         MPI_Win_free(&win);
         MPI_Free_mem(A);
-        MPI_Free_mem(B);
     }
     MPI_Comm_free(&CommDeuce);
     MTest_Finalize(errs);
-    MPI_Finalize(); 
-    return 0; 
-} 
+    MPI_Finalize();
+    return 0;
+}
index 11ee9dd..748170f 100644 (file)
@@ -3,28 +3,28 @@
  *  (C) 2001 by Argonne National Laboratory.
  *      See COPYRIGHT in top-level directory.
  */
-#include "mpi.h" 
+#include "mpi.h"
 #include "stdio.h"
 #include "stdlib.h"
 #include "mpitest.h"
 #include "squelch.h"
 
-/* tests passive target RMA on 2 processes. tests the lock-single_op-unlock 
+/* tests passive target RMA on 2 processes. tests the lock-single_op-unlock
    optimization. */
 
 #define SIZE1 100
 #define SIZE2 200
 
-int main(int argc, char *argv[]) 
-{ 
+int main(int argc, char *argv[])
+{
     int rank, nprocs, A[SIZE2], B[SIZE2], i, j;
     MPI_Comm CommDeuce;
     MPI_Win win;
     int errs = 0;
 
-    MTest_Init(&argc,&argv); 
-    MPI_Comm_size(MPI_COMM_WORLD,&nprocs); 
-    MPI_Comm_rank(MPI_COMM_WORLD,&rank); 
+    MTest_Init(&argc, &argv);
+    MPI_Comm_size(MPI_COMM_WORLD, &nprocs);
+    MPI_Comm_rank(MPI_COMM_WORLD, &rank);
 
     if (nprocs < 2) {
         printf("Run this program with 2 or more processes\n");
@@ -35,40 +35,44 @@ int main(int argc, char *argv[])
 
     if (rank < 2) {
         if (rank == 0) {
-            for (i=0; i<SIZE2; i++) A[i] = B[i] = i;
+            for (i = 0; i < SIZE2; i++)
+                A[i] = B[i] = i;
             MPI_Win_create(NULL, 0, 1, MPI_INFO_NULL, CommDeuce, &win);
 
             for (j = 0; j < 2; j++) {
-                for (i=0; i<SIZE1; i++) {
+                for (i = 0; i < SIZE1; i++) {
                     MPI_Win_lock(MPI_LOCK_SHARED, 1, j == 0 ? 0 : MPI_MODE_NOCHECK, win);
-                    MPI_Put(A+i, 1, MPI_INT, 1, i, 1, MPI_INT, win);
+                    MPI_Put(A + i, 1, MPI_INT, 1, i, 1, MPI_INT, win);
                     MPI_Win_unlock(1, win);
                 }
 
-                for (i=0; i<SIZE1; i++) {
+                for (i = 0; i < SIZE1; i++) {
                     MPI_Win_lock(MPI_LOCK_SHARED, 1, j == 0 ? 0 : MPI_MODE_NOCHECK, win);
-                    MPI_Get(B+i, 1, MPI_INT, 1, SIZE1+i, 1, MPI_INT, win);
+                    MPI_Get(B + i, 1, MPI_INT, 1, SIZE1 + i, 1, MPI_INT, win);
                     MPI_Win_unlock(1, win);
                 }
             }
 
             MPI_Win_free(&win);
 
-            for (i=0; i<SIZE1; i++)
-                if (B[i] != (-4)*(i+SIZE1)) {
-                    SQUELCH( printf("Get Error: B[%d] is %d, should be %d\n", i, B[i], (-4)*(i+SIZE1)); );
+            for (i = 0; i < SIZE1; i++)
+                if (B[i] != (-4) * (i + SIZE1)) {
+                    SQUELCH(printf
+                            ("Get Error: B[%d] is %d, should be %d\n", i, B[i],
+                             (-4) * (i + SIZE1)););
                     errs++;
                 }
         }
         else {  /* rank=1 */
-            for (i=0; i<SIZE2; i++) B[i] = (-4)*i;
-            MPI_Win_create(B, SIZE2*sizeof(int), sizeof(int), MPI_INFO_NULL, CommDeuce, &win);
+            for (i = 0; i < SIZE2; i++)
+                B[i] = (-4) * i;
+            MPI_Win_create(B, SIZE2 * sizeof(int), sizeof(int), MPI_INFO_NULL, CommDeuce, &win);
 
             MPI_Win_free(&win);
 
-            for (i=0; i<SIZE1; i++) {
+            for (i = 0; i < SIZE1; i++) {
                 if (B[i] != i) {
-                    SQUELCH( printf("Put Error: B[%d] is %d, should be %d\n", i, B[i], i); );
+                    SQUELCH(printf("Put Error: B[%d] is %d, should be %d\n", i, B[i], i););
                     errs++;
                 }
             }
@@ -76,6 +80,6 @@ int main(int argc, char *argv[])
     }
     MPI_Comm_free(&CommDeuce);
     MTest_Finalize(errs);
-    MPI_Finalize(); 
-    return 0; 
-} 
+    MPI_Finalize();
+    return 0;
+}
index 83cb3ef..0599439 100644 (file)
@@ -3,13 +3,13 @@
  *  (C) 2001 by Argonne National Laboratory.
  *      See COPYRIGHT in top-level directory.
  */
-#include "mpi.h" 
+#include "mpi.h"
 #include "stdio.h"
 #include "stdlib.h"
 #include "mpitest.h"
 #include "squelch.h"
 
-/* tests passive target RMA on 2 processes. tests the lock-single_op-unlock 
+/* tests passive target RMA on 2 processes. tests the lock-single_op-unlock
    optimization. */
 
 /* same as test4.c but uses alloc_mem */
 #define SIZE1 100
 #define SIZE2 200
 
-int main(int argc, char *argv[]) 
-{ 
-    int rank, nprocs, *A, *B, i; 
+int main(int argc, char *argv[])
+{
+    int rank, nprocs, *A, *B, i;
     MPI_Comm CommDeuce;
     MPI_Win win;
     int errs = 0;
 
-    MTest_Init(&argc,&argv); 
-    MPI_Comm_size(MPI_COMM_WORLD,&nprocs); 
-    MPI_Comm_rank(MPI_COMM_WORLD,&rank); 
+    MTest_Init(&argc, &argv);
+    MPI_Comm_size(MPI_COMM_WORLD, &nprocs);
+    MPI_Comm_rank(MPI_COMM_WORLD, &rank);
 
     if (nprocs < 2) {
         printf("Run this program with 2 or more processes\n");
@@ -48,38 +48,42 @@ int main(int argc, char *argv[])
         }
 
         if (rank == 0) {
-            for (i=0; i<SIZE2; i++) A[i] = B[i] = i;
+            for (i = 0; i < SIZE2; i++)
+                A[i] = B[i] = i;
             MPI_Win_create(NULL, 0, 1, MPI_INFO_NULL, CommDeuce, &win);
 
-            for (i=0; i<SIZE1; i++) {
+            for (i = 0; i < SIZE1; i++) {
                 MPI_Win_lock(MPI_LOCK_SHARED, 1, 0, win);
-                MPI_Put(A+i, 1, MPI_INT, 1, i, 1, MPI_INT, win);
+                MPI_Put(A + i, 1, MPI_INT, 1, i, 1, MPI_INT, win);
                 MPI_Win_unlock(1, win);
             }
 
-            for (i=0; i<SIZE1; i++) {
+            for (i = 0; i < SIZE1; i++) {
                 MPI_Win_lock(MPI_LOCK_SHARED, 1, 0, win);
-                MPI_Get(B+i, 1, MPI_INT, 1, SIZE1+i, 1, MPI_INT, win);
+                MPI_Get(B + i, 1, MPI_INT, 1, SIZE1 + i, 1, MPI_INT, win);
                 MPI_Win_unlock(1, win);
             }
 
             MPI_Win_free(&win);
 
-            for (i=0; i<SIZE1; i++)
-                if (B[i] != (-4)*(i+SIZE1)) {
-                    SQUELCH( printf("Get Error: B[%d] is %d, should be %d\n", i, B[i], (-4)*(i+SIZE1)); );
+            for (i = 0; i < SIZE1; i++)
+                if (B[i] != (-4) * (i + SIZE1)) {
+                    SQUELCH(printf
+                            ("Get Error: B[%d] is %d, should be %d\n", i, B[i],
+                             (-4) * (i + SIZE1)););
                     errs++;
                 }
         }
         else {  /* rank=1 */
-            for (i=0; i<SIZE2; i++) B[i] = (-4)*i;
-            MPI_Win_create(B, SIZE2*sizeof(int), sizeof(int), MPI_INFO_NULL, CommDeuce, &win);
+            for (i = 0; i < SIZE2; i++)
+                B[i] = (-4) * i;
+            MPI_Win_create(B, SIZE2 * sizeof(int), sizeof(int), MPI_INFO_NULL, CommDeuce, &win);
 
             MPI_Win_free(&win);
 
-            for (i=0; i<SIZE1; i++) {
+            for (i = 0; i < SIZE1; i++) {
                 if (B[i] != i) {
-                    SQUELCH( printf("Put Error: B[%d] is %d, should be %d\n", i, B[i], i); );
+                    SQUELCH(printf("Put Error: B[%d] is %d, should be %d\n", i, B[i], i););
                     errs++;
                 }
             }
@@ -90,6 +94,6 @@ int main(int argc, char *argv[])
     }
     MPI_Comm_free(&CommDeuce);
     MTest_Finalize(errs);
-    MPI_Finalize(); 
-    return 0; 
-} 
+    MPI_Finalize();
+    return 0;
+}
index 4cc02cf..56b293a 100644 (file)
@@ -3,7 +3,7 @@
  *  (C) 2001 by Argonne National Laboratory.
  *      See COPYRIGHT in top-level directory.
  */
-#include "mpi.h" 
+#include "mpi.h"
 #include "stdio.h"
 #include "mpitest.h"
 #include "squelch.h"
 
 #define SIZE 2000
 
-int main(int argc, char *argv[]) 
-{ 
+int main(int argc, char *argv[])
+{
     int rank, nprocs, i, A[SIZE], B[SIZE];
     MPI_Comm CommDeuce;
     MPI_Win win;
     int errs = 0;
 
-    MTest_Init(&argc,&argv); 
+    MTest_Init(&argc, &argv);
 
-    MPI_Comm_size(MPI_COMM_WORLD,&nprocs); 
-    MPI_Comm_rank(MPI_COMM_WORLD, &rank); 
+    MPI_Comm_size(MPI_COMM_WORLD, &nprocs);
+    MPI_Comm_rank(MPI_COMM_WORLD, &rank);
 
     if (nprocs < 2) {
         printf("Run this program with 2 or more processes\n");
@@ -33,34 +33,34 @@ int main(int argc, char *argv[])
 
     if (rank < 2) {
         if (rank == 0) {
-            for (i=0; i<SIZE; i++)
+            for (i = 0; i < SIZE; i++)
                 B[i] = 500 + i;
-            MPI_Win_create(B, SIZE*sizeof(int), sizeof(int), MPI_INFO_NULL, CommDeuce, &win);
+            MPI_Win_create(B, SIZE * sizeof(int), sizeof(int), MPI_INFO_NULL, CommDeuce, &win);
             MPI_Win_fence(0, win);
-            for (i=0; i<SIZE; i++) {
-                A[i] = i+100;
+            for (i = 0; i < SIZE; i++) {
+                A[i] = i + 100;
                 MPI_Get(&A[i], 1, MPI_INT, 1, i, 1, MPI_INT, win);
             }
             MPI_Win_fence(0, win);
-            for (i=0; i<SIZE; i++)
+            for (i = 0; i < SIZE; i++)
                 if (A[i] != 1000 + i) {
-                    SQUELCH( printf("Rank 0: A[%d] is %d, should be %d\n", i, A[i], 1000+i); );
+                    SQUELCH(printf("Rank 0: A[%d] is %d, should be %d\n", i, A[i], 1000 + i););
                     errs++;
                 }
         }
         if (rank == 1) {
-            for (i=0; i<SIZE; i++)
+            for (i = 0; i < SIZE; i++)
                 A[i] = 1000 + i;
-            MPI_Win_create(A, SIZE*sizeof(int), sizeof(int), MPI_INFO_NULL, CommDeuce, &win);
+            MPI_Win_create(A, SIZE * sizeof(int), sizeof(int), MPI_INFO_NULL, CommDeuce, &win);
             MPI_Win_fence(0, win);
-            for (i=0; i<SIZE; i++) {
-                B[i] = i+200;
+            for (i = 0; i < SIZE; i++) {
+                B[i] = i + 200;
                 MPI_Get(&B[i], 1, MPI_INT, 0, i, 1, MPI_INT, win);
             }
             MPI_Win_fence(0, win);
-            for (i=0; i<SIZE; i++)
+            for (i = 0; i < SIZE; i++)
                 if (B[i] != 500 + i) {
-                    SQUELCH( printf("Rank 1: B[%d] is %d, should be %d\n", i, B[i], 500+i); );
+                    SQUELCH(printf("Rank 1: B[%d] is %d, should be %d\n", i, B[i], 500 + i););
                     errs++;
                 }
         }
@@ -69,6 +69,6 @@ int main(int argc, char *argv[])
     }
     MPI_Comm_free(&CommDeuce);
     MTest_Finalize(errs);
-    MPI_Finalize(); 
-    return 0; 
-} 
+    MPI_Finalize();
+    return 0;
+}
index f0482d3..9e963f0 100644 (file)
@@ -3,7 +3,7 @@
  *  (C) 2001 by Argonne National Laboratory.
  *      See COPYRIGHT in top-level directory.
  */
-#include "mpi.h" 
+#include "mpi.h"
 #include "stdio.h"
 #include "mpitest.h"
 #include "squelch.h"
 
 #define SIZE 2000
 
-int main(int argc, char *argv[]) 
-{ 
+int main(int argc, char *argv[])
+{
     int rank, nprocs, i, *A, *B;
     MPI_Comm CommDeuce;
     MPI_Win win;
     int errs = 0;
 
-    MTest_Init(&argc,&argv); 
+    MTest_Init(&argc, &argv);
 
-    MPI_Comm_size(MPI_COMM_WORLD,&nprocs); 
-    MPI_Comm_rank(MPI_COMM_WORLD, &rank); 
+    MPI_Comm_size(MPI_COMM_WORLD, &nprocs);
+    MPI_Comm_rank(MPI_COMM_WORLD, &rank);
 
     if (nprocs < 2) {
         printf("Run this program with 2 or more processes\n");
@@ -46,34 +46,34 @@ int main(int argc, char *argv[])
         }
 
         if (rank == 0) {
-            for (i=0; i<SIZE; i++)
+            for (i = 0; i < SIZE; i++)
                 B[i] = 500 + i;
-            MPI_Win_create(B, SIZE*sizeof(int), sizeof(int), MPI_INFO_NULL, CommDeuce, &win);
+            MPI_Win_create(B, SIZE * sizeof(int), sizeof(int), MPI_INFO_NULL, CommDeuce, &win);
             MPI_Win_fence(0, win);
-            for (i=0; i<SIZE; i++) {
-                A[i] = i+100;
+            for (i = 0; i < SIZE; i++) {
+                A[i] = i + 100;
                 MPI_Get(&A[i], 1, MPI_INT, 1, i, 1, MPI_INT, win);
             }
             MPI_Win_fence(0, win);
-            for (i=0; i<SIZE; i++)
+            for (i = 0; i < SIZE; i++)
                 if (A[i] != 1000 + i) {
-                    SQUELCH( printf("Rank 0: A[%d] is %d, should be %d\n", i, A[i], 1000+i); );
+                    SQUELCH(printf("Rank 0: A[%d] is %d, should be %d\n", i, A[i], 1000 + i););
                     errs++;
                 }
         }
         if (rank == 1) {
-            for (i=0; i<SIZE; i++)
+            for (i = 0; i < SIZE; i++)
                 A[i] = 1000 + i;
-            MPI_Win_create(A, SIZE*sizeof(int), sizeof(int), MPI_INFO_NULL, CommDeuce, &win);
+            MPI_Win_create(A, SIZE * sizeof(int), sizeof(int), MPI_INFO_NULL, CommDeuce, &win);
             MPI_Win_fence(0, win);
-            for (i=0; i<SIZE; i++) {
-                B[i] = i+200;
+            for (i = 0; i < SIZE; i++) {
+                B[i] = i + 200;
                 MPI_Get(&B[i], 1, MPI_INT, 0, i, 1, MPI_INT, win);
             }
             MPI_Win_fence(0, win);
-            for (i=0; i<SIZE; i++)
+            for (i = 0; i < SIZE; i++)
                 if (B[i] != 500 + i) {
-                    SQUELCH( printf("Rank 1: B[%d] is %d, should be %d\n", i, B[i], 500+i); );
+                    SQUELCH(printf("Rank 1: B[%d] is %d, should be %d\n", i, B[i], 500 + i););
                     errs++;
                 }
         }
@@ -87,6 +87,6 @@ int main(int argc, char *argv[])
 
     MPI_Comm_free(&CommDeuce);
     MTest_Finalize(errs);
-    MPI_Finalize(); 
-    return 0; 
-} 
+    MPI_Finalize();
+    return 0;
+}
index e8185e5..0e759f4 100644 (file)
@@ -16,6 +16,8 @@ accpscw1 4
 transpose1 2
 transpose2 2
 transpose3 2
+#Needs MPI_Win_allocate
+#transpose3_shm 2
 #Needs lock/unlock
 #transpose5 2
 transpose6 1
@@ -34,6 +36,15 @@ test5 2
 #lockcontention2 8
 #lockcontention3 8
 #lockopts 2
+#lock_dt 2
+#lock_dt_flush 2
+#lock_dt_flushlocal 2
+#lockall_dt 4 timeLimit=240
+#lockall_dt_flush 4 timeLimit=240
+#lockall_dt_flushall 4 timeLimit=240
+#lockall_dt_flushlocal 4 timeLimit=240
+#lockall_dt_flushlocalall 4 timeLimit=240
+#lock_contention_dt 4 timeLimit=240
 #transpose4 2
 #fetchandadd 7
 #fetchandadd_tree 7
@@ -85,11 +96,15 @@ window_creation 2
 #put_base 2
 #put_bottom 2
 #win_flavors 4 mpiversion=3.0
+#win_flavors 3 mpiversion=3.0
 #manyrma2 2 timeLimit=500
 manyrma3 2
 #win_shared 4 mpiversion=3.0
+#win_shared_create_allocshm 4 mpiversion=3.0
+#win_shared_create_no_allocshm 4 mpiversion=3.0
 #win_shared_noncontig 4 mpiversion=3.0
 #win_shared_noncontig_put 4 mpiversion=3.0
+#win_zero 4 mpiversion=3.0
 #win_dynamic_acc 4 mpiversion=3.0
 #get_acc_local 1 mpiversion=3.0
 #linked_list 4 mpiversion=3.0
@@ -119,11 +134,45 @@ manyrma3 2
 #linked_list_bench_lock_excl 4 mpiversion=3.0
 #linked_list_bench_lock_shr 4 mpiversion=3.0
 #linked_list_bench_lock_shr_nocheck 4 mpiversion=3.0
+#mutex_bench_shm 4 mpiversion=3.0
+#mutex_bench_shm_ordered 4 mpiversion=3.0
+#rma-contig 2 mpiversion=3.0 timeLimit=720
 #badrma 2 mpiversion=3.0
 #acc-loc 4
 #fence_shm 2 mpiversion=3.0
 #mutex_bench 4 mpiversion=3.0
 #mutex_bench_shared 4 mpiversion=3.0
+win_shared_zerobyte 4 mpiversion=3.0
+win_shared_put_flush_get 4 mpiversion=3.0
+#get-struct 2
+at_complete 2
+#atomic_rmw_fop 3
+#atomic_rmw_cas 3
+#atomic_rmw_gacc 3
+#atomic_get 3 mpiversion=3.0 timeLimit=300
+#aint 2 mpiversion=3.1
+#acc-pairtype 2
+manyget 2
+#derived-acc-flush_local 3 mpiversion=3.0
+#large-acc-flush_local 3 mpiversion=3.0
+large-small-acc 2
+#win_shared_put_flush_load 3 mpiversion=3.0
+#win_shared_acc_flush_load 3 mpiversion=3.0
+#win_shared_gacc_flush_load 3 mpiversion=3.0
+#win_shared_fop_flush_load 3 mpiversion=3.0
+#win_shared_cas_flush_load 3 mpiversion=3.0
+#put_flush_get 3 mpiversion=3.0
+#acc_flush_get 3 mpiversion=3.0
+#gacc_flush_get 3 mpiversion=3.0
+#fop_flush_get 3 mpiversion=3.0
+#cas_flush_get 3 mpiversion=3.0
+#rget-unlock 2 mpiversion=3.0
+#overlap_wins_put 3
+#overlap_wins_acc 3
+#overlap_wins_gacc 3
+#overlap_wins_fop 3
+#overlap_wins_cas 3
+#lock_nested 3
 
 ## This test is not strictly correct.  This was meant to test out the
 ## case when MPI_Test is not nonblocking.  However, we ended up
index 908ecc0..d2ed149 100644 (file)
@@ -3,7 +3,7 @@
  *  (C) 2001 by Argonne National Laboratory.
  *      See COPYRIGHT in top-level directory.
  */
-#include "mpi.h" 
+#include "mpi.h"
 #include "stdio.h"
 #include <stdlib.h>
 #include "mpitest.h"
 #define NROWS 1000
 #define NCOLS 1000
 
-int main(int argc, char *argv[]) 
-{ 
+int main(int argc, char *argv[])
+{
     int rank, nprocs, **A, *A_data, i, j;
     MPI_Comm CommDeuce;
     MPI_Win win;
     MPI_Datatype column, xpose;
     int errs = 0;
 
-    MTest_Init(&argc,&argv); 
-    MPI_Comm_size(MPI_COMM_WORLD,&nprocs); 
-    MPI_Comm_rank(MPI_COMM_WORLD,&rank); 
+    MTest_Init(&argc, &argv);
+    MPI_Comm_size(MPI_COMM_WORLD, &nprocs);
+    MPI_Comm_rank(MPI_COMM_WORLD, &rank);
 
     if (nprocs < 2) {
         printf("Run this program with 2 or more processes\n");
@@ -39,14 +39,13 @@ int main(int argc, char *argv[])
         A = (int **) malloc(NROWS * sizeof(int *));
 
         A[0] = A_data;
-        for (i=1; i<NROWS; i++)
-            A[i] = A[i-1] + NCOLS;
+        for (i = 1; i < NROWS; i++)
+            A[i] = A[i - 1] + NCOLS;
 
-        if (rank == 0)
-        {
-            for (i=0; i<NROWS; i++)
-                for (j=0; j<NCOLS; j++)
-                    A[i][j] = i*NCOLS + j;
+        if (rank == 0) {
+            for (i = 0; i < NROWS; i++)
+                for (j = 0; j < NCOLS; j++)
+                    A[i][j] = i * NCOLS + j;
 
             /* create datatype for one column */
             MPI_Type_vector(NROWS, 1, NCOLS, MPI_INT, &column);
@@ -58,40 +57,35 @@ int main(int argc, char *argv[])
 
             MPI_Win_fence(0, win);
 
-            MPI_Put(&A[0][0], NROWS*NCOLS, MPI_INT, 1, 0, 1, xpose, win);
+            MPI_Put(&A[0][0], NROWS * NCOLS, MPI_INT, 1, 0, 1, xpose, win);
 
             MPI_Type_free(&column);
             MPI_Type_free(&xpose);
 
             MPI_Win_fence(0, win);
         }
-        else if (rank == 1)
-        {
-            for (i=0; i<NROWS; i++)
-                for (j=0; j<NCOLS; j++)
+        else if (rank == 1) {
+            for (i = 0; i < NROWS; i++)
+                for (j = 0; j < NCOLS; j++)
                     A[i][j] = -1;
-            MPI_Win_create(&A[0][0], NROWS*NCOLS*sizeof(int), sizeof(int), MPI_INFO_NULL, CommDeuce, &win);
+            MPI_Win_create(&A[0][0], NROWS * NCOLS * sizeof(int), sizeof(int), MPI_INFO_NULL,
+                           CommDeuce, &win);
             MPI_Win_fence(0, win);
 
             MPI_Win_fence(0, win);
 
-            for (j=0; j<NCOLS; j++)
-            {
-                for (i=0; i<NROWS; i++)
-                {
-                    if (A[j][i] != i*NCOLS + j)
-                    {
-                        if (errs < 50)
-                        {
+            for (j = 0; j < NCOLS; j++) {
+                for (i = 0; i < NROWS; i++) {
+                    if (A[j][i] != i * NCOLS + j) {
+                        if (errs < 50) {
                             printf("Error: A[%d][%d]=%d should be %d\n", j, i,
-                                   A[j][i], i*NCOLS + j);
+                                   A[j][i], i * NCOLS + j);
                         }
                         errs++;
                     }
                 }
             }
-            if (errs >= 50)
-            {
+            if (errs >= 50) {
                 printf("Total number of errors: %d\n", errs);
             }
         }
@@ -104,6 +98,6 @@ int main(int argc, char *argv[])
     }
     MPI_Comm_free(&CommDeuce);
     MTest_Finalize(errs);
-    MPI_Finalize(); 
-    return 0; 
-} 
+    MPI_Finalize();
+    return 0;
+}
index bfb30c4..101e1ea 100644 (file)
@@ -3,30 +3,30 @@
  *  (C) 2001 by Argonne National Laboratory.
  *      See COPYRIGHT in top-level directory.
  */
-#include "mpi.h" 
+#include "mpi.h"
 #include "stdio.h"
 #include "mpitest.h"
 
 /* transposes a matrix using put, fence, and derived
    datatypes. Uses vector and struct (Example 3.33 from MPI 1.1
    Standard). We could use vector and type_create_resized instead. Run
-   on 2 processes */ 
+   on 2 processes */
 
 #define NROWS 100
 #define NCOLS 100
 
-int main(int argc, char *argv[]) 
-{ 
+int main(int argc, char *argv[])
+{
     int rank, nprocs, A[NROWS][NCOLS], i, j, blocklen[2];
     MPI_Comm CommDeuce;
     MPI_Aint disp[2];
     MPI_Win win;
     MPI_Datatype column, column1, type[2];
-    int errs=0;
+    int errs = 0;
 
-    MTest_Init(&argc,&argv); 
-    MPI_Comm_size(MPI_COMM_WORLD,&nprocs); 
-    MPI_Comm_rank(MPI_COMM_WORLD,&rank); 
+    MTest_Init(&argc, &argv);
+    MPI_Comm_size(MPI_COMM_WORLD, &nprocs);
+    MPI_Comm_rank(MPI_COMM_WORLD, &rank);
 
     if (nprocs < 2) {
         printf("Run this program with 2 or more processes\n");
@@ -36,23 +36,22 @@ int main(int argc, char *argv[])
     MPI_Comm_split(MPI_COMM_WORLD, (rank < 2), rank, &CommDeuce);
 
     if (rank < 2) {
-        if (rank == 0)
-        {
-            for (i=0; i<NROWS; i++)
-                for (j=0; j<NCOLS; j++)
-                    A[i][j] = i*NCOLS + j;
+        if (rank == 0) {
+            for (i = 0; i < NROWS; i++)
+                for (j = 0; j < NCOLS; j++)
+                    A[i][j] = i * NCOLS + j;
 
             /* create datatype for one column */
             MPI_Type_vector(NROWS, 1, NCOLS, MPI_INT, &column);
 
             /* create datatype for one column, with the extent of one
-           integer. we could use type_create_resized instead. */
+             * integer. we could use type_create_resized instead. */
             disp[0] = 0;
             disp[1] = sizeof(int);
-            type[0]  = column;
-            type[1]  = MPI_UB;
-            blocklen[0]  = 1;
-            blocklen[1]  = 1;
+            type[0] = column;
+            type[1] = MPI_UB;
+            blocklen[0] = 1;
+            blocklen[1] = 1;
             MPI_Type_struct(2, blocklen, disp, type, &column1);
             MPI_Type_commit(&column1);
 
@@ -60,40 +59,35 @@ int main(int argc, char *argv[])
 
             MPI_Win_fence(0, win);
 
-            MPI_Put(A, NROWS*NCOLS, MPI_INT, 1, 0, NCOLS, column1, win);
+            MPI_Put(A, NROWS * NCOLS, MPI_INT, 1, 0, NCOLS, column1, win);
 
             MPI_Type_free(&column);
             MPI_Type_free(&column1);
 
             MPI_Win_fence(0, win);
         }
-        else
-        { /* rank=1 */
-            for (i=0; i<NROWS; i++)
-                for (j=0; j<NCOLS; j++)
+        else {  /* rank=1 */
+            for (i = 0; i < NROWS; i++)
+                for (j = 0; j < NCOLS; j++)
                     A[i][j] = -1;
-            MPI_Win_create(A, NROWS*NCOLS*sizeof(int), sizeof(int), MPI_INFO_NULL, CommDeuce, &win);
+            MPI_Win_create(A, NROWS * NCOLS * sizeof(int), sizeof(int), MPI_INFO_NULL, CommDeuce,
+                           &win);
             MPI_Win_fence(0, win);
 
             MPI_Win_fence(0, win);
 
-            for (j=0; j<NCOLS; j++)
-            {
-                for (i=0; i<NROWS; i++)
-                {
-                    if (A[j][i] != i*NCOLS + j)
-                    {
-                        if (errs < 50)
-                        {
+            for (j = 0; j < NCOLS; j++) {
+                for (i = 0; i < NROWS; i++) {
+                    if (A[j][i] != i * NCOLS + j) {
+                        if (errs < 50) {
                             printf("Error: A[%d][%d]=%d should be %d\n", j, i,
-                                   A[j][i], i*NCOLS + j);
+                                   A[j][i], i * NCOLS + j);
                         }
                         errs++;
                     }
                 }
             }
-            if (errs >= 50)
-            {
+            if (errs >= 50) {
                 printf("Total number of errors: %d\n", errs);
             }
         }
@@ -102,6 +96,6 @@ int main(int argc, char *argv[])
 
     MPI_Comm_free(&CommDeuce);
     MTest_Finalize(errs);
-    MPI_Finalize(); 
-    return 0; 
-} 
+    MPI_Finalize();
+    return 0;
+}
index 86ef3d5..50a5c4a 100644 (file)
@@ -3,7 +3,7 @@
  *  (C) 2001 by Argonne National Laboratory.
  *      See COPYRIGHT in top-level directory.
  */
-#include "mpi.h" 
+#include "mpi.h"
 #include "stdio.h"
 #include "mpitest.h"
 #include "squelch.h"
 #define NROWS 100
 #define NCOLS 100
 
-int main(int argc, char *argv[]) 
-{ 
-    int rank, nprocs, A[NROWS][NCOLS], i, j, destrank;
+int main(int argc, char *argv[])
+{
+    int rank, nprocs, i, j, destrank;
     MPI_Comm CommDeuce;
     MPI_Win win;
     MPI_Datatype column, xpose;
     MPI_Group comm_group, group;
-    int errs=0;
+    int errs = 0;
 
-    MTest_Init(&argc,&argv); 
-    MPI_Comm_size(MPI_COMM_WORLD,&nprocs); 
-    MPI_Comm_rank(MPI_COMM_WORLD,&rank); 
+    MTest_Init(&argc, &argv);
+    MPI_Comm_size(MPI_COMM_WORLD, &nprocs);
+    MPI_Comm_rank(MPI_COMM_WORLD, &rank);
 
     if (nprocs < 2) {
         printf("Run this program with 2 or more processes\n");
@@ -35,15 +35,15 @@ int main(int argc, char *argv[])
 
     MPI_Comm_split(MPI_COMM_WORLD, (rank < 2), rank, &CommDeuce);
 
-    if (rank < 2)
-    {
+    if (rank < 2) {
         MPI_Comm_group(CommDeuce, &comm_group);
 
-        if (rank == 0)
-        {
-            for (i=0; i<NROWS; i++)
-                for (j=0; j<NCOLS; j++)
-                    A[i][j] = i*NCOLS + j;
+        if (rank == 0) {
+            int A[NROWS][NCOLS];
+
+            for (i = 0; i < NROWS; i++)
+                for (j = 0; j < NCOLS; j++)
+                    A[i][j] = i * NCOLS + j;
 
             /* create datatype for one column */
             MPI_Type_vector(NROWS, 1, NCOLS, MPI_INT, &column);
@@ -51,49 +51,62 @@ int main(int argc, char *argv[])
             MPI_Type_hvector(NCOLS, 1, sizeof(int), column, &xpose);
             MPI_Type_commit(&xpose);
 
+#ifdef USE_WIN_ALLOCATE
+            int *base_ptr = NULL;
+            MPI_Win_allocate(0, 1, MPI_INFO_NULL, CommDeuce, &base_ptr, &win);
+#else
             MPI_Win_create(NULL, 0, 1, MPI_INFO_NULL, CommDeuce, &win);
+#endif
 
             destrank = 1;
             MPI_Group_incl(comm_group, 1, &destrank, &group);
             MPI_Win_start(group, 0, win);
 
-            MPI_Put(A, NROWS*NCOLS, MPI_INT, 1, 0, 1, xpose, win);
+            MPI_Put(A, NROWS * NCOLS, MPI_INT, 1, 0, 1, xpose, win);
 
             MPI_Type_free(&column);
             MPI_Type_free(&xpose);
 
             MPI_Win_complete(win);
         }
-        else
-        { /* rank=1 */
-            for (i=0; i<NROWS; i++)
-                for (j=0; j<NCOLS; j++)
-                    A[i][j] = -1;
-            MPI_Win_create(A, NROWS*NCOLS*sizeof(int), sizeof(int), MPI_INFO_NULL, CommDeuce, &win);
+        else {  /* rank=1 */
+            int *A;
+#ifdef USE_WIN_ALLOCATE
+            MPI_Win_allocate(NROWS * NCOLS * sizeof(int), sizeof(int), MPI_INFO_NULL, CommDeuce, &A,
+                             &win);
+#else
+            MPI_Alloc_mem(NROWS * NCOLS * sizeof(int), MPI_INFO_NULL, &A);
+            MPI_Win_create(A, NROWS * NCOLS * sizeof(int), sizeof(int), MPI_INFO_NULL, CommDeuce,
+                           &win);
+#endif
+            MPI_Win_lock(MPI_LOCK_SHARED, rank, 0, win);
+            for (i = 0; i < NROWS; i++)
+                for (j = 0; j < NCOLS; j++)
+                    A[i * NCOLS + j] = -1;
+            MPI_Win_unlock(rank, win);
+
             destrank = 0;
             MPI_Group_incl(comm_group, 1, &destrank, &group);
             MPI_Win_post(group, 0, win);
             MPI_Win_wait(win);
 
-            for (j=0; j<NCOLS; j++)
-            {
-                for (i=0; i<NROWS; i++)
-                {
-                    if (A[j][i] != i*NCOLS + j)
-                    {
-                        if (errs < 50)
-                        {
-                            SQUELCH( printf("Error: A[%d][%d]=%d should be %d\n", j, i,
-                                            A[j][i], i*NCOLS + j); );
+            for (j = 0; j < NCOLS; j++) {
+                for (i = 0; i < NROWS; i++) {
+                    if (A[j * NROWS + i] != i * NCOLS + j) {
+                        if (errs < 50) {
+                            SQUELCH(printf("Error: A[%d][%d]=%d should be %d\n", j, i,
+                                           A[j * NROWS + i], i * NCOLS + j););
                         }
                         errs++;
                     }
                 }
             }
-            if (errs >= 50)
-            {
+            if (errs >= 50) {
                 printf("Total number of errors: %d\n", errs);
             }
+#ifndef USE_WIN_ALLOCATE
+            MPI_Free_mem(A);
+#endif
         }
 
         MPI_Group_free(&group);
@@ -102,6 +115,6 @@ int main(int argc, char *argv[])
     }
     MPI_Comm_free(&CommDeuce);
     MTest_Finalize(errs);
-    MPI_Finalize(); 
-    return 0; 
-} 
+    MPI_Finalize();
+    return 0;
+}
index 6e81c43..1559a9d 100644 (file)
@@ -3,7 +3,7 @@
  *  (C) 2001 by Argonne National Laboratory.
  *      See COPYRIGHT in top-level directory.
  */
-#include "mpi.h" 
+#include "mpi.h"
 #include "stdio.h"
 #include "mpitest.h"
 
 #define NROWS 100
 #define NCOLS 100
 
-int main(int argc, char *argv[]) 
-{ 
+int main(int argc, char *argv[])
+{
     int rank, nprocs, A[NROWS][NCOLS], i, j;
     MPI_Comm CommDeuce;
     MPI_Win win;
     MPI_Datatype column, xpose;
     int errs = 0;
 
-    MTest_Init(&argc,&argv); 
-    MPI_Comm_size(MPI_COMM_WORLD,&nprocs); 
-    MPI_Comm_rank(MPI_COMM_WORLD,&rank); 
+    MTest_Init(&argc, &argv);
+    MPI_Comm_size(MPI_COMM_WORLD, &nprocs);
+    MPI_Comm_rank(MPI_COMM_WORLD, &rank);
 
     if (nprocs < 2) {
         printf("Run this program with 2 or more processes\n");
@@ -33,12 +33,11 @@ int main(int argc, char *argv[])
 
     MPI_Comm_split(MPI_COMM_WORLD, (rank < 2), rank, &CommDeuce);
 
-    if (rank < 2)
-    {
+    if (rank < 2) {
         if (rank == 0) {
-            for (i=0; i<NROWS; i++)
-                for (j=0; j<NCOLS; j++)
-                    A[i][j] = i*NCOLS + j;
+            for (i = 0; i < NROWS; i++)
+                for (j = 0; j < NCOLS; j++)
+                    A[i][j] = i * NCOLS + j;
 
             /* create datatype for one column */
             MPI_Type_vector(NROWS, 1, NCOLS, MPI_INT, &column);
@@ -50,7 +49,7 @@ int main(int argc, char *argv[])
 
             MPI_Win_lock(MPI_LOCK_SHARED, 1, 0, win);
 
-            MPI_Put(A, NROWS*NCOLS, MPI_INT, 1, 0, 1, xpose, win);
+            MPI_Put(A, NROWS * NCOLS, MPI_INT, 1, 0, 1, xpose, win);
 
             MPI_Type_free(&column);
             MPI_Type_free(&xpose);
@@ -58,20 +57,19 @@ int main(int argc, char *argv[])
             MPI_Win_unlock(1, win);
             MPI_Win_free(&win);
         }
-        else
-        { /* rank=1 */
-            for (i=0; i<NROWS; i++) 
-                for (j=0; j<NCOLS; j++)
+        else {  /* rank=1 */
+            for (i = 0; i < NROWS; i++)
+                for (j = 0; j < NCOLS; j++)
                     A[i][j] = -1;
-            MPI_Win_create(A, NROWS*NCOLS*sizeof(int), sizeof(int), MPI_INFO_NULL, CommDeuce, &win);
+            MPI_Win_create(A, NROWS * NCOLS * sizeof(int), sizeof(int), MPI_INFO_NULL, CommDeuce,
+                           &win);
 
             MPI_Win_free(&win);
 
-            for (j=0; j<NCOLS; j++)
-                for (i=0; i<NROWS; i++)
-                    if (A[j][i] != i*NCOLS + j) {
-                        printf("Error: A[%d][%d]=%d should be %d\n", j, i,
-                               A[j][i], i*NCOLS + j);
+            for (j = 0; j < NCOLS; j++)
+                for (i = 0; i < NROWS; i++)
+                    if (A[j][i] != i * NCOLS + j) {
+                        printf("Error: A[%d][%d]=%d should be %d\n", j, i, A[j][i], i * NCOLS + j);
                         errs++;
                     }
         }
@@ -79,6 +77,6 @@ int main(int argc, char *argv[])
 
     MPI_Comm_free(&CommDeuce);
     MTest_Finalize(errs);
-    MPI_Finalize(); 
-    return 0; 
-} 
+    MPI_Finalize();
+    return 0;
+}
index 2ae63bd..904fcdd 100644 (file)
@@ -3,29 +3,29 @@
  *  (C) 2001 by Argonne National Laboratory.
  *      See COPYRIGHT in top-level directory.
  */
-#include "mpi.h" 
+#include "mpi.h"
 #include "stdio.h"
 #include <stdlib.h>
 #include "mpitest.h"
 
 /* This does a transpose-cum-accumulate operation. Uses  vector and
    hvector datatypes (Example 3.32 from MPI 1.1 Standard). Run on 2
-   processes */ 
+   processes */
 
 #define NROWS 1000
 #define NCOLS 1000
 
-int main(int argc, char *argv[]) 
-{ 
+int main(int argc, char *argv[])
+{
     int rank, nprocs, **A, *A_data, i, j;
     MPI_Comm CommDeuce;
     MPI_Win win;
     MPI_Datatype column, xpose;
     int errs = 0;
 
-    MTest_Init(&argc,&argv); 
-    MPI_Comm_size(MPI_COMM_WORLD,&nprocs); 
-    MPI_Comm_rank(MPI_COMM_WORLD,&rank); 
+    MTest_Init(&argc, &argv);
+    MPI_Comm_size(MPI_COMM_WORLD, &nprocs);
+    MPI_Comm_rank(MPI_COMM_WORLD, &rank);
 
     if (nprocs < 2) {
         printf("Run this program with 2 or more processes\n");
@@ -34,20 +34,18 @@ int main(int argc, char *argv[])
 
     MPI_Comm_split(MPI_COMM_WORLD, (rank < 2), rank, &CommDeuce);
 
-    if (rank < 2)
-    {
+    if (rank < 2) {
         A_data = (int *) malloc(NROWS * NCOLS * sizeof(int));
         A = (int **) malloc(NROWS * sizeof(int *));
 
         A[0] = A_data;
-        for (i=1; i<NROWS; i++)
-            A[i] = A[i-1] + NCOLS;
+        for (i = 1; i < NROWS; i++)
+            A[i] = A[i - 1] + NCOLS;
 
-        if (rank == 0)
-        {
-            for (i=0; i<NROWS; i++)
-                for (j=0; j<NCOLS; j++)
-                    A[i][j] = i*NCOLS + j;
+        if (rank == 0) {
+            for (i = 0; i < NROWS; i++)
+                for (j = 0; j < NCOLS; j++)
+                    A[i][j] = i * NCOLS + j;
 
             /* create datatype for one column */
             MPI_Type_vector(NROWS, 1, NCOLS, MPI_INT, &column);
@@ -59,40 +57,35 @@ int main(int argc, char *argv[])
 
             MPI_Win_fence(0, win);
 
-            MPI_Accumulate(&A[0][0], NROWS*NCOLS, MPI_INT, 1, 0, 1, xpose, MPI_SUM, win);
+            MPI_Accumulate(&A[0][0], NROWS * NCOLS, MPI_INT, 1, 0, 1, xpose, MPI_SUM, win);
 
             MPI_Type_free(&column);
             MPI_Type_free(&xpose);
 
             MPI_Win_fence(0, win);
         }
-        else
-        { /* rank=1 */
-            for (i=0; i<NROWS; i++)
-                for (j=0; j<NCOLS; j++)
-                    A[i][j] = i*NCOLS + j;
-            MPI_Win_create(&A[0][0], NROWS*NCOLS*sizeof(int), sizeof(int), MPI_INFO_NULL, CommDeuce, &win);
+        else {  /* rank=1 */
+            for (i = 0; i < NROWS; i++)
+                for (j = 0; j < NCOLS; j++)
+                    A[i][j] = i * NCOLS + j;
+            MPI_Win_create(&A[0][0], NROWS * NCOLS * sizeof(int), sizeof(int), MPI_INFO_NULL,
+                           CommDeuce, &win);
             MPI_Win_fence(0, win);
 
             MPI_Win_fence(0, win);
 
-            for (j=0; j<NCOLS; j++)
-            {
-                for (i=0; i<NROWS; i++)
-                {
-                    if (A[j][i] != i*NCOLS + j + j*NCOLS + i)
-                    {
-                        if (errs < 50)
-                        {
+            for (j = 0; j < NCOLS; j++) {
+                for (i = 0; i < NROWS; i++) {
+                    if (A[j][i] != i * NCOLS + j + j * NCOLS + i) {
+                        if (errs < 50) {
                             printf("Error: A[%d][%d]=%d should be %d\n", j, i,
-                                   A[j][i], i*NCOLS + j + j*NCOLS + i);
+                                   A[j][i], i * NCOLS + j + j * NCOLS + i);
                         }
                         errs++;
                     }
                 }
             }
-            if (errs >= 50)
-            {
+            if (errs >= 50) {
                 printf("Total number of errors: %d\n", errs);
             }
         }
@@ -106,6 +99,6 @@ int main(int argc, char *argv[])
 
     MPI_Comm_free(&CommDeuce);
     MTest_Finalize(errs);
-    MPI_Finalize(); 
-    return 0; 
-} 
+    MPI_Finalize();
+    return 0;
+}
index 09471da..c9f36e1 100644 (file)
@@ -3,74 +3,69 @@
  *  (C) 2001 by Argonne National Laboratory.
  *      See COPYRIGHT in top-level directory.
  */
-#include "mpi.h" 
+#include "mpi.h"
 #include "stdio.h"
 #include "mpitest.h"
 
-/* This does a local transpose-cum-accumulate operation. Uses 
+/* This does a local transpose-cum-accumulate operation. Uses
    vector and hvector datatypes (Example 3.32 from MPI 1.1
    Standard). Run on 1 process. */
 
 #define NROWS 100
 #define NCOLS 100
 
-int main(int argc, char *argv[]) 
-{ 
+int main(int argc, char *argv[])
+{
     int rank, nprocs, A[NROWS][NCOLS], B[NROWS][NCOLS], i, j;
     MPI_Win win;
     MPI_Datatype column, xpose;
     int errs = 0;
-    MTest_Init(&argc,&argv); 
-    MPI_Comm_rank(MPI_COMM_WORLD,&rank); 
-    MPI_Comm_size(MPI_COMM_WORLD,&nprocs); 
 
-    if (rank==0)
-    {
-        for (i=0; i<NROWS; i++)
-            for (j=0; j<NCOLS; j++)
-                A[i][j] = B[i][j] = i*NCOLS + j;
-        
+    MTest_Init(&argc, &argv);
+    MPI_Comm_rank(MPI_COMM_WORLD, &rank);
+    MPI_Comm_size(MPI_COMM_WORLD, &nprocs);
+
+    if (rank == 0) {
+        for (i = 0; i < NROWS; i++)
+            for (j = 0; j < NCOLS; j++)
+                A[i][j] = B[i][j] = i * NCOLS + j;
+
         /* create datatype for one column */
         MPI_Type_vector(NROWS, 1, NCOLS, MPI_INT, &column);
         /* create datatype for matrix in column-major order */
         MPI_Type_hvector(NCOLS, 1, sizeof(int), column, &xpose);
         MPI_Type_commit(&xpose);
-        
-        MPI_Win_create(B, NROWS*NCOLS*sizeof(int), sizeof(int), MPI_INFO_NULL, MPI_COMM_SELF, &win); 
-        
-        MPI_Win_fence(0, win); 
-        
-        MPI_Accumulate(A, NROWS*NCOLS, MPI_INT, 0, 0, 1, xpose, MPI_SUM, win);
-        
+
+        MPI_Win_create(B, NROWS * NCOLS * sizeof(int), sizeof(int), MPI_INFO_NULL, MPI_COMM_SELF,
+                       &win);
+
+        MPI_Win_fence(0, win);
+
+        MPI_Accumulate(A, NROWS * NCOLS, MPI_INT, 0, 0, 1, xpose, MPI_SUM, win);
+
         MPI_Type_free(&column);
         MPI_Type_free(&xpose);
-        
-        MPI_Win_fence(0, win); 
-        
-        for (j=0; j<NCOLS; j++)
-        {
-            for (i=0; i<NROWS; i++)
-          {
-                if (B[j][i] != i*NCOLS + j + j*NCOLS + i)
-              {
-               if (errs < 20)
-               {
-                   printf("Error: B[%d][%d]=%d should be %d\n", j, i,
-                       B[j][i], i*NCOLS + j + j*NCOLS + i);
-               }
+
+        MPI_Win_fence(0, win);
+
+        for (j = 0; j < NCOLS; j++) {
+            for (i = 0; i < NROWS; i++) {
+                if (B[j][i] != i * NCOLS + j + j * NCOLS + i) {
+                    if (errs < 20) {
+                        printf("Error: B[%d][%d]=%d should be %d\n", j, i,
+                               B[j][i], i * NCOLS + j + j * NCOLS + i);
+                    }
                     errs++;
                 }
-          }
+            }
         }
-        if (errs >= 20)
-        {
-          printf("Total number of errors: %d\n", errs);
+        if (errs >= 20) {
+            printf("Total number of errors: %d\n", errs);
         }
-        MPI_Win_free(&win); 
+
+        MPI_Win_free(&win);
     }
     MTest_Finalize(errs);
-    MPI_Finalize(); 
-    return 0; 
-} 
+    MPI_Finalize();
+    return 0;
+}
index 954c399..cd9e20b 100644 (file)
@@ -3,7 +3,7 @@
  *  (C) 2001 by Argonne National Laboratory.
  *      See COPYRIGHT in top-level directory.
  */
-#include "mpi.h" 
+#include "mpi.h"
 #include <stdio.h>
 #include <stdlib.h>
 #include "mpitest.h"
 #define NROWS 1000
 #define NCOLS 1000
 
-int main(int argc, char *argv[]) 
-{ 
+int main(int argc, char *argv[])
+{
     int rank, nprocs, **A, *A_data, i, j;
     MPI_Comm CommDeuce;
     MPI_Win win;
     MPI_Datatype column, xpose;
     int errs = 0;
 
-    MTest_Init(&argc,&argv); 
-    MPI_Comm_size(MPI_COMM_WORLD,&nprocs); 
-    MPI_Comm_rank(MPI_COMM_WORLD,&rank); 
+    MTest_Init(&argc, &argv);
+    MPI_Comm_size(MPI_COMM_WORLD, &nprocs);
+    MPI_Comm_rank(MPI_COMM_WORLD, &rank);
 
     if (nprocs < 2) {
         printf("Run this program with 2 or more processes\n");
@@ -34,19 +34,17 @@ int main(int argc, char *argv[])
 
     MPI_Comm_split(MPI_COMM_WORLD, (rank < 2), rank, &CommDeuce);
 
-    if (rank < 2)
-    {
+    if (rank < 2) {
         A_data = (int *) malloc(NROWS * NCOLS * sizeof(int));
         A = (int **) malloc(NROWS * sizeof(int *));
 
         A[0] = A_data;
-        for (i=1; i<NROWS; i++)
-            A[i] = A[i-1] + NCOLS;
+        for (i = 1; i < NROWS; i++)
+            A[i] = A[i - 1] + NCOLS;
 
-        if (rank == 0)
-        {
-            for (i=0; i<NROWS; i++)
-                for (j=0; j<NCOLS; j++)
+        if (rank == 0) {
+            for (i = 0; i < NROWS; i++)
+                for (j = 0; j < NCOLS; j++)
                     A[i][j] = -1;
 
             /* create datatype for one column */
@@ -59,49 +57,44 @@ int main(int argc, char *argv[])
 
             MPI_Win_fence(0, win);
 
-            MPI_Get(&A[0][0], NROWS*NCOLS, MPI_INT, 1, 0, 1, xpose, win);
+            MPI_Get(&A[0][0], NROWS * NCOLS, MPI_INT, 1, 0, 1, xpose, win);
 
             MPI_Type_free(&column);
             MPI_Type_free(&xpose);
 
             MPI_Win_fence(0, win);
 
-            for (j=0; j<NCOLS; j++)
-            {
-                for (i=0; i<NROWS; i++)
-                {
-                    if (A[j][i] != i*NCOLS + j)
-                    {
-                        if (errs < 50)
-                        {
+            for (j = 0; j < NCOLS; j++) {
+                for (i = 0; i < NROWS; i++) {
+                    if (A[j][i] != i * NCOLS + j) {
+                        if (errs < 50) {
                             printf("Error: A[%d][%d]=%d should be %d\n", j, i,
-                                   A[j][i], i*NCOLS + j);
+                                   A[j][i], i * NCOLS + j);
                         }
                         errs++;
                     }
                 }
             }
-            if (errs >= 50)
-            {
+            if (errs >= 50) {
                 printf("Total number of errors: %d\n", errs);
             }
         }
-        else
-        {
-            for (i=0; i<NROWS; i++)
-                for (j=0; j<NCOLS; j++)
-                    A[i][j] = i*NCOLS + j;
+        else {
+            for (i = 0; i < NROWS; i++)
+                for (j = 0; j < NCOLS; j++)
+                    A[i][j] = i * NCOLS + j;
 
-            MPI_Win_create(&A[0][0], NROWS*NCOLS*sizeof(int), sizeof(int), MPI_INFO_NULL, CommDeuce, &win);
+            MPI_Win_create(&A[0][0], NROWS * NCOLS * sizeof(int), sizeof(int), MPI_INFO_NULL,
+                           CommDeuce, &win);
             MPI_Win_fence(0, win);
             MPI_Win_fence(0, win);
         }
         MPI_Win_free(&win);
-        free(A);
         free(A_data);
+        free(A);
     }
     MPI_Comm_free(&CommDeuce);
     MTest_Finalize(errs);
-    MPI_Finalize(); 
-    return 0; 
-} 
+    MPI_Finalize();
+    return 0;
+}
index 2640edd..d68f467 100644 (file)
 
 const int verbose = 0;
 
-int main(int argc, char **argv) {
-    int       i, j, rank, nproc;
-    int       errors = 0, all_errors = 0;
-    int       val = 0, one = 1;
-    int       iter;
+int main(int argc, char **argv)
+{
+    int i, rank, nproc;
+    int errors = 0, all_errors = 0;
+    int val = 0, one = 1;
+    int iter;
     MPI_Aint *val_ptrs;
-    MPI_Win   dyn_win;
+    MPI_Win dyn_win;
 
     MPI_Init(&argc, &argv);
 
@@ -33,22 +34,22 @@ int main(int argc, char **argv) {
     val_ptrs = malloc(nproc * sizeof(MPI_Aint));
     MPI_Get_address(&val, &val_ptrs[rank]);
 
-    MPI_Allgather(MPI_IN_PLACE, 0, MPI_DATATYPE_NULL, val_ptrs, 1, MPI_AINT,
-                  MPI_COMM_WORLD);
+    MPI_Allgather(MPI_IN_PLACE, 0, MPI_DATATYPE_NULL, val_ptrs, 1, MPI_AINT, MPI_COMM_WORLD);
 
     MPI_Win_create_dynamic(MPI_INFO_NULL, MPI_COMM_WORLD, &dyn_win);
     MPI_Win_attach(dyn_win, &val, sizeof(int));
 
     for (i = 0; i < iter; i++) {
-            MPI_Win_fence(MPI_MODE_NOPRECEDE, dyn_win);
-            MPI_Accumulate(&one, 1, MPI_INT, i%nproc, val_ptrs[i%nproc], 1, MPI_INT, MPI_SUM, dyn_win);
-            MPI_Win_fence(MPI_MODE_NOSUCCEED, dyn_win);
+        MPI_Win_fence(MPI_MODE_NOPRECEDE, dyn_win);
+        MPI_Accumulate(&one, 1, MPI_INT, i % nproc, val_ptrs[i % nproc], 1, MPI_INT, MPI_SUM,
+                       dyn_win);
+        MPI_Win_fence(MPI_MODE_NOSUCCEED, dyn_win);
     }
 
     MPI_Barrier(MPI_COMM_WORLD);
 
     /* Read and verify my data */
-    if ( val != iter ) {
+    if (val != iter) {
         errors++;
         printf("%d -- Got %d, expected %d\n", rank, val, iter);
     }
index c5179c4..4abc1d6 100644 (file)
 
 #define ELEM_SIZE 8
 
-int main( int argc, char *argv[] )
+int main(int argc, char *argv[])
 {
-    int     rank;
-    int     errors = 0, all_errors = 0;
-    int    *flavor, *model, flag;
-    void   *buf;
+    int rank;
+    int errors = 0, all_errors = 0;
+    int *flavor, *model, flag;
+    void *buf;
     MPI_Win window;
 
     MPI_Init(&argc, &argv);
@@ -24,63 +24,67 @@ int main( int argc, char *argv[] )
     /** Create using MPI_Win_create() **/
 
     if (rank > 0)
-      MPI_Alloc_mem(rank*ELEM_SIZE, MPI_INFO_NULL, &buf);
+        MPI_Alloc_mem(rank * ELEM_SIZE, MPI_INFO_NULL, &buf);
     else
-      buf = NULL;
+        buf = NULL;
 
-    MPI_Win_create(buf, rank*ELEM_SIZE, 1, MPI_INFO_NULL, MPI_COMM_WORLD, &window);
+    MPI_Win_create(buf, rank * ELEM_SIZE, 1, MPI_INFO_NULL, MPI_COMM_WORLD, &window);
     MPI_Win_get_attr(window, MPI_WIN_CREATE_FLAVOR, &flavor, &flag);
 
     if (!flag) {
-      printf("%d: MPI_Win_create - Error, no flavor\n", rank);
-      errors++;
-    } else if (*flavor != MPI_WIN_FLAVOR_CREATE) {
-      printf("%d: MPI_Win_create - Error, bad flavor (%d)\n", rank, *flavor);
-      errors++;
+        printf("%d: MPI_Win_create - Error, no flavor\n", rank);
+        errors++;
+    }
+    else if (*flavor != MPI_WIN_FLAVOR_CREATE) {
+        printf("%d: MPI_Win_create - Error, bad flavor (%d)\n", rank, *flavor);
+        errors++;
     }
 
     MPI_Win_get_attr(window, MPI_WIN_MODEL, &model, &flag);
 
     if (!flag) {
-      printf("%d: MPI_Win_create - Error, no model\n", rank);
-      errors++;
-    } else if ( ! (*model == MPI_WIN_SEPARATE || *model == MPI_WIN_UNIFIED) ) {
-      printf("%d: MPI_Win_create - Error, bad model (%d)\n", rank, *model);
-      errors++;
+        printf("%d: MPI_Win_create - Error, no model\n", rank);
+        errors++;
+    }
+    else if (!(*model == MPI_WIN_SEPARATE || *model == MPI_WIN_UNIFIED)) {
+        printf("%d: MPI_Win_create - Error, bad model (%d)\n", rank, *model);
+        errors++;
     }
 
     MPI_Win_free(&window);
 
     if (buf)
-      MPI_Free_mem(buf);
+        MPI_Free_mem(buf);
 
     /** Create using MPI_Win_allocate() **/
 
-    MPI_Win_allocate(rank*ELEM_SIZE, 1, MPI_INFO_NULL, MPI_COMM_WORLD, &buf, &window);
+    MPI_Win_allocate(rank * ELEM_SIZE, 1, MPI_INFO_NULL, MPI_COMM_WORLD, &buf, &window);
 
     if (rank > 0 && buf == NULL) {
-      printf("%d: MPI_Win_allocate - Error, bad base pointer\n", rank);
-      errors++;
+        printf("%d: MPI_Win_allocate - Error, bad base pointer\n", rank);
+        errors++;
     }
 
     MPI_Win_get_attr(window, MPI_WIN_CREATE_FLAVOR, &flavor, &flag);
 
     if (!flag) {
-      printf("%d: MPI_Win_allocate - Error, no flavor\n", rank);
-      errors++;
-    } else if (*flavor != MPI_WIN_FLAVOR_ALLOCATE) {
-      printf("%d: MPI_Win_allocate - Error, bad flavor (%d)\n", rank, *flavor);
-      errors++;
+        printf("%d: MPI_Win_allocate - Error, no flavor\n", rank);
+        errors++;
+    }
+    else if (*flavor != MPI_WIN_FLAVOR_ALLOCATE) {
+        printf("%d: MPI_Win_allocate - Error, bad flavor (%d)\n", rank, *flavor);
+        errors++;
     }
 
     MPI_Win_get_attr(window, MPI_WIN_MODEL, &model, &flag);
 
     if (!flag) {
-      printf("%d: MPI_Win_allocate - Error, no model\n", rank);
-      errors++;
-    } else if (*model != MPI_WIN_SEPARATE && *model != MPI_WIN_UNIFIED) {
-      printf("%d: MPI_Win_allocate - Error, bad model (%d)\n", rank, *model);
-      errors++;
+        printf("%d: MPI_Win_allocate - Error, no model\n", rank);
+        errors++;
+    }
+    else if (*model != MPI_WIN_SEPARATE && *model != MPI_WIN_UNIFIED) {
+        printf("%d: MPI_Win_allocate - Error, bad model (%d)\n", rank, *model);
+        errors++;
     }
 
     MPI_Win_free(&window);
@@ -92,21 +96,23 @@ int main( int argc, char *argv[] )
     MPI_Win_get_attr(window, MPI_WIN_CREATE_FLAVOR, &flavor, &flag);
 
     if (!flag) {
-      printf("%d: MPI_Win_create_dynamic - Error, no flavor\n", rank);
-      errors++;
-    } else if (*flavor != MPI_WIN_FLAVOR_DYNAMIC) {
-      printf("%d: MPI_Win_create_dynamic - Error, bad flavor (%d)\n", rank, *flavor);
-      errors++;
+        printf("%d: MPI_Win_create_dynamic - Error, no flavor\n", rank);
+        errors++;
+    }
+    else if (*flavor != MPI_WIN_FLAVOR_DYNAMIC) {
+        printf("%d: MPI_Win_create_dynamic - Error, bad flavor (%d)\n", rank, *flavor);
+        errors++;
     }
 
     MPI_Win_get_attr(window, MPI_WIN_MODEL, &model, &flag);
 
     if (!flag) {
-      printf("%d: MPI_Win_create_dynamic - Error, no model\n", rank);
-      errors++;
-    } else if (*model != MPI_WIN_SEPARATE && *model != MPI_WIN_UNIFIED) {
-      printf("%d: MPI_Win_create_dynamic - Error, bad model (%d)\n", rank, *model);
-      errors++;
+        printf("%d: MPI_Win_create_dynamic - Error, no model\n", rank);
+        errors++;
+    }
+    else if (*model != MPI_WIN_SEPARATE && *model != MPI_WIN_UNIFIED) {
+        printf("%d: MPI_Win_create_dynamic - Error, bad model (%d)\n", rank, *model);
+        errors++;
     }
 
     MPI_Win_free(&window);
index 3a2222d..3eb4380 100644 (file)
@@ -7,30 +7,59 @@
 
 #include <stdio.h>
 #include <mpi.h>
+#include <string.h>
 #include "mpitest.h"
 
 #define VERBOSE 0
 
-int main(int argc, char **argv) {
-    int      i, j, rank, nproc;
+int main(int argc, char **argv)
+{
+    int rank, nproc;
     MPI_Info info_in, info_out;
-    int      errors = 0, all_errors = 0;
-    MPI_Win  win;
-    void    *base;
-    char     invalid_key[] = "invalid_test_key";
-    char     buf[MPI_MAX_INFO_VAL];
-    int      flag;
+    int errors = 0, all_errors = 0;
+    MPI_Win win;
+    void *base;
+    char invalid_key[] = "invalid_test_key";
+    char buf[MPI_MAX_INFO_VAL];
+    int flag;
 
     MPI_Init(&argc, &argv);
 
     MPI_Comm_rank(MPI_COMM_WORLD, &rank);
     MPI_Comm_size(MPI_COMM_WORLD, &nproc);
 
+    /* Test#1: setting a valid key at window-create time */
+
     MPI_Info_create(&info_in);
-    MPI_Info_set(info_in, invalid_key, "true");
+    MPI_Info_set(info_in, "no_locks", "true");
+
+    MPI_Win_allocate(sizeof(int), sizeof(int), info_in, MPI_COMM_WORLD, &base, &win);
+
+    MPI_Win_get_info(win, &info_out);
+
+    MPI_Info_get(info_out, "no_locks", MPI_MAX_INFO_VAL, buf, &flag);
+    if (!flag || strncmp(buf, "true", strlen("true")) != 0) {
+        if (!flag)
+            printf("%d: no_locks is not defined\n", rank);
+        else
+            printf("%d: no_locks = %s, expected true\n", rank, buf);
+        errors++;
+    }
+
+    MPI_Info_free(&info_in);
+    MPI_Info_free(&info_out);
+
+    /* We create a new window with no info argument for the next text to ensure that we have the
+     * default settings */
 
+    MPI_Win_free(&win);
     MPI_Win_allocate(sizeof(int), sizeof(int), MPI_INFO_NULL, MPI_COMM_WORLD, &base, &win);
 
+    /* Test#2: setting and getting invalid key */
+
+    MPI_Info_create(&info_in);
+    MPI_Info_set(info_in, invalid_key, "true");
+
     MPI_Win_set_info(win, info_in);
     MPI_Win_get_info(win, &info_out);
 
@@ -45,22 +74,73 @@ int main(int argc, char **argv) {
     }
 #endif
 
+    MPI_Info_free(&info_in);
+    MPI_Info_free(&info_out);
+
+    /* Test#3: setting info key "no_lock" to false and getting the key */
+
+    MPI_Info_create(&info_in);
+    MPI_Info_set(info_in, "no_locks", "false");
+
+    MPI_Win_set_info(win, info_in);
+    MPI_Win_get_info(win, &info_out);
+
+    MPI_Info_get(info_out, "no_locks", MPI_MAX_INFO_VAL, buf, &flag);
+    if (!flag || strncmp(buf, "false", strlen("false")) != 0) {
+        if (!flag)
+            printf("%d: no_locks is not defined\n", rank);
+        else
+            printf("%d: no_locks = %s, expected false\n", rank, buf);
+        errors++;
+    }
+    if (flag && VERBOSE)
+        printf("%d: no_locks = %s\n", rank, buf);
+
+    MPI_Info_free(&info_in);
+    MPI_Info_free(&info_out);
+
+    /* Test#4: setting info key "no_lock" to true and getting the key */
+
+    MPI_Info_create(&info_in);
+    MPI_Info_set(info_in, "no_locks", "true");
+
+    MPI_Win_set_info(win, info_in);
+    MPI_Win_get_info(win, &info_out);
+
     MPI_Info_get(info_out, "no_locks", MPI_MAX_INFO_VAL, buf, &flag);
-    if (flag && VERBOSE) printf("%d: no_locks = %s\n", rank, buf);
+    if (!flag || strncmp(buf, "true", strlen("true")) != 0) {
+        if (!flag)
+            printf("%d: no_locks is not defined\n", rank);
+        else
+            printf("%d: no_locks = %s, expected true\n", rank, buf);
+        errors++;
+    }
+    if (flag && VERBOSE)
+        printf("%d: no_locks = %s\n", rank, buf);
+
+    MPI_Info_free(&info_in);
+    MPI_Info_free(&info_out);
+
+    /* Test#4: getting other info keys */
+
+    MPI_Win_get_info(win, &info_out);
 
     MPI_Info_get(info_out, "accumulate_ordering", MPI_MAX_INFO_VAL, buf, &flag);
-    if (flag && VERBOSE) printf("%d: accumulate_ordering = %s\n", rank, buf);
+    if (flag && VERBOSE)
+        printf("%d: accumulate_ordering = %s\n", rank, buf);
 
     MPI_Info_get(info_out, "accumulate_ops", MPI_MAX_INFO_VAL, buf, &flag);
-    if (flag && VERBOSE) printf("%d: accumulate_ops = %s\n", rank, buf);
+    if (flag && VERBOSE)
+        printf("%d: accumulate_ops = %s\n", rank, buf);
 
     MPI_Info_get(info_out, "same_size", MPI_MAX_INFO_VAL, buf, &flag);
-    if (flag && VERBOSE) printf("%d: same_size = %s\n", rank, buf);
+    if (flag && VERBOSE)
+        printf("%d: same_size = %s\n", rank, buf);
 
     MPI_Info_get(info_out, "alloc_shm", MPI_MAX_INFO_VAL, buf, &flag);
-    if (flag && VERBOSE) printf("%d: alloc_shm = %s\n", rank, buf);
+    if (flag && VERBOSE)
+        printf("%d: alloc_shm = %s\n", rank, buf);
 
-    MPI_Info_free(&info_in);
     MPI_Info_free(&info_out);
     MPI_Win_free(&win);
 
index fe730d2..63bb5f7 100644 (file)
 #include <stdlib.h>
 #include <stdio.h>
 
-int main(int argc, char **argv) {
+int main(int argc, char **argv)
+{
     int my_rank, shared_rank;
     void *mybase = NULL;
     MPI_Win win;
     MPI_Info win_info;
     MPI_Comm shared_comm;
-    int shm_win_size = 1024 * 1024 * 1024 * sizeof(char); /* 1GB */
+    int i;
+    int shm_win_size = 1024 * 1024 * 1024 * sizeof(char);       /* 1GB */
 
     MPI_Init(&argc, &argv);
 
     MPI_Comm_rank(MPI_COMM_WORLD, &my_rank);
 
-    MPI_Info_create(&win_info);
-    MPI_Info_set(win_info, (char*)"alloc_shm", (char*)"true");
+    for (i = 0; i < 2; i++) {
+        if (i == 0) {
+            MPI_Info_create(&win_info);
+            MPI_Info_set(win_info, (char *) "alloc_shm", (char *) "true");
+        }
+        else {
+            win_info = MPI_INFO_NULL;
+        }
 
-    MPI_Comm_split_type(MPI_COMM_WORLD, MPI_COMM_TYPE_SHARED, my_rank, MPI_INFO_NULL, &shared_comm);
+        MPI_Comm_split_type(MPI_COMM_WORLD, MPI_COMM_TYPE_SHARED, my_rank, MPI_INFO_NULL,
+                            &shared_comm);
 
-    MPI_Comm_rank(shared_comm, &shared_rank);
+        MPI_Comm_rank(shared_comm, &shared_rank);
 
-    /* every processes allocate 1GB window memory */
-    MPI_Win_allocate(shm_win_size, sizeof(char), win_info, MPI_COMM_WORLD, &mybase, &win);
+        /* every processes allocate 1GB window memory */
+        MPI_Win_allocate(shm_win_size, sizeof(char), win_info, MPI_COMM_WORLD, &mybase, &win);
 
-    MPI_Win_free(&win);
+        MPI_Win_free(&win);
 
-    MPI_Win_allocate_shared(shm_win_size, sizeof(char), win_info, shared_comm, &mybase, &win);
+        MPI_Win_allocate_shared(shm_win_size, sizeof(char), win_info, shared_comm, &mybase, &win);
 
-    MPI_Win_free(&win);
+        MPI_Win_free(&win);
 
-    /* some processes allocate 1GB and some processes allocate zero bytes */
-    if (my_rank % 2 == 0)
-        MPI_Win_allocate(shm_win_size, sizeof(char), win_info, MPI_COMM_WORLD, &mybase, &win);
-    else
-        MPI_Win_allocate(0, sizeof(char), win_info, MPI_COMM_WORLD, &mybase, &win);
+        /* some processes allocate 1GB and some processes allocate zero bytes */
+        if (my_rank % 2 == 0)
+            MPI_Win_allocate(shm_win_size, sizeof(char), win_info, MPI_COMM_WORLD, &mybase, &win);
+        else
+            MPI_Win_allocate(0, sizeof(char), win_info, MPI_COMM_WORLD, &mybase, &win);
 
-    MPI_Win_free(&win);
+        MPI_Win_free(&win);
 
-    if (shared_rank % 2 == 0)
-        MPI_Win_allocate_shared(shm_win_size, sizeof(char), win_info, shared_comm, &mybase, &win);
-    else
-        MPI_Win_allocate_shared(0, sizeof(char), win_info, shared_comm, &mybase, &win);
+        if (shared_rank % 2 == 0)
+            MPI_Win_allocate_shared(shm_win_size, sizeof(char), win_info, shared_comm, &mybase,
+                                    &win);
+        else
+            MPI_Win_allocate_shared(0, sizeof(char), win_info, shared_comm, &mybase, &win);
 
-    MPI_Win_free(&win);
+        MPI_Win_free(&win);
 
-    /* some processes allocate 1GB and some processes allocate smaller bytes */
-    if (my_rank % 2 == 0)
-        MPI_Win_allocate(shm_win_size, sizeof(char), win_info, MPI_COMM_WORLD, &mybase, &win);
-    else
-        MPI_Win_allocate(shm_win_size/2, sizeof(char), win_info, MPI_COMM_WORLD, &mybase, &win);
+        /* some processes allocate 1GB and some processes allocate smaller bytes */
+        if (my_rank % 2 == 0)
+            MPI_Win_allocate(shm_win_size, sizeof(char), win_info, MPI_COMM_WORLD, &mybase, &win);
+        else
+            MPI_Win_allocate(shm_win_size / 2, sizeof(char), win_info, MPI_COMM_WORLD, &mybase,
+                             &win);
 
-    MPI_Win_free(&win);
+        MPI_Win_free(&win);
 
-    /* some processes allocate 1GB and some processes allocate smaller bytes */
-    if (shared_rank % 2 == 0)
-        MPI_Win_allocate_shared(shm_win_size, sizeof(char), win_info, shared_comm, &mybase, &win);
-    else
-        MPI_Win_allocate_shared(shm_win_size/2, sizeof(char), win_info, shared_comm, &mybase, &win);
+        /* some processes allocate 1GB and some processes allocate smaller bytes */
+        if (shared_rank % 2 == 0)
+            MPI_Win_allocate_shared(shm_win_size, sizeof(char), win_info, shared_comm, &mybase,
+                                    &win);
+        else
+            MPI_Win_allocate_shared(shm_win_size / 2, sizeof(char), win_info, shared_comm, &mybase,
+                                    &win);
 
-    MPI_Win_free(&win);
+        MPI_Win_free(&win);
 
-    MPI_Comm_free(&shared_comm);
+        MPI_Comm_free(&shared_comm);
 
-    MPI_Info_free(&win_info);
+        if (i == 0)
+            MPI_Info_free(&win_info);
+    }
 
     if (my_rank == 0)
         printf(" No Errors\n");
index 03e35de..7dc5e0c 100644 (file)
 
 const int verbose = 0;
 
-int main(int argc, char **argv) {
-    int      i, j, rank, nproc;
-    int      shm_rank, shm_nproc;
+int main(int argc, char **argv)
+{
+    int i, j, rank, nproc;
+    int shm_rank, shm_nproc;
     MPI_Aint size;
-    int      errors = 0, all_errors = 0;
-    int     *base, *my_base;
-    int      disp_unit;
-    MPI_Win  shm_win;
+    int errors = 0, all_errors = 0;
+    int *base, *my_base;
+    int disp_unit;
+    MPI_Win shm_win;
     MPI_Comm shm_comm;
 
     MPI_Init(&argc, &argv);
@@ -36,11 +37,11 @@ int main(int argc, char **argv) {
     MPI_Comm_size(shm_comm, &shm_nproc);
 
     /* Allocate ELEM_PER_PROC integers for each process */
-    MPI_Win_allocate_shared(sizeof(int)*ELEM_PER_PROC, sizeof(int), MPI_INFO_NULL, 
-                             shm_comm, &my_base, &shm_win);
+    MPI_Win_allocate_shared(sizeof(int) * ELEM_PER_PROC, sizeof(int), MPI_INFO_NULL,
+                            shm_comm, &my_base, &shm_win);
 
     /* Locate absolute base */
-    MPI_Win_shared_query(shm_win, MPI_PROC_NULL, &size, &disp_unit, &base); 
+    MPI_Win_shared_query(shm_win, MPI_PROC_NULL, &size, &disp_unit, &base);
 
     /* make sure the query returned the right values */
     if (disp_unit != sizeof(int))
@@ -52,8 +53,9 @@ int main(int argc, char **argv) {
     if (shm_rank && (base == my_base))
         errors++;
 
-    if (verbose) printf("%d -- size = %d baseptr = %p my_baseptr = %p\n", shm_rank, 
-                        (int) size, (void*) base, (void*) my_base);
+    if (verbose)
+        printf("%d -- size = %d baseptr = %p my_baseptr = %p\n", shm_rank,
+               (int) size, (void *) base, (void *) my_base);
 
     MPI_Win_lock_all(MPI_MODE_NOCHECK, shm_win);
 
@@ -69,10 +71,10 @@ int main(int argc, char **argv) {
     /* Read and verify everyone's data */
     for (i = 0; i < shm_nproc; i++) {
         for (j = 0; j < ELEM_PER_PROC; j++) {
-            if ( base[i*ELEM_PER_PROC + j] != j ) {
+            if (base[i * ELEM_PER_PROC + j] != j) {
                 errors++;
                 printf("%d -- Got %d at rank %d index %d, expected %d\n", shm_rank,
-                       base[i*ELEM_PER_PROC + j], i, j, j);
+                       base[i * ELEM_PER_PROC + j], i, j, j);
             }
         }
     }
diff --git a/teshsuite/smpi/mpich3-test/rma/win_shared_create.c b/teshsuite/smpi/mpich3-test/rma/win_shared_create.c
new file mode 100644 (file)
index 0000000..0042184
--- /dev/null
@@ -0,0 +1,140 @@
+/* -*- Mode: C; c-basic-offset:4 ; indent-tabs-mode:nil ; -*- */
+/*
+ *
+ *  (C) 2014 by Argonne National Laboratory.
+ *      See COPYRIGHT in top-level directory.
+ */
+
+#include <stdio.h>
+#include <stdlib.h>
+#include <assert.h>
+#include <mpi.h>
+#include "mpitest.h"
+
+#define ELEM_PER_PROC 4
+int local_buf[ELEM_PER_PROC];
+
+const int verbose = 0;
+
+int main(int argc, char **argv)
+{
+    int i, rank, nproc;
+    int shm_rank, shm_nproc;
+    MPI_Aint size;
+    int errors = 0, all_errors = 0;
+    int **bases = NULL, *my_base = NULL;
+    int disp_unit;
+    MPI_Win shm_win = MPI_WIN_NULL, win = MPI_WIN_NULL;
+    MPI_Comm shm_comm = MPI_COMM_NULL;
+    MPI_Group shm_group = MPI_GROUP_NULL, world_group = MPI_GROUP_NULL;
+    int dst_shm_rank, dst_world_rank;
+    MPI_Info create_info = MPI_INFO_NULL;
+
+    MPI_Init(&argc, &argv);
+
+    MPI_Comm_rank(MPI_COMM_WORLD, &rank);
+    MPI_Comm_size(MPI_COMM_WORLD, &nproc);
+
+    MPI_Comm_split_type(MPI_COMM_WORLD, MPI_COMM_TYPE_SHARED, rank, MPI_INFO_NULL, &shm_comm);
+
+    MPI_Comm_rank(shm_comm, &shm_rank);
+    MPI_Comm_size(shm_comm, &shm_nproc);
+
+    /* Platform does not support shared memory, just return. */
+    if (shm_nproc < 2) {
+        goto exit;
+    }
+
+    /* Specify the last process in the node as the target process */
+    dst_shm_rank = shm_nproc - 1;
+    MPI_Comm_group(shm_comm, &shm_group);
+    MPI_Comm_group(MPI_COMM_WORLD, &world_group);
+    MPI_Group_translate_ranks(shm_group, 1, &dst_shm_rank, world_group, &dst_world_rank);
+
+    bases = calloc(shm_nproc, sizeof(int *));
+
+    /* Allocate shm window among local processes, then create a global window with
+     * those shm window buffers */
+    MPI_Win_allocate_shared(sizeof(int) * ELEM_PER_PROC, sizeof(int), MPI_INFO_NULL,
+                            shm_comm, &my_base, &shm_win);
+    if (verbose)
+        printf("%d -- allocate shared: my_base = %p, absolute base\n", shm_rank, my_base);
+
+    for (i = 0; i < shm_nproc; i++) {
+        MPI_Win_shared_query(shm_win, i, &size, &disp_unit, &bases[i]);
+        if (verbose)
+            printf("%d --    shared query: base[%d]=%p, size %ld, unit %d\n",
+                   shm_rank, i, bases[i], size, disp_unit);
+    }
+
+#ifdef USE_INFO_ALLOC_SHM
+    MPI_Info_create(&create_info);
+    MPI_Info_set(create_info, "alloc_shm", "true");
+#else
+    create_info = MPI_INFO_NULL;
+#endif
+
+    /* Reset data */
+    for (i = 0; i < ELEM_PER_PROC; i++) {
+        my_base[i] = 0;
+        local_buf[i] = i + 1;
+    }
+
+    MPI_Win_create(my_base, sizeof(int) * ELEM_PER_PROC, sizeof(int), create_info, MPI_COMM_WORLD,
+                   &win);
+
+    /* Do RMA through global window, then check value through shared window */
+    MPI_Win_lock_all(0, win);
+    MPI_Win_lock_all(0, shm_win);
+
+    if (shm_rank == 0) {
+        MPI_Put(&local_buf[0], 1, MPI_INT, dst_world_rank, 0, 1, MPI_INT, win);
+        MPI_Put(&local_buf[ELEM_PER_PROC - 1], 1, MPI_INT, dst_world_rank, ELEM_PER_PROC - 1, 1,
+                MPI_INT, win);
+        MPI_Win_flush(dst_world_rank, win);
+    }
+
+    MPI_Win_sync(shm_win);
+    MPI_Barrier(shm_comm);
+    MPI_Win_sync(shm_win);
+
+    if (bases[dst_shm_rank][0] != local_buf[0]) {
+        errors++;
+        printf("%d -- Got %d at rank %d index %d, expected %d\n", rank,
+               bases[dst_shm_rank][0], dst_shm_rank, 0, local_buf[0]);
+    }
+    if (bases[dst_shm_rank][ELEM_PER_PROC - 1] != local_buf[ELEM_PER_PROC - 1]) {
+        errors++;
+        printf("%d -- Got %d at rank %d index %d, expected %d\n", rank,
+               bases[dst_shm_rank][ELEM_PER_PROC - 1], dst_shm_rank,
+               ELEM_PER_PROC - 1, local_buf[ELEM_PER_PROC - 1]);
+    }
+
+    MPI_Win_unlock_all(shm_win);
+    MPI_Win_unlock_all(win);
+
+    MPI_Reduce(&errors, &all_errors, 1, MPI_INT, MPI_SUM, 0, MPI_COMM_WORLD);
+
+    MPI_Win_free(&win);
+    MPI_Win_free(&shm_win);
+
+  exit:
+    if (rank == 0 && all_errors == 0)
+        printf(" No Errors\n");
+
+    if (create_info != MPI_INFO_NULL)
+        MPI_Info_free(&create_info);
+    if (shm_comm != MPI_COMM_NULL)
+        MPI_Comm_free(&shm_comm);
+    if (shm_group != MPI_GROUP_NULL)
+        MPI_Group_free(&shm_group);
+    if (world_group != MPI_GROUP_NULL)
+        MPI_Group_free(&world_group);
+
+    MPI_Finalize();
+
+    if (bases)
+        free(bases);
+
+    return 0;
+}
index 22e37e1..db25c33 100644 (file)
 
 const int verbose = 0;
 
-int main(int argc, char **argv) {
-    int      i, j, rank, nproc;
-    int      shm_rank, shm_nproc;
+int main(int argc, char **argv)
+{
+    int i, j, rank, nproc;
+    int shm_rank, shm_nproc;
     MPI_Info alloc_shared_info;
-    int      errors = 0, all_errors = 0;
-    int      disp_unit;
-    int     *my_base;
-    MPI_Win  shm_win;
+    int errors = 0, all_errors = 0;
+    int disp_unit;
+    int *my_base;
+    MPI_Win shm_win;
     MPI_Comm shm_comm;
 
     MPI_Init(&argc, &argv);
@@ -39,8 +40,8 @@ int main(int argc, char **argv) {
     MPI_Comm_size(shm_comm, &shm_nproc);
 
     /* Allocate ELEM_PER_PROC integers for each process */
-    MPI_Win_allocate_shared(sizeof(int)*ELEM_PER_PROC, sizeof(int), alloc_shared_info, 
-                             shm_comm, &my_base, &shm_win);
+    MPI_Win_allocate_shared(sizeof(int) * ELEM_PER_PROC, sizeof(int), alloc_shared_info,
+                            shm_comm, &my_base, &shm_win);
 
     MPI_Win_lock_all(MPI_MODE_NOCHECK, shm_win);
 
@@ -55,16 +56,16 @@ int main(int argc, char **argv) {
 
     /* Read and verify everyone's data */
     for (i = 0; i < shm_nproc; i++) {
-        int      *base;
-        MPI_Aint  size;
+        int *base;
+        MPI_Aint size;
 
         MPI_Win_shared_query(shm_win, i, &size, &disp_unit, &base);
         assert(size >= ELEM_PER_PROC * sizeof(int));
 
         for (j = 0; j < ELEM_PER_PROC; j++) {
-            if ( base[j] != j ) {
+            if (base[j] != j) {
                 errors++;
-                printf("%d -- Got %d at rank %d index %d, expected %d\n", shm_rank, 
+                printf("%d -- Got %d at rank %d index %d, expected %d\n", shm_rank,
                        base[j], i, j, j);
             }
         }
index 0e68d2d..e733c87 100644 (file)
 
 const int verbose = 0;
 
-int main(int argc, char **argv) {
-    int      i, j, rank, nproc;
-    int      shm_rank, shm_nproc;
+int main(int argc, char **argv)
+{
+    int i, j, rank, nproc;
+    int shm_rank, shm_nproc;
     MPI_Info alloc_shared_info;
-    int      errors = 0, all_errors = 0;
-    int      disp_unit;
-    int     *my_base, my_size;
-    MPI_Win  shm_win;
+    int errors = 0, all_errors = 0;
+    int disp_unit;
+    int *my_base, my_size;
+    MPI_Win shm_win;
     MPI_Comm shm_comm;
 
     MPI_Init(&argc, &argv);
@@ -39,26 +40,25 @@ int main(int argc, char **argv) {
     MPI_Comm_size(shm_comm, &shm_nproc);
 
     /* Allocate ELEM_PER_PROC integers on each even rank process */
-    my_size = (shm_rank % 2 == 0) ? sizeof(int)*ELEM_PER_PROC : 0;
-    MPI_Win_allocate_shared(my_size, sizeof(int), alloc_shared_info,
-                             shm_comm, &my_base, &shm_win);
+    my_size = (shm_rank % 2 == 0) ? sizeof(int) * ELEM_PER_PROC : 0;
+    MPI_Win_allocate_shared(my_size, sizeof(int), alloc_shared_info, shm_comm, &my_base, &shm_win);
 
     for (i = 0; i < ELEM_PER_PROC; i++) {
-            MPI_Win_fence(MPI_MODE_NOPRECEDE, shm_win);
-            if (shm_rank % 2 == 0) {
-                MPI_Put(&i, 1, MPI_INT, 
-                        (shm_rank + 2 > shm_nproc) ? 0 : (shm_rank+2) % shm_nproc,
-                        i, 1, MPI_INT, shm_win);
-            }
-            MPI_Win_fence(MPI_MODE_NOSUCCEED, shm_win);
+        MPI_Win_fence(MPI_MODE_NOPRECEDE, shm_win);
+        if (shm_rank % 2 == 0) {
+            MPI_Put(&i, 1, MPI_INT,
+                    (shm_rank + 2 > shm_nproc) ? 0 : (shm_rank + 2) % shm_nproc,
+                    i, 1, MPI_INT, shm_win);
+        }
+        MPI_Win_fence(MPI_MODE_NOSUCCEED, shm_win);
     }
 
     MPI_Barrier(shm_comm);
 
     /* Read and verify everyone's data */
     for (i = 0; i < shm_nproc; i++) {
-        int      *base;
-        MPI_Aint  size;
+        int *base;
+        MPI_Aint size;
 
         MPI_Win_shared_query(shm_win, i, &size, &disp_unit, &base);
 
@@ -66,13 +66,14 @@ int main(int argc, char **argv) {
             assert(size >= ELEM_PER_PROC * sizeof(int));
 
             for (j = 0; j < ELEM_PER_PROC; j++) {
-                if ( base[j] != j ) {
+                if (base[j] != j) {
                     errors++;
                     printf("%d -- Got %d at rank %d index %d, expected %d\n", shm_rank,
                            base[j], i, j, j);
                 }
             }
-        } else {
+        }
+        else {
             assert(size == 0);
             assert(base == NULL);
         }
diff --git a/teshsuite/smpi/mpich3-test/rma/win_shared_put_flush_get.c b/teshsuite/smpi/mpich3-test/rma/win_shared_put_flush_get.c
new file mode 100644 (file)
index 0000000..5c4cfcf
--- /dev/null
@@ -0,0 +1,199 @@
+/* -*- Mode: C; c-basic-offset:4 ; indent-tabs-mode:nil ; -*- */
+/*
+ *
+ *  (C) 2014 by Argonne National Laboratory.
+ *      See COPYRIGHT in top-level directory.
+ */
+
+#include <stdio.h>
+#include <stdlib.h>
+#include <mpi.h>
+#include "mpitest.h"
+
+#define ITER 100
+#define BUF_CNT 4
+double local_buf[BUF_CNT], check_buf[BUF_CNT];
+
+const int verbose = 0;
+
+int main(int argc, char *argv[])
+{
+    int rank, nproc, i, x;
+    int errors = 0, all_errors = 0;
+    MPI_Win win = MPI_WIN_NULL;
+
+    MPI_Comm shm_comm = MPI_COMM_NULL;
+    int shm_nproc, shm_rank;
+    double **shm_bases = NULL, *my_base;
+    MPI_Win shm_win = MPI_WIN_NULL;
+    MPI_Group shm_group = MPI_GROUP_NULL, world_group = MPI_GROUP_NULL;
+    int *shm_ranks = NULL, *shm_ranks_in_world = NULL;
+    MPI_Aint get_target_base_offsets = 0;
+
+    int win_size = sizeof(double) * BUF_CNT;
+    int new_win_size = win_size;
+    int win_unit = sizeof(double);
+    int shm_root_rank_in_world;
+    int origin = -1, put_target, get_target;
+
+    MPI_Init(&argc, &argv);
+    MPI_Comm_rank(MPI_COMM_WORLD, &rank);
+    MPI_Comm_size(MPI_COMM_WORLD, &nproc);
+    MPI_Comm_group(MPI_COMM_WORLD, &world_group);
+
+    if (nproc != 4) {
+        if (rank == 0)
+            printf("Error: must be run with four processes\n");
+        MPI_Abort(MPI_COMM_WORLD, 1);
+    }
+
+    MPI_Comm_split_type(MPI_COMM_WORLD, MPI_COMM_TYPE_SHARED, rank, MPI_INFO_NULL, &shm_comm);
+    MPI_Comm_rank(shm_comm, &shm_rank);
+    MPI_Comm_size(shm_comm, &shm_nproc);
+    MPI_Comm_group(shm_comm, &shm_group);
+
+    /* Platform does not support shared memory or wrong host file, just return. */
+    if (shm_nproc != 2) {
+        goto exit;
+    }
+
+    shm_bases = (double **) calloc(shm_nproc, sizeof(double *));
+    shm_ranks = (int *) calloc(shm_nproc, sizeof(int));
+    shm_ranks_in_world = (int *) calloc(shm_nproc, sizeof(int));
+
+    if (shm_rank == 0)
+        shm_root_rank_in_world = rank;
+    MPI_Bcast(&shm_root_rank_in_world, 1, MPI_INT, 0, shm_comm);
+
+    /* Identify ranks of target processes which are located on node 0 */
+    if (rank == 0) {
+        for (i = 0; i < shm_nproc; i++) {
+            shm_ranks[i] = i;
+        }
+        MPI_Group_translate_ranks(shm_group, shm_nproc, shm_ranks, world_group, shm_ranks_in_world);
+    }
+    MPI_Bcast(shm_ranks_in_world, shm_nproc, MPI_INT, 0, MPI_COMM_WORLD);
+
+    put_target = shm_ranks_in_world[shm_nproc - 1];
+    get_target = shm_ranks_in_world[0];
+
+    /* Identify the rank of origin process which are located on node 1 */
+    if (shm_root_rank_in_world == 1 && shm_rank == 0) {
+        origin = rank;
+        if (verbose) {
+            printf("----   I am origin = %d, get_target = %d, put_target = %d\n",
+                   origin, get_target, put_target);
+        }
+    }
+
+    /* Allocate shared memory among local processes */
+    MPI_Win_allocate_shared(win_size, win_unit, MPI_INFO_NULL, shm_comm, &my_base, &shm_win);
+
+    if (shm_root_rank_in_world == 0 && verbose) {
+        MPI_Aint size;
+        int disp_unit;
+        for (i = 0; i < shm_nproc; i++) {
+            MPI_Win_shared_query(shm_win, i, &size, &disp_unit, &shm_bases[i]);
+            printf("%d --    shared query: base[%d]=%p, size %ld, "
+                   "unit %d\n", rank, i, shm_bases[i], size, disp_unit);
+        }
+    }
+
+    /* Get offset of put target(1) on get target(0) */
+    get_target_base_offsets = (shm_nproc - 1) * win_size / win_unit;
+
+    if (origin == rank && verbose)
+        printf("%d --    base_offset of put_target %d on get_target %d: %ld\n",
+               rank, put_target, get_target, get_target_base_offsets);
+
+    /* Create using MPI_Win_create(). Note that new window size of get_target(0)
+     * is equal to the total size of shm segments on this node, thus get_target
+     * process can read the byte located on put_target process.*/
+    for (i = 0; i < BUF_CNT; i++) {
+        local_buf[i] = (i + 1) * 1.0;
+        my_base[i] = 0.0;
+    }
+
+    if (get_target == rank)
+        new_win_size = win_size * shm_nproc;
+
+    MPI_Win_create(my_base, new_win_size, win_unit, MPI_INFO_NULL, MPI_COMM_WORLD, &win);
+
+    if (verbose)
+        printf("%d --    new window my_base %p, size %d\n", rank, my_base, new_win_size);
+
+    MPI_Barrier(MPI_COMM_WORLD);
+
+    /* Check if flush guarantees the completion of put operations on target side.
+     *
+     * P exclusively locks 2 processes whose windows are shared with each other.
+     * P first put and flush to a process, then get the updated data from another process.
+     * If flush returns before operations are done on the target side, the data may be
+     * incorrect.*/
+    for (x = 0; x < ITER; x++) {
+        for (i = 0; i < BUF_CNT; i++) {
+            local_buf[i] += x;
+            check_buf[i] = 0;
+        }
+
+        if (rank == origin) {
+            MPI_Win_lock(MPI_LOCK_EXCLUSIVE, put_target, 0, win);
+            MPI_Win_lock(MPI_LOCK_EXCLUSIVE, get_target, 0, win);
+
+            for (i = 0; i < BUF_CNT; i++) {
+                MPI_Put(&local_buf[i], 1, MPI_DOUBLE, put_target, i, 1, MPI_DOUBLE, win);
+            }
+            MPI_Win_flush(put_target, win);
+
+            MPI_Get(check_buf, BUF_CNT, MPI_DOUBLE, get_target,
+                    get_target_base_offsets, BUF_CNT, MPI_DOUBLE, win);
+            MPI_Win_flush(get_target, win);
+
+            for (i = 0; i < BUF_CNT; i++) {
+                if (check_buf[i] != local_buf[i]) {
+                    printf("%d(iter %d) - Got check_buf[%d] = %.1lf, expected %.1lf\n",
+                           rank, x, i, check_buf[i], local_buf[i]);
+                    errors++;
+                }
+            }
+
+            MPI_Win_unlock(put_target, win);
+            MPI_Win_unlock(get_target, win);
+        }
+    }
+
+    MPI_Barrier(MPI_COMM_WORLD);
+
+    MPI_Reduce(&errors, &all_errors, 1, MPI_INT, MPI_SUM, 0, MPI_COMM_WORLD);
+
+  exit:
+
+    if (rank == 0 && all_errors == 0)
+        printf(" No Errors\n");
+
+    if (shm_bases)
+        free(shm_bases);
+    if (shm_ranks)
+        free(shm_ranks);
+    if (shm_ranks_in_world)
+        free(shm_ranks_in_world);
+
+    if (shm_win != MPI_WIN_NULL)
+        MPI_Win_free(&shm_win);
+
+    if (win != MPI_WIN_NULL)
+        MPI_Win_free(&win);
+
+    if (shm_comm != MPI_COMM_NULL)
+        MPI_Comm_free(&shm_comm);
+
+    if (shm_group != MPI_GROUP_NULL)
+        MPI_Group_free(&shm_group);
+
+    if (world_group != MPI_GROUP_NULL)
+        MPI_Group_free(&world_group);
+
+    MPI_Finalize();
+
+    return 0;
+}
diff --git a/teshsuite/smpi/mpich3-test/rma/win_shared_rma_flush_load.c b/teshsuite/smpi/mpich3-test/rma/win_shared_rma_flush_load.c
new file mode 100644 (file)
index 0000000..1386fcd
--- /dev/null
@@ -0,0 +1,299 @@
+/* -*- Mode: C; c-basic-offset:4 ; indent-tabs-mode:nil ; -*- */
+/*
+ *
+ *  (C) 2015 by Argonne National Laboratory.
+ *      See COPYRIGHT in top-level directory.
+ */
+
+#include <stdio.h>
+#include <stdlib.h>
+#include <mpi.h>
+#include "mpitest.h"
+
+#define ITER 10000
+#define BUF_CNT 1
+int local_buf[BUF_CNT], result_addr[BUF_CNT];
+#ifdef TEST_CAS
+int compare_buf[BUF_CNT];
+#endif
+
+const int verbose = 0;
+
+/* This test checks the remote completion of flush with RMA write-like operations
+ * (PUT, ACC, GET_ACC, FOP, CAS), and confirms result by shm load.
+ * 1. P(target) and P(checker) allocate a shared window, and
+ *    then create a global window with P(origin) by using the shared window buffer.
+ * 2. P(origin) issues RMA operations and flush to P(target) through the global
+ *    window and then call send-recv to synchronize with P(checker).
+ * 3. P(checker) then checks the result through shm window by local load. */
+
+int rank = -1, nproc = 0;
+int origin = -1, target = -1, checker = -1;
+MPI_Win win = MPI_WIN_NULL, shm_win = MPI_WIN_NULL;
+int *shm_target_base = NULL, *my_base = NULL;
+
+/* Define operation name for error message */
+#ifdef TEST_PUT
+const char *rma_name = "Put";
+#elif defined(TEST_ACC)
+const char *rma_name = "Accumulate";
+#elif defined(TEST_GACC)
+const char *rma_name = "Get_accumulate";
+#elif defined(TEST_FOP)
+const char *rma_name = "Fetch_and_op";
+#elif defined(TEST_CAS)
+const char *rma_name = "Compare_and_swap";
+#else
+const char *rma_name = "None";
+#endif
+
+/* Issue functions for different RMA operations */
+#ifdef TEST_PUT
+static inline void issue_rma_op(int i)
+{
+    MPI_Put(&local_buf[i], 1, MPI_INT, target, i, 1, MPI_INT, win);
+}
+#elif defined(TEST_ACC)
+static inline void issue_rma_op(int i)
+{
+    MPI_Accumulate(&local_buf[i], 1, MPI_INT, target, i, 1, MPI_INT, MPI_REPLACE, win);
+}
+#elif defined(TEST_GACC)
+static inline void issue_rma_op(int i)
+{
+    MPI_Get_accumulate(&local_buf[i], 1, MPI_INT, &result_addr[i], 1, MPI_INT, target, i,
+                       1, MPI_INT, MPI_REPLACE, win);
+}
+#elif defined(TEST_FOP)
+static inline void issue_rma_op(int i)
+{
+    MPI_Fetch_and_op(&local_buf[i], &result_addr[i], MPI_INT, target, i, MPI_REPLACE, win);
+}
+#elif defined(TEST_CAS)
+static inline void issue_rma_op(int i)
+{
+    compare_buf[i] = i;        /* always equal to window value, thus swap happens */
+    MPI_Compare_and_swap(&local_buf[i], &compare_buf[i], &result_addr[i], MPI_INT, target, i, win);
+}
+#endif
+
+
+/* Local check function for GET-like operations */
+#if defined(TEST_GACC) || defined(TEST_FOP) || defined(TEST_CAS)
+
+/* Check local result buffer for GET-like operations */
+static int check_local_result(int iter)
+{
+    int i = 0;
+    int errors = 0;
+
+    for (i = 0; i < BUF_CNT; i++) {
+        if (result_addr[i] != i) {
+            printf("rank %d (iter %d) - check %s, got result_addr[%d] = %d, expected %d\n",
+                   rank, iter, rma_name, i, result_addr[i], i);
+            errors++;
+        }
+    }
+    return errors;
+}
+
+#else
+#define check_local_result(iter) (0)
+#endif
+
+static int run_test()
+{
+    int i = 0, x = 0;
+    int errors = 0;
+    int sbuf = 0, rbuf = 0;
+    MPI_Status stat;
+
+    for (x = 0; x < ITER; x++) {
+        /* 1. Target resets window data */
+        if (rank == target) {
+            for (i = 0; i < BUF_CNT; i++)
+                my_base[i] = i;
+            MPI_Win_sync(shm_win);      /* write is done on shm window */
+        }
+
+        MPI_Barrier(MPI_COMM_WORLD);
+
+        /* 2. Every one resets local data */
+        for (i = 0; i < BUF_CNT; i++) {
+            local_buf[i] = BUF_CNT + x * BUF_CNT + i;
+            result_addr[i] = 0;
+        }
+
+        /* 3. Origin issues RMA operation to target */
+        if (rank == origin) {
+            /* 3-1. Issue RMA. */
+            for (i = 0; i < BUF_CNT; i++) {
+                issue_rma_op(i);
+            }
+            MPI_Win_flush(target, win);
+
+            /* 3-2. Check local result buffer. */
+            errors += check_local_result(x);
+
+            /* sync with checker */
+            MPI_Send(&sbuf, 1, MPI_INT, checker, 999, MPI_COMM_WORLD);
+        }
+
+        /* 4. Checker confirms result on target */
+        if (rank == checker) {
+            /* sync with origin */
+            MPI_Recv(&rbuf, 1, MPI_INT, origin, 999, MPI_COMM_WORLD, &stat);
+
+            MPI_Win_sync(shm_win);
+
+            for (i = 0; i < BUF_CNT; i++) {
+                if (shm_target_base[i] != local_buf[i]) {
+                    printf("rank %d (iter %d) - check %s, got shm_target_base[%d] = %d, "
+                           "expected %d\n", rank, x, rma_name, i, shm_target_base[i], local_buf[i]);
+                    errors++;
+                }
+            }
+        }
+
+        MPI_Barrier(MPI_COMM_WORLD);
+    }
+
+    return errors;
+}
+
+int main(int argc, char *argv[])
+{
+    int i;
+    int errors = 0, all_errors = 0;
+    MPI_Comm shm_comm = MPI_COMM_NULL;
+    int shm_rank;
+    int *shm_ranks = NULL, *shm_root_ranks = NULL;
+    int win_size = sizeof(int) * BUF_CNT;
+    int win_unit = sizeof(int);
+    int shm_root_rank = -1, shm_target = -1, target_shm_root = -1;
+
+    MPI_Init(&argc, &argv);
+    MPI_Comm_rank(MPI_COMM_WORLD, &rank);
+    MPI_Comm_size(MPI_COMM_WORLD, &nproc);
+
+    if (nproc != 3) {
+        if (rank == 0)
+            printf("Error: must be run with three processes\n");
+        MPI_Barrier(MPI_COMM_WORLD);
+        MPI_Abort(MPI_COMM_WORLD, 1);
+    }
+
+#if !defined(TEST_PUT) && !defined(TEST_ACC) && !defined(TEST_GACC) && !defined(TEST_FOP) && !defined(TEST_CAS)
+    if (rank == 0)
+        printf("Error: must specify operation type at compile time\n");
+    MPI_Barrier(MPI_COMM_WORLD);
+    MPI_Abort(MPI_COMM_WORLD, 1);
+#endif
+
+    MPI_Comm_split_type(MPI_COMM_WORLD, MPI_COMM_TYPE_SHARED, rank, MPI_INFO_NULL, &shm_comm);
+    MPI_Comm_rank(shm_comm, &shm_rank);
+
+    shm_ranks = (int *) calloc(nproc, sizeof(int));
+    shm_root_ranks = (int *) calloc(nproc, sizeof(int));
+
+    /* Identify node id */
+    if (shm_rank == 0)
+        shm_root_rank = rank;
+    MPI_Bcast(&shm_root_rank, 1, MPI_INT, 0, shm_comm);
+
+    /* Exchange local root rank and local rank */
+    shm_ranks[rank] = shm_rank;
+    shm_root_ranks[rank] = shm_root_rank;
+
+    MPI_Allgather(MPI_IN_PLACE, 0, MPI_DATATYPE_NULL, shm_ranks, 1, MPI_INT, MPI_COMM_WORLD);
+    MPI_Allgather(MPI_IN_PLACE, 0, MPI_DATATYPE_NULL, shm_root_ranks, 1, MPI_INT, MPI_COMM_WORLD);
+
+    /* Check if there are at least two processes in shared memory. */
+    for (i = 0; i < nproc; i++) {
+        if (shm_ranks[i] != 0) {
+            target_shm_root = shm_root_ranks[i];
+            break;
+        }
+    }
+
+    /* Every process is in separate memory, we cannot create shared window. Just return. */
+    if (target_shm_root < 0)
+        goto exit;
+
+    /* Identify origin, target and checker ranks.
+     * the first process in shared memory is target, and the second one is checker;
+     * the last process is origin.*/
+    shm_target = 0;
+    for (i = 0; i < nproc; i++) {
+        if (shm_root_ranks[i] == target_shm_root) {
+            if (shm_ranks[i] == 0) {
+                target = i;
+            }
+            else if (shm_ranks[i] == 1) {
+                checker = i;
+            }
+            else {
+                /* all three processes are in shared memory, origin is the third one. */
+                origin = i;
+            }
+        }
+        else {
+            /* origin is in separate memory. */
+            origin = i;
+        }
+    }
+
+    if (verbose) {
+        printf("----   rank %d: origin = %d, checker = %d, target = %d, test %s\n",
+               rank, origin, checker, target, rma_name);
+    }
+
+    /* Allocate shared memory among local processes, then create a global window
+     * with the shared window buffers. */
+    MPI_Win_allocate_shared(win_size, win_unit, MPI_INFO_NULL, shm_comm, &my_base, &shm_win);
+    MPI_Win_create(my_base, win_size, win_unit, MPI_INFO_NULL, MPI_COMM_WORLD, &win);
+
+    /* Get address of target window on checker process. */
+    if (rank == checker) {
+        MPI_Aint size;
+        int disp_unit;
+        MPI_Win_shared_query(shm_win, shm_target, &size, &disp_unit, &shm_target_base);
+        if (verbose) {
+            printf("----   I am checker = %d, shm_target_base=%p\n", checker, shm_target_base);
+        }
+    }
+
+    /* Start checking. */
+    MPI_Win_lock_all(0, win);
+    MPI_Win_lock_all(0, shm_win);
+
+    errors = run_test();
+
+    MPI_Win_unlock_all(shm_win);
+    MPI_Win_unlock_all(win);
+
+    MPI_Reduce(&errors, &all_errors, 1, MPI_INT, MPI_SUM, 0, MPI_COMM_WORLD);
+
+  exit:
+
+    if (rank == 0 && all_errors == 0)
+        printf(" No Errors\n");
+
+    if (shm_ranks)
+        free(shm_ranks);
+    if (shm_root_ranks)
+        free(shm_root_ranks);
+
+    if (shm_win != MPI_WIN_NULL)
+        MPI_Win_free(&shm_win);
+
+    if (win != MPI_WIN_NULL)
+        MPI_Win_free(&win);
+
+    if (shm_comm != MPI_COMM_NULL)
+        MPI_Comm_free(&shm_comm);
+
+    MPI_Finalize();
+
+    return 0;
+}
diff --git a/teshsuite/smpi/mpich3-test/rma/win_shared_zerobyte.c b/teshsuite/smpi/mpich3-test/rma/win_shared_zerobyte.c
new file mode 100644 (file)
index 0000000..2b17d79
--- /dev/null
@@ -0,0 +1,116 @@
+/* -*- Mode: C; c-basic-offset:4 ; indent-tabs-mode:nil ; -*- */
+/*
+ *
+ *  (C) 2014 by Argonne National Laboratory.
+ *      See COPYRIGHT in top-level directory.
+ */
+
+#include <stdio.h>
+#include <stdlib.h>
+#include <assert.h>
+#include <mpi.h>
+#include "mpitest.h"
+
+const int verbose = 0;
+
+int main(int argc, char **argv)
+{
+    int i, rank, nproc;
+    int shm_rank, shm_nproc;
+    MPI_Aint size;
+    int errors = 0, all_errors = 0;
+    int **bases = NULL, *abs_base, *my_base;
+    int disp_unit;
+    MPI_Win shm_win;
+    MPI_Comm shm_comm;
+    int ELEM_PER_PROC = 0;
+
+    MPI_Init(&argc, &argv);
+
+    MPI_Comm_rank(MPI_COMM_WORLD, &rank);
+    MPI_Comm_size(MPI_COMM_WORLD, &nproc);
+
+    MPI_Comm_split_type(MPI_COMM_WORLD, MPI_COMM_TYPE_SHARED, rank, MPI_INFO_NULL, &shm_comm);
+
+    MPI_Comm_rank(shm_comm, &shm_rank);
+    MPI_Comm_size(shm_comm, &shm_nproc);
+
+    /* Platform does not support shared memory, just return. */
+    if (shm_nproc < 2) {
+        goto exit;
+    }
+
+    bases = calloc(shm_nproc, sizeof(int *));
+
+    if (shm_rank == 0 || shm_rank == shm_nproc - 1) {
+        ELEM_PER_PROC = 16;
+    }
+
+    /* Allocate ELEM_PER_PROC integers for each process */
+    MPI_Win_allocate_shared(sizeof(int) * ELEM_PER_PROC, sizeof(int), MPI_INFO_NULL,
+                            shm_comm, &my_base, &shm_win);
+
+    /* Locate absolute base */
+    MPI_Win_shared_query(shm_win, MPI_PROC_NULL, &size, &disp_unit, &abs_base);
+
+    if (verbose)
+        printf("%d -- allocate shared: my_base = %p, absolute base = %p\n", shm_rank, my_base,
+               abs_base);
+
+    for (i = 0; i < shm_nproc; i++) {
+        MPI_Win_shared_query(shm_win, i, &size, &disp_unit, &bases[i]);
+        if (verbose)
+            printf("%d --    shared query: base[%d]=%p, size %ld, unit %d\n",
+                   shm_rank, i, bases[i], size, disp_unit);
+    }
+
+    MPI_Win_lock_all(MPI_MODE_NOCHECK, shm_win);
+
+    /* Reset data */
+    for (i = 0; i < ELEM_PER_PROC; i++) {
+        my_base[i] = 0;
+    }
+
+    MPI_Win_sync(shm_win);
+    MPI_Barrier(shm_comm);
+    MPI_Win_sync(shm_win);
+
+    /* Read and verify everyone's data */
+    if (shm_rank == 0) {
+        bases[0][0] = 1;
+    }
+
+    MPI_Win_sync(shm_win);
+    MPI_Barrier(shm_comm);
+    MPI_Win_sync(shm_win);
+
+    if (bases[0][0] != 1) {
+        errors++;
+        printf("%d -- Got %d at rank %d index %d, expected %d\n", shm_rank, bases[0][0], 0, 0, 1);
+    }
+
+    if (bases[shm_nproc - 1][0] != 0) {
+        errors++;
+        printf("%d -- Got %d at rank %d index %d, expected %d\n", shm_rank,
+               bases[shm_nproc - 1][0], shm_nproc - 1, 0, 0);
+    }
+
+    MPI_Win_unlock_all(shm_win);
+    MPI_Win_free(&shm_win);
+
+    MPI_Reduce(&errors, &all_errors, 1, MPI_INT, MPI_SUM, 0, MPI_COMM_WORLD);
+
+  exit:
+
+    if (rank == 0 && all_errors == 0)
+        printf(" No Errors\n");
+
+    MPI_Comm_free(&shm_comm);
+
+    MPI_Finalize();
+
+    if (bases)
+        free(bases);
+
+    return 0;
+}
index c29b796..06a8823 100644 (file)
@@ -15,51 +15,51 @@ static char MTEST_Descrip[] = "Test win_call_errhandler";
 static int calls = 0;
 static int errs = 0;
 static MPI_Win mywin;
-void eh( MPI_Win *win, int *err, ... );
-void eh( MPI_Win *win, int *err, ... )
+void eh(MPI_Win * win, int *err, ...);
+void eh(MPI_Win * win, int *err, ...)
 {
     if (*err != MPI_ERR_OTHER) {
-       errs++;
-       printf( "Unexpected error code\n" );
+        errs++;
+        printf("Unexpected error code\n");
     }
     if (*win != mywin) {
-       errs++;
-       printf( "Unexpected window\n" );
+        errs++;
+        printf("Unexpected window\n");
     }
     calls++;
     return;
 }
-int main( int argc, char *argv[] )
+
+int main(int argc, char *argv[])
 {
     int buf[2];
-    MPI_Win        win;
+    MPI_Win win;
     MPI_Errhandler newerr;
-    int            i;
+    int i;
 
-    MTest_Init( &argc, &argv );
+    MTest_Init(&argc, &argv);
 
     /* Run this test multiple times to expose storage leaks (we found a leak
-       of error handlers with this test) */
-    for (i=0;i<1000; i++)  {
-       calls = 0;
-       
-       MPI_Win_create( buf, 2*sizeof(int), sizeof(int), 
-                       MPI_INFO_NULL, MPI_COMM_WORLD, &win );
-       mywin = win;
-       
-       MPI_Win_create_errhandler( eh, &newerr );
-       
-       MPI_Win_set_errhandler( win, newerr );
-       MPI_Win_call_errhandler( win, MPI_ERR_OTHER );
-       MPI_Errhandler_free( &newerr );
-       if (calls != 1) {
-           errs++;
-           printf( "Error handler not called\n" );
-       }
-       MPI_Win_free( &win );
+     * of error handlers with this test) */
+    for (i = 0; i < 1000; i++) {
+        calls = 0;
+
+        MPI_Win_create(buf, 2 * sizeof(int), sizeof(int), MPI_INFO_NULL, MPI_COMM_WORLD, &win);
+        mywin = win;
+
+        MPI_Win_create_errhandler(eh, &newerr);
+
+        MPI_Win_set_errhandler(win, newerr);
+        MPI_Win_call_errhandler(win, MPI_ERR_OTHER);
+        MPI_Errhandler_free(&newerr);
+        if (calls != 1) {
+            errs++;
+            printf("Error handler not called\n");
+        }
+        MPI_Win_free(&win);
     }
 
-    MTest_Finalize( errs );
+    MTest_Finalize(errs);
     MPI_Finalize();
     return 0;
 }
index a805350..f96501c 100644 (file)
 
 static int verbose = 0;
 
-int main(int argc, char ** argv) {
-  int      rank, nproc, i;
-  void    *base_ptrs[NUM_WIN];
-  MPI_Win  windows[NUM_WIN];
+int main(int argc, char **argv)
+{
+    int rank, nproc, i;
+    void *base_ptrs[NUM_WIN];
+    MPI_Win windows[NUM_WIN];
 
-  MPI_Init(&argc, &argv);
+    MPI_Init(&argc, &argv);
 
-  MPI_Comm_rank(MPI_COMM_WORLD, &rank);
-  MPI_Comm_size(MPI_COMM_WORLD, &nproc);
+    MPI_Comm_rank(MPI_COMM_WORLD, &rank);
+    MPI_Comm_size(MPI_COMM_WORLD, &nproc);
 
-  if (rank == 0) if (verbose) printf("Starting MPI window creation test with %d processes\n", nproc);
+    if (rank == 0)
+        if (verbose)
+            printf("Starting MPI window creation test with %d processes\n", nproc);
 
-  /* Perform a pile of window creations */
-  for (i = 0; i < NUM_WIN; i++) {
-    if (rank == 0) if (verbose) printf(" + Creating window %d\n", i);
+    /* Perform a pile of window creations */
+    for (i = 0; i < NUM_WIN; i++) {
+        if (rank == 0)
+            if (verbose)
+                printf(" + Creating window %d\n", i);
 
-    MPI_Alloc_mem(DATA_SZ, MPI_INFO_NULL, &base_ptrs[i]);
-    MPI_Win_create(base_ptrs[i], DATA_SZ, 1, MPI_INFO_NULL, MPI_COMM_WORLD, &windows[i]);
-  }
+        MPI_Alloc_mem(DATA_SZ, MPI_INFO_NULL, &base_ptrs[i]);
+        MPI_Win_create(base_ptrs[i], DATA_SZ, 1, MPI_INFO_NULL, MPI_COMM_WORLD, &windows[i]);
+    }
 
-  MPI_Barrier(MPI_COMM_WORLD);
+    MPI_Barrier(MPI_COMM_WORLD);
 
-  /* Free all the windows */
-  for (i = 0; i < NUM_WIN; i++) {
-    if (rank == 0) if (verbose) printf(" + Freeing window %d\n", i);
+    /* Free all the windows */
+    for (i = 0; i < NUM_WIN; i++) {
+        if (rank == 0)
+            if (verbose)
+                printf(" + Freeing window %d\n", i);
 
-    MPI_Win_free(&windows[i]);
-    MPI_Free_mem(base_ptrs[i]);
-  }
+        MPI_Win_free(&windows[i]);
+        MPI_Free_mem(base_ptrs[i]);
+    }
 
-  if (rank == 0) printf(" No Errors\n");
+    if (rank == 0)
+        printf(" No Errors\n");
 
-  MPI_Finalize();
+    MPI_Finalize();
 
-  return 0;
+    return 0;
 }
index 290f26e..dfffb15 100644 (file)
 #include <string.h>
 #endif
 
-int main( int argc, char *argv[] )
+int main(int argc, char *argv[])
 {
     int errs = 0;
     MPI_Win win;
     int cnt, namelen;
     char name[MPI_MAX_OBJECT_NAME], nameout[MPI_MAX_OBJECT_NAME];
 
-    MTest_Init( &argc, &argv );
+    MTest_Init(&argc, &argv);
 
     cnt = 0;
-    while (MTestGetWin( &win, 1 )) {
-       if (win == MPI_WIN_NULL) continue;
-    
-       sprintf( name, "win-%d", cnt );
-       cnt++;
-       MPI_Win_set_name( win, name );
-       nameout[0] = 0;
-       MPI_Win_get_name( win, nameout, &namelen );
-       if (strcmp( name, nameout )) {
-           errs++;
-           printf( "Unexpected name, was %s but should be %s\n",
-                   nameout, name );
-       }
+    while (MTestGetWin(&win, 1)) {
+        if (win == MPI_WIN_NULL)
+            continue;
 
-       MTestFreeWin( &win );
+        sprintf(name, "win-%d", cnt);
+        cnt++;
+        MPI_Win_set_name(win, name);
+        nameout[0] = 0;
+        MPI_Win_get_name(win, nameout, &namelen);
+        if (strcmp(name, nameout)) {
+            errs++;
+            printf("Unexpected name, was %s but should be %s\n", nameout, name);
+        }
+
+        MTestFreeWin(&win);
     }
 
-    MTest_Finalize( errs );
+    MTest_Finalize(errs);
     MPI_Finalize();
     return 0;
 }
index a8a784c..d28f806 100644 (file)
@@ -3,7 +3,7 @@
  *  (C) 2001 by Argonne National Laboratory.
  *      See COPYRIGHT in top-level directory.
  */
-#include "mpi.h" 
+#include "mpi.h"
 #include "stdio.h"
 #include "mpitest.h"
 
 #define SIZE1 10
 #define SIZE2 20
 
-int main(int argc, char *argv[]) 
-{ 
-    int rank, destrank, nprocs, A[SIZE2], B[SIZE2], i;
+int main(int argc, char *argv[])
+{
+    int rank, destrank, nprocs, A[SIZE2], i;
     MPI_Comm CommDeuce;
     MPI_Group comm_group, group;
     MPI_Win win;
     int errs = 0, flag;
 
-    MTest_Init(&argc,&argv); 
-    MPI_Comm_size(MPI_COMM_WORLD,&nprocs); 
-    MPI_Comm_rank(MPI_COMM_WORLD,&rank); 
+    MTest_Init(&argc, &argv);
+    MPI_Comm_size(MPI_COMM_WORLD, &nprocs);
+    MPI_Comm_rank(MPI_COMM_WORLD, &rank);
 
     if (nprocs < 2) {
         printf("Run this program with 2 or more processes\n");
@@ -36,27 +36,44 @@ int main(int argc, char *argv[])
         MPI_Comm_group(CommDeuce, &comm_group);
 
         if (rank == 0) {
-            for (i=0; i<SIZE2; i++) A[i] = B[i] = i;
+            int B[SIZE2];
+            for (i = 0; i < SIZE2; i++)
+                A[i] = B[i] = i;
+#ifdef USE_WIN_ALLOCATE
+            int *base_ptr = NULL;
+            MPI_Win_allocate(0, 1, MPI_INFO_NULL, CommDeuce, &base_ptr, &win);
+#else
             MPI_Win_create(NULL, 0, 1, MPI_INFO_NULL, CommDeuce, &win);
+#endif
             destrank = 1;
             MPI_Group_incl(comm_group, 1, &destrank, &group);
             MPI_Win_start(group, 0, win);
-            for (i=0; i<SIZE1; i++)
-                MPI_Put(A+i, 1, MPI_INT, 1, i, 1, MPI_INT, win); 
-            for (i=0; i<SIZE1; i++)
-                MPI_Get(B+i, 1, MPI_INT, 1, SIZE1+i, 1, MPI_INT, win);
+            for (i = 0; i < SIZE1; i++)
+                MPI_Put(A + i, 1, MPI_INT, 1, i, 1, MPI_INT, win);
+            for (i = 0; i < SIZE1; i++)
+                MPI_Get(B + i, 1, MPI_INT, 1, SIZE1 + i, 1, MPI_INT, win);
 
             MPI_Win_complete(win);
 
-            for (i=0; i<SIZE1; i++) 
-                if (B[i] != (-4)*(i+SIZE1)) {
-                    printf("Get Error: B[i] is %d, should be %d\n", B[i], (-4)*(i+SIZE1));
+            for (i = 0; i < SIZE1; i++)
+                if (B[i] != (-4) * (i + SIZE1)) {
+                    printf("Get Error: B[i] is %d, should be %d\n", B[i], (-4) * (i + SIZE1));
                     errs++;
                 }
         }
         else {  /* rank=1 */
-            for (i=0; i<SIZE2; i++) B[i] = (-4)*i;
-            MPI_Win_create(B, SIZE2*sizeof(int), sizeof(int), MPI_INFO_NULL, CommDeuce, &win);
+#ifdef USE_WIN_ALLOCATE
+            int *B;
+            MPI_Win_allocate(SIZE2 * sizeof(int), sizeof(int), MPI_INFO_NULL, CommDeuce, &B, &win);
+#else
+            int B[SIZE2];
+            MPI_Win_create(B, SIZE2 * sizeof(int), sizeof(int), MPI_INFO_NULL, CommDeuce, &win);
+#endif
+            MPI_Win_lock(MPI_LOCK_SHARED, rank, 0, win);
+            for (i = 0; i < SIZE2; i++)
+                B[i] = (-4) * i;
+            MPI_Win_unlock(rank, win);
+
             destrank = 0;
             MPI_Group_incl(comm_group, 1, &destrank, &group);
             MPI_Win_post(group, 0, win);
@@ -64,7 +81,7 @@ int main(int argc, char *argv[])
             while (!flag)
                 MPI_Win_test(win, &flag);
 
-            for (i=0; i<SIZE1; i++) {
+            for (i = 0; i < SIZE1; i++) {
                 if (B[i] != i) {
                     printf("Put Error: B[i] is %d, should be %d\n", B[i], i);
                     errs++;
@@ -74,10 +91,10 @@ int main(int argc, char *argv[])
 
         MPI_Group_free(&group);
         MPI_Group_free(&comm_group);
-        MPI_Win_free(&win); 
+        MPI_Win_free(&win);
     }
     MPI_Comm_free(&CommDeuce);
     MTest_Finalize(errs);
     MPI_Finalize();
-    return 0; 
-} 
+    return 0;
+}
diff --git a/teshsuite/smpi/mpich3-test/rma/wrma_flush_get.c b/teshsuite/smpi/mpich3-test/rma/wrma_flush_get.c
new file mode 100644 (file)
index 0000000..e2ae828
--- /dev/null
@@ -0,0 +1,215 @@
+/* -*- Mode: C; c-basic-offset:4 ; indent-tabs-mode:nil ; -*- */
+/*
+ *
+ *  (C) 2015 by Argonne National Laboratory.
+ *      See COPYRIGHT in top-level directory.
+ */
+
+#include <stdio.h>
+#include <stdlib.h>
+#include <mpi.h>
+#include "mpitest.h"
+
+#define ITER 10000
+#define BUF_CNT 1
+int local_buf[BUF_CNT], result_addr[BUF_CNT], check_addr[BUF_CNT];
+#ifdef TEST_CAS
+int compare_buf[BUF_CNT];
+#endif
+
+const int verbose = 0;
+
+/* This test checks the remote completion of flush with RMA write-like operations
+ * (PUT, ACC, GET_ACC, FOP, CAS), and confirms result by GET issued from another
+ * process.
+ * 1. Three processes create window by Win_allocate.
+ * 2. P(origin) issues RMA operations and flush to P(target), then call
+ *    send-recv to synchronize with P(checker).
+ * 3. P(checker) then issues get to P(target) to check the results.
+ */
+
+int rank = -1, nproc = 0;
+int origin = -1, target = -1, checker = -1;
+MPI_Win win = MPI_WIN_NULL;
+int *my_base = NULL;
+
+/* Define operation name for error message */
+#ifdef TEST_PUT
+const char *rma_name = "Put";
+#elif defined(TEST_ACC)
+const char *rma_name = "Accumulate";
+#elif defined(TEST_GACC)
+const char *rma_name = "Get_accumulate";
+#elif defined(TEST_FOP)
+const char *rma_name = "Fetch_and_op";
+#elif defined(TEST_CAS)
+const char *rma_name = "Compare_and_swap";
+#else
+const char *rma_name = "None";
+#endif
+
+/* Issue functions for different RMA operations */
+#ifdef TEST_PUT
+static inline void issue_rma_op(int i)
+{
+    MPI_Put(&local_buf[i], 1, MPI_INT, target, i, 1, MPI_INT, win);
+}
+#elif defined(TEST_ACC)
+static inline void issue_rma_op(int i)
+{
+    MPI_Accumulate(&local_buf[i], 1, MPI_INT, target, i, 1, MPI_INT, MPI_REPLACE, win);
+}
+#elif defined(TEST_GACC)
+static inline void issue_rma_op(int i)
+{
+    MPI_Get_accumulate(&local_buf[i], 1, MPI_INT, &result_addr[i], 1, MPI_INT, target, i,
+                       1, MPI_INT, MPI_REPLACE, win);
+}
+#elif defined(TEST_FOP)
+static inline void issue_rma_op(int i)
+{
+    MPI_Fetch_and_op(&local_buf[i], &result_addr[i], MPI_INT, target, i, MPI_REPLACE, win);
+}
+#elif defined(TEST_CAS)
+static inline void issue_rma_op(int i)
+{
+    compare_buf[i] = i;        /* always equal to window value, thus swap happens */
+    MPI_Compare_and_swap(&local_buf[i], &compare_buf[i], &result_addr[i], MPI_INT, target, i, win);
+}
+#endif
+
+
+/* Local check function for GET-like operations */
+#if defined(TEST_GACC) || defined(TEST_FOP) || defined(TEST_CAS)
+
+/* Check local result buffer for GET-like operations */
+static int check_local_result(int iter)
+{
+    int i = 0;
+    int errors = 0;
+
+    for (i = 0; i < BUF_CNT; i++) {
+        if (result_addr[i] != i) {
+            printf("rank %d (iter %d) - check %s, got result_addr[%d] = %d, expected %d\n",
+                   rank, iter, rma_name, i, result_addr[i], i);
+            errors++;
+        }
+    }
+    return errors;
+}
+
+#else
+#define check_local_result(iter) (0)
+#endif
+
+static int run_test()
+{
+    int i = 0, x = 0;
+    int errors = 0;
+    int sbuf = 0, rbuf = 0;
+    MPI_Status stat;
+
+    for (x = 0; x < ITER; x++) {
+        /* 1. Target resets window data */
+        if (rank == target) {
+            for (i = 0; i < BUF_CNT; i++)
+                my_base[i] = i;
+            MPI_Win_sync(win);  /* write is done on window */
+        }
+
+        MPI_Barrier(MPI_COMM_WORLD);
+
+        /* 2. Every one resets local data */
+        for (i = 0; i < BUF_CNT; i++) {
+            local_buf[i] = BUF_CNT + x * BUF_CNT + i;
+            result_addr[i] = 0;
+        }
+
+        /* 3. Origin issues RMA operation to target */
+        if (rank == origin) {
+            /* 3-1. Issue RMA. */
+            for (i = 0; i < BUF_CNT; i++) {
+                issue_rma_op(i);
+            }
+            MPI_Win_flush(target, win);
+
+            /* 3-2. Sync with checker */
+            MPI_Send(&sbuf, 1, MPI_INT, checker, 999, MPI_COMM_WORLD);
+
+            /* 3-3. Check local result buffer */
+            errors += check_local_result(x);
+        }
+
+        /* 4. Checker issues GET to target and checks result */
+        if (rank == checker) {
+            /* 4-1. Sync with origin */
+            MPI_Recv(&rbuf, 1, MPI_INT, origin, 999, MPI_COMM_WORLD, &stat);
+
+            /* 4-2. Get result and check */
+            MPI_Get(check_addr, BUF_CNT, MPI_INT, target, 0, BUF_CNT, MPI_INT, win);
+            MPI_Win_flush(target, win);
+
+            for (i = 0; i < BUF_CNT; i++) {
+                if (check_addr[i] != local_buf[i]) {
+                    printf("rank %d (iter %d) - check %s, got check_addr[%d] = %d, expected %d\n",
+                           rank, x, rma_name, i, check_addr[i], local_buf[i]);
+                    errors++;
+                }
+            }
+        }
+
+        MPI_Barrier(MPI_COMM_WORLD);
+    }
+
+    return errors;
+}
+
+int main(int argc, char *argv[])
+{
+    int errors = 0, all_errors = 0;
+    int win_size = sizeof(int) * BUF_CNT;
+    int win_unit = sizeof(int);
+
+    MPI_Init(&argc, &argv);
+    MPI_Comm_rank(MPI_COMM_WORLD, &rank);
+    MPI_Comm_size(MPI_COMM_WORLD, &nproc);
+
+    if (nproc != 3) {
+        if (rank == 0)
+            printf("Error: must be run with three processes\n");
+        MPI_Barrier(MPI_COMM_WORLD);
+        MPI_Abort(MPI_COMM_WORLD, 1);
+    }
+
+#if !defined(TEST_PUT) && !defined(TEST_ACC) && !defined(TEST_GACC) && !defined(TEST_FOP) && !defined(TEST_CAS)
+    if (rank == 0)
+        printf("Error: must specify operation type at compile time\n");
+    MPI_Barrier(MPI_COMM_WORLD);
+    MPI_Abort(MPI_COMM_WORLD, 1);
+#endif
+
+    /* Identify origin, target and checker ranks. */
+    target = 0;
+    checker = 2;
+    origin = 1;
+
+    MPI_Win_allocate(win_size, win_unit, MPI_INFO_NULL, MPI_COMM_WORLD, &my_base, &win);
+
+    /* Start checking. */
+    MPI_Win_lock_all(0, win);
+
+    errors = run_test();
+
+    MPI_Win_unlock_all(win);
+
+    MPI_Reduce(&errors, &all_errors, 1, MPI_INT, MPI_SUM, 0, MPI_COMM_WORLD);
+    if (rank == 0 && all_errors == 0)
+        printf(" No Errors\n");
+
+    if (win != MPI_WIN_NULL)
+        MPI_Win_free(&win);
+
+    MPI_Finalize();
+
+    return 0;
+}