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
00027
00028
00029
00030
00031 #include "Sundance.hpp"
00032 #include "Teuchos_CommandLineProcessor.hpp"
00033 #include "Teuchos_MPIComm.hpp"
00034 #include "Teuchos_MPISession.hpp"
00035 #include "SundanceAssembler.hpp"
00036 #include "SundanceQuadratureIntegral.hpp"
00037 #include "SundanceQuadratureEvalMediator.hpp"
00038 #include "SundanceDiscreteFuncEvaluator.hpp"
00039 #include "SundanceRefIntegral.hpp"
00040 #include "SundancePathUtils.hpp"
00041 #include "SundanceEvaluator.hpp"
00042 #include "SundanceEvalVector.hpp"
00043 #include "SundanceCellJacobianBatch.hpp"
00044 #include "SundanceUnaryFunctor.hpp"
00045 #include "SundanceGrouperBase.hpp"
00046 #include "SundanceSparsitySuperset.hpp"
00047 #include "SundanceDefaultPath.hpp"
00048 #include "SundanceDOFMapBuilder.hpp"
00049 #include "SundanceVersionString.hpp"
00050 #include "SundanceProductTransformation.hpp"
00051 #include <unistd.h>
00052 #ifndef _MSC_VER
00053 #include <sys/unistd.h>
00054 #else
00055 #include "winprocess.h"
00056 #endif
00057 #ifdef HAVE_MPI
00058 #include "mpi.h"
00059 #endif
00060
00061 #ifndef HAVE_TEUCHOS_EXPLICIT_INSTANTIATION
00062 #include "TSFLinearOperatorImpl.hpp"
00063 #endif
00064
00065 namespace Sundance
00066 {
00067
00068 void handleException(std::exception& e)
00069 {SundanceGlobal::handleException(e);}
00070
00071
00072 bool passFailTest(bool pass)
00073 {return SundanceGlobal::passFailTest(pass);}
00074
00075 bool passFailTest(double error, double tol)
00076 {return SundanceGlobal::passFailTest(error, tol);}
00077
00078
00079 bool passFailTest(const std::string& statusMsg,
00080 bool status, double error, double tol)
00081 {return SundanceGlobal::passFailTest(statusMsg, status, error, tol);}
00082
00083 int& testStatus()
00084 {return SundanceGlobal::testStatus();}
00085
00086
00087 CommandLineProcessor& clp()
00088 {return SundanceGlobal::clp();}
00089
00090
00091 int init(int* argc, char*** argv)
00092 {return SundanceGlobal::init(argc, argv);}
00093
00094
00095 int finalize() {return SundanceGlobal::finalize();}
00096
00097
00098
00099 void setOption(const std::string& optionName,
00100 int& value,
00101 const std::string& helpMsg)
00102 {
00103 SundanceGlobal::setOption(optionName, value, helpMsg);
00104 }
00105
00106 void setOption(const std::string& optionName,
00107 double& value,
00108 const std::string& helpMsg)
00109 {
00110 SundanceGlobal::setOption(optionName, value, helpMsg);
00111 }
00112
00113 void setOption(const std::string& optionName,
00114 std::string& value,
00115 const std::string& helpMsg)
00116 {
00117 SundanceGlobal::setOption(optionName, value, helpMsg);
00118 }
00119
00120 void setOption(const std::string& optionTrueName,
00121 const std::string& optionFalseName,
00122 bool& value,
00123 const std::string& helpMsg)
00124 {
00125 SundanceGlobal::setOption(optionTrueName,
00126 optionFalseName,
00127 value,
00128 helpMsg);
00129 }
00130 }
00131
00132 static Time& totalTimer()
00133 {
00134 static RCP<Time> rtn
00135 = TimeMonitor::getNewTimer("total Sundance time");
00136 return *rtn;
00137 }
00138
00139 int SundanceGlobal::init(int* argc, char*** argv)
00140 {
00141
00142 try
00143 {
00144
00145
00146 globalMPISession(argc, (char***) argv);
00147
00148
00149 totalTimer().start();
00150
00151 Tabs tab;
00152
00153
00154 std::string configFilename = "";
00155
00156 bool defaultFpCheck = false;
00157 bool debugWait = false;
00158 bool showVersion = false;
00159 bool showBanner = true;
00160 bool showTimings = false;
00161 bool cmdFpCheck = defaultFpCheck;
00162 int defaultWorkSetSize = 400;
00163 int cmdWorkSetSize = defaultWorkSetSize;
00164
00165 Assembler::workSetSize() = defaultWorkSetSize;
00166
00167 clp().setOption("config", &configFilename, "Configuration file");
00168 clp().setOption("fpcheck", "nofpcheck", &cmdFpCheck,
00169 "Check results of math lib calls in expr evals");
00170 clp().setOption("version", "noversion", &showVersion,
00171 "Show Sundance version number and exit");
00172 clp().setOption("banner", "nobanner", &showBanner,
00173 "Show Sundance banner on root processor at start of run");
00174 clp().setOption("timings", "notimings", &showTimings,
00175 "Show timings at end of run");
00176
00177 clp().setOption("workset", &cmdWorkSetSize,
00178 "Work set size");
00179
00180
00181 clp().setOption("debug", "nodebug", &debugWait, "Whether to attach a debugger to this process, holding until 'wait' is set to 0");
00182
00183
00184 clp().throwExceptions(false);
00185 clp().recogniseAllOptions(false);
00186
00187 CommandLineProcessor::EParseCommandLineReturn rtn
00188 = clp().parse(*argc, (char**) *argv);
00189
00190 TEST_FOR_EXCEPTION(rtn != CommandLineProcessor::PARSE_SUCCESSFUL,
00191 RuntimeError,
00192 "Command-line parsing failed");
00193
00194
00195 if (showVersion)
00196 {
00197 if (MPIComm::world().getRank()==0)
00198 {
00199 cout << "Simulation built using Sundance version "
00200 << VersionString::number()
00201 << " (" << VersionString::date() << ")" << std::endl;
00202
00203 cout << "Sundance is copyright (C) 2005 Sandia National Laboratories and is"
00204 << std::endl;
00205 cout << "licensed under the GNU Lesser General Public License, version 2.1" << std::endl;
00206 cout << tab << std::endl;
00207 exit(0);
00208 }
00209 }
00210 if (showBanner && MPIComm::world().getRank()==0)
00211 {
00212 cout << "Simulation built using Sundance version "
00213 << VersionString::number()
00214 << " (" << VersionString::date() << ")" << std::endl;
00215
00216 cout << "Sundance is copyright"
00217 << std::endl << " (C) 2005-2008 Sandia National Laboratories "
00218 << std::endl
00219 << " (C) 2007-2008 Texas Tech University"
00220 << std::endl;
00221 cout << "and is licensed under the GNU Lesser General Public License, version 2.1" << std::endl;
00222 cout << tab << std::endl;
00223 }
00224
00225 if (!showTimings) skipTimingOutput() = true;
00226
00227
00228 if (debugWait)
00229 {
00230 int wait=1;
00231 int pid = getpid();
00232 std::string myCommandName=((char**)(*argv))[0];
00233 std::string debugCmd = "ddd --gdb -x ~/.gdbinit " + myCommandName
00234 + " " + Teuchos::toString(pid) + " &";
00235 cout << "launching " << debugCmd << std::endl;
00236 system(debugCmd.c_str());
00237 while (wait) {;}
00238 }
00239
00240
00241 bool worksetSetOnCmdLine = cmdWorkSetSize != defaultWorkSetSize;
00242 if (worksetSetOnCmdLine)
00243 {
00244 Assembler::workSetSize() = (int) cmdWorkSetSize;
00245 }
00246 }
00247 catch(std::exception& e)
00248 {
00249 handleException(e);
00250 return 1;
00251 }
00252 return 0;
00253 }
00254
00255
00256 bool& SundanceGlobal::showStartupMessage()
00257 {
00258 #ifdef TRILINOS_6
00259 static bool rtn=false;
00260 return rtn;
00261 #else
00262 return MPISession::showStartupMessage();
00263 #endif
00264 }
00265
00266
00267
00268 void SundanceGlobal::handleException(std::exception& e)
00269 {
00270 cout << "Sundance detected exception: " << std::endl;
00271 cout << e.what() << std::endl;
00272 cout << "test FAILED" << std::endl;
00273 testStatus() = -1;
00274 }
00275
00276
00277 int SundanceGlobal::finalize()
00278 {
00279 totalTimer().stop();
00280
00281 try
00282 {
00283 Tabs tab;
00284 if (false && MPIComm::world().getRank()==0)
00285 {
00286 cout << tab << "eval vector flops: " << EvalVector::totalFlops() << std::endl;
00287 cout << tab << "quadrature flops: " << QuadratureIntegral::totalFlops() << std::endl;
00288 cout << tab << "ref integration flops: "
00289 << RefIntegral::totalFlops() << std::endl;
00290 cout << tab << "cell jacobian batch flops: " << CellJacobianBatch::totalFlops() << std::endl;
00291 cout << tab << "quadrature eval mediator: " << QuadratureEvalMediator::totalFlops() << std::endl;
00292 }
00293
00294 if (!skipTimingOutput()) TimeMonitor::summarize();
00295
00296 }
00297 catch(std::exception& e)
00298 {
00299 handleException(e);
00300 return 1;
00301 }
00302 return 0;
00303 }
00304
00305
00306
00307
00308
00309
00310 bool SundanceGlobal::checkTest(double error, double tol)
00311 {
00312 int myFail = error > tol;
00313 int anyFail = myFail;
00314 MPIComm::world().allReduce((void*) &myFail, (void*) &anyFail, 1, MPIComm::INT,
00315 MPIComm::SUM);
00316 return (anyFail == 0);
00317 }
00318
00319 bool SundanceGlobal:: passFailTest(double error, double tol)
00320 {
00321 bool pass;
00322 if (MPIComm::world().getRank()==0)
00323 {
00324 cout << "error norm = " << error << std::endl;
00325 cout << "tolerance = " << tol << std::endl;
00326 }
00327 pass = checkTest(error, tol);
00328 if (MPIComm::world().getRank()==0)
00329 {
00330 if (pass)
00331 {
00332 cout << "test PASSED" << std::endl;
00333 }
00334 else
00335 {
00336 cout << "test FAILED" << std::endl;
00337 }
00338 }
00339 testStatus() = pass!=true;
00340 return pass;
00341 }
00342
00343
00344 bool SundanceGlobal:: passFailTest(const std::string& statusMsg,
00345 bool status, double error, double tol)
00346 {
00347 bool pass;
00348 if (MPIComm::world().getRank()==0)
00349 {
00350
00351 cout << statusMsg << ": ";
00352 if (status) cout << "true" << std::endl;
00353 else cout << "false" << std::endl;
00354 cout << "error norm = " << error << std::endl;
00355 cout << "tolerance = " << tol << std::endl;
00356 }
00357 pass = checkTest(error, tol);
00358 if (MPIComm::world().getRank()==0)
00359 {
00360 if (status && pass)
00361 {
00362 cout << "test PASSED" << std::endl;
00363 }
00364 else
00365 {
00366 cout << "test FAILED" << std::endl;
00367 }
00368 }
00369 testStatus() = pass!=true;
00370 return pass;
00371 }
00372
00373 bool SundanceGlobal:: passFailTest(bool pass)
00374 {
00375 if (MPIComm::world().getRank()==0)
00376 {
00377 if (pass)
00378 {
00379 cout << "test PASSED" << std::endl;
00380 }
00381 else
00382 {
00383 cout << "test FAILED" << std::endl;
00384 }
00385 }
00386 testStatus() = pass!=true;
00387 return pass;
00388 }
00389
00390
00391 void SundanceGlobal::setOption(const std::string& optionName,
00392 int& value,
00393 const std::string& helpMsg)
00394 {
00395 clp().setOption(optionName.c_str(), &value, helpMsg.c_str());
00396 }
00397
00398 void SundanceGlobal::setOption(const std::string& optionName,
00399 double& value,
00400 const std::string& helpMsg)
00401 {
00402 clp().setOption(optionName.c_str(), &value, helpMsg.c_str());
00403 }
00404
00405 void SundanceGlobal::setOption(const std::string& optionName,
00406 std::string& value,
00407 const std::string& helpMsg)
00408 {
00409 clp().setOption(optionName.c_str(), &value, helpMsg.c_str());
00410 }
00411
00412 void SundanceGlobal::setOption(const std::string& optionTrueName,
00413 const std::string& optionFalseName,
00414 bool& value,
00415 const std::string& helpMsg)
00416 {
00417 clp().setOption(optionTrueName.c_str(),
00418 optionFalseName.c_str(),
00419 &value,
00420 helpMsg.c_str());
00421 }
00422
00423