Skip to content

Commit

Permalink
Support shared library, finally!
Browse files Browse the repository at this point in the history
  • Loading branch information
amontoison committed Jun 13, 2024
1 parent a351aa2 commit 56ba06c
Show file tree
Hide file tree
Showing 26 changed files with 309 additions and 155 deletions.
10 changes: 6 additions & 4 deletions .github/workflows/meson.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,14 @@ on:
types: [opened, synchronize, reopened]
jobs:
build:
name: ${{ matrix.os }}/${{ matrix.compiler }}-v${{ matrix.version }}
name: ${{ matrix.os }}/${{ matrix.compiler }}-v${{ matrix.version }}/Int${{ matrix.int }}
strategy:
fail-fast: false
matrix:
os: [windows-latest, ubuntu-latest, macos-13]
arch: ['x64']
version: ['11']
int: ['32', '64']
include:
- compiler: gcc
- os: ubuntu-latest
Expand All @@ -27,14 +28,14 @@ jobs:
version: '2023.2'
# - os: ubuntu-latest
# compiler: nvidia-hpc
# version: '23.11'
# version: '24.05'
runs-on: ${{ matrix.os }}
steps:
- name: Check out CUTEST
uses: actions/checkout@v4

- name: Setup Python
uses: actions/setup-python@v4
uses: actions/setup-python@v5
with:
python-version: '3.11'

Expand All @@ -60,7 +61,8 @@ jobs:
shell: bash
run: |
meson setup builddir --buildtype=debug \
--prefix=$GITHUB_WORKSPACE/cutest
--prefix=$GITHUB_WORKSPACE/cutest \
-Dquadruple=true
- name: Build CUTEST
shell: bash
Expand Down
118 changes: 60 additions & 58 deletions meson.build
Original file line number Diff line number Diff line change
Expand Up @@ -34,59 +34,59 @@ libcutest_include = []
libcutest_include += include_directories('include')

