Skip to content

Commit b40f19f

Browse files
committed
ompi_fortran_get_alignment.m4: fix test
LOC() is not a universal Fortran function (perhaps it's a GNU extension that at least some Fortran compilers have adopted? It doesn't seem to exist in the NAG compiler, at least). Additionally, doing the pointer arithmetic is not technically valid Fortran. So make the test for mpi_f08 handle alignment be similar to the other alignment tests: make instances of the variable in a common block and use C to compute the alignment. Signed-off-by: Jeff Squyres <jsquyres@cisco.com>
1 parent 08a80c5 commit b40f19f

File tree

1 file changed

+65
-31
lines changed

1 file changed

+65
-31
lines changed

config/ompi_fortran_get_alignment.m4

Lines changed: 65 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -136,44 +136,78 @@ EOF
136136
# OMPI_FORTRAN_F08_GET_HANDLE_ALIGNMENT(type, variable to set)
137137
# ------------------------------------------
138138
AC_DEFUN([OMPI_FORTRAN_F08_GET_HANDLE_ALIGNMENT],[
139+
unset happy
140+
OPAL_VAR_SCOPE_PUSH([happy ompi_conftest_h])
141+
139142
# Use of m4_translit suggested by Eric Blake:
140143
# http://lists.gnu.org/archive/html/bug-autoconf/2010-10/msg00016.html
141144
AS_VAR_PUSHDEF([type_var],
142145
m4_translit([[ompi_cv_fortran_alignment_$1]], [*], [p]))
143146

144147
AC_CACHE_CHECK([alignment of Fortran $1], type_var,
145-
[AC_LANG_PUSH([Fortran])
146-
AC_LINK_IFELSE([AC_LANG_SOURCE([[module alignment_mod
147-
type, BIND(C) :: test_mpi_handle
148-
integer :: MPI_VAL
149-
end type test_mpi_handle
150-
type(test_mpi_handle) :: t1
151-
type(test_mpi_handle) :: t2
152-
end module
153-
154-
program falignment
155-
use alignment_mod
156-
OPEN(UNIT=10, FILE="conftestval")
157-
if (LOC(t1) > LOC(t2)) then
158-
write (10,'(I5)') LOC(t1)-LOC(t2)
159-
else
160-
write (10,'(I5)') LOC(t2)-LOC(t1)
161-
endif
162-
CLOSE(10)
163-
164-
end program]])],
165-
[AS_IF([test "$cross_compiling" = "yes"],
166-
[AC_MSG_ERROR([Can not determine alignment of $1 when cross-compiling])],
167-
[OPAL_LOG_COMMAND([./conftest],
168-
[AS_VAR_SET(type_var, [`cat conftestval`])],
169-
[AC_MSG_ERROR([Could not determine alignment of $1])])])],
170-
171-
[AC_MSG_WARN([Could not determine alignment of $1])
172-
AC_MSG_WARN([See config.log for details])
173-
AC_MSG_ERROR([Cannot continue])])
174-
rm -rf conftest* *.mod 2> /dev/null
175-
AC_LANG_POP([Fortran])])
148+
[OMPI_FORTRAN_MAKE_C_FUNCTION([ompi_ac_align_fn], [align])
149+
# Fortran module
150+
cat > conftestf.f <<EOF
151+
program falign
152+
external align
153+
type, BIND(C) :: test_mpi_handle
154+
integer :: MPI_VAL
155+
end type test_mpi_handle
156+
type(test_mpi_handle) :: w,x,y,z
157+
CHARACTER a,b,c
158+
common /foo/a,w,b,x,y,c,z
159+
call align(w,x,y,z)
160+
end
161+
EOF
162+
163+
# C module
164+
if test -f conftest.h; then
165+
ompi_conftest_h="#include \"conftest.h\""
166+
else
167+
ompi_conftest_h=""
168+
fi
169+
cat > conftest.c <<EOF
170+
#include <stdio.h>
171+
#include <stdlib.h>
172+
173+
void $ompi_ac_align_fn(char *w, char *x, char *y, char *z)
174+
{
175+
unsigned long aw, ax, ay, az;
176+
FILE *f = fopen("conftestval", "w");
177+
if (!f) exit(1);
178+
aw = (unsigned long) w;
179+
ax = (unsigned long) x;
180+
ay = (unsigned long) y;
181+
az = (unsigned long) z;
182+
if (! ((aw%16)||(ax%16)||(ay%16)||(az%16))) fprintf(f, "%d\n", 16);
183+
else if (! ((aw%12)||(ax%12)||(ay%12)||(az%12))) fprintf(f, "%d\n", 12);
184+
else if (! ((aw%8)||(ax%8)||(ay%8)||(az%8))) fprintf(f, "%d\n", 8);
185+
else if (! ((aw%4)||(ax%4)||(ay%4)||(az%4))) fprintf(f, "%d\n", 4);
186+
else if (! ((aw%2)||(ax%2)||(ay%2)||(az%2))) fprintf(f, "%d\n", 2);
187+
else fprintf(f, "%d\n", 1);
188+
fclose(f);
189+
}
190+
EOF
191+
192+
OPAL_LOG_COMMAND([$CC $CFLAGS -I. -c conftest.c],
193+
[OPAL_LOG_COMMAND([$FC $FCFLAGS conftestf.f conftest.o -o conftest $LDFLAGS $LIBS],
194+
[happy="yes"], [happy="no"])], [happy="no"])
195+
196+
if test "$happy" = "no" ; then
197+
AC_MSG_RESULT([Error!])
198+
AC_MSG_ERROR([Could not determine alignment of $1])
199+
fi
200+
201+
AS_IF([test "$cross_compiling" = "yes"],
202+
[AC_MSG_RESULT([Error!])
203+
AC_MSG_ERROR([Can not determine alignment of $1 when cross-compiling])],
204+
[OPAL_LOG_COMMAND([./conftest],
205+
[AS_VAR_SET(type_var, [`cat conftestval`])],
206+
[AC_MSG_RESULT([Error!])
207+
AC_MSG_ERROR([Could not determine alignment of $1])])])
208+
rm -rf conftest*])
176209

177210
AS_VAR_COPY([$2], [type_var])
178211
AS_VAR_POPDEF([type_var])dnl
212+
OPAL_VAR_SCOPE_POP
179213
])dnl

0 commit comments

Comments
 (0)