Karim Belabas on Mon, 26 Sep 2005 18:25:14 +0200 |
[Date Prev] [Date Next] [Thread Prev] [Thread Next] [Date Index] [Thread Index]
Re: time in computations |
* Joerg Arndt [2005-09-26 17:57]: > * Igor Schein <igor@txc.com> [Sep 26. 2005 04:53]: > > On Sat, Sep 24, 2005 at 12:17:56AM -0400, Mak Trifkovic wrote: > > > Can I program something along these lines in PARI: do calculation xxx for > > > 1 hr; if you don't finish within that time, quit. > > > > > > Thanks, > > > Mak > > > > Workaround: > > > > limit cputime 3600 # if you're using csh or derivatives > > ulimit -t 3600 # if you're using Bourne shell or derivatives > > > > Unfortunately it applies to the whole session, not each command. > > Just start it in a subshell: > (ulimit -t 3600; gp < script.gp; ) > > > There's no way to do it natively from inside gp. I've brought up the > > desirability of this feature in the past, it'd be nice to have it > > accesible via default(), with default value 0 for unlimited. Here's a one-liner inspired by the above discussion: timeout(T,E) = extern( Str("ulimit -t ", T, "; echo \"", E, "\" | gp -q -f") ) (18:11) gp > timeout(10, "1 + 1") \\ allow 10 sec to compute 1 + 1 time = 0 ms. %1 = 2 (18:11) gp > timeout(10, "bnfinit(x^30 - 2)") (18:12) gp > \\ empty output [ Don't forget the quotes, otherwise the argument is fully evaluated before the "limited" subshell is launched ] Cheers, Karim. -- Karim Belabas 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]