Tpetra parallel linear algebra Version of the Day
Loading...
Searching...
No Matches
Tpetra_Details_checkGlobalError.cpp
1// @HEADER
2// *****************************************************************************
3// Tpetra: Templated Linear Algebra Services Package
4//
5// Copyright 2008 NTESS and the Tpetra contributors.
6// SPDX-License-Identifier: BSD-3-Clause
7// *****************************************************************************
8// @HEADER
9
10#include "Tpetra_Details_checkGlobalError.hpp"
12#include "Teuchos_CommHelpers.hpp"
13#include "Teuchos_TestForException.hpp"
14#include <iostream>
15#include <stdexcept>
16
17namespace Tpetra {
18namespace Details {
19
20void
21checkGlobalError(std::ostream& globalOutputStream,
22 const bool localSuccess,
23 const char localErrorMessage[],
24 const char globalErrorMessageHeader[],
25 const Teuchos::Comm<int>& comm)
26{
27 using Teuchos::outArg;
28 using Teuchos::REDUCE_MIN;
29 using Teuchos::reduceAll;
30 using std::endl;
31
32 int lclGood = localSuccess ? 1 : 0;
33 int gblGood = 0;
34 reduceAll(comm, REDUCE_MIN, lclGood, outArg(gblGood));
35 if (gblGood != 1) {
36 const int myRank = comm.getRank();
37 if (myRank == 0) {
38 globalOutputStream << endl << globalErrorMessageHeader
39 << endl;
40 }
41
42 if (localSuccess || localErrorMessage == nullptr) {
43 Details::gathervPrint(globalOutputStream, "", comm);
44 }
45 else {
46 std::ostringstream lclMsg;
47 lclMsg << endl;
48 constexpr int numStars = 60;
49 for (int star = 0; star < numStars; ++star) {
50 lclMsg << '*';
51 }
52 lclMsg << endl << "Proc " << myRank << ": "
53 << localErrorMessage << endl;
54 Details::gathervPrint(globalOutputStream, lclMsg.str(), comm);
55 }
56
57#ifdef HAVE_TPETRA_MPI
58 (void) MPI_Abort(MPI_COMM_WORLD, -1);
59#else
60 TEUCHOS_TEST_FOR_EXCEPTION
61 (true, std::runtime_error, "Tpetra reports a global error.");
62#endif // HAVE_TPETRA_MPI
63 }
64}
65
66} // namespace Details
67} // namespace Tpetra
Declaration of a function that prints strings from each process.
Nonmember function that computes a residual Computes R = B - A * X.
void gathervPrint(std::ostream &out, const std::string &s, const Teuchos::Comm< int > &comm)
On Process 0 in the given communicator, print strings from each process in that communicator,...
Namespace Tpetra contains the class and methods constituting the Tpetra library.