1 |
#include <stdlib.h> |
2 |
#include <stdio.h> |
3 |
#include <string.h> |
4 |
#include "config.h" |
5 |
|
6 |
#ifdef IS_MPI |
7 |
#include <mpi.h> |
8 |
|
9 |
int nChecks; |
10 |
#endif // IS_MPI |
11 |
|
12 |
#include "utils/simError.h" |
13 |
|
14 |
errorStruct painCave; |
15 |
|
16 |
#ifdef IS_MPI |
17 |
|
18 |
char checkPointMsg[MAX_SIM_ERROR_MSG_LENGTH]; |
19 |
int worldRank; |
20 |
|
21 |
#endif |
22 |
|
23 |
|
24 |
void initSimError( void ){ |
25 |
painCave.errMsg[0] = '\0'; |
26 |
painCave.isFatal = 0; |
27 |
painCave.severity = OOPSE_ERROR; |
28 |
#ifdef IS_MPI |
29 |
painCave.isEventLoop = 0; |
30 |
nChecks = 0; |
31 |
MPI_Comm_rank( MPI_COMM_WORLD, &worldRank ); |
32 |
#endif |
33 |
} |
34 |
|
35 |
int simError( void ) { |
36 |
|
37 |
int myError = 1; |
38 |
int isError; |
39 |
char errorMsg[MAX_SIM_ERROR_MSG_LENGTH]; |
40 |
char nodeMsg[MAX_SIM_ERROR_MSG_LENGTH]; |
41 |
|
42 |
strcpy(errorMsg, "OOPSE "); |
43 |
switch( painCave.severity ) { |
44 |
case OOPSE_WARNING: |
45 |
strcat(errorMsg, "WARNING"); |
46 |
break; |
47 |
case OOPSE_INFO: |
48 |
strcat(errorMsg, "INFO"); |
49 |
break; |
50 |
default: |
51 |
if( painCave.isFatal ) { |
52 |
strcat(errorMsg, "FATAL "); |
53 |
} |
54 |
strcat(errorMsg, "ERROR"); |
55 |
} |
56 |
|
57 |
#ifdef IS_MPI |
58 |
if ( painCave.isEventLoop ) { |
59 |
sprintf( nodeMsg, " (reported by MPI node %d)", worldRank); |
60 |
strncat(errorMsg, nodeMsg, strlen(nodeMsg)); |
61 |
} |
62 |
#endif |
63 |
|
64 |
strcat(errorMsg, ":\n\t"); |
65 |
|
66 |
strncat(errorMsg, painCave.errMsg, strlen(painCave.errMsg)); |
67 |
|
68 |
strcat(errorMsg, "\n"); |
69 |
fprintf(stderr, errorMsg); |
70 |
|
71 |
#ifdef IS_MPI |
72 |
if (painCave.isEventLoop) |
73 |
return 1; |
74 |
#endif |
75 |
|
76 |
if (painCave.isFatal) { |
77 |
#ifdef IS_MPI |
78 |
MPI_Allreduce( &myError, &isError, 1, MPI_INT, MPI_LOR, MPI_COMM_WORLD ); |
79 |
MPI_Finalize(); |
80 |
#endif |
81 |
exit(0); |
82 |
} |
83 |
|
84 |
return 1; |
85 |
} |
86 |
|
87 |
|
88 |
#ifdef IS_MPI |
89 |
|
90 |
void MPIcheckPoint( void ){ |
91 |
|
92 |
int myError = 0; |
93 |
int isError; |
94 |
|
95 |
MPI_Allreduce( &myError, &isError, 1, MPI_INT, MPI_LOR, MPI_COMM_WORLD ); |
96 |
if( isError ){ |
97 |
MPI_Finalize(); |
98 |
exit(0); |
99 |
} |
100 |
|
101 |
#ifdef CHECKPOINT_VERBOSE |
102 |
nChecks++; |
103 |
if( worldRank == 0 ){ |
104 |
fprintf(stderr, |
105 |
"Checkpoint #%d reached: %s\n", |
106 |
nChecks, |
107 |
checkPointMsg ); |
108 |
} |
109 |
#endif // CHECKPOINT_VERBOSE |
110 |
|
111 |
} |
112 |
|
113 |
#endif // IS_MPI |