Yet Another eXchange Tool  0.9.0
core.c
Go to the documentation of this file.
1 
9 /*
10  * Keywords: ScalES PPM error handling
11  * Maintainer: Thomas Jahns <jahns@dkrz.de>
12  * URL: https://www.dkrz.de/redmine/projects/scales-ppm
13  *
14  * Redistribution and use in source and binary forms, with or without
15  * modification, are permitted provided that the following conditions are
16  * met:
17  *
18  * Redistributions of source code must retain the above copyright notice,
19  * this list of conditions and the following disclaimer.
20  *
21  * Redistributions in binary form must reproduce the above copyright
22  * notice, this list of conditions and the following disclaimer in the
23  * documentation and/or other materials provided with the distribution.
24  *
25  * Neither the name of the DKRZ GmbH nor the names of its contributors
26  * may be used to endorse or promote products derived from this software
27  * without specific prior written permission.
28  *
29  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS
30  * IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
31  * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A
32  * PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER
33  * OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
34  * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
35  * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
36  * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
37  * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
38  * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
39  * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
40  *
41  * Commentary:
42  *
43  * The code in this file should be restricted to handle those parts
44  * the user program should keep as much control about as possible,
45  * like
46  *
47  * - error handling
48  * - file handling
49  *
50  * Thus the facilities provided here should always come with hooks
51  * for user-provided mechanisms.
52  *
53  * Code:
54  */
55 #ifdef HAVE_CONFIG_H
56 # include <config.h>
57 #endif
58 #include <stdio.h>
59 #include <stdlib.h>
60 #ifndef WITHOUT_FORTRAN
61 # if defined __clang__
62 # pragma GCC diagnostic push
63 # pragma GCC diagnostic ignored "-Wreserved-id-macro"
64 # pragma GCC diagnostic ignored "-Wstrict-prototypes"
65 # endif
66 # include <cfortran.h>
67 # if defined __clang__
68 # pragma GCC diagnostic pop
69 # endif
70 #endif
71 #ifdef USE_MPI
72 # include <mpi.h>
73 #endif
74 
75 #include "core/ppm_visibility.h"
76 #include "core/core.h"
77 #include "core/symprefix.h"
78 
80 
81 #ifndef WITHOUT_FORTRAN
82 #define F2C_Data COMMON_BLOCK(SYMPREFIX(F2C_DATA),symprefix(f2c_data))
83 
84 typedef struct
85 {
86  MPI_Fint symprefix(default_comm);
87 } SymPrefix(F2C_Def);
88 
90 
92 #endif
93 
94 void
96 {
97 #ifndef WITHOUT_FORTRAN
98  MPI_Fint comm_f;
99 # if defined(USE_MPI)
100  comm_f = MPI_Comm_c2f(comm);
101 # else
102  comm_f = comm;
103 # endif
104  F2C_Data.symprefix(default_comm) = comm_f;
105 #endif
106  SymPrefix(default_comm) = comm;
107 }
108 
109 void
110 SymPrefix(abort_default)(MPI_Comm comm, const char *msg, const char *source, int line)
111 {
112  fprintf(stderr, "Fatal error in %s, line %d: %s\n", source, line, msg);
113 #ifdef USE_MPI
114 #if defined (__xlC__) && defined (_AIX)
115 #pragma omp critical
116 #endif
117  if (SymPrefix(mpi_calls_are_allowed)())
118  MPI_Abort(comm, 1);
119  else
120  abort();
121 #else
122  (void)comm;
123 #endif
124  abort();
125 }
126 
128 
129 void
131 {
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  */
void SymPrefix() abort_default(MPI_Comm comm, const char *msg, const char *source, int line)
Definition: core.c:110
#define F2C_Data
Definition: core.c:82
COMMON_BLOCK_DEF(SymPrefix(F2C_Def), F2C_Data)
MPI_Comm SymPrefix(default_comm)
@ MPI_COMM_WORLD
Definition: core.h:73
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)
MPI_Fint symprefix(default_comm)
Define library-specific symbol prefix macros.