[GAP Forum] control the execution time of a function

Stephen Linton sal at mcs.st-andrews.ac.uk
Wed Jan 26 17:38:36 GMT 2011


It would be relatively easy, even in single-threaded GAP to 
use SIGALRM to effectively deliver a control-C after a pre-determined time.
Using some new machinery that will be in GAP 4.5, it would be possible to "catch" that
interrupt and return fail or whatever.

We will look into it.
	
Steve

On 26 Jan 2011, at 17:19, Bill Allombert wrote:

> On Wed, Jan 26, 2011 at 02:33:56PM +0000, Alexander Konovalov wrote:
>> Dear Georges,
>> 
>> On 25 Jan 2011, at 08:59, bolbita wrote:
>> 
>>> Dear GAP Forum,
>>> 
>>> I have little experience with GAP, and I wonder how can we control the execution time of a function.
>>> I dream about a function like
>>> UnderTimeControl := function (f, arg, maxtime)
>>> which would run the function f with arguments arg and a timer in parallel,
>>> and would return the result of f(arg) whenever its execution time is less than maxtime and would return fail 
>>> otherwise.
>> 
>> The current version of GAP is single-threaded so it's not directly possible
>> to have exactly the scenario you've described.However, there are several
>> possible workarounds of various difficulty and flexibility:
> 
> If that may help, this is how I implemented something similar in PARI/GP
> (which is also single-threaded):
> 
> 1) add a signal handler for SIGALRM
> 2) call the C function alarm(maxtime);
> 3) evaluate f(arg).
> 4) if the signal handler is called, stop the evaluation and return fail.
> 5) if 3) complete, call alarm(0) to disable the alarm.
> 
> Cheers,
> Bill.
> 
> _______________________________________________
> Forum mailing list
> Forum at mail.gap-system.org
> http://mail.gap-system.org/mailman/listinfo/forum




More information about the Forum mailing list