YetAnotherCoupler 3.1.1
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
77static void
78symprefix(abort_default)(MPI_Comm comm, const char *msg, const char *source, int line)
79{
80 fprintf(stderr, "Fatal error in %s, line %d: %s\n", source, line, msg);
81#if defined (__xlC__) && defined (_AIX)
82#pragma omp critical
83#endif
85 MPI_Abort(comm, 1);
86 abort();
87}
88
89static symprefix(abort_func) symprefix(abort_) =
90 (symprefix(abort_func))symprefix(abort_default);
91
92void
93symprefix(abort)(MPI_Comm comm, const char *msg, const char *source, int line) {
94 symprefix(abort_)(comm, msg, source, line);
95}
96
97
98void symprefix(abort_message)(const char *msg, const char *source, int line)
99{
100 symprefix(abort_)(symprefix(default_comm), msg, source, line);
101}
102
103void
108
109void
110symprefix(set_abort_handler)(symprefix(abort_func) custom_abort) {
111 symprefix(abort_) = custom_abort;
112}
113
114symprefix(abort_func)
115symprefix(get_abort_handler)(void) {
116 return symprefix(abort_);
117}
118
119symprefix(abort_func)
120symprefix(get_default_abort_handler)(void) {
121 return (symprefix(abort_func))symprefix(abort_default);
122}
123
124/*
125 * Local Variables:
126 * license-project-url: "https://www.dkrz.de/redmine/projects/scales-ppm"
127 * license-markup: "doxygen"
128 * license-default: "bsd"
129 * End:
130 */
static void symprefix() abort_default(MPI_Comm comm, const char *msg, const char *source, int line)
Definition core.c:78
void symprefix() set_default_comm(MPI_Comm comm)
Definition core.c:72
void symprefix() set_abort_handler(symprefix(abort_func) custom_abort)
Definition core.c:110
void symprefix() abort_message(const char *msg, const char *source, int line)
Definition core.c:98
void symprefix() restore_default_abort_handler(void)
Definition core.c:104
static int SymPrefix() mpi_calls_are_allowed(void)
Definition core.h:135
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:53
#define symprefix(symbol)
Definition symprefix.h:55