GHOST  1.1.2
General, Hybrid, and Optimized Sparse Toolkit
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros Groups Pages
error.h
Go to the documentation of this file.
1 
6 #ifndef GHOST_ERROR_H
7 #define GHOST_ERROR_H
8 
9 #ifdef __cplusplus
10 #include <cstring>
11 #else
12 #include <string.h>
13 #endif
14 #include "log.h"
15 
16 #ifndef GHOST_HAVE_ZOLTAN
17 #define ZOLTAN_OK 0
18 #endif
19 
23 typedef enum {
108 } ghost_error;
109 
110 #include "errorhandler.h"
111 
122 #define GHOST_CALL_RETURN(call) {\
123  ghost_error macroerr = GHOST_SUCCESS;\
124  GHOST_CALL(call,macroerr);\
125  if (macroerr != GHOST_SUCCESS) {\
126  return macroerr;\
127  }\
128 }\
129 
130 
140 #define GHOST_CALL_GOTO(call,label,__err) {\
141  GHOST_CALL(call,__err);\
142  if (__err != GHOST_SUCCESS) {\
143  goto label;\
144  }\
145 }\
146 
147 
155 #define GHOST_CALL(call,__err) {\
156  __err = call;\
157  if (__err != GHOST_SUCCESS) {\
158  GHOST_LOG(GHOST_ERROR,GHOST_ANSI_COLOR_RED,"%s",ghost_error_string((ghost_error)__err));\
159  }\
160 }\
161 
162 #define MPI_CALL_RETURN(call) {\
163  ghost_error macroerr = GHOST_SUCCESS;\
164  MPI_CALL(call,macroerr);\
165  if (macroerr != GHOST_SUCCESS) {\
166  return macroerr;\
167  }\
168 }\
169 
170 #define MPI_CALL_GOTO(call,label,__err) {\
171  MPI_CALL(call,__err);\
172  if (__err != GHOST_SUCCESS) {\
173  goto label;\
174  }\
175 }\
176 
177 #define MPI_CALL(call,__err) {\
178  int mpicallmacroerr = call;\
179  if (mpicallmacroerr != MPI_SUCCESS) {\
180  char errstr[MPI_MAX_ERROR_STRING];\
181  int strlen;\
182  MPI_Error_string(mpicallmacroerr,errstr,&strlen);\
183  GHOST_ERROR_LOG("MPI Error: %s",errstr);\
184  ghost_errorhandler h = ghost_errorhandler_get(GHOST_ERR_MPI);\
185  if (h) {\
186  h((void *)&mpicallmacroerr);\
187  }\
188  __err = GHOST_ERR_MPI;\
189  } else {\
190  __err = GHOST_SUCCESS;\
191  }\
192 }\
193 
194 #define HWLOC_CALL_RETURN(call) {\
195  ghost_error macroerr = GHOST_SUCCESS;\
196  HWLOC_CALL(call,macroerr);\
197  if (macroerr != GHOST_SUCCESS) {\
198  return macroerr;\
199  }\
200 }\
201 
202 #define HWLOC_CALL_GOTO(call,label,__err) {\
203  HWLOC_CALL(call,__err);\
204  if (__err != GHOST_SUCCESS) {\
205  goto label;\
206  }\
207 }\
208 
209 #define HWLOC_CALL(call,__err) {\
210  int __hwlocerr = call;\
211  if (__hwlocerr) {\
212  GHOST_ERROR_LOG("HWLOC Error: %d",__hwlocerr);\
213  ghost_errorhandler h = ghost_errorhandler_get(GHOST_ERR_HWLOC);\
214  if (h) {\
215  h((void *)&__hwlocerr);\
216  }\
217  __err = GHOST_ERR_HWLOC;\
218  } else {\
219  __err = GHOST_SUCCESS;\
220  }\
221 }\
222 
223 #define CUDA_CALL_RETURN(call) {\
224  ghost_error macroerr = GHOST_SUCCESS;\
225  CUDA_CALL(call,macroerr);\
226  if (macroerr != GHOST_SUCCESS) {\
227  return macroerr;\
228  }\
229 }\
230 
231 #define CUDA_CALL_GOTO(call,label,__err) {\
232  CUDA_CALL(call,__err);\
233  if (__err != GHOST_SUCCESS) {\
234  goto label;\
235  }\
236 }\
237 
238 #define CUDA_CALL(call,__err) {\
239  cudaError_t __cuerr = call;\
240  if (__cuerr != cudaSuccess) {\
241  GHOST_ERROR_LOG("CUDA Error: %s (%d)",cudaGetErrorString(__cuerr),(int)__cuerr);\
242  ghost_errorhandler h = ghost_errorhandler_get(GHOST_ERR_CUDA);\
243  if (h) {\
244  h((void *)&__cuerr);\
245  }\
246  __err = GHOST_ERR_CUDA;\
247  } else {\
248  __err = GHOST_SUCCESS;\
249  }\
250 }\
251 
252 #define CUBLAS_CALL_RETURN(call) {\
253  ghost_error macroerr = GHOST_SUCCESS;\
254  CUBLAS_CALL(call,macroerr);\
255  if (macroerr != GHOST_SUCCESS) {\
256  return macroerr;\
257  }\
258 }\
259 
260 #define CUBLAS_CALL_GOTO(call,label,__err) {\
261  CUBLAS_CALL(call,__err);\
262  if (__err != GHOST_SUCCESS) {\
263  goto label;\
264  }\
265 }\
266 
267 #define CUBLAS_CALL(call,__err) {\
268  cublasStatus_t err = call;\
269  if (err != CUBLAS_STATUS_SUCCESS) {\
270  switch (err) {\
271  case CUBLAS_STATUS_NOT_INITIALIZED:\
272  GHOST_ERROR_LOG("CUBLAS error: CUBLAS_STATUS_NOT_INITIALIZED");\
273  break;\
274  case CUBLAS_STATUS_ALLOC_FAILED:\
275  GHOST_ERROR_LOG("CUBLAS error: CUBLAS_STATUS_ALLOC_FAILED");\
276  break;\
277  case CUBLAS_STATUS_INVALID_VALUE:\
278  GHOST_ERROR_LOG("CUBLAS error: CUBLAS_STATUS_INVALID_VALUE");\
279  break;\
280  case CUBLAS_STATUS_ARCH_MISMATCH:\
281  GHOST_ERROR_LOG("CUBLAS error: CUBLAS_STATUS_ARCH_MISMATCH");\
282  break;\
283  case CUBLAS_STATUS_MAPPING_ERROR:\
284  GHOST_ERROR_LOG("CUBLAS error: CUBLAS_STATUS_MAPPING_ERROR");\
285  break;\
286  case CUBLAS_STATUS_EXECUTION_FAILED:\
287  GHOST_ERROR_LOG("CUBLAS error: CUBLAS_STATUS_EXECUTION_FAILED");\
288  break;\
289  case CUBLAS_STATUS_INTERNAL_ERROR:\
290  GHOST_ERROR_LOG("CUBLAS error: CUBLAS_STATUS_INTERNAL_ERROR");\
291  break;\
292  case CUBLAS_STATUS_NOT_SUPPORTED:\
293  GHOST_ERROR_LOG("CUBLAS error: CUBLAS_STATUS_NOT_SUPPORTED");\
294  break;\
295  case CUBLAS_STATUS_LICENSE_ERROR:\
296  GHOST_ERROR_LOG("CUBLAS error: CUBLAS_STATUS_LICENSE_ERROR");\
297  break;\
298  default:\
299  GHOST_ERROR_LOG("CUBLAS error: Unknown CUBLAS error");\
300  break;\
301  }\
302  ghost_errorhandler h = ghost_errorhandler_get(GHOST_ERR_CUBLAS);\
303  if (h) {\
304  h((void *)&err);\
305  }\
306  __err = GHOST_ERR_CUBLAS;\
307  } else {\
308  __err = GHOST_SUCCESS;\
309  }\
310 }\
311 
312 #define CURAND_CALL_RETURN(call) {\
313  ghost_error macroerr = GHOST_SUCCESS;\
314  CURAND_CALL(call,macroerr);\
315  if (macroerr != GHOST_SUCCESS) {\
316  return macroerr;\
317  }\
318 }\
319 
320 #define CURAND_CALL_GOTO(call,label,__err) {\
321  CURAND_CALL(call,__err);\
322  if (__err != GHOST_SUCCESS) {\
323  goto label;\
324  }\
325 }\
326 
327 #define CURAND_CALL(call,__err) {\
328  curandStatus_t err = call;\
329  if (err != CURAND_STATUS_SUCCESS) {\
330  GHOST_ERROR_LOG("CURAND Error: %d",(int)err);\
331  ghost_errorhandler h = ghost_errorhandler_get(GHOST_ERR_CURAND);\
332  if (h) {\
333  h((void *)&err);\
334  }\
335  __err = GHOST_ERR_CURAND;\
336  } else {\
337  __err = GHOST_SUCCESS;\
338  }\
339 }\
340 
341 #define CUSPARSE_CALL_RETURN(call) {\
342  ghost_error macroerr = GHOST_SUCCESS;\
343  CUSPARSE_CALL(call,macroerr);\
344  if (macroerr != GHOST_SUCCESS) {\
345  return macroerr;\
346  }\
347 }\
348 
349 #define CUSPARSE_CALL_GOTO(call,label,__err) {\
350  CUSPARSE_CALL(call,__err);\
351  if (__err != GHOST_SUCCESS) {\
352  goto label;\
353  }\
354 }\
355 
356 #define CUSPARSE_CALL(call,__err) {\
357  cusparseStatus_t err = call;\
358  if (err != CUSPARSE_STATUS_SUCCESS) {\
359  GHOST_ERROR_LOG("CUSPARSE Error: %d",(int)err);\
360  ghost_errorhandler h = ghost_errorhandler_get(GHOST_ERR_CUSPARSE);\
361  if (h) {\
362  h((void *)&err);\
363  }\
364  __err = GHOST_ERR_CUSPARSE;\
365  } else {\
366  __err = GHOST_SUCCESS;\
367  }\
368 }\
369 
370 #define SCOTCH_CALL_RETURN(call) {\
371  ghost_error macroerr = GHOST_SUCCESS;\
372  SCOTCH_CALL(call,macroerr);\
373  if (macroerr != GHOST_SUCCESS) {\
374  return macroerr;\
375  }\
376 }\
377 
378 #define SCOTCH_CALL_GOTO(call,label,__err) {\
379  SCOTCH_CALL(call,__err);\
380  if (__err != GHOST_SUCCESS) {\
381  goto label;\
382  }\
383 }\
384 
385 #define SCOTCH_CALL(call,__err) {\
386  int err = call;\
387  if (err) {\
388  GHOST_ERROR_LOG("SCOTCH Error: %d",err);\
389  ghost_errorhandler h = ghost_errorhandler_get(GHOST_ERR_SCOTCH);\
390  if (h) {\
391  h((void *)&err);\
392  }\
393  __err = GHOST_ERR_SCOTCH;\
394  } else {\
395  __err = GHOST_SUCCESS;\
396  }\
397 }\
398 
399 #define COLPACK_CALL_RETURN(call) {\
400  ghost_error macroerr = GHOST_SUCCESS;\
401  COLPACK_CALL(call,macroerr);\
402  if (macroerr != GHOST_SUCCESS) {\
403  return macroerr;\
404  }\
405 }\
406 
407 #define COLPACK_CALL_GOTO(call,label,__err) {\
408  COLPACK_CALL(call,__err);\
409  if (__err != GHOST_SUCCESS) {\
410  goto label;\
411  }\
412 }\
413 
414 #define COLPACK_CALL(call,__err) {\
415  int err = call;\
416  if (err != _TRUE) {\
417  GHOST_ERROR_LOG("ColPack Error: %d",err);\
418  ghost_errorhandler h = ghost_errorhandler_get(GHOST_ERR_COLPACK);\
419  if (h) {\
420  h((void *)&err);\
421  }\
422  __err = GHOST_ERR_COLPACK;\
423  } else {\
424  __err = GHOST_SUCCESS;\
425  }\
426 }\
427 
428 #define ZOLTAN_CALL_RETURN(call) {\
429  ghost_error macroerr = GHOST_SUCCESS;\
430  ZOLTAN_CALL(call,macroerr);\
431  if (macroerr != GHOST_SUCCESS) {\
432  return macroerr;\
433  }\
434 }\
435 
436 #define ZOLTAN_CALL_GOTO(call,label,__err) {\
437  ZOLTAN_CALL(call,__err);\
438  if (__err != GHOST_SUCCESS) {\
439  goto label;\
440  }\
441 }\
442 
443 #define ZOLTAN_CALL(call,__err) {\
444  int err = call;\
445  if (err != ZOLTAN_OK) {\
446  GHOST_ERROR_LOG("Zoltan Error: %d",err);\
447  ghost_errorhandler h = ghost_errorhandler_get(GHOST_ERR_ZOLTAN);\
448  if (h) {\
449  h((void *)&err);\
450  }\
451  __err = GHOST_ERR_ZOLTAN;\
452  } else {\
453  __err = GHOST_SUCCESS;\
454  }\
455 }\
456 
457 #define BLAS_CALL_RETURN(call) {\
458  ghost_error macroerr = GHOST_SUCCESS;\
459  BLAS_CALL(call,macroerr);\
460  if (macroerr != GHOST_SUCCESS) {\
461  return macroerr;\
462  }\
463 }\
464 
465 #define BLAS_CALL_GOTO(call,label,__err) {\
466  BLAS_CALL(call,__err);\
467  if (__err != GHOST_SUCCESS) {\
468  goto label;\
469  }\
470 }\
471 
472 #define BLAS_CALL(call,__err) {\
473  call;\
474  int err = ghost_blas_err_pop();\
475  if (err) {\
476  GHOST_ERROR_LOG("BLAS Error: %d",err);\
477  ghost_errorhandler h = ghost_errorhandler_get(GHOST_ERR_BLAS);\
478  if (h) {\
479  h((void *)&err);\
480  }\
481  __err = GHOST_ERR_BLAS;\
482  } else {\
483  __err = GHOST_SUCCESS;\
484  }\
485 }\
486 
487 #ifdef __cplusplus
488  extern "C" {
489 #endif
490 
501 
502 #ifdef __cplusplus
503  }
504 #endif
505 
506 #endif
No error occured.
Definition: error.h:27
An error in a CUSPARSE call occured.
Definition: error.h:47
An error in a Hwloc call occured.
Definition: error.h:55
An error during I/O occured.
Definition: error.h:75
An unknown error occured.
Definition: error.h:67
An error in a ColPack call occured.
Definition: error.h:83
An error in a BLAS call occured.
Definition: error.h:103
Functionality for user-defined error handlers.
ghost_error
Error return type.
Definition: error.h:23
An error in an MPI call occured.
Definition: error.h:35
One or more of the arguments are invalid.
Definition: error.h:31
An error in Red-Black splitting occured.
Definition: error.h:95
An error in a LAPACK call occured.
Definition: error.h:99
An error in a Zoltan call occured.
Definition: error.h:63
char * ghost_error_string(ghost_error e)
Get a string of the GHOST error.
Definition: error.c:4
An error in a CURAND call occured.
Definition: error.h:51
ERROR if the matrix is not colored.
Definition: error.h:91
An error with datatypes occured.
Definition: error.h:79
The function is not (yet) implemented.
Definition: error.h:71
An error in Block coloring occured.
Definition: error.h:87
An error in a CUDA call occured.
Definition: error.h:39
Macros for logging.
An error in a CUBLAS call occured.
Definition: error.h:43
Definition: error.h:107
An error in a SCOTCH call occured.
Definition: error.h:59