From 1973f411c06471e154f54fbd91306f1e99f5ae3c Mon Sep 17 00:00:00 2001 From: Nickolai Belakovski Date: Wed, 20 Dec 2023 10:18:28 +0800 Subject: [PATCH] Yet another attempt at making things work for all compilers, this one slightly less clunky --- c/CMakeLists.txt | 13 ------------- c/bobyqa_c.f90 | 6 ++++-- c/cobyla_c.f90 | 6 ++++-- c/lincoa_c.f90 | 6 ++++-- c/newuoa_c.f90 | 6 ++++-- c/uobyqa_c.f90 | 6 ++++-- 6 files changed, 20 insertions(+), 23 deletions(-) diff --git a/c/CMakeLists.txt b/c/CMakeLists.txt index 144118cc7d..960e131173 100644 --- a/c/CMakeLists.txt +++ b/c/CMakeLists.txt @@ -6,19 +6,6 @@ if (WIN32) set_target_properties(primac PROPERTIES RUNTIME_OUTPUT_DIRECTORY ${PROJECT_BINARY_DIR}/bin) endif() -# The newer intel compiler has issues when trying to capture a Fortran procedure pointer in a closure. -# We can fix this by appending norecursion to our compile options when we compile the C interface. -# More details may be found here: https://fortran-lang.discourse.group/t/strange-issue-with-ifx-compiler-and-assume-recursion/7013 -if (CMAKE_Fortran_COMPILER_ID MATCHES "IntelLLVM") - if (WIN32) - # The $<$ part is so that this only applies when compiling Fortran - # files and *not* when compiling prima.c (because 'assume' is not a valid compiler flag when - # compiling C). - target_compile_options(primac PRIVATE $<$:/assume:norecursion>) - else () - target_compile_options(primac PRIVATE $<$:-assume norecursion>) - endif () -endif () target_include_directories (primac PUBLIC $ diff --git a/c/bobyqa_c.f90 b/c/bobyqa_c.f90 index 23a769c187..e4a3748123 100644 --- a/c/bobyqa_c.f90 +++ b/c/bobyqa_c.f90 @@ -53,8 +53,10 @@ subroutine bobyqa_c(cobj_ptr, data_ptr, n, x, f, xl, xu, nf, rhobeg, rhoend, & real(RP) :: x_loc(n) real(RP) :: xl_loc(n) real(RP) :: xu_loc(n) -procedure(COBJ), pointer :: obj_ptr -procedure(CCALLBACK), pointer :: cb_ptr +! The initialization to null is necessary to avoid a bug with the newer Intel compiler. +! See details here: https://fortran-lang.discourse.group/t/strange-issue-with-ifx-compiler-and-assume-recursion/7013 +procedure(COBJ), pointer :: obj_ptr => null() +procedure(CCALLBACK), pointer :: cb_ptr => null() ! Read the inputs and convert them to the Fortran side types x_loc = real(x, kind(x_loc)) diff --git a/c/cobyla_c.f90 b/c/cobyla_c.f90 index 7f70e8bcbe..caa47bb514 100644 --- a/c/cobyla_c.f90 +++ b/c/cobyla_c.f90 @@ -70,8 +70,10 @@ subroutine cobyla_c(m_nlcon, cobjcon_ptr, data_ptr, n, x, f, cstrv, nlconstr, m_ real(RP) :: xu_loc(n) real(RP) :: f0_loc real(RP) :: nlconstr0_loc(m_nlcon) -procedure(COBJCON), pointer :: objcon_ptr -procedure(CCALLBACK), pointer :: cb_ptr +! The initialization to null is necessary to avoid a bug with the newer Intel compiler. +! See details here: https://fortran-lang.discourse.group/t/strange-issue-with-ifx-compiler-and-assume-recursion/7013 +procedure(COBJCON), pointer :: objcon_ptr => null() +procedure(CCALLBACK), pointer :: cb_ptr => null() ! Read the inputs and convert them to the Fortran side types ! Note that `transpose` is needed when reading 2D arrays, since they are stored in the row-major diff --git a/c/lincoa_c.f90 b/c/lincoa_c.f90 index 4e44f6f50d..d8c0e663b3 100644 --- a/c/lincoa_c.f90 +++ b/c/lincoa_c.f90 @@ -65,8 +65,10 @@ subroutine lincoa_c(cobj_ptr, data_ptr, n, x, f, cstrv, m_ineq, Aineq, bineq, m_ real(RP) :: x_loc(n) real(RP) :: xl_loc(n) real(RP) :: xu_loc(n) -procedure(COBJ), pointer :: obj_ptr -procedure(CCALLBACK), pointer :: cb_ptr +! The initialization to null is necessary to avoid a bug with the newer Intel compiler. +! See details here: https://fortran-lang.discourse.group/t/strange-issue-with-ifx-compiler-and-assume-recursion/7013 +procedure(COBJ), pointer :: obj_ptr => null() +procedure(CCALLBACK), pointer :: cb_ptr => null() ! Read the inputs and convert them to the Fortran side types ! Note that `transpose` is needed when reading 2D arrays, since they are stored in the row-major diff --git a/c/newuoa_c.f90 b/c/newuoa_c.f90 index bcba37edfc..a985f9d64c 100644 --- a/c/newuoa_c.f90 +++ b/c/newuoa_c.f90 @@ -47,8 +47,10 @@ subroutine newuoa_c(cobj_ptr, data_ptr, n, x, f, nf, rhobeg, rhoend, ftarget, ma real(RP) :: rhoend_loc real(RP) :: ftarget_loc real(RP) :: x_loc(n) -procedure(COBJ), pointer :: obj_ptr -procedure(CCALLBACK), pointer :: cb_ptr +! The initialization to null is necessary to avoid a bug with the newer Intel compiler. +! See details here: https://fortran-lang.discourse.group/t/strange-issue-with-ifx-compiler-and-assume-recursion/7013 +procedure(COBJ), pointer :: obj_ptr => null() +procedure(CCALLBACK), pointer :: cb_ptr => null() ! Read the inputs and convert them to the Fortran side types x_loc = real(x, kind(x_loc)) diff --git a/c/uobyqa_c.f90 b/c/uobyqa_c.f90 index ecb7ddae91..c87ac6380f 100644 --- a/c/uobyqa_c.f90 +++ b/c/uobyqa_c.f90 @@ -45,8 +45,10 @@ subroutine uobyqa_c(cobj_ptr, data_ptr, n, x, f, nf, rhobeg, rhoend, ftarget, ma real(RP) :: rhoend_loc real(RP) :: ftarget_loc real(RP) :: x_loc(n) -procedure(COBJ), pointer :: obj_ptr -procedure(CCALLBACK), pointer :: cb_ptr +! The initialization to null is necessary to avoid a bug with the newer Intel compiler. +! See details here: https://fortran-lang.discourse.group/t/strange-issue-with-ifx-compiler-and-assume-recursion/7013 +procedure(COBJ), pointer :: obj_ptr => null() +procedure(CCALLBACK), pointer :: cb_ptr => null() ! Read the inputs and convert them to the Fortran side types x_loc = real(x, kind(x_loc))