00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026 #include <winstd.H>
00027
00028 #if defined(BL_OLD_STL)
00029 #include <stdio.h>
00030 #include <stdlib.h>
00031 #include <string.h>
00032 #else
00033 #include <cstdio>
00034 #include <cstdlib>
00035 #include <cstring>
00036 #endif
00037
00038 #include <iostream>
00039 #include <iomanip>
00040 #include <new>
00041
00042 #include <BoxLib.H>
00043 #include <BLVERSION.H>
00044 #include <DistributionMapping.H>
00045 #include <FArrayBox.H>
00046 #include <ParallelDescriptor.H>
00047 #include <ParmParse.H>
00048 #include <Utility.H>
00049
00050 #define bl_str(s) # s
00051 #define bl_xstr(s) bl_str(s)
00052
00053
00054
00055
00056
00057 const char * const version =
00058
00059 "boxlib version "
00060 bl_xstr(BL_VERSION_MAJOR)
00061 "."
00062 bl_xstr(BL_VERSION_MINOR)
00063 " built "
00064 __DATE__
00065 " at "
00066 __TIME__;
00067
00068 #undef bl_str
00069 #undef bl_xstr
00070
00071
00072
00073
00074
00075
00076
00077 static
00078 void
00079 write_to_stderr_without_buffering (const char* str)
00080 {
00081
00082
00083
00084 fflush(NULL);
00085
00086 if (str)
00087 {
00088
00089
00090
00091 const char * const end = " !!!\n";
00092 fwrite(str, strlen(str), 1, stderr);
00093 fwrite(end, strlen(end), 1, stderr);
00094 }
00095 }
00096
00097 void
00098 BL_this_is_a_dummy_routine_to_force_version_into_executable ()
00099 {
00100 write_to_stderr_without_buffering(version);
00101 }
00102
00103 static
00104 void
00105 write_lib_id(const char* msg)
00106 {
00107 fflush(0);
00108 const char* const boxlib = "BoxLib::";
00109 fwrite(boxlib, strlen(boxlib), 1, stderr);
00110 if ( msg )
00111 {
00112 fwrite(msg, strlen(msg), 1, stderr);
00113 fwrite("::", 2, 1, stderr);
00114 }
00115 }
00116
00117 void
00118 BoxLib::Error (const char* msg)
00119 {
00120 write_lib_id("Error");
00121 write_to_stderr_without_buffering(msg);
00122 ParallelDescriptor::Abort();
00123 }
00124
00125 void
00126 BoxLib::Abort (const char* msg)
00127 {
00128 write_lib_id("Abort");
00129 write_to_stderr_without_buffering(msg);
00130 ParallelDescriptor::Abort();
00131 }
00132
00133 void
00134 BoxLib::Warning (const char* msg)
00135 {
00136 if (msg)
00137 {
00138 std::cerr << msg << '!' << '\n';
00139 }
00140 }
00141
00142 void
00143 BoxLib::Assert (const char* EX,
00144 const char* file,
00145 int line)
00146 {
00147 const int DIMENSION = 1024;
00148
00149 char buf[DIMENSION+1];
00150
00151 sprintf(buf,
00152 "Assertion `%s' failed, file \"%s\", line %d",
00153 EX,
00154 file,
00155 line);
00156
00157
00158
00159 buf[DIMENSION] = 0;
00160
00161 write_to_stderr_without_buffering(buf);
00162
00163 ParallelDescriptor::Abort();
00164 }
00165
00166 void
00167 BoxLib::OutOfMemory (const char* file,
00168 int line)
00169 {
00170 BoxLib::Assert("operator new", file, line);
00171 }
00172
00173 namespace
00174 {
00175 }
00176
00177 void
00178 BoxLib::Initialize (int& argc, char**& argv)
00179 {
00180
00181 #ifndef WIN32
00182
00183
00184
00185 std::set_new_handler(BoxLib::OutOfMemory);
00186 #endif
00187
00188
00189 ParallelDescriptor::StartParallel(&argc, &argv);
00190
00191 if (argc == 1)
00192 {
00193 ParmParse::Initialize(0,0,0);
00194 }
00195 else
00196 {
00197 if (strchr(argv[1],'='))
00198 {
00199 ParmParse::Initialize(argc-1,argv+1,0);
00200 }
00201 else
00202 {
00203 ParmParse::Initialize(argc-2,argv+2,argv[1]);
00204 }
00205 }
00206
00207
00208
00209
00210 BoxLib::InitRandom(ParallelDescriptor::MyProc() + 1);
00211
00212 FArrayBox::Initialize();
00213
00214 DistributionMapping::Initialize();
00215
00216 std::cout << std::setprecision(10);
00217 }
00218
00219 void
00220 BoxLib::Finalize ()
00221 {
00222 DistributionMapping::Finalize();
00223 FArrayBox::Finalize();
00224 ParmParse::Finalize();
00225 ParallelDescriptor::EndParallel();
00226 }