Blame test/mpi/cxx/pt2pt/sendrecvx.cxx
|
Packit Service |
c5cf8c |
/* -*- Mode: C++; c-basic-offset:4 ; -*- */
|
|
Packit Service |
c5cf8c |
/*
|
|
Packit Service |
c5cf8c |
* (C) 2001 by Argonne National Laboratory.
|
|
Packit Service |
c5cf8c |
* See COPYRIGHT in top-level directory.
|
|
Packit Service |
c5cf8c |
*
|
|
Packit Service |
c5cf8c |
*/
|
|
Packit Service |
c5cf8c |
/* style: c++ header */
|
|
Packit Service |
c5cf8c |
|
|
Packit Service |
c5cf8c |
/*
|
|
Packit Service |
c5cf8c |
* Simple test program for C++ binding
|
|
Packit Service |
c5cf8c |
*/
|
|
Packit Service |
c5cf8c |
|
|
Packit Service |
c5cf8c |
/* #include <stdio.h> */
|
|
Packit Service |
c5cf8c |
#include "mpi.h"
|
|
Packit Service |
c5cf8c |
#include "mpitestconf.h"
|
|
Packit Service |
c5cf8c |
#include "mpitestcxx.h"
|
|
Packit Service |
c5cf8c |
|
|
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 often 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 |
|
|
Packit Service |
c5cf8c |
int main(int argc, char *argv[])
|
|
Packit Service |
c5cf8c |
{
|
|
Packit Service |
c5cf8c |
int rank, size, errs = 0;
|
|
Packit Service |
c5cf8c |
|
|
Packit Service |
c5cf8c |
MTest_Init();
|
|
Packit Service |
c5cf8c |
|
|
Packit Service |
c5cf8c |
rank = MPI::COMM_WORLD.Get_rank();
|
|
Packit Service |
c5cf8c |
size = MPI::COMM_WORLD.Get_size();
|
|
Packit Service |
c5cf8c |
|
|
Packit Service |
c5cf8c |
if (size < 2) {
|
|
Packit Service |
c5cf8c |
cerr << "Size of comm_world must be at least 2\n";
|
|
Packit Service |
c5cf8c |
MPI::COMM_WORLD.Abort(1);
|
|
Packit Service |
c5cf8c |
}
|
|
Packit Service |
c5cf8c |
if (rank == 0) {
|
|
Packit Service |
c5cf8c |
int *buf = new int[100];
|
|
Packit Service |
c5cf8c |
int i;
|
|
Packit Service |
c5cf8c |
for (i = 0; i < 100; i++)
|
|
Packit Service |
c5cf8c |
buf[i] = i;
|
|
Packit Service |
c5cf8c |
MPI::COMM_WORLD.Send(buf, 100, MPI::INT, size - 1, 0);
|
|
Packit Service |
c5cf8c |
delete[]buf;
|
|
Packit Service |
c5cf8c |
} else if (rank == size - 1) {
|
|
Packit Service |
c5cf8c |
int *buf = new int[100];
|
|
Packit Service |
c5cf8c |
int i;
|
|
Packit Service |
c5cf8c |
MPI::COMM_WORLD.Recv(buf, 100, MPI::INT, 0, 0);
|
|
Packit Service |
c5cf8c |
for (i = 0; i < 100; i++) {
|
|
Packit Service |
c5cf8c |
if (buf[i] != i) {
|
|
Packit Service |
c5cf8c |
errs++;
|
|
Packit Service |
c5cf8c |
cerr << "Error: buf[" << i << "] = " << buf[i] << "\n";
|
|
Packit Service |
c5cf8c |
}
|
|
Packit Service |
c5cf8c |
}
|
|
Packit Service |
c5cf8c |
delete[]buf;
|
|
Packit Service |
c5cf8c |
}
|
|
Packit Service |
c5cf8c |
|
|
Packit Service |
c5cf8c |
MTest_Finalize(errs);
|
|
Packit Service |
c5cf8c |
return 0;
|
|
Packit Service |
c5cf8c |
}
|