1 /*****************************************************************************
2  *                                                                           *
3  * Copyright (c) 2003-2006 Intel Corporation.                                *
4  * All rights reserved.                                                      *
5  *                                                                           *
6  *****************************************************************************
7 
8 This code is covered by the Community Source License (CPL), version
9 1.0 as published by IBM and reproduced in the file "license.txt" in the
10 "license" subdirectory. Redistribution in source and binary form, with
11 or without modification, is permitted ONLY within the regulations
12 contained in above mentioned license.
13 
14 Use of the name and trademark "Intel(R) MPI Benchmarks" is allowed ONLY
15 within the regulations of the "License for Use of "Intel(R) MPI
16 Benchmarks" Name and Trademark" as reproduced in the file
17 "use-of-trademark-license.txt" in the "license" subdirectory.
18 
19 THE PROGRAM IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OR
20 CONDITIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED INCLUDING, WITHOUT
21 LIMITATION, ANY WARRANTIES OR CONDITIONS OF TITLE, NON-INFRINGEMENT,
22 MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE. Each Recipient is
23 solely responsible for determining the appropriateness of using and
24 distributing the Program and assumes all risks associated with its
25 exercise of rights under this Agreement, including but not limited to
26 the risks and costs of program errors, compliance with applicable
27 laws, damage to or loss of data, programs or equipment, and
28 unavailability or interruption of operations.
29 
30 EXCEPT AS EXPRESSLY SET FORTH IN THIS AGREEMENT, NEITHER RECIPIENT NOR
31 ANY CONTRIBUTORS SHALL HAVE ANY LIABILITY FOR ANY DIRECT, INDIRECT,
32 INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING
33 WITHOUT LIMITATION LOST PROFITS), HOWEVER CAUSED AND ON ANY THEORY OF
34 LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
35 NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OR
36 DISTRIBUTION OF THE PROGRAM OR THE EXERCISE OF ANY RIGHTS GRANTED
37 HEREUNDER, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGES.
38 
39 EXPORT LAWS: THIS LICENSE ADDS NO RESTRICTIONS TO THE EXPORT LAWS OF
40 YOUR JURISDICTION. It is licensee's responsibility to comply with any
41 export regulations applicable in licensee's jurisdiction. Under
42 CURRENT U.S. export regulations this software is eligible for export
43 from the U.S. and can be downloaded by or otherwise exported or
44 reexported worldwide EXCEPT to U.S.  embargoed destinations which
45 include Cuba, Iraq, Libya, North Korea, Iran, Syria, Sudan,
46 Afghanistan and any other country to which the U.S. has embargoed
47 goods and services.
48 
49  ***************************************************************************
50 
51 For more documentation than found here, see
52 
53 [1] doc/ReadMe_IMB.txt
54 
55 [2] Intel (R) MPI Benchmarks
56     Users Guide and Methodology Description
57     In
58     doc/IMB_ug.pdf
59 
60  File: IMB_err_handler.c
61 
62  Implemented functions:
63 
64  IMB_err_hand;
65  IMB_errors_mpi;
66  IMB_errors_win;
67  IMB_errors_io;
68  IMB_init_errhand;
69  IMB_set_errhand;
70  IMB_del_errhand;
71 
72  ***************************************************************************/
73 
74 
75 
76 
77 
78 #define nSET_ERRH
79 
80 #include "IMB_declare.h"
81 
82 #include "IMB_prototypes.h"
83 
84 /*-------------------------------------------------------------*/
85 
86 
87 
IMB_err_hand(int ERR_IS_MPI,int ERR_CODE)88 void IMB_err_hand(int ERR_IS_MPI, int ERR_CODE )
89 /*
90 
91 
92                       Handles input error code.
93                       Retrieves error string (MPI_Error_string) if is an MPI error code
94                       Calls MPI_Abort
95 
96 
97 
98 Input variables:
99 
100 -ERR_IS_MPI           (type int)
101                       Logical flag: error code belongs to MPI or not
102 
103 
104 -ERR_CODE             (type int)
105                       Input error code. If an MPI error code, the string is retrieved.
106                       Anyway MPI_Abort is called
107 
108 
109 
110 */
111 {
112   int i_break;
113 
114   if(! ERR_IS_MPI )
115     {
116       i_break=1;
117       fprintf(stderr,"Application error code %d occurred\n",ERR_CODE);
118       switch(ERR_CODE)
119 	{
120 	case APPL_ERR_INVCASE: fprintf(stderr,"INVALID benchmark name\n");
121 	  break;
122 	case APPL_ERR_MALLOC : fprintf(stderr,"Malloc failed \n");
123 	  break;
124 	case APPL_ERR_CINFO  : fprintf(stderr,"Invalid \"c_info\" setup\n");
125 	  break;
126 	}
127       ERR_CODE=MPI_ERR_INTERN;
128     }
129   else if ( ERR_CODE != MPI_SUCCESS )
130     {
131       char aux_string[MPI_MAX_ERROR_STRING];
132       int L;
133       i_break=1;
134       fprintf(stderr,"MPI error  %d occurred\n",ERR_CODE);
135       MPI_Error_string(ERR_CODE,aux_string, &L);
136       fprintf(stderr,"%s\n",aux_string);
137     }
138   else i_break=0;
139 
140   if(i_break )
141     {
142       MPI_Abort(MPI_COMM_WORLD, ERR_CODE);
143     }
144 }
145 
146 
147 
148 
IMB_errors_mpi(MPI_Comm * comm,int * ierr,...)149 void IMB_errors_mpi(MPI_Comm * comm, int* ierr, ...)
150 /*
151 
152 
153                       Error handler callback for MPI-1 errors
154 
155 
156 
157 Input variables:
158 
159 -comm                 (type MPI_Comm *)
160                       Communicator which is in error
161 
162 
163 -ierr                 (type int*)
164                       MPI error code
165 
166 
167 
168 */
169 {
170 IMB_err_hand(1,*ierr);
171 }
172 
173 #ifdef EXT
174 
IMB_errors_win(MPI_Win * WIN,int * ierr,...)175 void IMB_errors_win(MPI_Win * WIN, int* ierr, ...)
176 /*
177 
178 
179                       Error handler callback for onesided communications errors
180 
181 
182 
183 Input variables:
184 
185 -WIN                  (type MPI_Win *)
186                       MPI Window which is in error
187 
188 
189 -ierr                 (type int*)
190                       MPI error code
191 
192 
193 
194 */
195 {
196 IMB_err_hand(1,*ierr);
197 }
198 #endif
199 
200 #ifdef MPIIO
201 
IMB_errors_io(MPI_File * fh,int * ierr,...)202 void IMB_errors_io (MPI_File * fh, int* ierr, ...)
203 /*
204 
205 
206                       Error handler callback for MPI-IO errors
207 
208 
209 
210 Input variables:
211 
212 -fh                   (type MPI_File *)
213                       MPI File which is in error
214 
215 
216 -ierr                 (type int*)
217                       MPI error code
218 
219 
220 
221 */
222 {
223 IMB_err_hand(1,*ierr);
224 }
225 #endif
226 
227 
228 
229 
IMB_init_errhand(struct comm_info * c_info)230 void IMB_init_errhand(struct comm_info* c_info)
231 /*
232 
233 
234                       Creates MPI error handler component of c_info by MPI_<>_create_errhandler
235 
236 
237 
238 In/out variables:
239 
240 -c_info               (type struct comm_info*)
241                       Collection of all base data for MPI;
242                       see [1] for more information
243 
244                       Error handler component is created
245                       (c_info->ERR for MPI-1; c_info->ERRW for EXT; c_info->ERRF for MPIIO)
246 
247 
248 
249 */
250 {
251 #ifdef SET_ERRH
252 
253 MPI_Errhandler_create(IMB_errors_mpi,&c_info->ERR);
254 
255 #ifdef EXT
256 MPI_Win_create_errhandler(IMB_errors_win, &c_info->ERRW);
257 #endif
258 
259 #ifdef MPIIO
260 MPI_File_create_errhandler(IMB_errors_io, &c_info->ERRF);
261 #endif
262 
263 #endif
264 }
265 
266 
267 
268 
IMB_set_errhand(struct comm_info * c_info)269 void IMB_set_errhand(struct comm_info* c_info)
270 /*
271 
272 
273                       Sets MPI error handler component of c_info by MPI_<>_set_errhandler
274 
275 
276 
277 In/out variables:
278 
279 -c_info               (type struct comm_info*)
280                       Collection of all base data for MPI;
281                       see [1] for more information
282 
283                       Error handler component is set
284 
285 
286 
287 */
288 {
289 #ifdef SET_ERRH
290 
291 if( c_info->communicator != MPI_COMM_NULL )
292 MPI_Errhandler_set(c_info->communicator, c_info->ERR);
293 
294 #ifdef EXT
295 if( c_info->WIN != MPI_WIN_NULL )
296 MPI_Win_set_errhandler(c_info->WIN, c_info->ERRW);
297 #endif
298 
299 #ifdef MPIIO
300 if( c_info->fh != MPI_FILE_NULL )
301 MPI_File_set_errhandler(c_info->fh, c_info->ERRF);
302 #endif
303 
304 #endif
305 }
306 
307 
308 
309 
IMB_del_errhand(struct comm_info * c_info)310 void IMB_del_errhand(struct comm_info* c_info)
311 /*
312 
313 
314                       Deletes MPI error handler component of c_info by MPI_Errhandler_free
315 
316 
317 
318 In/out variables:
319 
320 -c_info               (type struct comm_info*)
321                       Collection of all base data for MPI;
322                       see [1] for more information
323 
324                       MPI error handler component of c_info is deleted
325 
326 
327 
328 */
329 {
330 #ifdef SET_ERRH
331 MPI_Errhandler_free(&c_info->ERR);
332 
333 #ifdef EXT
334 MPI_Errhandler_free(&c_info->ERRW);
335 #endif
336 
337 #ifdef MPIIO
338 MPI_Errhandler_free(&c_info->ERRF);
339 #endif
340 
341 #endif
342 }
343