Commit 7e1dea02 authored by Lorenz Huedepohl's avatar Lorenz Huedepohl

Work around Intel compiler oddities

For some reason, and only in certain cases, the built-in
preprocessor of ifort cannot handle constructs such as

  #define FOO bar

  print *, "foo&
  &FOO&
  &baz"

or more specifically

  #define DATATYPE double

  print *, some_&
  &DATATYPE&
  &_routine

which, however, are quite handy. GCC seems to handle those as
expected.
parent 78543e3c
......@@ -113,6 +113,7 @@ if test x"$with_mpi" = x"yes"; then
AC_MSG_ERROR([Could not compile an MPI Fortran program])
fi
fi
if test x"${enable_openmp}" = x"yes"; then
AX_ELPA_OPENMP
if test "$ac_cv_prog_fc_openmp" = unsupported; then
......@@ -1099,6 +1100,20 @@ AC_CONFIG_FILES([
${PKG_CONFIG_FILE}:elpa.pc.in
])
AC_MSG_CHECKING([if workaround for Intel's broken preprocessor is needed])
if test x"$FC" = x"mpiifort" ; then
need_manual_cpp=yes
fi
if test x"$FC" = x"ifort" ; then
need_manual_cpp=yes
fi
if test x"$need_manual_cpp" = x"yes" ; then
AC_MSG_RESULT([yes])
FC="\$(top_srcdir)/manual_cpp $FC"
else
AC_MSG_RESULT([no])
fi
AC_OUTPUT
if test "${can_compile_avx}" = "no" ; then
......
#!/usr/bin/python
from __future__ import print_function
import os
import sys
import subprocess
def cpp_arg(arg):
return arg.startswith("-I") or \
arg.startswith("-D") or \
arg.startswith("-U")
def check_call(args, **kwargs):
if os.getenv("V") == "1":
print(" ".join(args))
return subprocess.check_call(args, **kwargs)
def check_call_redirect(args, filename=None, **kwargs):
if os.getenv("V") == "1":
print(" ".join(args), ">", filename)
with open(filename, "wb") as fd:
return subprocess.check_call(args, stdout=fd, **kwargs)
args = sys.argv[1:]
cpp_args = filter(cpp_arg, args)
files = filter(lambda q : q.endswith(".F90"), args)
args = filter(lambda q : not q.endswith(".F90"), args)
if len(files) > 1:
raise Exception("Specify exactly one .F90 file")
elif len(files) == 0:
# No .F90 file specified, execute program as-is
os.execvp(args[0], args[1:])
tmp_filename = "manually_preprocessed_" + file.replace("/", "__")
try:
output = args.index("-o")
outputname = args[output + 1]
tmp_filename += "-" + outputname.replace("/", "__") + ".F90"
except ValueError:
pass
# preprocess
check_call_redirect(["cpp","-P", "-traditional", "-Wall", "-Werror"] + cpp_args + [file], filename=tmp_filename)
# compile
check_call(args + [tmp_filename])
# cleanup
os.remove(tmp_filename)
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment