diff --git a/cbind/Makefile b/cbind/Makefile index 88d0120d..85a09130 100644 --- a/cbind/Makefile +++ b/cbind/Makefile @@ -5,7 +5,7 @@ LIBDIR=../lib INCDIR=../include LIBNAME=$(CBINDLIBNAME) -lib: based +lib: based precd /bin/cp -p $(CPUPDFLAG) $(HERE)/$(LIBNAME) $(LIBDIR) /bin/cp -p $(CPUPDFLAG) *$(.mod) *.h $(INCDIR) @@ -13,10 +13,13 @@ lib: based based: cd base && $(MAKE) lib LIBNAME=$(LIBNAME) +precd: + cd prec && $(MAKE) lib LIBNAME=$(LIBNAME) clean: cd base && $(MAKE) clean + cd prec && $(MAKE) clean veryclean: clean diff --git a/cbind/prec/Makefile b/cbind/prec/Makefile new file mode 100644 index 00000000..dbd3d67f --- /dev/null +++ b/cbind/prec/Makefile @@ -0,0 +1,32 @@ +TOP=../.. +include $(TOP)/Make.inc +LIBDIR=$(TOP)/lib +INCLUDEDIR=$(TOP)/include +HERE=.. + +FINCLUDES=$(FMFLAG). $(FMFLAG)$(INCLUDEDIR) +CINCLUDES=-I. -I$(INCLUDEDIR) + +OBJS=psb_prec_cbind_mod.o psb_dprec_cbind_mod.o psb_c_dprec.o +CMOD=psb_prec_cbind.h psb_c_dprec.h + + +LIBMOD=psb_prec_cbind_mod$(.mod) +LOCAL_MODS=$(LIBMOD) +LIBNAME=$(CPRECLIBNAME) + + +lib: $(OBJS) $(CMOD) + $(AR) $(HERE)/$(LIBNAME) $(OBJS) + $(RANLIB) $(HERE)/$(LIBNAME) + /bin/cp -p $(HERE)/$(LIBNAME) $(LIBDIR) + /bin/cp -p $(LIBMOD) $(CMOD) $(INCLUDEDIR) + +psb_prec_cbind_mod.o: psb_dprec_cbind_mod.o +veryclean: clean + /bin/rm -f $(HERE)/$(LIBNAME) + +clean: + /bin/rm -f $(OBJS) $(LOCAL_MODS) + +veryclean: clean diff --git a/cbind/prec/psb_c_dprec.c b/cbind/prec/psb_c_dprec.c new file mode 100644 index 00000000..f3234337 --- /dev/null +++ b/cbind/prec/psb_c_dprec.c @@ -0,0 +1,12 @@ +#include +#include "psb_c_dprec.h" + +psb_c_dprec* psb_c_new_dprec() +{ + psb_c_dprec* temp; + + temp=(psb_c_dprec *) malloc(sizeof(psb_c_dprec)); + temp->dprec=NULL; + return(temp); +} + diff --git a/cbind/prec/psb_c_dprec.h b/cbind/prec/psb_c_dprec.h new file mode 100644 index 00000000..bb8775c1 --- /dev/null +++ b/cbind/prec/psb_c_dprec.h @@ -0,0 +1,24 @@ +#ifndef PSB_C_DPREC_ +#define PSB_C_DPREC_ +#include "psb_base_cbind.h" +/* Object handle related routines */ +/* Note: psb_get_XXX_handle returns: <= 0 unsuccessful */ +/* >0 valid handle */ +#ifdef __cplusplus +extern "C" { +#endif + +typedef struct PSB_C_DPREC { + void *dprec; +} psb_c_dprec; + +psb_c_dprec* psb_c_new_dprec(); + +int psb_c_dprecinit(psb_c_dprec *ph, const char *ptype); +int psb_c_dprecbld(psb_c_dspmat *ah, psb_c_descriptor *cdh, psb_c_dprec *ph); +int psb_c_dprecfree(psb_c_dprec *ph); +#ifdef __cplusplus +} +#endif + +#endif diff --git a/cbind/prec/psb_dprec_cbind_mod.f90 b/cbind/prec/psb_dprec_cbind_mod.f90 new file mode 100644 index 00000000..1e756d11 --- /dev/null +++ b/cbind/prec/psb_dprec_cbind_mod.f90 @@ -0,0 +1,118 @@ +module psb_dprec_cbind_mod + + use iso_c_binding + use psb_prec_mod, only : psb_dprec_type + use psb_objhandle_mod + use psb_base_string_cbind_mod + + type, bind(c) :: psb_c_dprec + type(c_ptr) :: item = c_null_ptr + end type psb_c_dprec + + +contains + + + function psb_c_dprecinit(ph,ptype) bind(c) result(res) + use psb_base_mod + use psb_prec_mod + use psb_base_string_cbind_mod + implicit none + integer(c_int) :: res + type(psb_c_dprec) :: ph + character(c_char) :: ptype(*) + type(psb_dprec_type), pointer :: precp + integer :: info + character(len=80) :: fptype + + res = -1 + if (c_associated(ph%item)) then + return + end if + + allocate(precp,stat=info) + if (info /= 0) return + ph%item = c_loc(precp) + + call stringc2f(ptype,fptype) + + call psb_precinit(precp,fptype,info) + + res = min(0,info) + return + end function psb_c_dprecinit + + + + function psb_c_dprecbld(ah,cdh,ph) bind(c) result(res) + use psb_base_mod + use psb_prec_mod + use psb_objhandle_mod + use psb_base_string_cbind_mod + implicit none + + integer(c_int) :: res + type(psb_c_dspmat) :: ah + type(psb_c_dprec) :: ph + type(psb_c_descriptor) :: cdh + + type(psb_desc_type), pointer :: descp + type(psb_dspmat_type), pointer :: ap + type(psb_dprec_type), pointer :: precp + + integer :: info + + res = -1 +!!$ write(*,*) 'Entry: ', psb_c_cd_get_local_rows(cdh) + if (c_associated(cdh%item)) then + call c_f_pointer(cdh%item,descp) + else + return + end if + if (c_associated(ah%item)) then + call c_f_pointer(ah%item,ap) + else + return + end if + if (c_associated(ph%item)) then + call c_f_pointer(ph%item,precp) + else + return + end if + + call psb_precbld(ap,descp, precp, info) + + res = min(info,0) + + end function psb_c_dprecbld + + + function psb_c_dprecfree(ph) bind(c) result(res) + use psb_base_mod + use psb_prec_mod + use psb_objhandle_mod + use psb_base_string_cbind_mod + implicit none + + integer(c_int) :: res + type(psb_c_dprec) :: ph + + type(psb_dprec_type), pointer :: precp + + integer :: info + + res = -1 + if (c_associated(ph%item)) then + call c_f_pointer(ph%item,precp) + else + return + end if + + call psb_precfree(precp, info) + + res = min(info,0) + + end function psb_c_dprecfree + + +end module psb_dprec_cbind_mod diff --git a/cbind/prec/psb_dprec_cbind_mod.mod b/cbind/prec/psb_dprec_cbind_mod.mod new file mode 100644 index 00000000..b153ab91 Binary files /dev/null and b/cbind/prec/psb_dprec_cbind_mod.mod differ diff --git a/cbind/prec/psb_prec_cbind.h b/cbind/prec/psb_prec_cbind.h new file mode 100644 index 00000000..1dabd9cf --- /dev/null +++ b/cbind/prec/psb_prec_cbind.h @@ -0,0 +1,6 @@ +#ifndef PSB_PREC_CBIND_ +#define PSB_PREC_CBIND_ + +#include "psb_c_dprec.h" + +#endif diff --git a/cbind/prec/psb_prec_cbind_mod.f90 b/cbind/prec/psb_prec_cbind_mod.f90 new file mode 100644 index 00000000..946b159f --- /dev/null +++ b/cbind/prec/psb_prec_cbind_mod.f90 @@ -0,0 +1,3 @@ +module psb_prec_cbind_mod + use psb_dprec_cbind_mod +end module psb_prec_cbind_mod