Skip to content

Commit

Permalink
Yet another attempt at making things work for all compilers, this one…
Browse files Browse the repository at this point in the history
… slightly less clunky
  • Loading branch information
nbelakovski committed Dec 20, 2023
1 parent ce98064 commit 1973f41
Show file tree
Hide file tree
Showing 6 changed files with 20 additions and 23 deletions.
13 changes: 0 additions & 13 deletions c/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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 $<$<COMPILE_LANGUAGE:Fortran> 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 $<$<COMPILE_LANGUAGE:Fortran>:/assume:norecursion>)
else ()
target_compile_options(primac PRIVATE $<$<COMPILE_LANGUAGE:Fortran>:-assume norecursion>)
endif ()
endif ()

target_include_directories (primac PUBLIC
$<INSTALL_INTERFACE:include>
Expand Down
6 changes: 4 additions & 2 deletions c/bobyqa_c.f90
Original file line number Diff line number Diff line change
Expand Up @@ -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))
Expand Down
6 changes: 4 additions & 2 deletions c/cobyla_c.f90
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
6 changes: 4 additions & 2 deletions c/lincoa_c.f90
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
6 changes: 4 additions & 2 deletions c/newuoa_c.f90
Original file line number Diff line number Diff line change
Expand Up @@ -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))
Expand Down
6 changes: 4 additions & 2 deletions c/uobyqa_c.f90
Original file line number Diff line number Diff line change
Expand Up @@ -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))
Expand Down

0 comments on commit 1973f41

Please sign in to comment.