1 /*
2 * Copyright (c) 2004-2007 The Trustees of Indiana University and Indiana
3 * University Research and Technology
4 * Corporation. All rights reserved.
5 * Copyright (c) 2004-2006 The University of Tennessee and The University
6 * of Tennessee Research Foundation. All rights
7 * reserved.
8 * Copyright (c) 2004-2005 High Performance Computing Center Stuttgart,
9 * University of Stuttgart. All rights reserved.
10 * Copyright (c) 2004-2005 The Regents of the University of California.
11 * All rights reserved.
12 * Copyright (c) 2010 Cisco Systems, Inc. All rights reserved.
13 * Copyright (c) 2018 Research Organization for Information Science
14 * and Technology (RIST). All rights reserved.
15 * $COPYRIGHT$
16 *
17 * Additional copyrights may follow
18 *
19 * $HEADER$
20 */
21
22 #ifndef OMPI_C_BINDINGS_H
23 #define OMPI_C_BINDINGS_H
24
25 #include "ompi_config.h"
26 #include "mpi.h"
27 #include "ompi/datatype/ompi_datatype.h"
28
29 /* This library needs to be here so that we can define
30 * the OPAL_CR_* checks
31 */
32 #include "opal/runtime/opal_cr.h"
33
34 BEGIN_C_DECLS
35
36 /* If compiling in the profile directory, then we don't have weak
37 symbols and therefore we need the defines to map from MPI->PMPI.
38 NOTE: pragma weak stuff is handled on a file-by-file basis; it
39 doesn't work to simply list all of the pragmas in a top-level
40 header file. */
41
42 /* These macros have to be used to check the corectness of the datatype depending on the
43 * operations that we have to do with them. They can be used on all functions, not only
44 * on the top level MPI functions, as they does not trigger the error handler. Is the user
45 * responsability to do it.
46 */
47 #define OMPI_CHECK_DATATYPE_FOR_SEND( RC, DDT, COUNT ) \
48 do { \
49 /* (RC) = MPI_SUCCESS; */ \
50 if( NULL == (DDT) || MPI_DATATYPE_NULL == (DDT) ) (RC) = MPI_ERR_TYPE; \
51 else if( (COUNT) < 0 ) (RC) = MPI_ERR_COUNT; \
52 else if( !opal_datatype_is_committed(&((DDT)->super)) ) (RC) = MPI_ERR_TYPE; \
53 else if( !opal_datatype_is_valid(&((DDT)->super)) ) (RC) = MPI_ERR_TYPE; \
54 } while (0)
55
56 #define OMPI_CHECK_DATATYPE_FOR_RECV( RC, DDT, COUNT ) \
57 do { \
58 /* (RC) = MPI_SUCCESS; */ \
59 if( NULL == (DDT) || MPI_DATATYPE_NULL == (DDT) ) (RC) = MPI_ERR_TYPE; \
60 else if( (COUNT) < 0 ) (RC) = MPI_ERR_COUNT; \
61 else if( !opal_datatype_is_committed(&((DDT)->super)) ) (RC) = MPI_ERR_TYPE; \
62 /* XXX Fix flags else if( ompi_datatype_is_overlapped((DDT)) ) (RC) = MPI_ERR_TYPE; */ \
63 else if( !opal_datatype_is_valid(&((DDT)->super)) ) (RC) = MPI_ERR_TYPE; \
64 } while (0)
65
66 #define OMPI_CHECK_DATATYPE_FOR_ONE_SIDED( RC, DDT, COUNT ) \
67 do { \
68 /*(RC) = MPI_SUCCESS; */ \
69 if( NULL == (DDT) || MPI_DATATYPE_NULL == (DDT) ) (RC) = MPI_ERR_TYPE; \
70 else if( (COUNT) < 0 ) (RC) = MPI_ERR_COUNT; \
71 else if( !opal_datatype_is_committed(&((DDT)->super)) ) (RC) = MPI_ERR_TYPE; \
72 else if( opal_datatype_is_overlapped(&((DDT)->super)) ) (RC) = MPI_ERR_TYPE; \
73 else if( !opal_datatype_is_valid(&((DDT)->super)) ) (RC) = MPI_ERR_TYPE; \
74 } while(0)
75
76 #define OMPI_CHECK_DATATYPE_FOR_VIEW( RC, DDT, COUNT ) \
77 do { \
78 /* (RC) = MPI_SUCCESS; */ \
79 if( NULL == (DDT) || MPI_DATATYPE_NULL == (DDT) ) (RC) = MPI_ERR_TYPE; \
80 else if( (COUNT) < 0 ) (RC) = MPI_ERR_COUNT; \
81 else if( !opal_datatype_is_committed(&((DDT)->super)) ) (RC) = MPI_ERR_TYPE; \
82 /* XXX Fix flags else if( ompi_datatype_is_overlapped((DDT)) ) (RC) = MPI_ERR_TYPE; */ \
83 else if( !opal_datatype_is_valid(&((DDT)->super)) ) (RC) = MPI_ERR_TYPE; \
84 else if( !ompi_datatype_is_monotonic((DDT)) ) (RC) = MPI_ERR_TYPE; \
85 } while (0)
86
87
88 /* This macro has to be used to check the correctness of the user buffer depending on the datatype.
89 * This macro expects that the DDT parameter is a valid pointer to an ompi datatype object.
90 */
91 #define OMPI_CHECK_USER_BUFFER(RC, BUFFER, DDT, COUNT) \
92 do { \
93 if ( NULL == (BUFFER) && 0 < (COUNT) && MPI_SUCCESS == (RC) ) { \
94 if ( (DDT)->super.flags & OPAL_DATATYPE_FLAG_PREDEFINED ) { \
95 (RC) = MPI_ERR_BUFFER; \
96 } else { \
97 size_t size = 0; \
98 ptrdiff_t true_lb = 0; \
99 ptrdiff_t true_extended = 0; \
100 ompi_datatype_type_size((DDT), &size); \
101 ompi_datatype_get_true_extent((DDT), &true_lb, &true_extended); \
102 if ( 0 < size && 0 == true_lb ) { \
103 (RC) = MPI_ERR_BUFFER; \
104 } \
105 } \
106 } \
107 } while (0)
108
109 END_C_DECLS
110
111 #endif /* OMPI_C_BINDINGS_H */