|
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 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 |
#ifdef HAVE_STRING_H
|
|
Packit Service |
c5cf8c |
#include <string.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 errs = 0;
|
|
Packit Service |
c5cf8c |
char *port_name, *port_name_out;
|
|
Packit Service |
c5cf8c |
char serv_name[256];
|
|
Packit Service |
c5cf8c |
int merr, mclass;
|
|
Packit Service |
c5cf8c |
const char *errmsg;
|
|
Packit Service |
c5cf8c |
int msglen;
|
|
Packit Service |
c5cf8c |
int rank;
|
|
Packit Service |
c5cf8c |
|
|
Packit Service |
c5cf8c |
MTest_Init();
|
|
Packit Service |
c5cf8c |
|
|
Packit Service |
c5cf8c |
port_name = new char[MPI::MAX_PORT_NAME];
|
|
Packit Service |
c5cf8c |
port_name_out = new char[MPI::MAX_PORT_NAME];
|
|
Packit Service |
c5cf8c |
|
|
Packit Service |
c5cf8c |
rank = MPI::COMM_WORLD.Get_rank();
|
|
Packit Service |
c5cf8c |
|
|
Packit Service |
c5cf8c |
/* Note that according to the MPI standard, port_name must
|
|
Packit Service |
c5cf8c |
* have been created by MPI_Open_port. For current testing
|
|
Packit Service |
c5cf8c |
* purposes, we'll use a fake name. This test should eventually use
|
|
Packit Service |
c5cf8c |
* a valid name from Open_port */
|
|
Packit Service |
c5cf8c |
|
|
Packit Service |
c5cf8c |
strcpy(port_name, "otherhost:122");
|
|
Packit Service |
c5cf8c |
strcpy(serv_name, "MyTest");
|
|
Packit Service |
c5cf8c |
|
|
Packit Service |
c5cf8c |
MPI::COMM_WORLD.Set_errhandler(MPI::ERRORS_THROW_EXCEPTIONS);
|
|
Packit Service |
c5cf8c |
|
|
Packit Service |
c5cf8c |
if (rank == 0) {
|
|
Packit Service |
c5cf8c |
try {
|
|
Packit Service |
c5cf8c |
MPI::Publish_name(serv_name, MPI::INFO_NULL, port_name);
|
|
Packit Service |
c5cf8c |
}
|
|
Packit Service |
c5cf8c |
catch(MPI::Exception e) {
|
|
Packit Service |
c5cf8c |
errs++;
|
|
Packit Service |
c5cf8c |
errmsg = e.Get_error_string();
|
|
Packit Service |
c5cf8c |
cout << "Error in Publish_name " << errmsg << "\n";
|
|
Packit Service |
c5cf8c |
}
|
|
Packit Service |
c5cf8c |
|
|
Packit Service |
c5cf8c |
MPI::COMM_WORLD.Barrier();
|
|
Packit Service |
c5cf8c |
MPI::COMM_WORLD.Barrier();
|
|
Packit Service |
c5cf8c |
|
|
Packit Service |
c5cf8c |
try {
|
|
Packit Service |
c5cf8c |
MPI::Unpublish_name(serv_name, MPI::INFO_NULL, port_name);
|
|
Packit Service |
c5cf8c |
}
|
|
Packit Service |
c5cf8c |
catch(MPI::Exception e) {
|
|
Packit Service |
c5cf8c |
errs++;
|
|
Packit Service |
c5cf8c |
errmsg = e.Get_error_string();
|
|
Packit Service |
c5cf8c |
cout << "Error in Unpublish name " << errmsg << "\n";
|
|
Packit Service |
c5cf8c |
}
|
|
Packit Service |
c5cf8c |
} else {
|
|
Packit Service |
c5cf8c |
MPI::COMM_WORLD.Barrier();
|
|
Packit Service |
c5cf8c |
|
|
Packit Service |
c5cf8c |
merr = MPI::SUCCESS;
|
|
Packit Service |
c5cf8c |
try {
|
|
Packit Service |
c5cf8c |
MPI::Lookup_name(serv_name, MPI::INFO_NULL, port_name_out);
|
|
Packit Service |
c5cf8c |
}
|
|
Packit Service |
c5cf8c |
catch(MPI::Exception e) {
|
|
Packit Service |
c5cf8c |
errs++;
|
|
Packit Service |
c5cf8c |
merr = e.Get_error_code();
|
|
Packit Service |
c5cf8c |
errmsg = e.Get_error_string();
|
|
Packit Service |
c5cf8c |
cout << "Error in Lookup name " << errmsg << "\n";
|
|
Packit Service |
c5cf8c |
}
|
|
Packit Service |
c5cf8c |
if (merr == MPI::SUCCESS) {
|
|
Packit Service |
c5cf8c |
if (strcmp(port_name, port_name_out)) {
|
|
Packit Service |
c5cf8c |
errs++;
|
|
Packit Service |
c5cf8c |
cout << "Lookup name returned the wrong value (" << port_name_out << ")\n";
|
|
Packit Service |
c5cf8c |
}
|
|
Packit Service |
c5cf8c |
}
|
|
Packit Service |
c5cf8c |
|
|
Packit Service |
c5cf8c |
MPI::COMM_WORLD.Barrier();
|
|
Packit Service |
c5cf8c |
}
|
|
Packit Service |
c5cf8c |
|
|
Packit Service |
c5cf8c |
|
|
Packit Service |
c5cf8c |
MPI::COMM_WORLD.Barrier();
|
|
Packit Service |
c5cf8c |
|
|
Packit Service |
c5cf8c |
merr = MPI::SUCCESS;
|
|
Packit Service |
c5cf8c |
port_name_out[0] = 0;
|
|
Packit Service |
c5cf8c |
try {
|
|
Packit Service |
c5cf8c |
MPI::Lookup_name(serv_name, MPI::INFO_NULL, port_name_out);
|
|
Packit Service |
c5cf8c |
}
|
|
Packit Service |
c5cf8c |
catch(MPI::Exception e) {
|
|
Packit Service |
c5cf8c |
merr = e.Get_error_code();
|
|
Packit Service |
c5cf8c |
}
|
|
Packit Service |
c5cf8c |
if (!merr) {
|
|
Packit Service |
c5cf8c |
errs++;
|
|
Packit Service |
c5cf8c |
cout << "Lookup name returned name after it was unpublished\n";
|
|
Packit Service |
c5cf8c |
cout << "The name returned was " << port_name_out << "\n";
|
|
Packit Service |
c5cf8c |
} else {
|
|
Packit Service |
c5cf8c |
/* Must be class MPI::ERR_NAME */
|
|
Packit Service |
c5cf8c |
mclass = MPI::Get_error_class(merr);
|
|
Packit Service |
c5cf8c |
if (mclass != MPI::ERR_NAME) {
|
|
Packit Service |
c5cf8c |
char *lerrmsg;
|
|
Packit Service |
c5cf8c |
lerrmsg = new char[MPI::MAX_ERROR_STRING];
|
|
Packit Service |
c5cf8c |
errs++;
|
|
Packit Service |
c5cf8c |
MPI::Get_error_string(merr, lerrmsg, msglen);
|
|
Packit Service |
c5cf8c |
cout << "Lookup name returned the wrong error class (" << mclass <<
|
|
Packit Service |
c5cf8c |
"), msg " << lerrmsg << "\n";
|
|
Packit Service |
c5cf8c |
delete[]lerrmsg;
|
|
Packit Service |
c5cf8c |
}
|
|
Packit Service |
c5cf8c |
}
|
|
Packit Service |
c5cf8c |
|
|
Packit Service |
c5cf8c |
delete[]port_name;
|
|
Packit Service |
c5cf8c |
delete[]port_name_out;
|
|
Packit Service |
c5cf8c |
|
|
Packit Service |
c5cf8c |
MTest_Finalize(errs);
|
|
Packit Service |
c5cf8c |
return 0;
|
|
Packit Service |
c5cf8c |
}
|