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