Skip to content

Commit

Permalink
read and use environment variable PARI_SIZE
Browse files Browse the repository at this point in the history
  • Loading branch information
JohnCremona committed Aug 15, 2017
1 parent 22e165e commit b6bd23d
Show file tree
Hide file tree
Showing 8 changed files with 47 additions and 23 deletions.
3 changes: 2 additions & 1 deletion README
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,8 @@ run: either (i) after ./configure, edit ./Makefile and all */Makefile,
setting FLINT_LEVEL=2 (instead of =1); or (ii) edit configure itself
similarly (in two places) and rerun it; or (iii) append
CXXFLAGS='-DFLINT_LEVEL=2' to the make invocation (and ignore warnings
about FLINT_LEVEL being redefined).
about FLINT_LEVEL being redefined). To carry out (ii): run
sed -i '/FLINT_LEVEL/s/1/2/' configure

(c) Boost is optional (from eclib-2013-09-00) and provides parallel
capabilities in the form_finder class. Configure with --with-boost
Expand Down
4 changes: 2 additions & 2 deletions configure.ac
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
# Process this file with autoconf to produce a configure script.

AC_PREREQ([2.65])
AC_INIT([eclib], [20170711], [john.cremona@gmail.com])
AC_INIT([eclib], [20170815], [john.cremona@gmail.com])
AM_INIT_AUTOMAKE([-Wall])
AC_MSG_NOTICE([Configuring eclib...])
AC_CONFIG_SRCDIR([libsrc])
Expand Down Expand Up @@ -36,7 +36,7 @@ LT_INIT
# NB The suffix of the library name (libec.so here) is (c-a).a.r

LT_CURRENT=3
LT_REVISION=7
LT_REVISION=8
LT_AGE=0
AC_SUBST(LT_CURRENT)
AC_SUBST(LT_REVISION)
Expand Down
10 changes: 8 additions & 2 deletions doc/mwrank/mwrank.info
Original file line number Diff line number Diff line change
Expand Up @@ -237,7 +237,13 @@ You can aid the factorization of large integers in several ways:

(a) Pari (i.e. the library libpari) is now a requirement, and is used
to factorization of integers greater than a bound set to 10^8 in
libsrc/marith.cc. This is the only use made of the Pari library.
libsrc/marith.cc. This is the only use made of the Pari library. By
default the pari library is initialized with parisize=1000000. If you
see an error message saying " [hint] set 'parisizemax' to a non-zero
value in your GPRC" do not follow the hint (which is wrong, we are not
using gp at all) but instead set the environment variable PARI_SIZE to
some larger value (e.g. do "export PARI_SIZE=100000000" but this will
depend on your system).

(b) By default the programs initialise an array of primes < 10^6, so
will succeed in factoring all numbers < 10^8 by trial division. This
Expand Down Expand Up @@ -272,4 +278,4 @@ John Cremona (john.cremona@gmail.com)

3 February 1995, updated 12 January 1998, 25 September 2000, 5 July 2001,
12 November 2003, 5 January 2005, 10 May 2005, 31 December 2011, 2
January 2016.
January 2016, 15 August 2017.
5 changes: 5 additions & 0 deletions libsrc/eclib/interface.h
Original file line number Diff line number Diff line change
Expand Up @@ -301,4 +301,9 @@ inline int is_approx_zero(const bigcomplex& z)

#undef setbit

// Utility to return a string from an environment variable with a
// default to use if the variable is not set or empty.

string getenv_with_default(string env_var, string def_val);

#endif // #define _INTERFACE_H_
5 changes: 0 additions & 5 deletions libsrc/eclib/moddata.h
Original file line number Diff line number Diff line change
Expand Up @@ -63,11 +63,6 @@ class moddata :public level {
long unitdiv(long res) const {return unitdivlist[reduce(res)];}
};

// Utility to return a string from an environment variable with a
// default to use if the variable is not set or empty.

string getenv_with_default(string env_var, string def_val);

// Returns oldform filename. Default is "newforms/", but can
// be changed via OF_DIR environment variable.
string of_filename(long n, char c);
Expand Down
11 changes: 11 additions & 0 deletions libsrc/interface.cc
Original file line number Diff line number Diff line change
Expand Up @@ -307,5 +307,16 @@ istream& operator>>(istream& is, CC& z)
return is;
}

string getenv_with_default(string env_var, string def_val)
{
stringstream s;
if (getenv(env_var.c_str()) != NULL) {
s << getenv(env_var.c_str());
} else {
s<<def_val;
}
return s.str();
}

#endif // NTL_ALL

11 changes: 0 additions & 11 deletions libsrc/moddata.cc
Original file line number Diff line number Diff line change
Expand Up @@ -147,17 +147,6 @@ void moddata::display() const
cout << "unitdivlist: " << unitdivlist << endl;
}

string getenv_with_default(string env_var, string def_val)
{
stringstream s;
if (getenv(env_var.c_str()) != NULL) {
s << getenv(env_var.c_str());
} else {
s<<def_val;
}
return s.str();
}

string of_filename(long n, char c)
{
stringstream s;
Expand Down
21 changes: 19 additions & 2 deletions libsrc/parifact.cc
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,11 @@
//
//////////////////////////////////////////////////////////////////////////

#include <eclib/interface.h> // for getenv_with_default
#include <pari/pari.h>
#include <eclib/parifact.h>


//#define DEBUG_GPFACT

#include <iostream>
Expand All @@ -33,7 +35,13 @@ string
factor(const string n)
{
if (!avma) {
pari_init(1000000, 1000000);
long pari_size = strtol(getenv_with_default("PARI_SIZE", "100000").c_str(), NULL, 0);
if (pari_size==0) // e.g. syntax error in the environment variable PARI_SIZE
pari_size = 1000000;
#ifdef DEBUG_GPFACT
std::cout<<"calling pari_init with pari_size = "<<pari_size<<endl;
#endif
pari_init(pari_size, 1000000);
}
#ifdef DEBUG_GPFACT
std::cout<<"factor called with "<<n<<endl;
Expand All @@ -46,6 +54,9 @@ factor(const string n)
settyp(x,t_VEC);

string ans(GENtostr(x));
#ifdef DEBUG_GPFACT
std::cout<<"factor returns "<<ans<<endl;
#endif
avma=av; // restore pari stackpointer
return ans;
}
Expand All @@ -54,7 +65,13 @@ int
is_prime(const string p)
{
if (!avma) {
pari_init(1000000, 1000000);
long pari_size = strtol(getenv_with_default("PARI_SIZE", "100000").c_str(), NULL, 0);
#ifdef DEBUG_GPFACT
std::cout<<"calling pari_init with pari_size = "<<pari_size<<endl;
#endif
if (pari_size==0) // e.g. syntax error in the environment variable PARI_SIZE
pari_size = 1000000;
pari_init(pari_size, 1000000);
}
pari_sp av=avma; // store pari stack pointer

Expand Down

0 comments on commit b6bd23d

Please sign in to comment.