File: commerrx.cxx

package info (click to toggle)
mpich 3.2-7
  • links: PTS, VCS
  • area: main
  • in suites: stretch
  • size: 81,040 kB
  • ctags: 68,664
  • sloc: ansic: 358,905; f90: 54,597; perl: 18,527; cpp: 10,203; sh: 9,839; xml: 8,195; fortran: 7,799; makefile: 4,868; ruby: 53; sed: 9; php: 8
file content (94 lines) | stat: -rw-r--r-- 2,191 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
/* -*- Mode: C; c-basic-offset:4 ; indent-tabs-mode:nil ; -*- */
/*
 *  (C) 2011 by Argonne National Laboratory.
 *      See COPYRIGHT in top-level directory.
 */

/*
  Tests invocation of error handlers on a variety of communicators, including
  COMM_NULL.  
*/

#include "mpitestconf.h"
#include <mpi.h>
#include <iostream>
#include "mpitestcxx.h"

/* returns number of errors found */
int testCommCall( MPI::Comm &comm )
{
    int i;
    bool sawException = false;

    comm.Set_errhandler( MPI::ERRORS_THROW_EXCEPTIONS );
    try {
	// Invalid send
	comm.Send( &i, -1, MPI::DATATYPE_NULL, -1, -10 );
    } catch (MPI::Exception &ex ) {
	// This is good
	sawException = true;
    }
    catch (...) {
	// This is bad
    }
    if (!sawException) {
	int len;
	char commname[MPI_MAX_OBJECT_NAME];
	comm.Get_name( commname, len );
	std::cout << "Did not see MPI exception on invalid call on communicator " <<
	    commname << "\n";
    }
    return sawException ? 0 : 1;
}

int testNullCommCall( void )
{
    int i;
    bool sawException = false;
    const MPI::Comm &comm = MPI::COMM_NULL;

    MPI::COMM_WORLD.Set_errhandler( MPI::ERRORS_THROW_EXCEPTIONS );
    try {
	// Invalid send
	comm.Send( &i, -1, MPI::DATATYPE_NULL, -1, -10 );
    } catch (MPI::Exception &ex ) {
	// This is good
	sawException = true;
    }
    catch (...) {
	// This is bad
    }
    if (!sawException) {
	std::cout << "Did not see MPI exception on invalid call on communicator COMM_NULL\n";
    }
    return sawException ? 0 : 1;
}

int main( int argc, char *argv[] )
{
    int errs = 0;
    bool periods[2] = { false, false };
    int  dims[2] = { 0, 0 };

    MTest_Init( );

    MPI::Compute_dims( MPI::COMM_WORLD.Get_size(), 2, dims );
    MPI::Cartcomm cart = MPI::COMM_WORLD.Create_cart( 2, dims, periods, true );
    cart.Set_name( "Cart comm" );
    // Graphcomm graph = COMM_WORLD.Create_graph( );

    errs += testCommCall( MPI::COMM_WORLD );
    errs += testNullCommCall( );
    errs += testCommCall( MPI::COMM_SELF );
    errs += testCommCall( cart );
    //errs += testCommCall( graph );
    
    MTest_Finalize( errs );

    cart.Free();
    // graph.Free();

    MPI::Finalize();

    return 0;
}