# Sources
subdir('src/algencan')
subdir('src/bobyqa')
subdir('src/cg_descent')
subdir('src/cgplus')
subdir('src/cobyla')
subdir('src/curvi')
# subdir('src/algencan') # needs algencan_
# subdir('src/bobyqa') # needs bobyqa_
# subdir('src/cg_descent') # needs cg_descent_
# subdir('src/cgplus') # needs cgfam_
# subdir('src/cobyla') # needs cobyla_
# subdir('src/curvi') # needs curvih_, curvif_, curvig_
subdir('src/derchk')
subdir('src/dfo')
subdir('src/directsearch')
subdir('src/e04nqf')
subdir('src/filtersd')
subdir('src/filtersqp')
# subdir('src/gen77')
# subdir('src/gen90')
# subdir('src/genc')
subdir('src/gsl')
subdir('src/highs')
# subdir('src/dfo') # needs dfo_
# subdir('src/directsearch') # needs nm_, pattrn_, smd_, shh_
# subdir('src/e04nqf') # needs e04npf_, e04nrf_, e04nqf_
# subdir('src/filtersd') # needs filtersd_
# subdir('src/filtersqp') # needs readpar_, readscale_, filtersqp_
# subdir('src/gen77') # ?
# subdir('src/gen90') # ?
# subdir('src/genc') # ?
# subdir('src/gsl') # needs <gsl/gsl_vector_complex_long_double.h>
# subdir('src/highs') # needs Fortran module highs_fortran_api
subdir('src/hrb')
subdir('src/ipopt')
subdir('src/knitro')
subdir('src/la04')
subdir('src/lbfgs')
# subdir('src/lbfgsb')
# subdir('src/lincoa')
# subdir('src/loqo')
# subdir('src/matlab')
# subdir('src/minos')
# subdir('src/newuoa')
# subdir('src/nitsol')
# subdir('src/nlpqlp')
# subdir('src/nomad')
# subdir('src/npsol')
# subdir('src/octave')
# subdir('src/osqp')
# subdir('src/pds')
# subdir('src/pennlp')
# subdir('src/praxis')
# subdir('src/ql')
# subdir('src/qplib')
# subdir('src/ral_nlls')
# subdir('src/snopt')
# subdir('src/spg')
# subdir('src/sqic')
# subdir('src/stats')
# subdir('src/stenmin')
subdir('src/tao')
subdir('src/tenmin')
# subdir('src/ipopt') # needs ipcreate_, ipsolve_, ipfree_
# subdir('src/knitro') # needs KN_get_release, KN_new, ...
# subdir('src/la04') # needs mc49ad_, la04id_, la04ad_
# subdir('src/lbfgs') # needs lbfgs_
# subdir('src/lbfgsb') # needs setulb_
# subdir('src/lincoa') # needs lincoa_
# subdir('src/loqo') # needs openlp, nlsetup, solvelp
# subdir('src/matlab') # --- not supported by build system ---
# subdir('src/minos') # needs m1open_, mispec_, minoss_
# subdir('src/newuoa') # needs newuoa_
# subdir('src/nitsol') # needs nitsol_, ...
# subdir('src/nlpqlp') # needs nlpqlp_
subdir('src/nomad')
# subdir('src/npsol') # needs npfile_, npoptn_, npsol_
# subdir('src/octave') # --- not supported by build system ---
# subdir('src/osqp') # needs osqp.h
# subdir('src/pds') # needs search_, getss_, pds_, result_
# subdir('src/pennlp') # needs pennlpf_
# subdir('src/praxis') # needs praxis_
# subdir('src/ql') # needs ql_
subdir('src/qplib')
# subdir('src/ral_nlls') # needs the Fortran module RAL_NLLS_precision
# subdir('src/snopt') # needs sninit_, snspec_, snoptb_
# subdir('src/spg') # needs spg_
# subdir('src/sqic') # needs crd2spr_, crd2spr_, crd2spr_, ctsqic_
subdir('src/stats')
# subdir('src/stenmin') # needs stumcd_
# subdir('src/tao') # needs petsc/finclude/petsctao.h and Fortran module petsctao
# subdir('src/tenmin') # needs tensor_
# subdir('src/test')
subdir('src/tools')
subdir('src/tron')
subdir('src/uncmin')
subdir('src/vf13')
subdir('src/worhp')
# subdir('src/tron') # needs dnrm2_, dgpnrm2_
# subdir('src/uncmin') # needs optif9_
# subdir('src/vf13') # needs vf13ad_
# subdir('src/worhp') # needs worhp.h

# Preprocessing
if fc.get_id() == 'intel-cl' or fc.get_id() == 'intel-llvm-cl'
Expand Down Expand Up @@ -177,15 +177,17 @@ if build_quadruple
endif

# Binaries
# foreach binary: cutest_binaries
# binname = binary[0]
# binfile = binary[1]
# executable(binname,
# sources : binfile,
# include_directories : libcutest_include,
# link_with : libcutest_double,
# install : true)
# endforeach
# if get_option('default_library') == 'shared'
# foreach binary: cutest_binaries + cutest_c_binaries
# binname = binary[0]
# binfile = binary[1]
# executable(binname,
# sources : binfile,
# include_directories : libcutest_include,
# link_with : libcutest_double,
# install : true)
# endforeach
# endif

