TIMPI
timpi_assert.C
Go to the documentation of this file.
1 // The TIMPI Message-Passing Parallelism Library.
2 // Copyright (C) 2002-2025 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 // Local includes
20 #include "timpi/timpi_assert.h"
21 
22 // TIMPI includes
23 #include "timpi/timpi_config.h"
24 #include "timpi/communicator.h"
25 
26 namespace TIMPI
27 {
28 
29 void report_here(const char * file, int line, const char * date, const char * time)
30 {
31  std::ostringstream here_msg; // Build in one buffer to reduce interleaving
32 #ifdef TIMPI_HAVE_MPI
33  TIMPI::Communicator commworld(MPI_COMM_WORLD);
34  const std::size_t proc_id = commworld.rank();
35  here_msg << "[" << proc_id << "] ";
36 #endif
37  here_msg << file << ", line " << line << ", compiled "
38  << date << " at " << time << std::endl;
39  std::cerr << here_msg.str();
40 }
41 
42 
43 void report_error(const char * file, int line, const char * date, const char * time)
44 {
45  // It is possible to have an error *inside* report_error; e.g. when
46  // we start using a TIMPI::print_trace. Don't infinitely recurse.
47  static bool reporting_error = false;
48  if (reporting_error)
49  {
50  // I heard you like error reporting, so we put an error report
51  // in report_error() so you can report errors from the report.
52  std::cerr << "TIMPI encountered an error while attempting to report_error." << std::endl;
53  return;
54  }
55  reporting_error = true;
56 
57  report_here(file, line, date, time);
58 
59  reporting_error = false;
60 }
61 
62 } // namespace TIMPI
processor_id_type rank() const
Definition: communicator.h:208
void report_error(const char *file, int line, const char *date, const char *time)
Definition: timpi_assert.C:43
Encapsulates the MPI_Comm object.
Definition: communicator.h:108
void report_here(const char *file, int line, const char *date, const char *time)
Definition: timpi_assert.C:29