2

I have written a GAP program that returns "true" or "false" as output.

I would like to modify the program in the following way:

If the computation is not finished after 20 seconds, then its output shall be "false".

Is this possible with GAP?

Example:

I would like to use this program in order to test if an ideal in a family of ideals has a certain property. If the computation does not finish after 20 seconds, then the ideal will most likely not have this property.

I would like to have a probabilistic program in that sense.

Thank you.

  • 1
    Revealing my ignorance, what is a GAP program and will the software have access (at various logical points in the code) to the system time? Alternatively, will the software have access to the cpu time taken? I know for sure that (for example) Java provides access to the system time, so one can measure at a given point in the code the elapsed system time that the program has been running. It is unclear whether that is more reliable than measuring elapsed cpu time. Further, while I suspect that (for example) Java (also) provides cpu time, I am not 100% sure. – user2661923 Feb 05 '21 at 20:56
  • 2
    Whether or not you can do this in your program, you can probably do it in a shell script , or bat file that runs your program. – Ethan Bolker Feb 05 '21 at 21:05

1 Answers1

2

In version 4.8 it is possible to call a function with a provided timeout as described in this answer. However, this functionality seems to have serious problems as described in this issue on GitHub and was therefore withdrawn in version 4.9 as stated here.

There is no convenient way (and with convenient I am rereferring to some sort of build in functionality) to achieve what you desire in the current version of plain GAP if we consider the GAP reference as a complete description of its capabilities.

However, using the parallelization options described in HPC-GAP, we could start our calculation in a separate thread, while letting the main thread checking the exceeded time. I have never used it, so I am not sure if this would actually work. I tried it, but failed.

We could also embed the entire GAP system as a C library and call GAP functions in a C program. We could easily monitor the runtime within this program.

Also, and already mentioned by Ethan Bolker in the comments, you can write a GAP program and call it via a shell script. Monitoring the runtime there is also possible. The procedure is described in this answer.

It might also be convenient in some cases to use the GAP interface in SageMath.

David Scholz
  • 2,006