File: fint_2_int.h

package info (click to toggle)
openmpi 5.0.7-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 202,312 kB
  • sloc: ansic: 612,441; makefile: 42,495; sh: 11,230; javascript: 9,244; f90: 7,052; java: 6,404; perl: 5,154; python: 1,856; lex: 740; fortran: 61; cpp: 20; tcl: 12
file content (237 lines) | stat: -rw-r--r-- 9,497 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
/*
 * Copyright (c) 2004-2005 The Trustees of Indiana University and Indiana
 *                         University Research and Technology
 *                         Corporation.  All rights reserved.
 * Copyright (c) 2004-2009 The University of Tennessee and The University
 *                         of Tennessee Research Foundation.  All rights
 *                         reserved.
 * Copyright (c) 2004-2005 High Performance Computing Center Stuttgart,
 *                         University of Stuttgart.  All rights reserved.
 * Copyright (c) 2004-2005 The Regents of the University of California.
 *                         All rights reserved.
 * Copyright (c) 2011-2012 Cisco Systems, Inc.  All rights reserved.
 * Copyright (c) 2012      Oracle and/or its affiliates.  All rights reserved.
 * Copyright (c) 2014-2019 Research Organization for Information Science
 *                         and Technology (RIST).  All rights reserved.
 * $COPYRIGHT$
 *
 * Additional copyrights may follow
 *
 * $HEADER$
 */

#ifndef OMPI_FORTRAN_BASE_FINT_2_INT_H
#define OMPI_FORTRAN_BASE_FINT_2_INT_H

#include "ompi_config.h"

#include <stdlib.h>

/*
 * Define MACROS to take account of different size of MPI_Fint from int
 */

#if OMPI_SIZEOF_FORTRAN_INTEGER == SIZEOF_INT
  #define OMPI_ARRAY_NAME_DECL(a)
  #define OMPI_2_DIM_ARRAY_NAME_DECL(a, dim2)
  #define OMPI_SINGLE_NAME_DECL(a)
  #define OMPI_ARRAY_NAME_CONVERT(a) a
  #define OMPI_SINGLE_NAME_CONVERT(a) a
  #define OMPI_INT_2_FINT(a) a
  #define OMPI_FINT_2_INT(a) a
  #define OMPI_PFINT_2_PINT(a) a
  #define OMPI_ARRAY_FINT_2_INT_ALLOC(in, n)
  #define OMPI_ARRAY_FINT_2_INT(in, n)
  #define OMPI_2_DIM_ARRAY_FINT_2_INT(in, n, dim2)
  #define OMPI_ARRAY_FINT_2_INT_CLEANUP(in)
  #define OMPI_SINGLE_FINT_2_INT(in)
  #define OMPI_SINGLE_INT_2_FINT(in)
  #define OMPI_ARRAY_INT_2_FINT(in, n)

#elif OMPI_SIZEOF_FORTRAN_INTEGER > SIZEOF_INT
  #define OMPI_ARRAY_NAME_DECL(a) int *c_##a
  #define OMPI_2_DIM_ARRAY_NAME_DECL(a, dim2) int (*c_##a)[dim2], dim2_index
  #define OMPI_SINGLE_NAME_DECL(a) int c_##a
  #define OMPI_ARRAY_NAME_CONVERT(a) c_##a
  #define OMPI_SINGLE_NAME_CONVERT(a) &c_##a
  #define OMPI_INT_2_FINT(a) a
  #define OMPI_FINT_2_INT(a) (int) (a)
  #define OMPI_PFINT_2_PINT(a) (int *) (a)

  /* This is for OUT parameters. Does only alloc */
  #define OMPI_ARRAY_FINT_2_INT_ALLOC(in, n) \
    OMPI_ARRAY_NAME_CONVERT(in) = malloc((n) * sizeof(int))

  /* This is for IN/IN-OUT parameters. Does alloc and assignment */
  #define OMPI_ARRAY_FINT_2_INT(in, n) \
    do { \
      int converted_n = (int)(n); \
      OMPI_ARRAY_NAME_CONVERT(in) = malloc(converted_n * sizeof(int)); \
      while(--converted_n >= 0) { \
        OMPI_ARRAY_NAME_CONVERT(in)[converted_n] = (int) in[converted_n]; \
      } \
    } while (0)

  /* This is for 2-dim arrays */
  #define OMPI_2_DIM_ARRAY_FINT_2_INT(in, n, dim2) \
    do { \
      int converted_n = (int)(n); \
      OMPI_ARRAY_NAME_CONVERT(in) = (int (*)[dim2]) malloc(converted_n * sizeof(*OMPI_ARRAY_NAME_CONVERT(in))); \
      while(--converted_n >= 0) { \
        for(dim2_index = 0; dim2_index < dim2; ++dim2_index) { \
          OMPI_ARRAY_NAME_CONVERT(in)[converted_n][dim2_index] = (int)in[converted_n][dim2_index]; \
        } \
      } \
    } while (0)

  /* This is for IN parameters. Does only free */
  #define OMPI_ARRAY_FINT_2_INT_CLEANUP(in) \
    free(OMPI_ARRAY_NAME_CONVERT(in))

  /* This is for single IN parameter */
  #define OMPI_SINGLE_FINT_2_INT(in) \
    OMPI_ARRAY_NAME_CONVERT(in) = (int) *(in)

  /* This is for single OUT parameter */
  #define OMPI_SINGLE_INT_2_FINT(in) \
    *(in) = OMPI_ARRAY_NAME_CONVERT(in)

  /* This is for OUT/IN-OUT parameters. Does back assignment and free */
  #define OMPI_ARRAY_INT_2_FINT(in, n) \
    do { \
      int converted_n = (int)(n); \
      while(--converted_n >= 0) { \
        in[converted_n] = OMPI_ARRAY_NAME_CONVERT(in)[converted_n]; \
      } \
      free(OMPI_ARRAY_NAME_CONVERT(in)); \
    } while (0)
