1 /******************************************************************************
2 * Copyright 1998-2019 Lawrence Livermore National Security, LLC and other
3 * HYPRE Project Developers. See the top-level COPYRIGHT file for details.
4 *
5 * SPDX-License-Identifier: (Apache-2.0 OR MIT)
6 ******************************************************************************/
7
8 #include "_hypre_utilities.h"
9
10 HYPRE_Int hypre__global_error = 0;
11
12 /* Process the error with code ierr raised in the given line of the
13 given source file. */
hypre_error_handler(const char * filename,HYPRE_Int line,HYPRE_Int ierr,const char * msg)14 void hypre_error_handler(const char *filename, HYPRE_Int line, HYPRE_Int ierr, const char *msg)
15 {
16 hypre_error_flag |= ierr;
17
18 #ifdef HYPRE_PRINT_ERRORS
19 if (msg)
20 {
21 hypre_fprintf(
22 stderr, "hypre error in file \"%s\", line %d, error code = %d - %s\n",
23 filename, line, ierr, msg);
24 }
25 else
26 {
27 hypre_fprintf(
28 stderr, "hypre error in file \"%s\", line %d, error code = %d\n",
29 filename, line, ierr);
30 }
31 #endif
32 }
33
HYPRE_GetError()34 HYPRE_Int HYPRE_GetError()
35 {
36 return hypre_error_flag;
37 }
38
HYPRE_CheckError(HYPRE_Int ierr,HYPRE_Int hypre_error_code)39 HYPRE_Int HYPRE_CheckError(HYPRE_Int ierr, HYPRE_Int hypre_error_code)
40 {
41 return ierr & hypre_error_code;
42 }
43
HYPRE_DescribeError(HYPRE_Int ierr,char * msg)44 void HYPRE_DescribeError(HYPRE_Int ierr, char *msg)
45 {
46 if (ierr == 0)
47 hypre_sprintf(msg,"[No error] ");
48
49 if (ierr & HYPRE_ERROR_GENERIC)
50 hypre_sprintf(msg,"[Generic error] ");
51
52 if (ierr & HYPRE_ERROR_MEMORY)
53 hypre_sprintf(msg,"[Memory error] ");
54
55 if (ierr & HYPRE_ERROR_ARG)
56 hypre_sprintf(msg,"[Error in argument %d] ", HYPRE_GetErrorArg());
57
58 if (ierr & HYPRE_ERROR_CONV)
59 hypre_sprintf(msg,"[Method did not converge] ");
60 }
61
HYPRE_GetErrorArg()62 HYPRE_Int HYPRE_GetErrorArg()
63 {
64 return (hypre_error_flag>>3 & 31);
65 }
66
HYPRE_ClearAllErrors()67 HYPRE_Int HYPRE_ClearAllErrors()
68 {
69 hypre_error_flag = 0;
70 return (hypre_error_flag != 0);
71 }
72
HYPRE_ClearError(HYPRE_Int hypre_error_code)73 HYPRE_Int HYPRE_ClearError(HYPRE_Int hypre_error_code)
74 {
75 hypre_error_flag &= ~hypre_error_code;
76 return (hypre_error_flag & hypre_error_code);
77 }
78
79