Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
Merge branch 'master' into CRTP
[simgrid.git] / teshsuite / smpi / mpich3-test / errhan / commcall.c
1 /* -*- Mode: C; c-basic-offset:4 ; indent-tabs-mode:nil ; -*- */
2 /*
3  *
4  *  (C) 2003 by Argonne National Laboratory.
5  *      See COPYRIGHT in top-level directory.
6  */
7 #include "mpi.h"
8 #include <stdio.h>
9 #include "mpitest.h"
10
11 /*
12 static char MTEST_Descrip[] = "Test comm_call_errhandler";
13 */
14
15 static int calls = 0;
16 static int errs = 0;
17 static MPI_Comm mycomm;
18 void eh(MPI_Comm * comm, int *err, ...);
19 void eh(MPI_Comm * comm, int *err, ...)
20 {
21     if (*err != MPI_ERR_OTHER) {
22         errs++;
23         printf("Unexpected error code\n");
24     }
25     if (*comm != mycomm) {
26         errs++;
27         printf("Unexpected communicator\n");
28     }
29     calls++;
30     return;
31 }
32
33 int main(int argc, char *argv[])
34 {
35     MPI_Comm comm;
36     MPI_Errhandler newerr;
37     int i;
38     int reset_handler;
39
40     MTest_Init(&argc, &argv);
41
42     comm = MPI_COMM_WORLD;
43     mycomm = comm;
44
45     MPI_Comm_create_errhandler(eh, &newerr);
46
47     MPI_Comm_set_errhandler(comm, newerr);
48     MPI_Comm_call_errhandler(comm, MPI_ERR_OTHER);
49     MPI_Errhandler_free(&newerr);
50     if (calls != 1) {
51         errs++;
52         printf("Error handler not called\n");
53     }
54
55     /* Here we apply the test to many copies of a communicator */
56     for (reset_handler = 0; reset_handler <= 1; ++reset_handler) {
57         for (i = 0; i < 1000; i++) {
58             MPI_Comm comm2;
59             calls = 0;
60             MPI_Comm_dup(MPI_COMM_WORLD, &comm);
61             mycomm = comm;
62             MPI_Comm_create_errhandler(eh, &newerr);
63
64             MPI_Comm_set_errhandler(comm, newerr);
65             MPI_Comm_call_errhandler(comm, MPI_ERR_OTHER);
66             if (calls != 1) {
67                 errs++;
68                 printf("Error handler not called\n");
69             }
70             MPI_Comm_dup(comm, &comm2);
71             calls = 0;
72             mycomm = comm2;
73             /* comm2 must inherit the error handler from comm */
74             MPI_Comm_call_errhandler(comm2, MPI_ERR_OTHER);
75             if (calls != 1) {
76                 errs++;
77                 printf("Error handler not called\n");
78             }
79
80             if (reset_handler) {
81                 /* extra checking of the reference count handling */
82                 MPI_Comm_set_errhandler(comm, MPI_ERRORS_ARE_FATAL);
83             }
84             MPI_Errhandler_free(&newerr);
85
86             MPI_Comm_free(&comm);
87             MPI_Comm_free(&comm2);
88         }
89     }
90
91     MTest_Finalize(errs);
92     return MTestReturnValue(errs);
93 }