2 This source code file is part of thread_mpi.
3 Written by Sander Pronk, Erik Lindahl, and possibly others.
5 Copyright (c) 2009, Sander Pronk, Erik Lindahl.
8 Redistribution and use in source and binary forms, with or without
9 modification, are permitted provided that the following conditions are met:
10 1) Redistributions of source code must retain the above copyright
11 notice, this list of conditions and the following disclaimer.
12 2) Redistributions in binary form must reproduce the above copyright
13 notice, this list of conditions and the following disclaimer in the
14 documentation and/or other materials provided with the distribution.
15 3) Neither the name of the copyright holders nor the
16 names of its contributors may be used to endorse or promote products
17 derived from this software without specific prior written permission.
19 THIS SOFTWARE IS PROVIDED BY US ''AS IS'' AND ANY
20 EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
21 WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
22 DISCLAIMED. IN NO EVENT SHALL WE BE LIABLE FOR ANY
23 DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
24 (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
25 LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
26 ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
27 (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
28 SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
30 If you want to redistribute modifications, please consider that
31 scientific software is very special. Version control is crucial -
32 bugs must be traceable. We will be happy to consider code for
33 inclusion in the official distribution, but derived work should not
34 be called official thread_mpi. Details are found in the README & COPYING
38 #ifdef HAVE_TMPI_CONFIG_H
39 #include "tmpi_config.h"
54 #if ! (defined( _WIN32 ) || defined( _WIN64 ) )
65 struct tmpi_errhandler_ tmpi_errors_are_fatal
= { 0, tmpi_errors_are_fatal_fn
};
66 struct tmpi_errhandler_ tmpi_errors_return
= { 0, tmpi_errors_return_fn
};
69 tMPI_Errhandler TMPI_ERRORS_ARE_FATAL
=&tmpi_errors_are_fatal
;
70 tMPI_Errhandler TMPI_ERRORS_RETURN
=&tmpi_errors_return
;
75 /* error messages. Must match error codes in thread_mpi.h */
76 static const char *tmpi_errmsg
[] =
79 "malloc failure in tMPI (out of memory)",
80 "tMPI Initialization error",
81 "tMPI Finalize error",
84 "Invalid tMPI_Status",
85 "Invalid tMPI_Group rank",
86 "Invalid Cartesian topology dimensions",
87 "Invalid Cartesian topology coordinates",
88 "Insufficient number processes for Cartesian topology",
89 "Invalid counterpart for MPI transfer",
90 "Receive buffer size too small for transmission",
91 "Overlapping send/receive buffers: probably due to thread-unsafe code.",
92 "Invalid send destination",
93 "Invalid receive source",
94 "Invalid buffer (null pointer in send or receive buffer)",
95 "Multicast operation mismatch (multicast not collective across comm)",
96 "Invalid reduce operator",
97 "Out of receive envelopes: this shouldn't happen (probably a bug).",
98 "Out of receive requests: this shouldn't happen (probably a bug).",
99 "Transmission failure",
105 int tMPI_Error(tMPI_Comm comm
, int tmpi_errno
)
109 comm
->erh
->err
=tmpi_errno
;
110 comm
->erh
->fn(&comm
, &tmpi_errno
);
114 /* initialization errors have no comm */
115 tmpi_errors_are_fatal_fn(NULL
, &tmpi_errno
);
121 int tMPI_Error_string(int errorcode
, char *strn
, size_t *resultlen
)
123 if (errorcode
<0 || errorcode
>=N_TMPI_ERR
)
124 errorcode
=TMPI_ERR_UNKNOWN
;
126 #if ! (defined( _WIN32 ) || defined( _WIN64 ) )
127 strncpy(strn
, tmpi_errmsg
[errorcode
], TMPI_MAX_ERROR_STRING
);
129 strncpy_s(strn
, TMPI_MAX_ERROR_STRING
, tmpi_errmsg
[errorcode
], TMPI_MAX_ERROR_STRING
);
131 *resultlen
=strlen(strn
);
135 int tMPI_Create_errhandler(tMPI_Errhandler_fn
*function
,
136 tMPI_Errhandler
*errhandler
)
139 tMPI_Trace_print("tMPI_Create_errhandler(%p, %p)", function
, errhandler
);
142 /* we don't use a special malloc here because this is the error handler
143 creation function. */
144 *errhandler
=(tMPI_Errhandler
)malloc(sizeof(struct tmpi_errhandler_
));
147 fprintf(stderr
, "tMPI fatal error (%s), bailing out\n",
148 tmpi_errmsg
[TMPI_ERR_MALLOC
]);
151 (*errhandler
)->err
=0;
152 (*errhandler
)->fn
=*function
;
156 int tMPI_Errhandler_free(tMPI_Errhandler
*errhandler
)
159 tMPI_Trace_print("tMPI_Errhandler_free(%p)", errhandler
);
167 int tMPI_Comm_set_errhandler(tMPI_Comm comm
, tMPI_Errhandler errhandler
)
170 tMPI_Trace_print("tMPI_Comm_set_errhandler(%p, %p)", comm
, errhandler
);
173 comm
->erh
= errhandler
;
177 int tMPI_Comm_get_errhandler(tMPI_Comm comm
, tMPI_Errhandler
*errhandler
)
180 tMPI_Trace_print("tMPI_Comm_get_errhandler(%p, %p)", comm
, errhandler
);
183 *errhandler
=comm
->erh
;
187 void tmpi_errors_are_fatal_fn(tMPI_Comm
*comm
, int *err
)
189 char errstr
[TMPI_MAX_ERROR_STRING
];
192 tMPI_Error_string(*err
, errstr
, &len
);
195 fprintf(stderr
, "tMPI error: %s (in valid comm)\n", errstr
);
199 fprintf(stderr
, "tMPI error: %s\n", errstr
);
205 void tmpi_errors_return_fn(tMPI_Comm
*comm
, int *err
)
207 char errstr
[TMPI_MAX_ERROR_STRING
];
210 tMPI_Error_string(*err
, errstr
, &len
);
213 fprintf(stderr
, "tMPI error: %s (in valid comm)\n", errstr
);
217 fprintf(stderr
, "tMPI error: %s\n", errstr
);