YAC 3.12.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 "ppm/core.h"
67#include "ppm/symprefix.h"
68
69static MPI_Comm symprefix(default_comm) = MPI_COMM_WORLD;
70
71void
73{
74 symprefix(default_comm) = comm;
75}
76
77// GCOVR_EXCL_START
78static void
79symprefix(abort_default)(MPI_Comm comm, const char *msg, const char *source, int line)
80{
81 fprintf(stderr, "Fatal error in %s, line %d: %s\n", source, line, msg);
82#if defined (__xlC__) && defined (_AIX)
83#pragma omp critical
84#endif
86 MPI_Abort(comm, 1);
87 abort();
88}
89// GCOVR_EXCL_STOP
90
91static symprefix(abort_func) symprefix(abort_) =
92 (symprefix(abort_func))symprefix(abort_default);
93
94void
95symprefix(abort)(MPI_Comm comm, const char *msg, const char *source, int line) {
96 symprefix(abort_)(comm, msg, source, line);
97}
98
99
100void symprefix(abort_message)(const char *msg, const char *source, int line)
101{
102 symprefix(abort_)(symprefix(default_comm), msg, source, line);
103}
104
105void
110
111void
112symprefix(set_abort_handler)(symprefix(abort_func) custom_abort) {
113 symprefix(abort_) = custom_abort;
114}
115
116symprefix(abort_func)
117symprefix(get_abort_handler)(void) {
118 return symprefix(abort_);
119}
120
121symprefix(abort_func)
122symprefix(get_default_abort_handler)(void) {
123 return (symprefix(abort_func))symprefix(abort_default);
124}
125
127{
128 int init_flag = 0, finished_flag = 0;
129 return MPI_Initialized(&init_flag) == MPI_SUCCESS && init_flag
130 && MPI_Finalized(&finished_flag) == MPI_SUCCESS && !finished_flag;
131}
132
133/*
134 * Local Variables:
135 * license-project-url: "https://www.dkrz.de/redmine/projects/scales-ppm"
136 * license-markup: "doxygen"
137 * license-default: "bsd"
138 * End:
139 */
int symprefix mpi_calls_are_allowed(void)
Definition core.c:126
void symprefix set_abort_handler(symprefix(abort_func) custom_abort)
Definition core.c:112
void symprefix set_default_comm(MPI_Comm comm)
Definition core.c:72
void symprefix restore_default_abort_handler(void)
Definition core.c:106
void symprefix abort_message(const char *msg, const char *source, int line)
Definition core.c:100
static void symprefix abort_default(MPI_Comm comm, const char *msg, const char *source, int line)
Definition core.c:79
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