/* -*- Mode: C++; c-basic-offset:4 ; -*- */ /* * * (C) 2003 by Argonne National Laboratory. * See COPYRIGHT in top-level directory. */ #include "mpi.h" #include "mpitestconf.h" #ifdef HAVE_IOSTREAM // Not all C++ compilers have iostream instead of iostream.h #include #ifdef HAVE_NAMESPACE_STD // Those that do need the std namespace; otherwise, a bare "cout" // is likely to fail to compile using namespace std; #endif #else #include #endif #include "mpitestcxx.h" /* * buf is a 2-d array, stored as a 1-d vector, with * buf(i,j) = buf[i + nrows*j], 0<=i= size) right = MPI::PROC_NULL; // Initialize the buffer for (i = 0; i < nrows; i++) { buf[i] = -1; buf[(ncols + 1) * nrows + i] = -1; } for (j = 0; j < ncols; j++) { for (i = 0; i < nrows; i++) { buf[i + (j + 1) * nrows] = rank * (ncols * nrows) + i + j * nrows; } } win.Fence(MPI::MODE_NOPRECEDE); win.Put(&buf[0 + nrows], nrows, MPI::INT, left, ncols + 1, nrows, MPI::INT); win.Put(&buf[0 + ncols * nrows], nrows, MPI::INT, right, 0, nrows, MPI::INT); win.Fence(MPI::MODE_NOSTORE + MPI::MODE_NOPUT + MPI::MODE_NOSUCCEED); // Check the results if (left != MPI::PROC_NULL) { for (i = 0; i < nrows; i++) { ans = rank * (ncols * nrows) - nrows + i; if (buf[i] != ans) { errs++; if (errs != 10) { cout << rank << " buf[" << i << ",0] = " << buf[i] << " expected " << ans << "\n"; } } } } if (right != MPI::PROC_NULL) { for (i = 0; i < nrows; i++) { ans = (rank + 1) * (ncols * nrows) + i; if (buf[i + (ncols + 1) * nrows] != ans) { errs++; if (errs <= 10) { cout << rank << " buf[" << i << ",ncols+1] = " << buf[i + (ncols + 1) * nrows] << " expected " << ans << "\n"; } } } } win.Free(); MTestFreeComm(comm); } MTest_Finalize(errs); return 0; }