Karim Belabas on Sat, 25 Jun 2022 18:48:48 +0200


[Date Prev] [Date Next] [Thread Prev] [Thread Next] [Date Index] [Thread Index]

Re: FORTRAN memory issues and use of the sum function 'somme'


Hi,

  there many ways to answer you general question (I would advise to
start by reading 4.3 Garbage collection in the User's Guide to the PARI
library to understand our model, then the examples at 4.3.3), but in
order to sum glog(X) for X=1:N, why not use glngamma(N +1) ?

This will be *much* faster and use essentially no memory.

Cheers,

    K.B.

* Brereton, Ashley [2022-06-25 18:13]:
> Hi there,
> 
> I was hoping somebody could help with an issue with memory usage.
> 
> My code is written in Fortran. In my code, I have a (simplified) loop (see below). The code fails because the pari stack size isn't big enough.
> 
> It seems like 'u' is stored at a new memory address for each loop iteration, and so the memory fills up - though I may be wrong!
> 
> If I am indeed correct, my question is, does anybody know how to either:
> 
> a) overwrite at the same memory address or
> b) clear the memory (I tried to use allocatable for 'u' and deallocate inside the loop, but with no success).
> 
> 
> My loop will be used for a simple sum: glog(X) for X=1:N, how do I use the 'somme' function in my Fortran code? This is the gadd function for reference. I'm hoping the somme function can get around the memory issue!
> 
>    !
>     type(C_PTR) function gadd( x , y) bind(C,name='gadd')
>       import C_PTR
>       type(C_PTR), VALUE :: x
>       type(C_PTR), VALUE :: y
>     end function gadd
>     !
> 
> Any help would be greatly appreciated!
> 
> Thank you in advance,
> Ash
> 
> 
> 
> 
> 
> %%%%%%%%%%%%%%%
> 
>  use ISO_C_BINDING, only : C_PTR
>  use PARI
> 
>   type(C_PTR)        :: u
>   integer(kind=C_LONG) :: I
>   integer(kind=C_LONG) :: prec   = 10 ! 152 decimal digits
> 
> 
> CALL pari_init(10000000_8, 2_8)
> 
> 
>    DO I=1_8,100000_8
> 
>         u = stor(I,prec)
> 
>    ENDDO
> 
> 
>   CALL pari_close()
> 
> 
> %%%%%%%%%%%%%%%
--
Karim Belabas, IMB (UMR 5251), Université de Bordeaux
Vice-président en charge du Numérique
T: (+33) 05 40 00 29 77; http://www.math.u-bordeaux.fr/~kbelabas/
`