Skip to content

Commit

Permalink
Trac #15654: PARI discriminant speed depends on stack size
Browse files Browse the repository at this point in the history
This is weird and bad:
{{{
sage: x = polygen(ZpFM(3,10))
sage: p = ((x-1)^50 + x)._pari_init_()
sage: %time pari(p).poldisc()
CPU times: user 52.73 s, sys: 0.00 s, total: 52.73 s
Wall time: 52.82 s
2*3 + 3^4 + 2*3^6 + 3^7 + 2*3^8 + 2*3^9 + O(3^10)
sage: pari.allocatemem(2<<20)
PARI stack size set to 2097152 bytes
sage: %time pari(p).poldisc()
CPU times: user 0.08 s, sys: 0.00 s, total: 0.08 s
Wall time: 0.08 s
2*3 + 3^4 + 2*3^6 + 3^7 + 2*3^8 + 2*3^9 + O(3^10)
}}}

'''Upstream''': [http://pari.math.u-bordeaux.fr/cgi-
bin/bugreport.cgi?bug=1507]

URL: http://trac.sagemath.org/15654
Reported by: jdemeyer
Ticket author(s): Jeroen Demeyer
Reviewer(s): David Roe
  • Loading branch information
Release Manager authored and vbraun committed Feb 2, 2014
2 parents cc4c7a4 + a955e45 commit 66f5010
Show file tree
Hide file tree
Showing 5 changed files with 77 additions and 321 deletions.
319 changes: 0 additions & 319 deletions build/pkgs/pari/SPKG.txt
Original file line number Diff line number Diff line change
Expand Up @@ -66,322 +66,3 @@ of doubt, have a look at the file spkg-src.
directory. However, it should not be there in a final version.

4) cd ..; sage --spkg pari-version-name

== Changelog ==

=== pari-2.5.5.p1 (Jeroen Demeyer, 12 November 2013) ===
* Trac #15402: add patch q_eint1.patch

=== pari-2.5.5.p0 (Jeroen Demeyer, 2 October 2013) ===
* Trac #15250: upgrade to version 2.5.5.

=== pari-2.5.4.p0 (Jeroen Demeyer, 13 May 2013) ===
* Trac #14539: upgrade to version 2.5.4.
* Improve documentation of patches.

=== pari-2.5.3.p3 (Jeroen Demeyer, 31 January 2013) ===
* Trac #13054: polred.patch: fix polred() bug.
* Trac #6743: remove Cygwin-specific hacks from spkg-install.

=== pari-2.5.3.p2 (Jeroen Demeyer, 7 January 2013) ===
* Trac #13921: KERNELCFLAGS.patch: when SAGE_DEBUG=yes, compile mp.c
with -O1 (and without -funroll-loops) to avoid a segmentation fault
on some OS X systems.
* Rename PARI_EXTRA_OPTS to PARI_CONFIGURE (consistent with other
packages).
* Trac #13863: galoisanalysis_p4.patch: fix a segmentation fault
under Electric Fence.

=== pari-2.5.3.p1 (Jeroen Demeyer, 3 January 2013) ===
* Trac #13902: add a patch (backported from upstream PARI 2.6.0)
for integer determinants.

=== pari-2.5.3.p0 (Jeroen Demeyer, 5 October 2012) ===
* Trac #13534: upgrade to version 2.5.3
* Remove upstreamed patch rootpol.patch

=== pari-2.5.2.p2 (Jean-Pierre Flori, 30 September 2012) ===
* Trac #13333: add upstream patch to copy libpari.dll.a on Cygwin.

=== pari-2.5.2.p1 (Paul Zimmermann, 28 August 2012) ===
* Trac #13314: add upstream patch rootpol.patch for rootpol().

=== pari-2.5.2.p0 (Jeroen Demeyer, 1 August 2012) ===
* Trac #13320: upgrade to version 2.5.2
* Rename spkg-make to spkg-src
* Remove various upstreamed patches:
- pari_1302.patch
- pari_1304.patch
- reorder_init_opts.patch

=== pari-2.5.1.p3 (Jeroen Demeyer, 20 March 2012) ===
* Trac #12638: add upstream patch pari_1304.patch for issquarefree(0),
see http://pari.math.u-bordeaux.fr/cgi-bin/bugreport.cgi?bug=1304

