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