00001 #include "mainapp.h"
00002 #include <stdlib.h>
00003 #include <signal.h>
00004 #include <fenv.h>
00005 #include <limits.h>
00006 #include "hdf5orthowriter.h"
00007 #include "flashco2brine.h"
00008 #ifdef USE_MPI
00009 #include"netmpi.h"
00010 #include "mainappmpi.h"
00011 #endif
00012
00013 #include "timer.h"
00014
00015
00016 MainApp *global_app=NULL;
00017 bool abort_once=false;
00018
00019
00020
00021
00022 void closeFiles(int sig_num)
00023 {
00024 if (!abort_once)
00025 {
00026 abort_once=true;
00027 printf("An abort evend was signaled......\n");
00028 global_app->abortEvent();
00029 printf("Trying to output the data......Ok\n");
00030 }
00031 else
00032 printf("Trying to output the data......Failed\n");
00033 printf("Closing Output file\ngoodby\n");
00034 HDF5OrthoWriter::getHDF5OrthoWriter().close();
00035
00036 }
00037
00038
00039
00040
00041 void fpehandler(int sig_num)
00042 {
00043 signal(SIGFPE, fpehandler);
00044 printf("SIGFPE %d: FLOATING POINT EXCEPTION OCCURRED\n",sig_num);
00045 printf("Segmentation Fault signal will be sent to cause\n");
00046 printf("production of a core file\n");
00047 closeFiles(0);
00048 kill(getpid(),SIGSEGV);
00049 abort();
00050 }
00051
00052
00053
00054
00055
00056
00057 int main(int argc,char **argv)
00058 {
00059
00060
00061
00062 char errorMessage[1000];
00063
00064
00065
00066
00067
00068
00069 feenableexcept(FE_DIVBYZERO|FE_INVALID);
00070 signal(SIGFPE,fpehandler);
00071 signal(SIGKILL,closeFiles);
00072 signal(SIGABRT,closeFiles);
00073 signal(SIGTERM,closeFiles);
00074
00075 sprintf(errorMessage,"Invalid arguments passed\n\
00076 Usage: %s [Options] <CONFILE FILE NAME>\n\
00077 Options:\n\
00078 -g\tActivate unit tests mode\n",argv[0]);
00079
00080
00081 if (argc != 3 && argc!= 2)
00082 {
00083 printf("%s",errorMessage);
00084 return 0;
00085 }
00086
00087
00088
00089 std::string configFile;
00090 bool bunit_test=false;
00091
00092
00093
00094
00095 if (argc == 3)
00096 {
00097 std::string option = argv[1];
00098 if (option == "-g")
00099 bunit_test=true;
00100 else
00101 {
00102 printf("%s",errorMessage);
00103 return 0;
00104 }
00105 configFile=argv[2];
00106 }
00107 else if (argc == 2)
00108 configFile=argv[1];
00109
00110
00111
00112
00113
00114
00115
00116 #ifndef USE_MPI
00117 Timer t1(PROCESSOR_TIME);
00118 t1.start();
00119
00120
00121 MainApp app;
00122 global_app = &app;
00123 app.execute(configFile,bunit_test);
00124
00125 t1.end();
00126 std::cout << "Total Exec Time: " << t1.printTime() << std::endl;
00127 return 0;
00128
00129 #else
00130
00131
00132 MPI_Init(&argc,&argv);
00133 if (argc != 2)
00134 {
00135 printf("%s",errorMessage);
00136 return 0;
00137 }
00138 system("echo $HOSTNAME $SSH_HOST $SSH_CONNECTION");
00139 MainAppMPI app;
00140 app.execute(argv[1]);
00141
00142 MPI_Finalize();
00143 return 0;
00144
00145 #endif
00146
00147
00148
00149
00150 }
00151
00152
00153
00154
00155
00156
00157
00158
00159
00160
00161
00162
00163
00164
00165
00166
00167
00168
00169
00170
00171
00172
00173
00174
00175
00176
00177
00178
00179
00180
00181
00182
00183
00184
00185
00186
00187
00188
00189
00190