=== pari-2.5.1.p2 (Jeroen Demeyer, 13 March 2012) ===
* Trac #12638: add upstream patch pari_1302.patch for ispower(),
see http://pari.math.u-bordeaux.fr/cgi-bin/bugreport.cgi?bug=1302
* Apply all patches at -p1 level instead of -p0 (just like most other
Sage packages).

=== pari-2.5.1.p1 (Jeroen Demeyer, 7 March 2012) ===
* Trac #12638: add patch GCC_PR49330.patch to work around a bug
in gcc-4.6.3 on OS X 10.4 PPC.

=== pari-2.5.1.p0 (Jeroen Demeyer, 11 February 2012) ===
* Trac #12363: upgrade to PARI 2.5.1.
* Use git instead of svn in spkg-make to obtain the PARI sources.
* Remove upstreamed patch osx_13318_13330.patch.

=== pari-2.5.0.p3 (Jeroen Demeyer, 20 December 2011) ===
* Trac #12158: add reorder_init_opts.patch such that warnings
during pari_init_opts() do not cause segfaults.

=== pari-2.5.0.p2 (Jeroen Demeyer, 26 July 2011) ===
* Trac #11130: update to PARI stable version 2.5.0, which is
equal to svn version 13228.
* Moving to this upstream version fixes #10195, #10767, #11604.
* Remove all previous upstream patches.
* Add current working directory "." to default path in gprc.expect.
* Add patches osx_13318_13330.patch from upstream to fix linking on
Mac OS X.

=== pari-2.4.3.alpha.p7 (Leif Leonhardy, July 16th, 2011) ===
* Trac #11605: Fix typo in spkg-install and add `exit 1` (again) in
case the build fails.
* Quote some more variables and filenames in messages.

=== pari-2.4.3.alpha.p6 (Dima Pasechnik, 22 April, 2011) ===
* Trac #10240: made a proper check for libpari.dll on Cygwin.

=== pari-2.4.3.alpha.p5 (Jeroen Demeyer, January 23th, 2011) ===
* Avoid parallel "make install" because of race conditions.
* Remove Makefile_mv.patch because it doesn't actually fix the race
conditions in "make install".

