ViewVC Help
View File | Revision Log | Show Annotations | View Changeset | Root Listing
root/group/trunk/OOPSE/libBASS/simError.c
Revision: 1218
Committed: Wed Jun 2 14:21:54 2004 UTC (20 years, 11 months ago) by gezelter
Content type: text/plain
File size: 1912 byte(s)
Log Message:
severity levels in simError

File Contents

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