ExecutableSupport.cpp

00001 /*
00002 
00003 Copyright (C) University of Oxford, 2005-2010
00004 
00005 University of Oxford means the Chancellor, Masters and Scholars of the
00006 University of Oxford, having an administrative office at Wellington
00007 Square, Oxford OX1 2JD, UK.
00008 
00009 This file is part of Chaste.
00010 
00011 Chaste is free software: you can redistribute it and/or modify it
00012 under the terms of the GNU Lesser General Public License as published
00013 by the Free Software Foundation, either version 2.1 of the License, or
00014 (at your option) any later version.
00015 
00016 Chaste is distributed in the hope that it will be useful, but WITHOUT
00017 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
00018 FITNESS FOR A PARTICULAR PURPOSE.  See the GNU Lesser General Public
00019 License for more details. The offer of Chaste under the terms of the
00020 License is subject to the License being interpreted in accordance with
00021 English Law and subject to any action against the University of Oxford
00022 being under the jurisdiction of the English Courts.
00023 
00024 You should have received a copy of the GNU Lesser General Public License
00025 along with Chaste. If not, see <http://www.gnu.org/licenses/>.
00026 
00027 */
00028 
00029 #include "ExecutableSupport.hpp"
00030 
00031 #include <iostream>
00032 
00033 #include "CommandLineArguments.hpp"
00034 #include "Exception.hpp"
00035 #include "PetscTools.hpp"
00036 #include "PetscException.hpp"
00037 #include "Version.hpp"
00038 #include "OutputFileHandler.hpp"
00039 #include <sys/utsname.h>
00040 
00041 #include "ChasteSerialization.hpp"
00042 #include <hdf5.h>
00043 
00044 #ifdef CHASTE_VTK
00045 #define _BACKWARD_BACKWARD_WARNING_H 1 //Cut out the strstream deprecated warning for now (gcc4.3)
00046 #include <vtkVersion.h>
00047 #endif
00048 
00049 #ifdef CHASTE_CVODE
00050 #include <sundials/sundials_config.h>
00051 #endif
00052 //#include <xsd/cxx/version.hxx>
00053 
00054 std::string ExecutableSupport::mOutputDirectory;
00055 
00056 void ExecutableSupport::SetOutputDirectory(const std::string& rOutputDirectory)
00057 {
00058     mOutputDirectory = rOutputDirectory;
00059 }
00060 
00061 void ExecutableSupport::InitializePetsc(int* pArgc, char*** pArgv)
00062 {
00063     // Store the arguments in case other code needs them
00064     CommandLineArguments::Instance()->p_argc = pArgc;
00065     CommandLineArguments::Instance()->p_argv = pArgv;
00066     // Initialise PETSc
00067     PETSCEXCEPT(PetscInitialize(pArgc, pArgv, PETSC_NULL, PETSC_NULL));
00068 }
00069 
00070 void ExecutableSupport::ShowCopyright()
00071 {
00072     //Compilation information
00073     std::stringstream provenance_msg;
00074     provenance_msg << "This version of Chaste was compiled on:\n";
00075     provenance_msg << ChasteBuildInfo::GetBuildTime() << " by " << ChasteBuildInfo::GetBuilderUnameInfo() << " (uname)\n";
00076     provenance_msg << "from revision number " << ChasteBuildInfo::GetRevisionNumber() << " with build type " << ChasteBuildInfo::GetBuildInformation() << ".\n\n";
00077 
00078     //Only show one copy of copyright/header
00079     if (PetscTools::AmMaster())
00080     {
00081         std::cout << "Copyright (C) University of Oxford, 2005-2010 \n\n\
00082 \
00083 Chaste is free software: you can redistribute it and/or modify \n\
00084 it under the terms of the Lesser GNU General Public License as published by \n\
00085 the Free Software Foundation, either version 2.1 of the License, or \n\
00086 (at your option) any later version. \n\n\
00087 \
00088 Chaste is distributed in the hope that it will be useful, \n\
00089 but WITHOUT ANY WARRANTY; without even the implied warranty of \n\
00090 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the \n\
00091 Lesser GNU General Public License for more details. \n\n\
00092 \
00093 You should have received a copy of the Lesser GNU General Public License \n\
00094 along with Chaste.  If not, see <http://www.gnu.org/licenses/>.\n\n";
00095 
00096         //Write provenance information to stdout
00097         std::cout << provenance_msg.str() << std::flush;
00098     }
00099 }
00100 
00101 void ExecutableSupport::ShowParallelLaunching()
00102 {
00103     if (!PetscTools::IsSequential())
00104     {
00106         for (unsigned i=0; i<PetscTools::GetNumProcs(); i++)
00107         {
00108             if (i==PetscTools::GetMyRank())
00109             {
00110                 std::cout << "Chaste launched on process " << PetscTools::GetMyRank()
00111                     << " of " << PetscTools::GetNumProcs() << "." << std::endl << std::flush;
00112             }
00113             PetscTools::Barrier();
00114         }
00115     }
00116 }
00117 
00118 void ExecutableSupport::WriteMachineInfoFile(std::string fileBaseName)
00119 {
00120     OutputFileHandler out_file_handler(mOutputDirectory, false);
00121     std::stringstream file_name;
00122     file_name << fileBaseName << "_" << PetscTools::GetMyRank() << ".txt";
00123     out_stream out_file = out_file_handler.OpenOutputFile(file_name.str());
00124     *out_file << "Process " << PetscTools::GetMyRank() << " of "
00125         << PetscTools::GetNumProcs() << "." << std::endl << std::flush;
00126 
00127     struct utsname uts_info;
00128     uname(&uts_info);
00129 
00130     *out_file << "uname sysname  = " << uts_info.sysname << std::endl << std::flush;
00131     *out_file << "uname nodename = " << uts_info.nodename << std::endl << std::flush;
00132     *out_file << "uname release  = " << uts_info.release << std::endl << std::flush;
00133     *out_file << "uname version  = " << uts_info.version << std::endl << std::flush;
00134     *out_file << "uname machine  = " << uts_info.machine << std::endl << std::flush;
00135     char buffer[100];
00136     FILE * system_info;
00137 
00138     *out_file << "\nInformation on number and type of processors:\n";
00139     system_info = popen("grep ^model.name /proc/cpuinfo", "r");
00140     while ( fgets(buffer, 100, system_info) != NULL )
00141     {
00142         *out_file << buffer;
00143     }
00144     fclose(system_info);
00145 
00146     *out_file << "\nInformation on processor caches, in the same order as above:\n";
00147     system_info = popen("grep ^cache.size /proc/cpuinfo", "r");
00148     while ( fgets(buffer, 100, system_info) != NULL )
00149     {
00150         *out_file << buffer;
00151     }
00152     fclose(system_info);
00153 
00154     *out_file << "\nInformation on system memory:\n";
00155     system_info = popen("grep ^MemTotal /proc/meminfo", "r");
00156     while ( fgets(buffer, 100, system_info) != NULL )
00157     {
00158         *out_file << buffer;
00159     }
00160     fclose(system_info);
00161 
00162     out_file->close();
00163 }
00164 
00165 void ExecutableSupport::WriteProvenanceInfoFile()
00166 {
00167     OutputFileHandler out_file_handler(mOutputDirectory, false);
00168     out_stream out_file = out_file_handler.OpenOutputFile("provenance_info_", PetscTools::GetMyRank(), ".txt");
00169 
00170     //Compilation information
00171     std::stringstream provenance_msg;
00172     provenance_msg << "This version of Chaste was compiled on:\n";
00173     provenance_msg << ChasteBuildInfo::GetBuildTime() << " by " << ChasteBuildInfo::GetBuilderUnameInfo() << " (uname)\n";
00174     provenance_msg << "from revision number " << ChasteBuildInfo::GetRevisionNumber() << " with build type " << ChasteBuildInfo::GetBuildInformation() << ".\n\n";
00175     *out_file << provenance_msg.str();
00176 
00177     WriteLibraryInfo( out_file );
00178 
00179     out_file->close();
00180 }
00181 
00182 void ExecutableSupport::WriteLibraryInfo( out_stream &outFile )
00183 {
00184     *outFile << "Compiler: " << ChasteBuildInfo::GetCompilerType()
00185              << ", version " << ChasteBuildInfo::GetCompilerVersion() << std::endl;
00186 
00187     *outFile << "Compiler flags \"" << ChasteBuildInfo::GetCompilerFlags() << "\"" << std::endl;
00188 
00189     *outFile << std::endl;
00190     *outFile << "Library versions: " << std::endl;
00191     *outFile << "  PETSc: " << PETSC_VERSION_MAJOR << "." << PETSC_VERSION_MINOR << "." << PETSC_VERSION_SUBMINOR << std::endl;
00192     *outFile << "  Boost: " << BOOST_VERSION  / 100000 << "." << BOOST_VERSION / 100 % 1000 << "." << BOOST_VERSION % 100 << std::endl;
00193     *outFile << "  HDF5: " << H5_VERS_MAJOR <<  "." << H5_VERS_MINOR << "." << H5_VERS_RELEASE << std::endl;
00194 
00195     *outFile << std::endl;
00196     *outFile << "Binary versions: " << std::endl;
00197     *outFile << "  XSD: " <<  ChasteBuildInfo::GetXsdVersion() << std::endl;
00198 
00199     *outFile << std::endl;
00200     *outFile << "Includes support for: " << std::endl;
00201 
00202 #ifdef CHASTE_VTK
00203     *outFile << "  VTK: " << VTK_MAJOR_VERSION << "." << VTK_MINOR_VERSION << std::endl;
00204 #else
00205     *outFile << "  VTK: no" << std::endl;
00206 #endif
00207 
00208 #ifdef CHASTE_CVODE
00209     *outFile << "  SUNDIALS: " << SUNDIALS_PACKAGE_VERSION << " (includes Cvode of a different version number)" << std::endl;
00210 #else
00211     *outFile << "  SUNDIALS: no" << std::endl;
00212 #endif
00213 
00214 #ifdef CHASTE_ADAPTIVITY
00215     *outFile << "  Adaptivity: yes" << std::endl;
00216 #else
00217     *outFile << "  Adaptivity: no" << std::endl;
00218 #endif
00219 
00220 }
00221 
00222 void ExecutableSupport::StandardStartup(int* pArgc, char*** pArgv)
00223 {
00224     InitializePetsc(pArgc, pArgv);
00225     ShowCopyright();
00226     ShowParallelLaunching();
00227 }
00228 
00229 void ExecutableSupport::PrintError(const std::string& rMessage, bool masterOnly)
00230 {
00231     if (!masterOnly || PetscTools::AmMaster())
00232     {
00233         // Write the error message to stderr
00234         std::cerr << rMessage << std::endl;
00235     }
00236 
00237     // Write the error message to file
00238     OutputFileHandler out_file_handler(mOutputDirectory, false);
00239     out_stream out_file = out_file_handler.OpenOutputFile("chaste_errors_", PetscTools::GetMyRank(), ".txt", std::ios::out | std::ios::app);
00240     *out_file << rMessage << std::endl;
00241     out_file->close();
00242 }
00243 
00244 void ExecutableSupport::FinalizePetsc()
00245 {
00246     PetscFinalize();
00247 }

Generated on Mon Nov 1 12:35:16 2010 for Chaste by  doxygen 1.5.5