Skip to content

Commit 98fdeee

Browse files
authored
Merge pull request #6448 from markalle/macro_writing_input_arg
in-place conversion macro writes into INPUT argument
2 parents 76516bc + 0a7f1e3 commit 98fdeee

File tree

4 files changed

+32
-36
lines changed

4 files changed

+32
-36
lines changed

ompi/mpi/fortran/base/fint_2_int.h

Lines changed: 26 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,8 @@
1111
* All rights reserved.
1212
* Copyright (c) 2011-2012 Cisco Systems, Inc. All rights reserved.
1313
* Copyright (c) 2012 Oracle and/or its affiliates. All rights reserved.
14-
* Copyright (c) 2014 Research Organization for Information Science
15-
* and Technology (RIST). All rights reserved.
14+
* Copyright (c) 2014-2019 Research Organization for Information Science
15+
* and Technology (RIST). All rights reserved.
1616
* $COPYRIGHT$
1717
*
1818
* Additional copyrights may follow
@@ -161,9 +161,24 @@
161161

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

166-
#if OMPI_SIZEOF_FORTRAN_LOGICAL == SIZEOF_INT
181+
#if (OMPI_SIZEOF_FORTRAN_LOGICAL == SIZEOF_INT) && (OMPI_FORTRAN_VALUE_TRUE == 1)
167182
# define OMPI_LOGICAL_NAME_DECL(in) /* Not needed for int==logical */
168183
# define OMPI_LOGICAL_NAME_CONVERT(in) in /* Not needed for int==logical */
169184
# define OMPI_LOGICAL_SINGLE_NAME_CONVERT(in) in /* Not needed for int==logical */
@@ -172,37 +187,15 @@
172187
# define OMPI_ARRAY_LOGICAL_2_INT_ALLOC(in,n) /* Not needed for int==logical */
173188
# define OMPI_ARRAY_LOGICAL_2_INT_CLEANUP(in) /* Not needed for int==logical */
174189

175-
# if OMPI_FORTRAN_VALUE_TRUE == 1
176-
# define OMPI_FORTRAN_MUST_CONVERT_LOGICAL_2_INT 0
177-
# define OMPI_LOGICAL_2_INT(a) a
178-
# define OMPI_INT_2_LOGICAL(a) a
179-
# define OMPI_ARRAY_LOGICAL_2_INT(in, n)
180-
# define OMPI_ARRAY_INT_2_LOGICAL(in, n)
181-
# define OMPI_SINGLE_INT_2_LOGICAL(a) /* Single-OUT variable -- Not needed for int==logical, true=1 */
182-
# else
183-
# define OMPI_FORTRAN_MUST_CONVERT_LOGICAL_2_INT 1
184-
# define OMPI_LOGICAL_2_INT(a) ((a)==0? 0 : 1)
185-
# define OMPI_INT_2_LOGICAL(a) ((a)==0? 0 : OMPI_FORTRAN_VALUE_TRUE)
186-
# define OMPI_SINGLE_INT_2_LOGICAL(a) *a=OMPI_INT_2_LOGICAL(OMPI_LOGICAL_NAME_CONVERT(*a))
187-
# define OMPI_ARRAY_LOGICAL_2_INT(in, n) do { \
188-
int converted_n = (int)(n); \
189-
OMPI_ARRAY_LOGICAL_2_INT_ALLOC(in, converted_n + 1); \
190-
while (--converted_n >= 0) { \
191-
OMPI_LOGICAL_ARRAY_NAME_CONVERT(in)[converted_n]=OMPI_LOGICAL_2_INT(in[converted_n]); \
192-
} \
193-
} while (0)
194-
# define OMPI_ARRAY_INT_2_LOGICAL(in, n) do { \
195-
int converted_n = (int)(n); \
196-
while (--converted_n >= 0) { \
197-
in[converted_n]=OMPI_INT_2_LOGICAL(OMPI_LOGICAL_ARRAY_NAME_CONVERT(in)[converted_n]); \
198-
} \
199-
OMPI_ARRAY_LOGICAL_2_INT_CLEANUP(in); \
200-
} while (0)
201-
202-
# endif
190+
# define OMPI_FORTRAN_MUST_CONVERT_LOGICAL_2_INT 0
191+
# define OMPI_LOGICAL_2_INT(a) a
192+
# define OMPI_INT_2_LOGICAL(a) a
193+
# define OMPI_ARRAY_LOGICAL_2_INT(in, n)
194+
# define OMPI_ARRAY_INT_2_LOGICAL(in, n)
195+
# define OMPI_SINGLE_INT_2_LOGICAL(a) /* Single-OUT variable -- Not needed for int==logical, true=1 */
203196
#else
204197
/*
205-
* For anything other than Fortran-logical == C-int, we have to convert
198+
* For anything other than Fortran-logical == C-int or some .TRUE. is not 1 in C, we have to convert
206199
*/
207200
# define OMPI_FORTRAN_MUST_CONVERT_LOGICAL_2_INT 1
208201
# define OMPI_LOGICAL_NAME_DECL(in) int c_##in
@@ -238,7 +231,7 @@
238231
} \
239232
OMPI_ARRAY_LOGICAL_2_INT_CLEANUP(in); \
240233
} while (0)
241-
#endif /* OMPI_SIZEOF_FORTRAN_LOGICAL */
234+
#endif /* OMPI_SIZEOF_FORTRAN_LOGICAL && OMPI_FORTRAN_VALUE_TRUE */
242235

