Yet Another eXchange Tool  0.9.0
core.h
Go to the documentation of this file.
1 
8 /*
9  * Maintainer: Thomas Jahns <jahns@dkrz.de>
10  * URL: https://www.dkrz.de/redmine/projects/scales-ppm
11  *
12  * Redistribution and use in source and binary forms, with or without
13  * modification, are permitted provided that the following conditions are
14  * met:
15  *
16  * Redistributions of source code must retain the above copyright notice,
17  * this list of conditions and the following disclaimer.
18  *
19  * Redistributions in binary form must reproduce the above copyright
20  * notice, this list of conditions and the following disclaimer in the
21  * documentation and/or other materials provided with the distribution.
22  *
23  * Neither the name of the DKRZ GmbH nor the names of its contributors
24  * may be used to endorse or promote products derived from this software
25  * without specific prior written permission.
26  *
27  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS
28  * IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
29  * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A
30  * PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER
31  * OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
32  * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
33  * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
34  * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
35  * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
36  * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
37  * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
38  *
39  * Commentary:
40  *
41  * The code in this file should be restricted to handle those parts
42  * the user program should keep as much control about as possible,
43  * like
44  *
45  * - error handling
46  * - file handling
47  *
48  * Thus the facilities provided here should always come with hooks
49  * for user-provided mechanisms.
50  *
51  * Code:
52  */
53 #ifndef PPM_CORE_H
54 #define PPM_CORE_H
55 #ifdef HAVE_CONFIG_H
56 #include <config.h>
57 #endif
58 #ifdef USE_MPI
59 #include <mpi.h>
60 #else
64 typedef int MPI_Comm;
68 typedef int MPI_Fint;
72 enum {
75 };
76 #endif
77 
78 #include "core/symprefix.h"
79 
80 /* If we're not using GNU C, elide __attribute__ */
81 #ifndef __GNUC__
82 # define __attribute__(x) /*NOTHING*/
83 #endif
84 #define XT_UNUSED(x) UNUSED_ ## x __attribute__((__unused__))
85 
86 
90 typedef void (*SymPrefix(abort_func))(MPI_Comm comm, const char *msg,
91  const char *source, int line)
92  __attribute__((noreturn));
96 extern SymPrefix(abort_func) SymPrefix(abort);
97 
101 void
103 
107 extern MPI_Comm SymPrefix(default_comm);
108 
120 extern void
121 SymPrefix(abort_default)(MPI_Comm comm, const char *msg,
122  const char *source, int line)
123  __attribute__((noreturn));
124 
128 extern void
130 
131 #define die(msg) \
132  SymPrefix(abort)(SymPrefix(default_comm), (msg), __FILE__, __LINE__)
133 
134 #ifdef USE_MPI
135 static inline int
136 SymPrefix(mpi_calls_are_allowed)(void)
137 {
138  int init_flag = 0, finished_flag = 0;
139  return MPI_Initialized(&init_flag) == MPI_SUCCESS && init_flag
140  && MPI_Finalized(&finished_flag) == MPI_SUCCESS && !finished_flag;
141 }
142 #endif
143 
144 #endif
145 /*
146  * Local Variables:
147  * license-project-url: "https://www.dkrz.de/redmine/projects/scales-ppm"
148  * license-default: "bsd"
149  * license-markup: "doxygen"
150  * End:
151  */
@ MPI_COMM_WORLD
Definition: core.h:73
@ MPI_COMM_NULL
Definition: core.h:74
int MPI_Fint
Definition: core.h:68
void SymPrefix() restore_default_abort_handler(void)
int MPI_Comm
Definition: core.h:64
void SymPrefix() set_default_comm(MPI_Comm comm)
SymPrefix(abort_func) SymPrefix(abort)
Definition: core.c:127
#define __attribute__(x)
Definition: core.h:82
void SymPrefix() abort_default(MPI_Comm comm, const char *msg, const char *source, int line) __attribute__((noreturn))
Definition: core.c:110
Define library-specific symbol prefix macros.