1 /*
2  * Copyright (C) by Argonne National Laboratory
3  *     See COPYRIGHT in top-level directory
4  */
5 
6 #include "mpi.h"
7 #include <stdio.h>
8 #include "mpitest.h"
9 
10 /*
11 static char MTEST_Descrip[] = "Test the routines to control error handlers on windows";
12 */
13 static int calls = 0;
14 static int errs = 0;
15 static MPI_Win mywin;
16 static int expected_err_class = MPI_ERR_OTHER;
17 
18 void weh(MPI_Win * win, int *err, ...);
weh(MPI_Win * win,int * err,...)19 void weh(MPI_Win * win, int *err, ...)
20 {
21     int errclass;
22     MPI_Error_class(*err, &errclass);
23     if (errclass != expected_err_class) {
24         errs++;
25         printf("Unexpected error code (class = %d)\n", errclass);
26     }
27     if (*win != mywin) {
28         errs++;
29         printf("Unexpected window (got %x expected %x)\n", (int) *win, (int) mywin);
30     }
31     calls++;
32     return;
33 }
34 
main(int argc,char * argv[])35 int main(int argc, char *argv[])
36 {
37     int err;
38     int buf[2];
39     MPI_Win win;
40     MPI_Comm comm;
41     MPI_Errhandler newerr, olderr;
42 
43     MTEST_VG_MEM_INIT(buf, 2 * sizeof(int));
44 
45     MTest_Init(&argc, &argv);
46     comm = MPI_COMM_WORLD;
47     MPI_Win_create_errhandler(weh, &newerr);
48 
49     MPI_Win_create(buf, 2 * sizeof(int), sizeof(int), MPI_INFO_NULL, comm, &win);
50 
51     mywin = win;
52     MPI_Win_get_errhandler(win, &olderr);
53     if (olderr != MPI_ERRORS_ARE_FATAL) {
54         errs++;
55         printf("Expected errors are fatal\n");
56     }
57 
58     MPI_Win_set_errhandler(win, newerr);
59 
60     expected_err_class = MPI_ERR_RANK;
61     err = MPI_Put(buf, 1, MPI_INT, -5, 0, 1, MPI_INT, win);
62     if (calls != 1) {
63         errs++;
64         printf("newerr not called\n");
65         calls = 1;
66     }
67     expected_err_class = MPI_ERR_OTHER;
68     MPI_Win_call_errhandler(win, MPI_ERR_OTHER);
69     if (calls != 2) {
70         errs++;
71         printf("newerr not called (2)\n");
72     }
73 
74     MPI_Win_free(&win);
75     MPI_Errhandler_free(&newerr);
76 
77     MTest_Finalize(errs);
78     return MTestReturnValue(errs);
79 }
80