OpenMPI 0.1.1

- Main Page
- Related Pages
- Modules
- Data Structures
- Files

- File List
- Globals

fint_2_int.h
1 /*
2 * Copyright (c) 2004-2005 The Trustees of Indiana University and Indiana
3 * University Research and Technology
4 * Corporation. All rights reserved.
5 * Copyright (c) 2004-2009 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) 2011 Cisco Systems, Inc. All rights reserved.
13 * $COPYRIGHT$
14 *
15 * Additional copyrights may follow
16 *
17 * $HEADER$
18 */
19
20 #ifndef OMPI_FINT_2_INT_H
21 #define OMPI_FINT_2_INT_H
22
23 #include "ompi_config.h"
24
25 #include <stdlib.h>
26
27 /*
28 * Define MACROS to take account of different size of MPI_Fint from int
29 */
30
31 #if OMPI_SIZEOF_FORTRAN_INTEGER == SIZEOF_INT
32 #define OMPI_ARRAY_NAME_DECL(a)
33 #define OMPI_2_DIM_ARRAY_NAME_DECL(a, dim2)
34 #define OMPI_SINGLE_NAME_DECL(a)
35 #define OMPI_ARRAY_NAME_CONVERT(a) a
36 #define OMPI_SINGLE_NAME_CONVERT(a) a
37 #define OMPI_INT_2_FINT(a) a
38 #define OMPI_FINT_2_INT(a) a
39 #define OMPI_ARRAY_FINT_2_INT_ALLOC(in, n)
40 #define OMPI_ARRAY_FINT_2_INT(in, n)
41 #define OMPI_2_DIM_ARRAY_FINT_2_INT(in, n, dim2)
42 #define OMPI_ARRAY_FINT_2_INT_CLEANUP(in)
43 #define OMPI_SINGLE_FINT_2_INT(in)
44 #define OMPI_SINGLE_INT_2_FINT(in)
45 #define OMPI_ARRAY_INT_2_FINT(in, n)
46
47 #elif OMPI_SIZEOF_FORTRAN_INTEGER > SIZEOF_INT
48 #define OMPI_ARRAY_NAME_DECL(a) int *c_##a
49 #define OMPI_2_DIM_ARRAY_NAME_DECL(a, dim2) int (*c_##a)[dim2], dim2_index
50 #define OMPI_SINGLE_NAME_DECL(a) int c_##a
51 #define OMPI_ARRAY_NAME_CONVERT(a) c_##a
52 #define OMPI_SINGLE_NAME_CONVERT(a) &c_##a
53 #define OMPI_INT_2_FINT(a) a
54 #define OMPI_FINT_2_INT(a) (int) (a)
55
56 /* This is for OUT parameters. Does only alloc */
57 #define OMPI_ARRAY_FINT_2_INT_ALLOC(in, n) \
58 OMPI_ARRAY_NAME_CONVERT(in) = malloc(n * sizeof(int))
59
60 /* This is for IN/IN-OUT parameters. Does alloc and assignment */
61 #define OMPI_ARRAY_FINT_2_INT(in, n) \
62 do { \
63 int converted_n = (int)(n); \
64 OMPI_ARRAY_NAME_CONVERT(in) = malloc(converted_n * sizeof(int)); \
65 while(--converted_n >= 0) { \
66 OMPI_ARRAY_NAME_CONVERT(in)[converted_n] = (int) in[converted_n]; \
67 } \
68 } while (0)
69
70 /* This is for 2-dim arrays */
71 #define OMPI_2_DIM_ARRAY_FINT_2_INT(in, n, dim2) \
72 do { \
73 int converted_n = (int)(n); \
74 OMPI_ARRAY_NAME_CONVERT(in) = (int (*)[dim2]) malloc(converted_n * sizeof(*OMPI_ARRAY_NAME_CONVERT(in))); \
75 while(--converted_n >= 0) { \
76 for(dim2_index = 0; dim2_index < dim2; ++dim2_index) { \
77 OMPI_ARRAY_NAME_CONVERT(in)[converted_n][dim2_index] = (int)in[converted_n][dim2_index]; \
78 } \
79 } \
80 } while (0)
81
82 /* This is for IN parameters. Does only free */
83 #define OMPI_ARRAY_FINT_2_INT_CLEANUP(in) \
84 free(OMPI_ARRAY_NAME_CONVERT(in))
85
86 /* This is for single IN parameter */
87 #define OMPI_SINGLE_FINT_2_INT(in) \
88 OMPI_ARRAY_NAME_CONVERT(in) = (int) *(in)
89
90 /* This is for single OUT parameter */
91 #define OMPI_SINGLE_INT_2_FINT(in) \
92 *(in) = OMPI_ARRAY_NAME_CONVERT(in)
93
94 /* This is for OUT/IN-OUT parametes. Does back assignment and free */
95 #define OMPI_ARRAY_INT_2_FINT(in, n) \
96 do { \
97 int converted_n = (int)(n); \
98 while(--converted_n >= 0) { \
99 in[converted_n] = OMPI_ARRAY_NAME_CONVERT(in)[converted_n]; \
100 } \
101 free(OMPI_ARRAY_NAME_CONVERT(in)); \
102 } while (0)
103 #else /* int > MPI_Fint */
104 #define OMPI_ARRAY_NAME_DECL(a) int *c_##a
105 #define OMPI_2_DIM_ARRAY_NAME_DECL(a, dim2) int (*c_##a)[dim2], dim2_index
106 #define OMPI_SINGLE_NAME_DECL(a) int c_##a
107 #define OMPI_ARRAY_NAME_CONVERT(a) c_##a
108 #define OMPI_SINGLE_NAME_CONVERT(a) &c_##a
109 #define OMPI_INT_2_FINT(a) (MPI_Fint)(a)
110 #define OMPI_FINT_2_INT(a) (a)
111
112 /* This is for OUT parameters. Does only alloc */
113 #define OMPI_ARRAY_FINT_2_INT_ALLOC(in, n) \
114 OMPI_ARRAY_NAME_CONVERT(in) = malloc(n * sizeof(int))
115
116 #define OMPI_ARRAY_FINT_2_INT(in, n) \
117 do { \
118 int converted_n = (int)(n); \
119 OMPI_ARRAY_NAME_CONVERT(in) = malloc(converted_n * sizeof(int)); \
120 while(--converted_n >= 0) { \
121 OMPI_ARRAY_NAME_CONVERT(in)[converted_n] = in[converted_n]; \
122 } \
123 } while (0)
124
125 #define OMPI_2_DIM_ARRAY_FINT_2_INT(in, n, dim2) \
126 do { \
127 int converted_n = (int)(n); \
128 OMPI_ARRAY_NAME_CONVERT(in) = (int (*)[dim2]) malloc(converted_n * sizeof(*OMPI_ARRAY_NAME_CONVERT(in))); \
129 while(--converted_n >= 0) { \
130 for(dim2_index = 0; dim2_index < dim2; ++dim2_index) { \
131 OMPI_ARRAY_NAME_CONVERT(in)[converted_n][dim2_index] = in[converted_n][dim2_index]; \
132 } \
133 } \
134 } while (0)
135
136 #define OMPI_ARRAY_FINT_2_INT_CLEANUP(in) \
137 free(OMPI_ARRAY_NAME_CONVERT(in))
138
139 #define OMPI_SINGLE_FINT_2_INT(in) \
140 OMPI_ARRAY_NAME_CONVERT(in) = *(in)
141
142 #define OMPI_SINGLE_INT_2_FINT(in) \
143 *in = (MPI_Fint) OMPI_ARRAY_NAME_CONVERT(in)
144
145 #define OMPI_ARRAY_INT_2_FINT(in, n) \
146 do { \
147 int converted_n = (int)(n); \
148 while(--converted_n >= 0) { \
149 in[converted_n] = OMPI_ARRAY_NAME_CONVERT(in)[converted_n]; \
150 } \
151 free(OMPI_ARRAY_NAME_CONVERT(in)); \
152 } while (0)
153
154 #endif
155
156 /*
157 * Define MACROS to take account of different size of logical from int
158 */
159
160 #if OMPI_SIZEOF_FORTRAN_LOGICAL == SIZEOF_INT
161 # define OMPI_LOGICAL_NAME_DECL(in) /* Not needed for int==logical */
162 # define OMPI_LOGICAL_NAME_CONVERT(in) in /* Not needed for int==logical */
163 # define OMPI_LOGICAL_SINGLE_NAME_CONVERT(in) in /* Not needed for int==logical */
164 # define OMPI_LOGICAL_ARRAY_NAME_DECL(in) /* Not needed for int==logical */
165 # define OMPI_LOGICAL_ARRAY_NAME_CONVERT(in) in /* Not needed for int==logical */
166 # define OMPI_ARRAY_LOGICAL_2_INT_ALLOC(in,n) /* Not needed for int==logical */
167 # define OMPI_ARRAY_LOGICAL_2_INT_CLEANUP(in) /* Not needed for int==logical */
168
169 # if OMPI_FORTRAN_VALUE_TRUE == 1
170 # define OMPI_FORTRAN_MUST_CONVERT_LOGICAL_2_INT 0
171 # define OMPI_LOGICAL_2_INT(a) a
172 # define OMPI_INT_2_LOGICAL(a) a
173 # define OMPI_ARRAY_LOGICAL_2_INT(in, n)
174 # define OMPI_ARRAY_INT_2_LOGICAL(in, n)
175 # define OMPI_SINGLE_INT_2_LOGICAL(a) /* Single-OUT variable -- Not needed for int==logical, true=1 */
176 # else
177 # define OMPI_FORTRAN_MUST_CONVERT_LOGICAL_2_INT 1
178 # define OMPI_LOGICAL_2_INT(a) ((a)==0? 0 : 1)
179 # define OMPI_INT_2_LOGICAL(a) ((a)==0? 0 : OMPI_FORTRAN_VALUE_TRUE)
180 # define OMPI_SINGLE_INT_2_LOGICAL(a) *a=OMPI_INT_2_LOGICAL(OMPI_LOGICAL_NAME_CONVERT(*a))
181 # define OMPI_ARRAY_LOGICAL_2_INT(in, n) do { \
182 int converted_n = (int)(n); \
183 OMPI_ARRAY_LOGICAL_2_INT_ALLOC(in, converted_n + 1); \
184 while (--converted_n >= 0) { \
185 OMPI_LOGICAL_ARRAY_NAME_CONVERT(in)[converted_n]=OMPI_LOGICAL_2_INT(in[converted_n]); \
186 } \
187 } while (0)
188 # define OMPI_ARRAY_INT_2_LOGICAL(in, n) do { \
189 int converted_n = (int)(n); \
190 while (--converted_n >= 0) { \
191 in[converted_n]=OMPI_INT_2_LOGICAL(OMPI_LOGICAL_ARRAY_NAME_CONVERT(in)[converted_n]); \
192 } \
193 free(OMPI_LOGICAL_ARRAY_NAME_CONVERT(in)); \
194 } while (0)
195
196 # endif
197 #else
198 /*
199 * For anything other than Fortran-logical == C-int, we have to convert
200 */
201 # define OMPI_FORTRAN_MUST_CONVERT_LOGICAL_2_INT 1
202 # define OMPI_LOGICAL_NAME_DECL(in) int c_##in
203 # define OMPI_LOGICAL_NAME_CONVERT(in) c_##in
204 # define OMPI_LOGICAL_SINGLE_NAME_CONVERT(in) &c_##in
205 # define OMPI_LOGICAL_ARRAY_NAME_DECL(in) int * c_##in
206 # define OMPI_LOGICAL_ARRAY_NAME_CONVERT(in) c_##in
207 # define OMPI_ARRAY_LOGICAL_2_INT_ALLOC(in,n) \
208 OMPI_LOGICAL_ARRAY_NAME_CONVERT(in) = malloc(n * sizeof(int))
209 # define OMPI_ARRAY_LOGICAL_2_INT_CLEANUP(in) \
210 free(OMPI_LOGICAL_ARRAY_NAME_CONVERT(in))
211
212 # if OMPI_FORTRAN_VALUE_TRUE == 1
213 # define OMPI_LOGICAL_2_INT(a) (int)a
214 # define OMPI_INT_2_LOGICAL(a) (ompi_fortran_logical_t)a
215 # define OMPI_SINGLE_INT_2_LOGICAL(a) *a=(OMPI_INT_2_LOGICAL(OMPI_LOGICAL_NAME_CONVERT(a)))
216 # else
217 # define OMPI_LOGICAL_2_INT(a) ((a)==0? 0 : 1)
218 # define OMPI_INT_2_LOGICAL(a) ((a)==0? 0 : OMPI_FORTRAN_VALUE_TRUE)
219 # define OMPI_SINGLE_INT_2_LOGICAL(a) *a=(OMPI_INT_2_LOGICAL(OMPI_LOGICAL_NAME_CONVERT(a)))
220 # endif
221 # define OMPI_ARRAY_LOGICAL_2_INT(in, n) do { \
222 int converted_n = (int)(n); \
223 OMPI_ARRAY_LOGICAL_2_INT_ALLOC(in, converted_n + 1); \
224 while (--converted_n >= 0) { \
225 OMPI_LOGICAL_ARRAY_NAME_CONVERT(in)[converted_n]=OMPI_LOGICAL_2_INT(in[converted_n]); \
226 } \
227 } while (0)
228 # define OMPI_ARRAY_INT_2_LOGICAL(in, n) do { \
229 int converted_n = (int)(n); \
230 while (--converted_n >= 0) { \
231 in[converted_n]=OMPI_INT_2_LOGICAL(OMPI_LOGICAL_ARRAY_NAME_CONVERT(in)[converted_n]); \
232 } \
233 free(OMPI_LOGICAL_ARRAY_NAME_CONVERT(in)); \
234 } while (0)
235 #endif /* OMPI_SIZEOF_FORTRAN_LOGICAL */
236
237
238 #endif /* OMPI_FINT_2_INT_H */