=== pari-2.4.3.alpha.p4 (Jeroen Demeyer, January 11th, 2011) ===
* Trac #10430 (fixing also #9620, #10279, #10369, #10559)
* Use `patch` to apply patches (at -p0 level because this is how svn
gives the diffs).
* Apply patches for PARI bugs 1084, 1132, 1141, 1143, 1144.
* Move all comments about the patches to patches/README.txt
* Simplify the "install" part of spkg-install by doing "make install"
instead of copying everything by hand. This requires a small patch
to config/Makefile.SH (install_doc_no_make.patch) to ensure that
"make install-doc" does not build the documentation.
* Add patch Makefile_mv.patch to fix race condition in parallel make
install, see
http://pari.math.u-bordeaux.fr/cgi-bin/bugreport.cgi?bug=1148
* Add patch perl_path.patch to change first line of all perl scripts
to "#!/usr/bin/env perl" (#10559).
* Add src/desc/pari.desc after config/get_MANIFEST in spkg-make to
remove build-time dependency on perl

=== pari-2.4.3.alpha.p0 (Jeroen Demeyer, November 4th, 2010) ===
* Update to PARI 2.4.3 (by using SVN revision 12623). Note that the
PARI developers consider version 2.4.3 to be an "alpha" version with
the idea that 2.4.4 might be a "beta" version and 2.5 will then be
the "stable" version.
* Removed patch for gphelp.in which is now upstream
* Removed patch for paripriv.h because of an upstream change removing
the need for the patch
* Rebased patch for config/get_fltk

=== pari-2.4.3.svn-12577.p9 (Jeroen Demeyer, September 24th, 2010) ===
* Add gprc.expect file to be installed in $SAGE_LOCAL/etc
* Remove $detex = 1; from gphelp.in patch

=== pari-2.4.3.svn-12577.p7 (Jeroen Demeyer, September 17th, 2010) ===
* Add -fno-common to DLCFLAGS on all Darwin systems instead of
PPC/PPC64 only.
* Add upstream fix for rnfequation(,,1) over Q

=== pari-2.4.3.svn-12577.p6 (Jeroen Demeyer, September 11th, 2010) ===
* Add upstream fix for config/get_dlcflags and remove the patch
* Add upstream fix for bnfinit() and the rnfkummer test
* Instead of patching Configure, force bash in spkg-install

=== pari-2.4.3.svn-12577.p5 (Leif Leonhardy, Jeroen Demeyer, September 5th, 2010) ===
* Added patches to:
- config/get_config_options:
* Make invalid arguments to "--graphic" a "Configure" error
(rather than potentially running into *compilation* errors
later).
- config/get_fltk: (see also/ported from #9722)
* Add libstdc++ to the libraries (to support Fedora 13 et al.).
* Also check the presence of the FLTK include directory to
prevent compilation errors on broken installations.
- config/get_X11: (see also/ported from #9722)
* Also search */lib64/* directories when doing a 64-bit build.
* Give more specific messages.
* Slightly extended existing patch to src/kernel/gmp/mp.c:
- Allow disabling PARI's use of "GMP internals" by preprocessor
directive (i.e. by adding "-DPARI_DONT_USE_GMP_INTERNALS" to
CFLAGS). Brief explanation added.
* spkg-install:
- Don't override user-specified CFLAGS (w.r.t. optimization, unless
SAGE_DEBUG=yes).
- Handle PARI_EXTRA_OPTS properly, and print informative messages
(regarding graphics support for plotting).
- Recognize SAGE_TUNE_PARI in addition to SAGE_TUNE_pari, and
add "--tune" to PARI_EXTRA_OPTS if self-tuning was requested.
- Clear/unset lots of (environment) variables used by PARI that might
unintentionally get their values from user settings.
- Quote *all* occurrences of SAGE_LOCAL (and some other expressions).
- Use $UNAME instead of `uname` everywhere, use "elif ...".
- *Always* use $MAKE (changed for "install-data").
- Begin all error messages with "Error".
- Removed useless tests of $? at end.
- Some clean-up (typos, formatting); some comments, some messages added.
* spkg-check:
- Use $MAKE instead of "make".
- Don't override user-specified CFLAGS (w.r.t. optimization, unless
SAGE_DEBUG=yes).
- Begin error message with "Error".
- Some clean-up.
* Slight corrections to SPKG.txt.
* Updated patches/README.txt, some cosmetic changes.
* Remove patch for config/Makefile.SH and add upstream fix instead
in spkg-make.
* Add upstream fix for src/test/tune.c which should fix tuning.
* Add -O0 to CFLAGS in spkg-make to speed up compiling (the output of
the compiling is not used anyway).

=== pari-2.4.3.svn-12577.p4 (Jeroen Demeyer, August 22, 2010) ===
* Change "test -e" to "test -f" for Solaris.
* Configure using "#!/usr/bin/env bash" instead of "#!/bin/sh"

=== pari-2.4.3.svn-12577.p3 (Jeroen Demeyer, August 21, 2010) ===
* Cosmetic changes

=== pari-2.4.3.svn-12577.p2 (Jeroen Demeyer, August 17, 2010) ===
* Patch get_dlcflags on Darwin

=== pari-2.4.3.svn-12577 (Jeroen Demeyer, August 5, 2010) ===

=== pari-2.4.3.svn-12546 (Jeroen Demeyer, July 25, 2010) ===
* Removed the non-existent get_dlld patching.
* Cleaned up patches/README.txt

=== pari-2.4.3.svn.p7 (Jeroen Demeyer, July 23, 2010) ===
* pari 2.4.3 version svn 12543
* Remove patches for get_cc, get_dlcflags, get_kernel, get_dlld

=== pari-2.4.3.svn.p6 (Jeroen Demeyer, July 22, 2010) ===
* pari 2.4.3 version svn 12541
* Added spkg-make script to automate building of this spkg
* Changed patch logic in spkg-install
* Add patches for PARI bug 1079

=== pari-2.4.3.svn.p5 (John Cremona July 13, 2010) ===
* pari 2.4.3 version svn 12541
* adds spkg-check by David Kirkby

=== pari-2.4.3.svn.p1, p2, p3, p4 (Robert Bradshaw and William Stein,
June 26, 2010; John Cremona July 13, 2010) ===
* Major new version
* p4 contains pari 2.4.3 version svn 12534

=== pari-2.3.5.p1 (Mike Hansen, May 25th, 2010) ===
* Do the same fix for Cygwin that we do on Solaris.

=== pari-2.3.5.p0 (Georg S. Weber, May 2nd, 2010 ===
* restore resp. correct the file patches/get_dlld
(there seems to have been a copy'n'paste issue w.r.t. pari-2.3.3.p8)
so that pari is buildable (again) as a dynamical library on Mac OS
(fixes trac ticket #8837, see there for more details)

=== pari-2.3.5 (Mike Hansen, March 5th, 2010 ===
* Update to PARI 2.3.5
* Removed the alglin2.c patch since it was included upstream.

=== pari-2.3.3.p8 (Jaap Spies, January 28th 2010) ===
* Added 64 bit support for Open Solaris x64
* This is trac http://trac.sagemath.org/sage_trac/ticket/8099

=== pari-2.3.3.p7 (David Kirkby, January 12th 2010) ===
* #7901 Changes $MKDIR to 'mkdir' in the spkg-install file.
* #7738 Removed Michael Abshoff as a maintainer.
* Corrected the date on the previous entry - (it was
previously marked as 2009.

=== pari-2.3.3.p6 (Mike Hansen, January 4th, 2010) ===
* Fix on FreeBSD -- see #7825.

=== pari-2.3.3.p5 (David Kirkby, October 14th, 2009) ===
* Removed the use of $CP, since it has been agreed there is no
need for 'cp' to be specified as an environment variable
and to just use the normal CP command. Likewise for 'rm'
* Copied over a paripriv.h specific to Solaris, just as was done
on OS X. This is trac #6579 which allows 'modified sage library code'
to build on Solaris (SPARC) with no changes as long as the
Sun compiler suite can not be found in the path. If that can
be found, then the 'modified sage library code' will fail
for a different reason (see #6595)

=== pari-2.3.3.p4 (???????????????????????????????????) ===

=== pari-2.3.3.p3 (???????????????????????????????????) ===

=== pari-2.3.3.p2 (Minh Van Nguyen, October 02nd, 2009) ===
* Change optimization flag of src/config/get_cc from "-O3" to
"-O1". This fixes a build issue on 32-bit Fedora 11. See ticket #7092.

=== pari-2.3.3.p1 (David Kirkby, June 30th, 2009) ===
* Change code in spkg-install which was supposed to add -fPIC on
Solaris, to code that actually does add -fPIC on Solaris.
Prior to this, PARI built fine on a Sun Blade 2000 without
-fPIC, but failed on a Sun T5240 (hostname t2). I'm not
entirely sure whether this is actually need on Solaris x86
or not - GCC manual says SPARC (no mention of Solaris x86)
but someone on comp.unxi.solaris reckons it should be on
Solaris x86 too.

Hopefully this issue can be resolved by the PARI developers and
so the hack removed later. I'll report it to the PAPI developers.

Thanks are due to Marc Glisse marc.glisse@gmail.com
whose reply to my query on comp.unix.solaris solved this.

* Corrected a mis-spelling on my name written by someone else.

=== pari-2.3.3.p0 (Michael Abshoff, Feb. 18th, 2008) ===
* apply Karim's hnf patch
* add OSX 10.5 64 bit build support

=== pari-2.3.3 (William Stein) ===
* upgrade to the 2.3.3 release

=== pari-2.3.2 ===

* 2007-10-31: (Carl Witty)
disable runpath altogether; we want Sage to be relocatable.
install gphelp, and required documentation source files.

* 2007-09-09: (Michael Abshoff)
add -fPIC to DCLFLAGS on Linux PPC in src/config/get_dlcflags

* 2007-03-04: included Pablo De Napoli (denapo@gmail.com)'s
improvement so PARI will build on systems with runpath support.
See sage/runpath.txt for details.

* 2006-09-28: (William Stein and Justin Walker)
Modified PARI build scripts so that they build the
PARI *shared* library even under OS X, and on OS X intel
they build the x86/gmp kernel.


* I took the standard PARI tarball, but ran the script spkg-dist on it
to create this directory. This script does various things to some
of the PARI files to make them work better with SAGE, the most
important being to replace calls to exit() with calls to abort().

* Also, I placed a directory "sage" in this directory with some files
needed by spkg-install.

* This changed removed -- 09/28/2006
#* I changed a line of config/Makefile.SH to
# DLLDFLAGS = $DLLDFLAGS -mimpure-text


* Put the extra galois groups data files in the data/galdata subdirectory,
2 changes: 1 addition & 1 deletion build/pkgs/pari/package-version.txt
Original file line number Diff line number Diff line change
@@ -1 +1 @@
2.5.5.p1
2.5.5.p2
4 changes: 4 additions & 0 deletions build/pkgs/pari/patches/README.txt
Original file line number Diff line number Diff line change
Expand Up @@ -69,3 +69,7 @@ C files:
- 54eb37055167dbd8d4856b1bd698cf7018db561b
and completely backport new algorithm for mpveceint1(). The prefix
q_ in the patch filename is to ensure it comes after polred.patch.
* det_garbage.patch (Jeroen Demeyer, #15654): When computing a
determinant(), only collect garbage once per outer loop iteration.
Better increase PARI stack size instead of collecting garbage too
often.
56 changes: 56 additions & 0 deletions build/pkgs/pari/patches/det_garbage.patch
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
Binary files src/Olinux-x86_64/alglin1.o and b/Olinux-x86_64/alglin1.o differ
Only in src/Olinux-x86_64: libpari-gmp.so.2.5.5
diff -ru src/src/basemath/alglin1.c b/src/basemath/alglin1.c
--- src/src/basemath/alglin1.c 2014-01-09 15:43:35.847263581 +0100
+++ b/src/basemath/alglin1.c 2014-01-09 15:55:47.903649326 +0100
@@ -2412,6 +2412,7 @@
a = RgM_shallowcopy(a);
for (i=1; i<nbco; i++)
{
+ int garbage = 0; /* Only gerepile() once per loop iteration */
for(k=i; k<=nbco; k++)
{
gcoeff(a,k,i) = modii(gcoeff(a,k,i), p);
@@ -2435,7 +2436,7 @@
for (j=i+1; j<=nbco; j++)
{
gcoeff(a,j,k) = Fp_sub(gcoeff(a,j,k), Fp_mul(m,gcoeff(a,j,i),p),p);
- if (low_stack(lim, stack_lim(av,1)))
+ if (low_stack(lim, stack_lim(av,1)) && (garbage++ == 0))
{
if(DEBUGMEM>1) pari_warn(warnmem,"det. col = %ld",i);
gerepileall(av,2, &a,&x);
@@ -2994,6 +2995,7 @@
a = RgM_shallowcopy(a);
for (i=1; i<nbco; i++)
{
+ int garbage = 0; /* Only gerepile() once per loop iteration */
k = pivot(a, data, i, NULL);
if (k > nbco) return gerepilecopy(av, gcoeff(a,i,i));
if (k != i)
@@ -3013,7 +3015,7 @@
for (j=i+1; j<=nbco; j++)
{
gcoeff(a,j,k) = gsub(gcoeff(a,j,k), gmul(m,gcoeff(a,j,i)));
- if (low_stack(lim, stack_lim(av,1)))
+ if (low_stack(lim, stack_lim(av,1)) && (garbage++ == 0))
{
if(DEBUGMEM>1) pari_warn(warnmem,"det. col = %ld",i);
gerepileall(av,2, &a,&x);
@@ -3063,6 +3065,7 @@
{
GEN ci, ck, m;
int diveuc = (gequal1(pprec)==0);
+ int garbage = 0; /* Only gerepile() once per loop iteration */

p = gcoeff(a,i,i);
if (gequal0(p))
@@ -3099,7 +3102,7 @@
GEN p1 = gsub(gmul(p,gel(ck,j)), gmul(m,gel(ci,j)));
if (diveuc) p1 = mydiv(p1,pprec);
gel(ck,j) = gerepileupto(av2, p1);
- if (low_stack(lim,stack_lim(av,2)))
+ if (low_stack(lim,stack_lim(av,2)) && (garbage++ == 0))
{
if(DEBUGMEM>1) pari_warn(warnmem,"det. col = %ld",i);
gerepileall(av,2, &a,&pprec);

0 comments on commit 66f5010

Please sign in to comment.