ViewVC Help
View File | Revision Log | Show Annotations | View Changeset | Root Listing
root/group/trunk/OOPSE/libBASS/simError.c
Revision: 1220
Committed: Wed Jun 2 14:56:06 2004 UTC (20 years, 11 months ago) by chrisfen
Content type: text/plain
File size: 1943 byte(s)
Log Message:
Formatting Changes

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, ":\n\t");
64
65 strncat(errorMsg, painCave.errMsg, strlen(painCave.errMsg));
66
67 strcat(errorMsg, "\n");
68 fprintf(stderr, errorMsg);
69
70 #ifdef IS_MPI
71 if (painCave.isEventLoop)
72 return 1;
73 #endif
74
75 if (painCave.isFatal) {
76 #ifdef IS_MPI
77 MPI_Allreduce( &myError, &isError, 1, MPI_INT, MPI_LOR, MPI_COMM_WORLD );
78 MPI_Finalize();
79 #endif
80 exit(0);
81 }
82
83 return 1;
84 }
85
86
87 #ifdef IS_MPI
88
89 void MPIcheckPoint( void ){
90
91 int myError = 0;
92 int isError;
93
94 MPI_Allreduce( &myError, &isError, 1, MPI_INT, MPI_LOR, MPI_COMM_WORLD );
95 if( isError ){
96 MPI_Finalize();
97 exit(0);
98 }
99
100 #ifdef CHECKPOINT_VERBOSE
101 nChecks++;
102 if( worldRank == 0 ){
103 fprintf(stderr,
104 "Checkpoint #%d reached: %s\n",
105 nChecks,
106 checkPointMsg );
107 }
108 #endif // CHECKPOINT_VERBOSE
109
110 }
111
112 #endif // IS_MPI