Bill Allombert on Sun, 26 Jun 2022 00:21:43 +0200


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

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


On Sat, Jun 25, 2022 at 07:15:07PM +0200, Bill Allombert wrote:
> On Sat, Jun 25, 2022 at 04:12:56PM +0000, Brereton, Ashley wrote:
> > 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!
> 
> Yes, this is correct, you should read the chapter 'Garbage collection'
> of the documentation.
> 
> Let say you want to do the sum
> 
>    DO I=1_8,100000_8
>         u = gadd(u, stor(I,prec))
>    ENDDO
> 
> you should do
>    av = avma
>    DO I=1_8,100000_8
>         u = gadd(u, stor(I,prec))
>         u = gerepilecopy(av, u); 
>    ENDDO
> 
> or better, only do 'u = gerepilecopy(av, u);' every 1000 iterations or so.
> 
> (avma is a global variable from libpari)

I see an issue: if PARI is build with TLS support, avma is a thread
local variable and it seems that fortran does not allow to access them
outside openmp. So maybe we should add a function get_avma() at least
for symmetry with set_avma(), even if we do not use it in C code.

Cheers,
Bill