Karim Belabas on Thu, 27 Oct 2005 19:34:20 +0200 |
[Date Prev] [Date Next] [Thread Prev] [Thread Next] [Date Index] [Thread Index]
Re: Lifting and handling errors |
* Chris Condrat [2005-10-23 07:05]: > I'm coding a program that generates a very long multivariate polynomial with > a great number of polynomial and integer modulo operations. The program, and > amount of data fed to it, is such that I expect that the stack will > overflow, in fact that's part of the design--a sort of > work-as-far-as-you-can design. When a stack-overflow is encountered, I'd > like to be able to dump out the polynomial before the stack-overflow-causing > operation, as is, to a text file, so I can feed it to a different program. > I'd also like to be able to apply lift() operations to the polynomial to > "clean it up" before it is dumped, but I'm afraid that because of the stack > overflow, there may not be enough room to complete that operation without > another stack-overflow. > Any hints on how these tasks could be accomplished would be appreciated. Indeed lift() will probably overflow the stack again. The current documentation of 'trap' suggests installing an error handler by typing { trap(errpile, print(reorder); writebin("crash")) } This will save the values of all user variables in file 'crash' when stack overflow occurs. And print their names on screen for diagnostics. Unfortunately, the current semantics of trap() is terrible [ overloading a command with distinct functionnalities, can't rethrow, no flexibility in trapping specific sets of errors, ^C is treated as an exception... ], so it is likely to change sometime in the future. But as a temporary workaround, it should work in your example. Hope this helps, 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]