Karim Belabas on Mon, 09 Jun 2008 08:46:53 +0200


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

Re: Erreur de segmentation ???


* Bill Allombert [2008-05-26 22:19]:
> On Mon, May 26, 2008 at 11:35:34AM +0200, Olivier Ramare wrote:
>> Bill Allombert a écrit :
>>>Now of course, the question is whether this is a memory leak in GP,
>>>or you are allocating too much memory.
>>>  
>> 
>> Ok, I found it :-)
>> This script is not supposed to allocate any (sizeable) memory chunk.
>> The main part Walk does not.
>> It calls DiscreteValue, which has local variables and this is the
>> source of all the stack. The main variable is
>> 
>> mybiggamma = vector(bigD)  (well, bigD is 2 here)
>> 
>> and making this variable global saves a lot (but not all: the
>> stack still increases somewhat but at a much lower rate).
>> 
>> If I'm not mistaken, this *is* a memory leak.
> 
> I reran your script with PARI 2.4.3SVN (the development version) and 
> the memory usage was constant (about 6Mb). So this really start
> looking like a memory leak in the stable version.

This is a leak. The following patch should solve it:

Index: src/language/anal.c
===================================================================
--- src/language/anal.c	(revision 10178)
+++ src/language/anal.c	(working copy)
@@ -640,7 +640,7 @@
   var_cell *v = (var_cell*) ep->args;
 
   if (v == INITIAL) return;
-  if (v->flag == COPY_VAL) killbloc((GEN)ep->value);
+  killbloc((GEN)ep->value);
   ep->value = v->value;
   ep->args  = (void*) v->prev;
   free((void*)v);

Without recompiling, a simple workaround is to move initializations by
*vector* values out of the 'local' declaration. I.e. replace

  local(mybiggamma = vector(bigD));

by 

  local(mybiggamma);
  mybiggamma = vector(bigD));

This problem was specific to the old parser-evaluator and died with it,
it no longer exists in current svn.

    K.B.

P.S: [Olivier] I guess you're aware that the script can be made rather faster by
moving constant expressions out of the inner loops ? ( our optimizer is
not really up to the task yet :-)

Also expressions like

  for(d = 1, bigD, bestoldvalue[1][d] = mygamma[d]);
  bestoldvalue[2] = bigY;
  bestoldvalue[4] = etaa;
  bestoldvalue[5] = lambdaa;
  bestoldvalue[6] = majo;

are more conveniently written as

  bestoldvalue = [mygamma, bigY, p, etaa, lambdaa, majo];

(don't see the need to include the constant p in that structure, but ...).
The latter happens to be about 5 times faster in svn; and (relatively) even
better in pari-stable.

--
Karim Belabas, IMB (UMR 5251)  Tel: (+33) (0)5 40 00 26 17
Universite Bordeaux 1          Fax: (+33) (0)5 40 00 69 50
351, cours de la Liberation    http://www.math.u-bordeaux.fr/~belabas/
F-33405 Talence (France)       http://pari.math.u-bordeaux.fr/  [PARI/GP]
`