Blame test/mpi/errors/cxx/errhan/errsetx.cxx

Packit 0848f5
/* -*- Mode: C++; c-basic-offset:4 ; -*- */
Packit 0848f5
/*
Packit 0848f5
 *
Packit 0848f5
 *  (C) 2006 by Argonne National Laboratory.
Packit 0848f5
 *      See COPYRIGHT in top-level directory.
Packit 0848f5
 */
Packit 0848f5
#include "mpitestconf.h"
Packit 0848f5
#include "mpi.h"
Packit 0848f5
#ifdef HAVE_IOSTREAM
Packit 0848f5
// Not all C++ compilers have iostream instead of iostream.h
Packit 0848f5
#include <iostream>
Packit 0848f5
#ifdef HAVE_NAMESPACE_STD
Packit 0848f5
// Those that do often need the std namespace; otherwise, a bare "cout"
Packit 0848f5
// is likely to fail to compile
Packit 0848f5
using namespace std;
Packit 0848f5
#endif
Packit 0848f5
#else
Packit 0848f5
#include <iostream.h>
Packit 0848f5
#endif
Packit 0848f5
Packit 0848f5
#ifdef HAVE_STRING_H
Packit 0848f5
#include <string.h>
Packit 0848f5
#endif
Packit 0848f5
#include "mpitestcxx.h"
Packit 0848f5
Packit 0848f5
static int ncalls = 0;
Packit 0848f5
void efn( MPI::Comm &comm, int *code, ... )
Packit 0848f5
{
Packit 0848f5
    ncalls ++;
Packit 0848f5
}
Packit 0848f5
Packit 0848f5
int main( int argc, char *argv[] )
Packit 0848f5
{
Packit 0848f5
    MPI::Errhandler eh;
Packit 0848f5
    int size;
Packit 0848f5
    bool foundMsg;
Packit 0848f5
    int errs = 0;
Packit 0848f5
Packit 0848f5
    MTest_Init( );
Packit 0848f5
Packit 0848f5
    size = MPI::COMM_WORLD.Get_size();
Packit 0848f5
Packit 0848f5
    // Test that we can change the default error handler to not throw
Packit 0848f5
    // an exception (our error handler could also throw an exception,
Packit 0848f5
    // but we want to make sure that the exception is not thrown 
Packit 0848f5
    // by the MPI code)
Packit 0848f5
Packit 0848f5
    eh = MPI::Comm::Create_errhandler( efn );
Packit 0848f5
    MPI::COMM_WORLD.Set_errhandler( eh );
Packit 0848f5
    try {
Packit 0848f5
	foundMsg = MPI::COMM_WORLD.Iprobe( size, 0 );
Packit 0848f5
    } catch (MPI::Exception ex) {
Packit 0848f5
	cout << "Caught exception from iprobe (should have called error handler instead)\n";
Packit 0848f5
	errs++;
Packit 0848f5
	if (ex.Get_error_class() == MPI_SUCCESS) {
Packit 0848f5
	    errs++;
Packit 0848f5
	    cout << "Unexpected error from Iprobe" << endl;
Packit 0848f5
	}
Packit 0848f5
    }
Packit 0848f5
    if (ncalls != 1) {
Packit 0848f5
	errs++;
Packit 0848f5
	cout << "Did not invoke error handler when invoking iprobe with an invalid rank" << endl;
Packit 0848f5
    }
Packit 0848f5
Packit 0848f5
    eh.Free();
Packit 0848f5
Packit 0848f5
    // Find out how many errors we saw
Packit 0848f5
Packit 0848f5
    MTest_Finalize( errs );
Packit 0848f5
    MPI::Finalize();
Packit 0848f5
Packit 0848f5
    return 0;
Packit 0848f5
}