|
Packit Service |
c5cf8c |
/* -*- Mode: C++; c-basic-offset:4 ; -*- */
|
|
Packit Service |
c5cf8c |
/*
|
|
Packit Service |
c5cf8c |
*
|
|
Packit Service |
c5cf8c |
* (C) 2003 by Argonne National Laboratory.
|
|
Packit Service |
c5cf8c |
* See COPYRIGHT in top-level directory.
|
|
Packit Service |
c5cf8c |
*/
|
|
Packit Service |
c5cf8c |
#include "mpi.h"
|
|
Packit Service |
c5cf8c |
#include "mpitestconf.h"
|
|
Packit Service |
c5cf8c |
#ifdef HAVE_IOSTREAM
|
|
Packit Service |
c5cf8c |
// Not all C++ compilers have iostream instead of iostream.h
|
|
Packit Service |
c5cf8c |
#include <iostream>
|
|
Packit Service |
c5cf8c |
#ifdef HAVE_NAMESPACE_STD
|
|
Packit Service |
c5cf8c |
// Those that do need the std namespace; otherwise, a bare "cout"
|
|
Packit Service |
c5cf8c |
// is likely to fail to compile
|
|
Packit Service |
c5cf8c |
using namespace std;
|
|
Packit Service |
c5cf8c |
#endif
|
|
Packit Service |
c5cf8c |
#else
|
|
Packit Service |
c5cf8c |
#include <iostream.h>
|
|
Packit Service |
c5cf8c |
#endif
|
|
Packit Service |
c5cf8c |
#include "mpitestcxx.h"
|
|
Packit Service |
c5cf8c |
|
|
Packit Service |
c5cf8c |
/*
|
|
Packit Service |
c5cf8c |
* buf is a 2-d array, stored as a 1-d vector, with
|
|
Packit Service |
c5cf8c |
* buf(i,j) = buf[i + nrows*j], 0<=i
|
|
Packit Service |
c5cf8c |
* We store into cols 1<=j<=ncols, and put into the two
|
|
Packit Service |
c5cf8c |
* "ghost" columns.
|
|
Packit Service |
c5cf8c |
*/
|
|
Packit Service |
c5cf8c |
#define MAX_NROWS 25
|
|
Packit Service |
c5cf8c |
#define MAX_NCOLS 12
|
|
Packit Service |
c5cf8c |
int main(int argc, char *argv[])
|
|
Packit Service |
c5cf8c |
{
|
|
Packit Service |
c5cf8c |
MPI::Intracomm comm;
|
|
Packit Service |
c5cf8c |
int errs = 0;
|
|
Packit Service |
c5cf8c |
MPI::Win win;
|
|
Packit Service |
c5cf8c |
int i, j, nrows = MAX_NROWS, ncols = MAX_NCOLS;
|
|
Packit Service |
c5cf8c |
int left, right, ans, size, rank;
|
|
Packit Service |
c5cf8c |
int buf[MAX_NROWS * (MAX_NCOLS + 2)];
|
|
Packit Service |
c5cf8c |
MPI::Aint aint;
|
|
Packit Service |
c5cf8c |
|
|
Packit Service |
c5cf8c |
MTest_Init();
|
|
Packit Service |
c5cf8c |
|
|
Packit Service |
c5cf8c |
while (MTestGetIntracommGeneral(comm, 2, false)) {
|
|
Packit Service |
c5cf8c |
aint = nrows * (ncols + 2) * sizeof(int);
|
|
Packit Service |
c5cf8c |
win = MPI::Win::Create(buf, aint, sizeof(int) * nrows, MPI::INFO_NULL, comm);
|
|
Packit Service |
c5cf8c |
size = comm.Get_size();
|
|
Packit Service |
c5cf8c |
rank = comm.Get_rank();
|
|
Packit Service |
c5cf8c |
|
|
Packit Service |
c5cf8c |
left = rank - 1;
|
|
Packit Service |
c5cf8c |
if (left < 0)
|
|
Packit Service |
c5cf8c |
left = MPI::PROC_NULL;
|
|
Packit Service |
c5cf8c |
right = rank + 1;
|
|
Packit Service |
c5cf8c |
if (right >= size)
|
|
Packit Service |
c5cf8c |
right = MPI::PROC_NULL;
|
|
Packit Service |
c5cf8c |
|
|
Packit Service |
c5cf8c |
// Initialize the buffer
|
|
Packit Service |
c5cf8c |
for (i = 0; i < nrows; i++) {
|
|
Packit Service |
c5cf8c |
buf[i] = -1;
|
|
Packit Service |
c5cf8c |
buf[(ncols + 1) * nrows + i] = -1;
|
|
Packit Service |
c5cf8c |
}
|
|
Packit Service |
c5cf8c |
for (j = 0; j < ncols; j++) {
|
|
Packit Service |
c5cf8c |
for (i = 0; i < nrows; i++) {
|
|
Packit Service |
c5cf8c |
buf[i + (j + 1) * nrows] = rank * (ncols * nrows) + i + j * nrows;
|
|
Packit Service |
c5cf8c |
}
|
|
Packit Service |
c5cf8c |
}
|
|
Packit Service |
c5cf8c |
win.Fence(MPI::MODE_NOPRECEDE);
|
|
Packit Service |
c5cf8c |
|
|
Packit Service |
c5cf8c |
win.Put(&buf[0 + nrows], nrows, MPI::INT, left, ncols + 1, nrows, MPI::INT);
|
|
Packit Service |
c5cf8c |
win.Put(&buf[0 + ncols * nrows], nrows, MPI::INT, right, 0, nrows, MPI::INT);
|
|
Packit Service |
c5cf8c |
win.Fence(MPI::MODE_NOSTORE + MPI::MODE_NOPUT + MPI::MODE_NOSUCCEED);
|
|
Packit Service |
c5cf8c |
|
|
Packit Service |
c5cf8c |
// Check the results
|
|
Packit Service |
c5cf8c |
if (left != MPI::PROC_NULL) {
|
|
Packit Service |
c5cf8c |
for (i = 0; i < nrows; i++) {
|
|
Packit Service |
c5cf8c |
ans = rank * (ncols * nrows) - nrows + i;
|
|
Packit Service |
c5cf8c |
if (buf[i] != ans) {
|
|
Packit Service |
c5cf8c |
errs++;
|
|
Packit Service |
c5cf8c |
if (errs != 10) {
|
|
Packit Service |
c5cf8c |
cout << rank << " buf[" << i << ",0] = " <<
|
|
Packit Service |
c5cf8c |
buf[i] << " expected " << ans << "\n";
|
|
Packit Service |
c5cf8c |
}
|
|
Packit Service |
c5cf8c |
}
|
|
Packit Service |
c5cf8c |
}
|
|
Packit Service |
c5cf8c |
}
|
|
Packit Service |
c5cf8c |
if (right != MPI::PROC_NULL) {
|
|
Packit Service |
c5cf8c |
for (i = 0; i < nrows; i++) {
|
|
Packit Service |
c5cf8c |
ans = (rank + 1) * (ncols * nrows) + i;
|
|
Packit Service |
c5cf8c |
if (buf[i + (ncols + 1) * nrows] != ans) {
|
|
Packit Service |
c5cf8c |
errs++;
|
|
Packit Service |
c5cf8c |
if (errs <= 10) {
|
|
Packit Service |
c5cf8c |
cout << rank << " buf[" << i << ",ncols+1] = " <<
|
|
Packit Service |
c5cf8c |
buf[i + (ncols + 1) * nrows] << " expected " << ans << "\n";
|
|
Packit Service |
c5cf8c |
}
|
|
Packit Service |
c5cf8c |
}
|
|
Packit Service |
c5cf8c |
}
|
|
Packit Service |
c5cf8c |
}
|
|
Packit Service |
c5cf8c |
win.Free();
|
|
Packit Service |
c5cf8c |
MTestFreeComm(comm);
|
|
Packit Service |
c5cf8c |
}
|
|
Packit Service |
c5cf8c |
|
|
Packit Service |
c5cf8c |
MTest_Finalize(errs);
|
|
Packit Service |
c5cf8c |
return 0;
|
|
Packit Service |
c5cf8c |
}
|