# Fortran modules
if install_modules
Expand Down
2 changes: 2 additions & 0 deletions src/lbfgsb/meson.build
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
cutest_binaries += [['lbfgsb_main', files('lbfgsb_main.F')]]
cutest_tests += [['lbfgsb_test', files('lbfgsb_test.F')]]
2 changes: 2 additions & 0 deletions src/lincoa/meson.build
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
cutest_binaries += [['lincoa_main', files('lincoa_main.F90')]]
cutest_tests += [['lincoa_test', files('lincoa_test.F90')]]
1 change: 1 addition & 0 deletions src/loqo/meson.build
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
cutest_c_binaries += [['loqo_main_c', files('loqo_main.c')]]
2 changes: 2 additions & 0 deletions src/minos/meson.build
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
cutest_binaries += [['minos_main', files('minos_main.F')]]
cutest_tests += [['minos_test', files('minos_test.F')]]
2 changes: 2 additions & 0 deletions src/newuoa/meson.build
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
cutest_binaries += [['newuoa_main', files('newuoa_main.F90')]]
cutest_tests += [['newuoa_test', files('newuoa_test.F90')]]
2 changes: 2 additions & 0 deletions src/nitsol/meson.build
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
cutest_binaries += [['nitsol_main', files('nitsol_main.F')]]
cutest_tests += [['nitsol_test', files('nitsol_test.F')]]
2 changes: 2 additions & 0 deletions src/nlpqlp/meson.build
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
cutest_binaries += [['nlpqlp_main', files('nlpqlp_main.F')]]
cutest_tests += [['nlpqlp_test', files('nlpqlp_test.F')]]
1 change: 1 addition & 0 deletions src/nomad/meson.build
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
cutest_c_binaries += [['nomad_main_c', files('nomad_main.c')]]
2 changes: 2 additions & 0 deletions src/npsol/meson.build
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
cutest_binaries += [['npsol_main', files('npsol_main.F')]]
cutest_tests += [['npsol_test', files('npsol_test.F')]]
2 changes: 2 additions & 0 deletions src/osqp/meson.build
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
cutest_c_binaries += [['osqp_main_c', files('osqp_main.c')]]
cutest_c_tests += [['osqp_test_c', files('osqp_test.c')]]
2 changes: 2 additions & 0 deletions src/pds/meson.build
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
cutest_binaries += [['pds_main', files('pds_main.F')]]
cutest_tests += [['pds_test', files('pds_test.F')]]
2 changes: 2 additions & 0 deletions src/pennlp/meson.build
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
cutest_binaries += [['pennlp_main', files('pennlp_main.F')]]
cutest_tests += [['pennlp_test', files('pennlp_test.F')]]
2 changes: 2 additions & 0 deletions src/praxis/meson.build
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
cutest_binaries += [['praxis_main', files('praxis_main.F')]]
cutest_tests += [['praxis_test', files('praxis_test.F')]]
2 changes: 2 additions & 0 deletions src/ql/meson.build
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
cutest_binaries += [['ql_main', files('ql_main.F')]]
cutest_tests += [['ql_test', files('ql_test.F')]]
1 change: 1 addition & 0 deletions src/qplib/meson.build
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
cutest_binaries += [['qplib_main', files('qplib_main.F90')]]
2 changes: 2 additions & 0 deletions src/ral_nlls/meson.build
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
cutest_binaries += [['ral_nlls_main', files('ral_nlls_main.F90')]]
cutest_tests += [['ral_nlls_test', files('ral_nlls_test.F90')]]
1 change: 0 additions & 1 deletion src/ral_nlls/ral_nlls_dummy.F90

This file was deleted.

2 changes: 2 additions & 0 deletions src/snopt/meson.build
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
cutest_binaries += [['snopt_main', files('snopt_main.F')]]
cutest_tests += [['snopt_test', files('snopt_test.F')]]
2 changes: 2 additions & 0 deletions src/spg/meson.build
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
cutest_binaries += [['spg_main', files('spg_main.F')]]
cutest_tests += [['spg_test', files('spg_test.F')]]
2 changes: 2 additions & 0 deletions src/sqic/meson.build
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
cutest_binaries += [['sqic_main', files('sqic_main.F90')]]
cutest_tests += [['sqic_test', files('sqic_test.F90')]]
1 change: 1 addition & 0 deletions src/stats/meson.build
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
cutest_binaries += [['stats_main', files('stats_main.F90')]]
2 changes: 2 additions & 0 deletions src/stenmin/meson.build
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
cutest_binaries += [['stenmin_main', files('stenmin_main.F')]]
cutest_tests += [['stenmin_test', files('stenmin_test.F')]]
111 changes: 111 additions & 0 deletions src/tools/cutest_delegate.f90
Original file line number Diff line number Diff line change
@@ -0,0 +1,111 @@
#ifdef REAL_32
#define cutest_delegate_r cutest_delegate_s
#define LOAD_ROUTINE_NAME "load_routines_s_"
#define ELFUN_BIND_NAME "elfun_s_"
#define GROUP_BIND_NAME "group_s_"
#define RANGE_BIND_NAME "range_s_"
#elif REAL_128
#define cutest_delegate_r cutest_delegate_q
#define LOAD_ROUTINE_NAME "load_routines_q"
#define ELFUN_BIND_NAME "elfun_q_"
#define GROUP_BIND_NAME "group_q_"
#define RANGE_BIND_NAME "range_q_"
#else
#define cutest_delegate_r cutest_delegate_d
#define LOAD_ROUTINE_NAME "load_routines_"
#define ELFUN_BIND_NAME "elfun_"
#define GROUP_BIND_NAME "group_"
#define RANGE_BIND_NAME "range_"
#endif

