libmesh_common.C
Go to the documentation of this file.
1 // The libMesh Finite Element Library.
2 // Copyright (C) 2002-2018 Benjamin S. Kirk, John W. Peterson, Roy H. Stogner
3 
4 // This library is free software; you can redistribute it and/or
5 // modify it under the terms of the GNU Lesser General Public
6 // License as published by the Free Software Foundation; either
7 // version 2.1 of the License, or (at your option) any later version.
8 
9 // This library is distributed in the hope that it will be useful,
10 // but WITHOUT ANY WARRANTY; without even the implied warranty of
11 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 // Lesser General Public License for more details.
13 
14 // You should have received a copy of the GNU Lesser General Public
15 // License along with this library; if not, write to the Free Software
16 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
17 
18 
19 // libmesh includes
20 #include "libmesh/libmesh.h"
21 #include "libmesh/libmesh_common.h"
22 #include "libmesh/print_trace.h"
23 
24 // C/C++ includes
25 #ifdef LIBMESH_HAVE_SYS_TYPES_H
26 #include <sys/types.h>
27 #endif
28 #ifdef LIBMESH_HAVE_UNISTD_H
29 #include <unistd.h> // needed for getpid()
30 #endif
31 
32 #ifdef LIBMESH_HAVE_CSIGNAL
33 # include <csignal>
34 #endif
35 
36 namespace libMesh
37 {
38 
39 namespace MacroFunctions
40 {
41 void here(const char * file, int line, const char * date, const char * time)
42 {
43  libMesh::err << "[" << static_cast<std::size_t>(libMesh::global_processor_id()) << "] "
44  << file
45  << ", line " << line
46  << ", compiled " << date
47  << " at " << time
48  << std::endl;
49 }
50 
51 
52 
53 void stop(const char * file, int line, const char * date, const char * time)
54 {
56  {
57  libMesh::MacroFunctions::here(file, line, date, time);
58 #if defined(LIBMESH_HAVE_CSIGNAL) && defined(SIGSTOP)
59  libMesh::out << "Stopping process " << getpid() << "..." << std::endl;
60  std::raise(SIGSTOP);
61  libMesh::out << "Continuing process " << getpid() << "..." << std::endl;
62 #else
63  libMesh::out << "WARNING: libmesh_stop() does not work; no operating system support." << std::endl;
64 #endif
65  }
66 }
67 
68 
69 void report_error(const char * file, int line, const char * date, const char * time)
70 {
71  // It is possible to have an error *inside* report_error; e.g. from
72  // print_trace. We don't want to infinitely recurse.
73  static bool reporting_error = false;
74  if (reporting_error)
75  {
76  // I heard you like error reporting, so we put an error report
77  // in report_error() so you can report errors from the report.
78  libMesh::err << "libMesh encountered an error while attempting to report_error." << std::endl;
79  return;
80  }
81  reporting_error = true;
82 
83  if (libMesh::global_n_processors() == 1 ||
84  libMesh::on_command_line("--print-trace"))
86  else
88  libMesh::MacroFunctions::here(file, line, date, time);
89 
90  reporting_error = false;
91 }
92 
93 } // namespace MacroFunctions
94 } // namespace libMesh
processor_id_type global_n_processors()
Definition: libmesh_base.h:75
void write_traceout()
Definition: print_trace.C:233
void print_trace(std::ostream &out_stream)
Definition: print_trace.C:196
void stop(const char *file, int line, const char *date, const char *time)
OStreamProxy err(std::cerr)
void here(const char *file, int line, const char *date, const char *time)
processor_id_type global_processor_id()
Definition: libmesh_base.h:85
bool on_command_line(std::string arg)
Definition: libmesh.C:876
void report_error(const char *file, int line, const char *date, const char *time)
OStreamProxy out(std::cout)