$extrastylesheet
libmesh_common.C
Go to the documentation of this file.
00001 // The libMesh Finite Element Library.
00002 // Copyright (C) 2002-2014 Benjamin S. Kirk, John W. Peterson, Roy H. Stogner
00003 
00004 // This library is free software; you can redistribute it and/or
00005 // modify it under the terms of the GNU Lesser General Public
00006 // License as published by the Free Software Foundation; either
00007 // version 2.1 of the License, or (at your option) any later version.
00008 
00009 // This library is distributed in the hope that it will be useful,
00010 // but WITHOUT ANY WARRANTY; without even the implied warranty of
00011 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00012 // Lesser General Public License for more details.
00013 
00014 // You should have received a copy of the GNU Lesser General Public
00015 // License along with this library; if not, write to the Free Software
00016 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
00017 
00018 
00019 // libmesh includes
00020 #include "libmesh/libmesh.h"
00021 #include "libmesh/libmesh_common.h"
00022 #include "libmesh/print_trace.h"
00023 
00024 // C/C++ includes
00025 #include <unistd.h>  // needed for getpid()
00026 
00027 #ifdef LIBMESH_HAVE_CSIGNAL
00028 #  include <csignal>
00029 #endif
00030 
00031 namespace libMesh
00032 {
00033 
00034 namespace MacroFunctions
00035 {
00036 void here(const char* file, int line, const char* date, const char* time)
00037 {
00038   libMesh::err << "[" << static_cast<std::size_t>(libMesh::global_processor_id()) << "] "
00039                << file
00040                << ", line " << line
00041                << ", compiled " << date
00042                << " at " << time
00043                << std::endl;
00044 }
00045 
00046 
00047 
00048 void stop(const char* file, int line, const char* date, const char* time)
00049 {
00050   if (libMesh::global_n_processors() == 1)
00051     {
00052       libMesh::MacroFunctions::here(file, line, date, time);
00053 #ifdef LIBMESH_HAVE_CSIGNAL
00054       libMesh::out << "Stopping process " << getpid() << "..." << std::endl;
00055       std::raise(SIGSTOP);
00056       libMesh::out << "Continuing process " << getpid() << "..." << std::endl;
00057 #else
00058       libMesh::out << "WARNING:  libmesh_stop() does not work without the <csignal> header file!" << std::endl;
00059 #endif
00060     }
00061 }
00062 
00063 
00064 void report_error(const char* file, int line, const char* date, const char* time)
00065 {
00066   // It is possible to have an error *inside* report_error; e.g. from
00067   // print_trace.  We don't want to infinitely recurse.
00068   static bool reporting_error = false;
00069   if (reporting_error)
00070     {
00071       // I heard you like error reporting, so we put an error report
00072       // in report_error() so you can report errors from the report.
00073       libMesh::err << "libMesh encountered an error while attempting to report_error." << std::endl;
00074       return;
00075     }
00076   reporting_error = true;
00077 
00078   if (libMesh::global_n_processors() == 1 ||
00079       // Note: support both 'underscore' and 'dash' flavors of the option
00080       libMesh::on_command_line("--print_trace") ||
00081       libMesh::on_command_line("--print-trace"))
00082     libMesh::print_trace();
00083   else
00084     libMesh::write_traceout();
00085   libMesh::MacroFunctions::here(file, line, date, time);
00086 
00087   reporting_error = false;
00088 }
00089 
00090 } // namespace MacroFunctions
00091 } // namespace libMesh