YAC 3.21.0
Yet Another Coupler
Loading...
Searching...
No Matches
core.c
Go to the documentation of this file.
1// SPDX-FileCopyrightText: Thomas Jahns <jahns@dkrz.de>
2//
3// SPDX-License-Identifier: BSD-3-Clause
4
13/*
14 * Keywords: ScalES PPM error handling
15 * Maintainer: Thomas Jahns <jahns@dkrz.de>
16 * URL: https://www.dkrz.de/redmine/projects/scales-ppm
17 *
18 * Redistribution and use in source and binary forms, with or without
19 * modification, are permitted provided that the following conditions are
20 * met:
21 *
22 * Redistributions of source code must retain the above copyright notice,
23 * this list of conditions and the following disclaimer.
24 *
25 * Redistributions in binary form must reproduce the above copyright
26 * notice, this list of conditions and the following disclaimer in the
27 * documentation and/or other materials provided with the distribution.
28 *
29 * Neither the name of the DKRZ GmbH nor the names of its contributors
30 * may be used to endorse or promote products derived from this software
31 * without specific prior written permission.
32 *
33 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS
34 * IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
35 * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A
36 * PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER
37 * OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
38 * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
39 * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
40 * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
41 * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
42 * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
43 * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
44 *
45 * Commentary:
46 *
47 * The code in this file should be restricted to handle those parts
48 * the user program should keep as much control about as possible,
49 * like
50 *
51 * - error handling
52 * - file handling
53 *
54 * Thus the facilities provided here should always come with hooks
55 * for user-provided mechanisms.
56 *
57 * Code:
58 */
59#ifdef HAVE_CONFIG_H
60#include "config.h"
61#endif
62
63#include <stdlib.h>
64#include <stdio.h>
65
66#include <mpi.h>
67
68#include "ppm/core.h"
69#include "ppm/symprefix.h"
70
71static MPI_Comm symprefix(default_comm) = MPI_COMM_WORLD;
72
73void
75{
76 symprefix(default_comm) = comm;
77}
78
79// GCOVR_EXCL_START
80static void
81symprefix(abort_default)(MPI_Comm comm, const char *msg, const char *source, int line)
82{
83 fprintf(stderr, "Fatal error in %s, line %d: %s\n", source, line, msg);
84#if defined (__xlC__) && defined (_AIX)
85#pragma omp critical
86#endif
88 MPI_Abort(comm, 1);
89 abort();
90}
91// GCOVR_EXCL_STOP
92
93static symprefix(abort_func) symprefix(abort_) =
94 (symprefix(abort_func))symprefix(abort_default);
95
96void
97symprefix(abort)(MPI_Comm comm, const char *msg, const char *source, int line) {
98 symprefix(abort_)(comm, msg, source, line);
99}
100
101
102void symprefix(abort_message)(const char *msg, const char *source, int line)
103{
104 symprefix(abort_)(symprefix(default_comm), msg, source, line);
105}
106
107void
112
113void
114symprefix(set_abort_handler)(symprefix(abort_func) custom_abort) {
115 symprefix(abort_) = custom_abort;
116}
117
118symprefix(abort_func)
119symprefix(get_abort_handler)(void) {
120 return symprefix(abort_);
121}
122
123symprefix(abort_func)
124symprefix(get_default_abort_handler)(void) {
125 return (symprefix(abort_func))symprefix(abort_default);
126}
127
129{
130 int init_flag = 0, finished_flag = 0;
131 return MPI_Initialized(&init_flag) == MPI_SUCCESS && init_flag
132 && MPI_Finalized(&finished_flag) == MPI_SUCCESS && !finished_flag;
133}
134
135/*
136 * Local Variables:
137 * license-project-url: "https://www.dkrz.de/redmine/projects/scales-ppm"
138 * license-markup: "doxygen"
139 * license-default: "bsd"
140 * End:
141 */
int symprefix mpi_calls_are_allowed(void)
Definition core.c:128
void symprefix set_abort_handler(symprefix(abort_func) custom_abort)
Definition core.c:114
void symprefix set_default_comm(MPI_Comm comm)
Definition core.c:74
void symprefix restore_default_abort_handler(void)
Definition core.c:108
void symprefix abort_message(const char *msg, const char *source, int line)
Definition core.c:102
static void symprefix abort_default(MPI_Comm comm, const char *msg, const char *source, int line)
Definition core.c:81
void symprefix abort(MPI_Comm comm, const char *msg, const char *source, int line) __attribute__((noreturn))
Define library-specific symbol prefix macros.
#define symprefix(symbol)
Definition symprefix.h:57