[GAP Forum] Run GAP command for x seconds

Christopher Jefferson caj21 at st-andrews.ac.uk
Thu Jan 28 09:28:09 GMT 2021


Hi,

I agree with Frank. There is an alternative function (which uses the same underlying mechanism) -- IO_CallWithTimeout (and IO_CallWithTimeoutList, which just takes the function arguments as a list).

IO_CallWithTimeout(rec(seconds := 2), Intersection, AlternatingGroup(20), AlternatingGroup(20)*(1,2));

(note that IO_CallWithTimeout uses different names for the times, seconds in this case).

After about 2 seconds outputs [ false ]

Chris



-----Original Message-----
From: Frank Lübeck <frank.luebeck at math.rwth-aachen.de> 
Sent: 27 January 2021 18:19
To: Carl-Fredrik Nyberg Brodda (MTH - Postgraduate Researcher) <C.Nyberg-Brodda at uea.ac.uk>
Cc: forum at gap-system.org
Subject: Re: [GAP Forum] Run GAP command for x seconds

On Wed, Jan 27, 2021 at 04:54:03PM +0000, Carl-Fredrik Nyberg Brodda (MTH - Postgraduate Researcher) wrote:
> Thank you for your response. I am having trouble getting the timeout 
> to work. Do you have an example of using the timeout?
>
> I have attempted to pass the last (third, optional) argument of 
> ParTakeFirstResultByFork as rec(TimeOut := rec(tv_sec :=2, tv_usec := 
> 0)), hoping for my execution to run for 2 seconds, but this does not 
> work (it never times out). I have also tried setting the tv_sec record 
> to be the current time (plus 10 seconds or so), but this does not time out either.

Hi,

This looks correct and it works for me, for example:

gap> Runtimes();  ParTakeFirstResultByFork([function(x) while true do 
gap> od; end], [[1]],rec(TimeOut := rec(tv_sec :=2, tv_usec := 0 ))); 
gap> Runtimes();
rec( system_time := 90, system_time_children := 15, user_time := 1103,
  user_time_children := 3985 )
[  ]
rec( system_time := 94, system_time_children := 15, user_time := 1103,
  user_time_children := 5984 )

I'm only using Linux systems. Some functions of the IO package may not work as expected when GAP is used in Windows (but I don't know the details). 

Best regards again,
  Frank Lübeck

> Best,
> Carl-Fredrik Nyberg Brodda
> ________________________________
> From: Frank Lübeck <frank.luebeck at math.rwth-aachen.de>
> Sent: Wednesday, January 27, 2021 3:53 PM
> To: Carl-Fredrik Nyberg Brodda (MTH - Postgraduate Researcher) 
> <C.Nyberg-Brodda at uea.ac.uk>
> Cc: forum at gap-system.org <forum at gap-system.org>
> Subject: Re: [GAP Forum] Run GAP command for x seconds
> 
> On Wed, Jan 27, 2021 at 02:53:14PM +0000, Carl-Fredrik Nyberg Brodda (MTH - Postgraduate Researcher) wrote:
> > Hi all,
> >
> > A problem which I recently stumbled upon is the following: is there 
> > a way to execute a given GAP command only for a certain amount of 
> > time, before stepping past the command and continuing execution?
> >
> > Let us say I have a table of finitely many finitely presented 
> > groups, and wish to see whether GAP has a "naive" solution for their 
> > word problem. I find a KnuthBendixRewritingSystem() of the group, 
> > and then run
> > MakeConfluent() on this rewriting system. Of course, this process 
> > may not terminate at all! But sometimes it does. My problem is 
> > essentially that I wish to run MakeConfluent() for some amount of 
> > time (say 5 seconds), and then, if the command has not terminated, 
> > continue on with the next group. This avoids all decidability 
> > issues, and would in other programming languages be easily implemented with a timer.
> >
> > Of course the problem is general, so the above is just a use-case. 
> > Is there something that can help with this?
> >
> > Best,
> > Carl-Fredrik Nyberg Brodda
> 
> Dear Forum,
> 
> I have used successfully the function
>     ParTakeFirstResultByFork
> from the IO package for this kind of applications.
> It has an optional third argument which allows to specify a timeout.
> 
> Best regards,
>    Frank

--
///  Dr. Frank Lübeck, Lehrstuhl für Algebra und Zahlentheorie, \\\  Pontdriesch 14/16, 52062 Aachen, Germany ///  E-mail: Frank.Luebeck at Math.RWTH-Aachen.De
\\\  WWW:    http://www.math.rwth-aachen.de/~Frank.Luebeck/

_______________________________________________
Forum mailing list
Forum at gap-system.org
https://mail.gap-system.org/mailman/listinfo/forum



More information about the Forum mailing list