243236

244237
#endif /* OMPI_FORTRAN_BASE_FINT_2_INT_H */

ompi/mpi/fortran/mpif-h/cart_create_f.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
* Copyright (c) 2011-2012 Cisco Systems, Inc. All rights reserved.
1313
* Copyright (c) 2015 Research Organization for Information Science
1414
* and Technology (RIST). All rights reserved.
15+
* Copyright (c) 2019 IBM Corporation. All rights reserved.
1516
* $COPYRIGHT$
1617
*
1718
* Additional copyrights may follow
@@ -96,5 +97,5 @@ void ompi_cart_create_f(MPI_Fint *old_comm, MPI_Fint *ndims, MPI_Fint *dims,
9697
* Need to convert back into Fortran, to not surprise the user
9798
*/
9899
OMPI_ARRAY_FINT_2_INT_CLEANUP(dims);
99-
OMPI_ARRAY_INT_2_LOGICAL(periods, size);
100+
OMPI_ARRAY_LOGICAL_2_INT_CLEANUP(periods);
100101
}

ompi/mpi/fortran/mpif-h/cart_map_f.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
* Copyright (c) 2011-2012 Cisco Systems, Inc. All rights reserved.
1313
* Copyright (c) 2015 Research Organization for Information Science
1414
* and Technology (RIST). All rights reserved.
15+
* Copyright (c) 2019 IBM Corporation. All rights reserved.
1516
* $COPYRIGHT$
1617
*
1718
* Additional copyrights may follow
@@ -89,6 +90,6 @@ void ompi_cart_map_f(MPI_Fint *comm, MPI_Fint *ndims, MPI_Fint *dims,
8990
if (NULL != ierr) *ierr = OMPI_INT_2_FINT(c_ierr);
9091

9192
OMPI_ARRAY_FINT_2_INT_CLEANUP(dims);
92-
OMPI_ARRAY_INT_2_LOGICAL(periods, size);
93+
OMPI_ARRAY_LOGICAL_2_INT_CLEANUP(periods);
9394
OMPI_SINGLE_INT_2_FINT(newrank);
9495
}

ompi/mpi/fortran/mpif-h/cart_sub_f.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
* Copyright (c) 2011-2012 Cisco Systems, Inc. All rights reserved.
1313
* Copyright (c) 2015 Research Organization for Information Science
1414
* and Technology (RIST). All rights reserved.
15+
* Copyright (c) 2019 IBM Corporation. All rights reserved.
1516
* $COPYRIGHT$
1617
*
1718
* Additional copyrights may follow
@@ -101,5 +102,5 @@ void ompi_cart_sub_f(MPI_Fint *comm, ompi_fortran_logical_t *remain_dims,
101102
*new_comm = PMPI_Comm_c2f(c_new_comm);
102103
}
103104

104-
OMPI_ARRAY_INT_2_LOGICAL(remain_dims, ndims);
105+
OMPI_ARRAY_LOGICAL_2_INT_CLEANUP(remain_dims);
105106
}

0 commit comments

Comments
 (0)