Skip to content

Commit

Permalink
Update cutest_delegate.f90
Browse files Browse the repository at this point in the history
  • Loading branch information
amontoison committed Jun 13, 2024
1 parent b1474b2 commit e25d7d0
Show file tree
Hide file tree
Showing 2 changed files with 57 additions and 14 deletions.
40 changes: 39 additions & 1 deletion .github/workflows/meson.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,40 +7,77 @@ on:
types: [opened, synchronize, reopened]
jobs:
build:
name: ${{ matrix.os }}/${{ matrix.compiler }}-v${{ matrix.version }}/Int${{ matrix.int }}
name: ${{ matrix.os }}/${{ matrix.compiler }}-v${{ matrix.version }}/Mode-${{ matrix.mode }}/Int${{ matrix.int }}
strategy:
fail-fast: false
matrix:
os: [windows-latest, ubuntu-latest, macos-13]
arch: ['x64']
version: ['11']
int: ['32', '64']
mode: ['static', 'shared']
include:
- compiler: gcc
- os: ubuntu-latest
compiler: intel-classic
version: '2021.10'
int: '32'
mode: 'static'
- os: ubuntu-latest
compiler: intel-classic
version: '2021.10'
int: '32'
mode: 'shared'
- os: ubuntu-latest
compiler: intel-classic
version: '2021.10'
int: '64'
mode: 'static'
- os: ubuntu-latest
compiler: intel-classic
version: '2021.10'
int: '64'
mode: 'shared'
- os: windows-latest
compiler: intel
version: '2023.2'
int: '32'
mode: 'static'
- os: windows-latest
compiler: intel
version: '2023.2'
int: '32'
mode: 'shared'
- os: windows-latest
compiler: intel
version: '2023.2'
int: '64'
mode: 'static'
- os: windows-latest
compiler: intel
version: '2023.2'
int: '64'
mode: 'shared'
- os: ubuntu-latest
compiler: intel
version: '2023.2'
int: '32'
mode: 'static'
- os: ubuntu-latest
compiler: intel
version: '2023.2'
int: '32'
mode: 'shared'
- os: ubuntu-latest
compiler: intel
version: '2023.2'
int: '64'
mode: 'static'
- os: ubuntu-latest
compiler: intel
version: '2023.2'
int: '64'
mode: 'shared'
# - os: ubuntu-latest
# compiler: nvidia-hpc
# version: '24.05'
Expand Down Expand Up @@ -81,6 +118,7 @@ jobs:
fi
meson setup builddir --buildtype=debug \
--prefix=$GITHUB_WORKSPACE/cutest \
-Ddefault_library=${mode} \
-Dquadruple=true \
-Dcutest_int64=$INT64
Expand Down
31 changes: 18 additions & 13 deletions src/tools/cutest_delegate.f90
Original file line number Diff line number Diff line change
Expand Up @@ -18,28 +18,36 @@
#define RANGE_BIND_NAME "range_"
#endif

#ifdef _WIN32
#define DLOPEN_BIND_NAME LoadLibrary
#define DLSYM_BIND_NAME GetProcAddress
#else
#define DLOPEN_BIND_NAME dlopen
#define DLSYM_BIND_NAME dlsym
#endif

module cutest_delegate_r
use, intrinsic :: iso_c_binding
implicit none

! Interface pour dlopen
! Interface for dlopen / LoadLibrary
interface
function dlopen(name, mode) bind(C, name="dlopen")
function cutest_dlopen(name, mode) bind(C, name=DLOPEN_BIND_NAME)
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 function cutest_dlopen
end interface

! Interface pour dlsym
! Interface for dlsym / GetProcAddress
interface
function dlsym(handle, symbol) bind(C, name="dlsym")
function cutest_dlsym(handle, symbol) bind(C, name=DLSYM_BIND_NAME)
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 function cutest_dlsym
end interface

! Constantes pour les modes d'ouverture de bibliothèques
Expand All @@ -65,23 +73,22 @@ subroutine load_routines(libname) bind(C, name=LOAD_ROUTINE_NAME)
character(kind=c_char), dimension(*), intent(in) :: libname

! Charge la bibliothèque dynamique
lib_handle = dlopen(libname, RTLD_LAZY)
lib_handle = cutest_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)
ptr_elfun = cutest_dlsym(lib_handle, ELFUN_BIND_NAME//c_null_char)
ptr_group = cutest_dlsym(lib_handle, GROUP_BIND_NAME//c_null_char)
ptr_range = cutest_dlsym(lib_handle, RANGE_BIND_NAME//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()
Expand All @@ -90,7 +97,6 @@ subroutine elfun() bind(C, name=ELFUN_BIND_NAME)
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()
Expand All @@ -99,7 +105,6 @@ subroutine group() bind(C, name=GROUP_BIND_NAME)
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()
Expand Down

0 comments on commit e25d7d0

Please sign in to comment.