From 727a99e376fc8f02d7f2a9a8f5559a57073d9c34 Mon Sep 17 00:00:00 2001 From: Salvatore Filippone Date: Wed, 6 Oct 2021 13:22:41 +0200 Subject: [PATCH] Improve handling of psi_c_diffadd and psb_sizeof_XX --- base/modules/cutil.c | 24 ++--------------- base/modules/penv/psi_penv_mod.F90 | 41 +++++++++++++++++++----------- base/modules/psb_const_mod.F90 | 26 +++++++++---------- 3 files changed, 41 insertions(+), 50 deletions(-) diff --git a/base/modules/cutil.c b/base/modules/cutil.c index 13b7e1e9..503e14a5 100644 --- a/base/modules/cutil.c +++ b/base/modules/cutil.c @@ -1,29 +1,9 @@ #include #include #include -#include "psb_internals.h" -#ifdef LowerUnderscore -#define psi_c_diffadd psi_c_diffadd_ -#endif -#ifdef LowerDoubleUnderscore -#define psi_c_diffadd psi_c_diffadd__ -#endif -#ifdef LowerCase -#define psi_c_diffadd psi_c_diffadd -#endif -#ifdef UpperUnderscore -#define psi_c_diffadd PSI_C_DIFFADD_ -#endif -#ifdef UpperDoubleUnderscore -#define psi_c_diffadd PSI_C_DIFFADD__ -#endif -#ifdef UpperCase -#define psi_c_diffadd PSI_C_DIFFADD -#endif - -void psi_c_diffadd(char *p1, char *p2, int *ret) +void psi_c_diffadd(void *p1, void *p2, int *ret) { - *ret = (int)(p2-p1); + *ret = (int)((char *)p2-(char *)p1); return; } diff --git a/base/modules/penv/psi_penv_mod.F90 b/base/modules/penv/psi_penv_mod.F90 index 6a5dd7aa..2e880367 100644 --- a/base/modules/penv/psi_penv_mod.F90 +++ b/base/modules/penv/psi_penv_mod.F90 @@ -696,21 +696,32 @@ contains subroutine psi_get_sizes() use psb_const_mod - real(psb_dpk_) :: dv(2) - real(psb_spk_) :: sv(2) - integer(psb_i2pk_):: i2v(2) - integer(psb_mpk_) :: mv(2) - integer(psb_ipk_) :: iv(2) - integer(psb_lpk_) :: lv(2) - integer(psb_epk_) :: ev(2) - - call psi_c_diffadd(sv(1),sv(2),psb_sizeof_sp) - call psi_c_diffadd(dv(1),dv(2),psb_sizeof_dp) - call psi_c_diffadd(i2v(1),i2v(2),psb_sizeof_i2p) - call psi_c_diffadd(mv(1),mv(2),psb_sizeof_mp) - call psi_c_diffadd(iv(1),iv(2),psb_sizeof_ip) - call psi_c_diffadd(lv(1),lv(2),psb_sizeof_lp) - call psi_c_diffadd(ev(1),ev(2),psb_sizeof_ep) + use iso_c_binding + + real(psb_dpk_), target :: dv(2) + real(psb_spk_), target :: sv(2) + integer(psb_i2pk_), target :: i2v(2) + integer(psb_mpk_), target :: mv(2) + integer(psb_ipk_), target :: iv(2) + integer(psb_lpk_), target :: lv(2) + integer(psb_epk_), target :: ev(2) + interface + subroutine psi_c_diffadd(p1, p2, val) & + & bind(c,name="psi_c_diffadd") + use iso_c_binding + import :: psb_mpk_ + type(c_ptr), value :: p1, p2 + integer(psb_mpk_) :: val + end subroutine psi_c_diffadd + end interface + + call psi_c_diffadd(c_loc(sv(1)),c_loc(sv(2)),psb_sizeof_sp) + call psi_c_diffadd(c_loc(dv(1)),c_loc(dv(2)),psb_sizeof_dp) + call psi_c_diffadd(c_loc(i2v(1)),c_loc(i2v(2)),psb_sizeof_i2p) + call psi_c_diffadd(c_loc(mv(1)),c_loc(mv(2)),psb_sizeof_mp) + call psi_c_diffadd(c_loc(iv(1)),c_loc(iv(2)),psb_sizeof_ip) + call psi_c_diffadd(c_loc(lv(1)),c_loc(lv(2)),psb_sizeof_lp) + call psi_c_diffadd(c_loc(ev(1)),c_loc(ev(2)),psb_sizeof_ep) end subroutine psi_get_sizes diff --git a/base/modules/psb_const_mod.F90 b/base/modules/psb_const_mod.F90 index 5f13edaf..c2277da0 100644 --- a/base/modules/psb_const_mod.F90 +++ b/base/modules/psb_const_mod.F90 @@ -101,24 +101,24 @@ module psb_const_mod integer, parameter :: psb_lpk_ = -1 #endif - integer(psb_ipk_), save :: psb_sizeof_sp - integer(psb_ipk_), save :: psb_sizeof_dp - integer(psb_ipk_), save :: psb_sizeof_i2p = 2 - integer(psb_ipk_), save :: psb_sizeof_mp = 4 - integer(psb_ipk_), save :: psb_sizeof_ep = 8 + integer(psb_mpk_), save :: psb_sizeof_sp + integer(psb_mpk_), save :: psb_sizeof_dp + integer(psb_mpk_), save :: psb_sizeof_i2p = 2 + integer(psb_mpk_), save :: psb_sizeof_mp = 4 + integer(psb_mpk_), save :: psb_sizeof_ep = 8 #if defined(IPK4) && defined(LPK4) - integer(psb_ipk_), save :: psb_sizeof_ip = 4 - integer(psb_ipk_), save :: psb_sizeof_lp = 4 + integer(psb_mpk_), save :: psb_sizeof_ip = 4 + integer(psb_mpk_), save :: psb_sizeof_lp = 4 #elif defined(IPK4) && defined(LPK8) - integer(psb_ipk_), save :: psb_sizeof_ip = 4 - integer(psb_ipk_), save :: psb_sizeof_lp = 8 + integer(psb_mpk_), save :: psb_sizeof_ip = 4 + integer(psb_mpk_), save :: psb_sizeof_lp = 8 #elif defined(IPK8) && defined(LPK8) - integer(psb_ipk_), save :: psb_sizeof_ip = 8 - integer(psb_ipk_), save :: psb_sizeof_lp = 8 + integer(psb_mpk_), save :: psb_sizeof_ip = 8 + integer(psb_mpk_), save :: psb_sizeof_lp = 8 #else - integer(psb_ipk_), save :: psb_sizeof_ip = -1 - integer(psb_ipk_), save :: psb_sizeof_lp = -1 + integer(psb_mpk_), save :: psb_sizeof_ip = -1 + integer(psb_mpk_), save :: psb_sizeof_lp = -1 #endif !