1 /* -*- Mode: C; c-basic-offset:4 ; -*- */
2 /*
3 * Copyright (c) 2004-2005 The Trustees of Indiana University and Indiana
4 * University Research and Technology
5 * Corporation. All rights reserved.
6 * Copyright (c) 2004-2007 The University of Tennessee and The University
7 * of Tennessee Research Foundation. All rights
8 * reserved.
9 * Copyright (c) 2004-2005 High Performance Computing Center Stuttgart,
10 * University of Stuttgart. All rights reserved.
11 * Copyright (c) 2004-2005 The Regents of the University of California.
12 * All rights reserved.
13 * Copyright (c) 2010 Cisco Systems, Inc. All rights reserved.
14 * Copyright (c) 2010 Oracle and/or its affiliates. All rights reserved.
15 * Copyright (c) 2012 Los Alamos National Security, LLC. All rights
16 * reserved.
17 * $COPYRIGHT$
18 *
19 * Additional copyrights may follow
20 *
21 * $HEADER$
22 */
23 /** @file **/
24
25 #ifndef OMPI_ERRCODE_INTERN_H
26 #define OMPI_ERRCODE_INTERN_H
27
28 #include "ompi_config.h"
29
30 #include "mpi.h"
31 #include "ompi/constants.h"
32 #include "opal/class/opal_object.h"
33 #include "opal/class/opal_pointer_array.h"
34
35 #define OMPI_MAX_ERROR_STRING 64
36
37 BEGIN_C_DECLS
38
39 /**
40 * Back-end type for MPI error codes
41 */
42 struct ompi_errcode_intern_t {
43 opal_object_t super;
44 int code;
45 int mpi_code;
46 int index;
47 char errstring[OMPI_MAX_ERROR_STRING];
48 };
49 typedef struct ompi_errcode_intern_t ompi_errcode_intern_t;
50
51 OMPI_DECLSPEC extern opal_pointer_array_t ompi_errcodes_intern;
52 OMPI_DECLSPEC extern int ompi_errcode_intern_lastused;
53
54 /**
55 * Return the MPI errcode for a given internal error code. */
56 static inline int ompi_errcode_get_mpi_code(int errcode)
57 {
58 int ret = MPI_ERR_UNKNOWN;
59 int i;
60 ompi_errcode_intern_t *errc;
61
62 /* If the errcode is >= 0, then it's already an MPI error code, so
63 just return it. */
64 if (errcode >= 0) {
65 return errcode;
66 }
67
68 /* Otherwise, it's an internal OMPI code and we need to translate
69 it */
70 for (i = 0; i < ompi_errcode_intern_lastused; i++) {
71 errc = (ompi_errcode_intern_t *)opal_pointer_array_get_item(&ompi_errcodes_intern, i);
72 if (errc->code == errcode) {
73 ret = errc->mpi_code;
74 break;
75 }
76 }
77 return ret;
78 }
79
80 /**
81 * Initialize the error codes
82 *
83 * @returns OMPI_SUCCESS Upon success
84 * @returns OMPI_ERROR Otherwise
85 *
86 * Invoked from ompi_mpi_init(); sets up all static MPI error codes,
87 */
88 int ompi_errcode_intern_init(void);
89
90 /**
91 * Finalize the error codes.
92 *
93 * @returns OMPI_SUCCESS Always
94 *
95 * Invokes from ompi_mpi_finalize(); tears down the error code array.
96 */
97 int ompi_errcode_intern_finalize(void);
98
99 END_C_DECLS
100
101 #endif /* OMPI_ERRCODE_INTERNAL_H */