|
Packit Service |
c5cf8c |
/* -*- Mode: C++; c-basic-offset:4 ; -*- */
|
|
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 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 |
#include "mpitestcxx.h"
|
|
Packit Service |
c5cf8c |
|
|
Packit Service |
c5cf8c |
int main(int argc, char *argv[])
|
|
Packit Service |
c5cf8c |
{
|
|
Packit Service |
c5cf8c |
int error;
|
|
Packit Service |
c5cf8c |
int rank, size;
|
|
Packit Service |
c5cf8c |
char port[MPI_MAX_PORT_NAME];
|
|
Packit Service |
c5cf8c |
MPI::Status status;
|
|
Packit Service |
c5cf8c |
MPI::Intercomm comm;
|
|
Packit Service |
c5cf8c |
|
|
Packit Service |
c5cf8c |
MTEST_VG_MEM_INIT(port, MPI_MAX_PORT_NAME * sizeof(char));
|
|
Packit Service |
c5cf8c |
|
|
Packit Service |
c5cf8c |
MPI::Init(argc, argv);
|
|
Packit Service |
c5cf8c |
|
|
Packit Service |
c5cf8c |
size = MPI::COMM_WORLD.Get_size();
|
|
Packit Service |
c5cf8c |
rank = MPI::COMM_WORLD.Get_rank();
|
|
Packit Service |
c5cf8c |
|
|
Packit Service |
c5cf8c |
if (size < 2) {
|
|
Packit Service |
c5cf8c |
cout << "Two processes needed.\n";
|
|
Packit Service |
c5cf8c |
return 0;
|
|
Packit Service |
c5cf8c |
}
|
|
Packit Service |
c5cf8c |
|
|
Packit Service |
c5cf8c |
if (rank == 0) {
|
|
Packit Service |
c5cf8c |
MPI::Open_port(MPI::INFO_NULL, port);
|
|
Packit Service |
c5cf8c |
MPI::COMM_WORLD.Send(port, MPI::MAX_PORT_NAME, MPI::CHAR, 1, 0);
|
|
Packit Service |
c5cf8c |
comm = MPI::COMM_SELF.Accept(port, MPI::INFO_NULL, 0);
|
|
Packit Service |
c5cf8c |
MPI::Close_port(port);
|
|
Packit Service |
c5cf8c |
comm.Disconnect();
|
|
Packit Service |
c5cf8c |
} else if (rank == 1) {
|
|
Packit Service |
c5cf8c |
MPI::COMM_WORLD.Recv(port, MPI::MAX_PORT_NAME, MPI::CHAR, 0, 0);
|
|
Packit Service |
c5cf8c |
comm = MPI::COMM_SELF.Connect(port, MPI::INFO_NULL, 0);
|
|
Packit Service |
c5cf8c |
comm.Disconnect();
|
|
Packit Service |
c5cf8c |
}
|
|
Packit Service |
c5cf8c |
|
|
Packit Service |
c5cf8c |
MPI::COMM_WORLD.Barrier();
|
|
Packit Service |
c5cf8c |
|
|
Packit Service |
c5cf8c |
MTest_Finalize(0);
|
|
Packit Service |
c5cf8c |
return 0;
|
|
Packit Service |
c5cf8c |
}
|