#else /* int > MPI_Fint  */
  #define OMPI_ARRAY_NAME_DECL(a) int *c_##a
  #define OMPI_2_DIM_ARRAY_NAME_DECL(a, dim2) int (*c_##a)[dim2], dim2_index
  #define OMPI_SINGLE_NAME_DECL(a) int c_##a
  #define OMPI_ARRAY_NAME_CONVERT(a) c_##a
  #define OMPI_SINGLE_NAME_CONVERT(a) &c_##a
  #define OMPI_INT_2_FINT(a) (MPI_Fint)(a)
  #define OMPI_FINT_2_INT(a) (a)
  #define OMPI_PFINT_2_PINT(a) a

  /* This is for OUT parameters. Does only alloc */
  #define OMPI_ARRAY_FINT_2_INT_ALLOC(in, n) \
    OMPI_ARRAY_NAME_CONVERT(in) = malloc((n) * sizeof(int))

  #define OMPI_ARRAY_FINT_2_INT(in, n) \
    do { \
      int converted_n = (int)(n); \
      OMPI_ARRAY_NAME_CONVERT(in) = malloc(converted_n * sizeof(int)); \
      while(--converted_n >= 0) { \
        OMPI_ARRAY_NAME_CONVERT(in)[converted_n] = in[converted_n]; \
      } \
    } while (0)

  #define OMPI_2_DIM_ARRAY_FINT_2_INT(in, n, dim2) \
    do { \
      int converted_n = (int)(n); \
      OMPI_ARRAY_NAME_CONVERT(in) = (int (*)[dim2]) malloc(converted_n * sizeof(*OMPI_ARRAY_NAME_CONVERT(in))); \
      while(--converted_n >= 0) { \
        for(dim2_index = 0; dim2_index < dim2; ++dim2_index) { \
          OMPI_ARRAY_NAME_CONVERT(in)[converted_n][dim2_index] = in[converted_n][dim2_index]; \
        } \
      } \
    } while (0)

  #define OMPI_ARRAY_FINT_2_INT_CLEANUP(in) \
    free(OMPI_ARRAY_NAME_CONVERT(in))

  #define OMPI_SINGLE_FINT_2_INT(in) \
     OMPI_ARRAY_NAME_CONVERT(in) = *(in)

  #define OMPI_SINGLE_INT_2_FINT(in) \
    *in = (MPI_Fint) OMPI_ARRAY_NAME_CONVERT(in)

  #define OMPI_ARRAY_INT_2_FINT(in, n) \
    do { \
      int converted_n = (int)(n); \
      while(--converted_n >= 0) { \
        in[converted_n] = OMPI_ARRAY_NAME_CONVERT(in)[converted_n]; \
      } \
      free(OMPI_ARRAY_NAME_CONVERT(in)); \
    } while (0)

#endif

/*
 * Define MACROS to take account of different size of logical from int
 *
 * There used to be an in-place option for the below conversions of
 * logical arrays.  So if mpi_cart_create(..., periods, ...) took an
 * input array of Fortran logicals, it would walk the array converting
 * the elements to C-logical values, then at the end it would restore
 * the values back to Fortran logicals.
 *
 * The problem with that is periods is an INPUT argument and some
 * Fortran compilers even put it in read-only memory because of that.
 * So writing to it wasn't generally okay, even though we were restoring it
 * before returning.
 *
 * The in-place option is hence only valid if no conversion is ever needed
 * (e.g. Fortran logical and C int have the same size *and** Fortran logical
 * .TRUE. value is 1 in C.
 */