module cutest_delegate_r
use, intrinsic :: iso_c_binding
implicit none

! Interface pour dlopen
interface
function dlopen(name, mode) bind(C, name="dlopen")
use iso_c_binding, only: c_ptr, c_int, c_char
type(c_ptr) :: dlopen
character(kind=c_char), dimension(*) :: name
integer(kind=c_int) :: mode
end function dlopen
end interface

! Interface pour dlsym
interface
function dlsym(handle, symbol) bind(C, name="dlsym")
use iso_c_binding, only: c_funptr, c_ptr, c_char
type(c_funptr) :: dlsym
type(c_ptr), value :: handle
character(kind=c_char), dimension(*) :: symbol
end function dlsym
end interface

! Constantes pour les modes d'ouverture de bibliothèques
integer, parameter :: RTLD_LAZY = 1

! Handles pour les fonctions externes
type(c_ptr) :: lib_handle
type(c_funptr) :: ptr_elfun
type(c_funptr) :: ptr_group
type(c_funptr) :: ptr_range

! Pointeurs de procédure pour les fonctions externes
procedure(), pointer :: fun_elfun => null()
procedure(), pointer :: fun_group => null()
procedure(), pointer :: fun_range => null()

contains

! Routine pour charger les routines depuis la bibliothèque dynamique
subroutine load_routines(libname) bind(C, name=LOAD_ROUTINE_NAME)
use iso_c_binding
implicit none
character(kind=c_char), dimension(*), intent(in) :: libname

! Charge la bibliothèque dynamique
lib_handle = dlopen(libname, RTLD_LAZY)
if (.not. c_associated(lib_handle)) then
stop "Unable to load library"
end if

! Récupère les adresses des fonctions
ptr_elfun = dlsym(lib_handle, "elfun"//c_null_char)
ptr_group = dlsym(lib_handle, "group"//c_null_char)
ptr_range = dlsym(lib_handle, "range"//c_null_char)

! Associe les pointeurs de procédure Fortran avec les adresses obtenues
call c_f_procpointer(ptr_elfun, fun_elfun)
call c_f_procpointer(ptr_group, fun_group)
call c_f_procpointer(ptr_range, fun_range)
end subroutine load_routines

! Routine pour appeler la fonction elfun
subroutine elfun() bind(C, name=ELFUN_BIND_NAME)
if (associated(fun_elfun)) then
call fun_elfun()
else
print *, "Error: fun_elfun is not associated."
end if
end subroutine elfun

! Routine pour appeler la fonction group
subroutine group() bind(C, name=GROUP_BIND_NAME)
if (associated(fun_group)) then
call fun_group()
else
print *, "Error: fun_group is not associated."
end if
end subroutine group

! Routine pour appeler la fonction range
subroutine range() bind(C, name=RANGE_BIND_NAME)
if (associated(fun_range)) then
call fun_range()
else
print *, "Error: fun_range is not associated."
end if
end subroutine range

end module cutest_delegate_r
Loading

0 comments on commit 56ba06c

Please sign in to comment.