Commit 848f332b authored by Lorenz Huedepohl's avatar Lorenz Huedepohl

Workaround for PGI bug with variable length string pointer

PGI has problems with elpa_int_value_to_string() where we return a
variable-length string pointer. A workaround for now is to copy the string into
a non-pointer variable of the same length.

This closes issue #55
parent b29b780a
......@@ -958,10 +958,18 @@ m4_include([m4/ax_fc_check_define.m4])
AC_MSG_CHECKING([if workaround for broken preprocessor is needed])
need_manual_cpp=no
AX_FC_CHECK_DEFINE([__INTEL_COMPILER],[need_manual_cpp=yes],[])
AX_FC_CHECK_DEFINE([__PGI],[need_manual_cpp=yes],[])
AX_FC_CHECK_DEFINE([__INTEL_COMPILER],[is_intel=yes],[])
AX_FC_CHECK_DEFINE([__PGI],[is_pgi=yes],[])
ACTUAL_FC="$FC"
AC_SUBST([ACTUAL_FC])
if test x"$is_intel" = x"yes" ; then
need_manual_cpp=yes
fi
if test x"$is_pgi" = x"yes" ; 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"
......@@ -969,6 +977,10 @@ else
AC_MSG_RESULT([no])
fi
if test x"$is_pgi" = x"yes" ; then
AC_DEFINE([PGI_VARIABLE_STRING_BUG], [1], [Work around a PGI bug with variable-length string results])
fi
dnl PGI compiler uses -module to specify module output
dnl directory. This clashes with libtools -module link option
......
......@@ -1207,15 +1207,31 @@ module elpa_api
character(kind=c_char, len=*), intent(in) :: name
integer(kind=c_int), intent(in) :: value
integer(kind=c_int), intent(out), optional :: error
#ifdef PGI_VARIABLE_STRING_BUG
character(kind=c_char, len=elpa_int_value_to_strlen_c(name // C_NULL_CHAR, value)), pointer :: string_ptr
character(kind=c_char, len=elpa_int_value_to_strlen_c(name // C_NULL_CHAR, value)) :: string
#else
character(kind=c_char, len=elpa_int_value_to_strlen_c(name // C_NULL_CHAR, value)), pointer :: string
#endif
integer(kind=c_int) :: actual_error
type(c_ptr) :: ptr
actual_error = elpa_int_value_to_string_c(name // C_NULL_CHAR, value, ptr)
if (c_associated(ptr)) then
#ifdef PGI_VARIABLE_STRING_BUG
call c_f_pointer(ptr, string_ptr)
string = string_ptr
#else
call c_f_pointer(ptr, string)
#endif
else
#ifdef PGI_VARIABLE_STRING_BUG
nullify(string_ptr)
#else
nullify(string)
#endif
endif
if (present(error)) then
......
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