#if (OMPI_SIZEOF_FORTRAN_LOGICAL == SIZEOF_INT) && (OMPI_FORTRAN_VALUE_TRUE == 1)
#  define OMPI_LOGICAL_NAME_DECL(in)               /* Not needed for int==logical */
#  define OMPI_LOGICAL_NAME_CONVERT(in)        in  /* Not needed for int==logical */
#  define OMPI_LOGICAL_SINGLE_NAME_CONVERT(in) in /* Not needed for int==logical */
#  define OMPI_LOGICAL_ARRAY_NAME_DECL(in)         /* Not needed for int==logical */
#  define OMPI_LOGICAL_ARRAY_NAME_CONVERT(in)  in  /* Not needed for int==logical */
#  define OMPI_ARRAY_LOGICAL_2_INT_ALLOC(in,n)     /* Not needed for int==logical */
#  define OMPI_ARRAY_LOGICAL_2_INT_CLEANUP(in)     /* Not needed for int==logical */

#  define OMPI_FORTRAN_MUST_CONVERT_LOGICAL_2_INT    0
#  define OMPI_LOGICAL_2_INT(a) a
#  define OMPI_INT_2_LOGICAL(a) a
#  define OMPI_ARRAY_LOGICAL_2_INT(in, n)
#  define OMPI_ARRAY_INT_2_LOGICAL(in, n)
#  define OMPI_SINGLE_INT_2_LOGICAL(a)            /* Single-OUT variable -- Not needed for int==logical, true=1 */
#else
/*
 * For anything other than Fortran-logical == C-int or some .TRUE. is not 1 in C, we have to convert
 */
#  define OMPI_FORTRAN_MUST_CONVERT_LOGICAL_2_INT    1
#  define OMPI_LOGICAL_NAME_DECL(in)           int c_##in
#  define OMPI_LOGICAL_NAME_CONVERT(in)        c_##in
#  define OMPI_LOGICAL_SINGLE_NAME_CONVERT(in) &c_##in
#  define OMPI_LOGICAL_ARRAY_NAME_DECL(in)     int * c_##in
#  define OMPI_LOGICAL_ARRAY_NAME_CONVERT(in)  c_##in
#  define OMPI_ARRAY_LOGICAL_2_INT_ALLOC(in,n) \
      OMPI_LOGICAL_ARRAY_NAME_CONVERT(in) = malloc((n) * sizeof(int))
#  define OMPI_ARRAY_LOGICAL_2_INT_CLEANUP(in) \
      free(OMPI_LOGICAL_ARRAY_NAME_CONVERT(in))

#  if OMPI_FORTRAN_VALUE_TRUE == 1
#    define OMPI_LOGICAL_2_INT(a) (int)a
#    define OMPI_INT_2_LOGICAL(a) (ompi_fortran_logical_t)a
#    define OMPI_SINGLE_INT_2_LOGICAL(a) *a=(OMPI_INT_2_LOGICAL(OMPI_LOGICAL_NAME_CONVERT(a)))
#  else
#    define OMPI_LOGICAL_2_INT(a) ((a)==0? 0 : 1)
#    define OMPI_INT_2_LOGICAL(a) ((a)==0? 0 : OMPI_FORTRAN_VALUE_TRUE)
#    define OMPI_SINGLE_INT_2_LOGICAL(a) *a=(OMPI_INT_2_LOGICAL(OMPI_LOGICAL_NAME_CONVERT(a)))
#  endif
#  define OMPI_ARRAY_LOGICAL_2_INT(in, n) do { \
       int converted_n = (int)(n); \
       OMPI_ARRAY_LOGICAL_2_INT_ALLOC(in, converted_n + 1); \
       while (--converted_n >= 0) { \
         OMPI_LOGICAL_ARRAY_NAME_CONVERT(in)[converted_n]=OMPI_LOGICAL_2_INT(in[converted_n]); \
       } \
     } while (0)
#  define OMPI_ARRAY_INT_2_LOGICAL(in, n) do { \
       int converted_n = (int)(n); \
       while (--converted_n >= 0) { \
         in[converted_n]=OMPI_INT_2_LOGICAL(OMPI_LOGICAL_ARRAY_NAME_CONVERT(in)[converted_n]); \
       } \
       OMPI_ARRAY_LOGICAL_2_INT_CLEANUP(in); \
     }  while (0)
#endif /* OMPI_SIZEOF_FORTRAN_LOGICAL && OMPI_FORTRAN_VALUE_TRUE */


#endif /* OMPI_FORTRAN_BASE_FINT_2_INT_H */