~ubuntu-branches/ubuntu/hardy/openmpi/hardy-updates

« back to all changes in this revision

Viewing changes to ompi/mpi/f77/fint_2_int.h

  • Committer: Bazaar Package Importer
  • Author(s): Mark Hymers
  • Date: 2006-10-15 00:46:11 UTC
  • Revision ID: james.westby@ubuntu.com-20061015004611-uuhxnaxyjmuxfd5h
Tags: upstream-1.1
ImportĀ upstreamĀ versionĀ 1.1

Show diffs side-by-side

added added

removed removed

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