Vlasiator ebf0dd394 on dev (v5.4.0 + 1054 commits)
Loading...
Searching...
No Matches
common.cpp
Go to the documentation of this file.
1/*
2 * This file is part of Vlasiator.
3 * Copyright 2010-2016 Finnish Meteorological Institute
4 *
5 * For details of usage, see the COPYING file and read the "Rules of the Road"
6 * at http://www.physics.helsinki.fi/vlasiator/
7 *
8 * This program is free software; you can redistribute it and/or modify
9 * it under the terms of the GNU General Public License as published by
10 * the Free Software Foundation; either version 2 of the License, or
11 * (at your option) any later version.
12 *
13 * This program is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 * GNU General Public License for more details.
17 *
18 * You should have received a copy of the GNU General Public License along
19 * with this program; if not, write to the Free Software Foundation, Inc.,
20 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
21 */
22#include <mpi.h>
23#include <iostream>
24#include <string.h>
25#include <stdio.h>
26#include "common.h"
27
37 const bool condition,
38 const std::string& message,
39 const char * const file,
40 const int line
41) {
42 #pragma omp critical
43 {
44 if (condition && (globalflags::bailingOut == 0)) {
45 int myRank;
46 MPI_Comm_rank(MPI_COMM_WORLD,&myRank);
47 std::cerr << "Process " << myRank << " bailing out";
48 if((strcmp(file, "") != 0) && (line != 0)) {
49 std::cerr << " at " << file << ":" << line;
50 }
51 std::cerr << ".";
52 if(strcmp(message.c_str(), "") != 0) {
53 std::cerr << " " << message;
54 }
55 std::cerr << std::endl;
57 }
58 }
59}
60
69 const bool condition,
70 const char * const file,
71 const int line
72) {
73 bailout(condition, "", file, line);
74}
75
83 const bool condition,
84 const std::string& message
85) {
86 bailout(condition, message, "", 0);
87}
88
90[[ noreturn ]] void abort_mpi(const std::string str, const int err_type) {
91 // Single string so output isn't mangled by multiple processes
92 std::cerr << (err_type ? std::string(__FILE__) + ":" + std::to_string(__LINE__) + ": " + str : str) + "\n";
93 MPI_Abort(MPI_COMM_WORLD, 1);
94
95 // Dummy abort to convince compiler function doesn't return
96 // TODO replace with std::unreachable once we switch to C++23
97 abort();
98}
Binary file
Definition Dispersion.m:11
void abort_mpi(const std::string str, const int err_type)
Definition common.cpp:90
void bailout(const bool condition, const std::string &message, const char *const file, const int line)
A function to stop the simulation if the boolean condition is true. Raises a flag which gets MPI_Redu...
Definition common.cpp:36
#define str(s)
int myRank
Definition gpu_base.cpp:48
static int bailingOut
Definition common.h:538