Quellcodebibliothek Statistik Leitseite products/sources/formale Sprachen/GAP/doc/hpc/   (Algebra von RWTH Aachen Version 4.15.1©)  Datei vom 18.9.2025 mit Größe 35 kB image not shown  

Quelle  chap1_mj.html   Sprache: HTML

 
 products/sources/formale Sprachen/GAP/doc/hpc/chap1_mj.html


<?xml version="1.0" encoding="UTF-8"?>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
         "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">

<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en">
<head>
<script type="text/javascript"
  src="https://cdn.jsdelivr.net/npm/mathjax@2/MathJax.js?config=TeX-AMS-MML_HTMLorMML">
</script>
<title>GAP (hpc) - Chapter 1: Tasks</title>
<meta http-equiv="content-type" content="text/html; charset=UTF-8" />
<meta name="generator" content="GAPDoc2HTML" />
<link rel="stylesheet" type="text/css" href="manual.css" />
<script src="manual.js" type="text/javascript"></script>
<script type="text/javascript">overwriteStyle();</script>
</head>
<body class="chap1"  onload="jscontent()">


<div class="chlinktop"><span class="chlink1">Goto Chapter: </span><a href="chap0_mj.html">Top</a>  <a href="chap1_mj.html">1</a>  <a href="chap2_mj.html">2</a>  <a href="chap3_mj.html">3</a>  <a href="chap4_mj.html">4</a>  <a href="chap5_mj.html">5</a>  <a href="chap6_mj.html">6</a>  <a href="chap7_mj.html">7</a>  <a href="chap8_mj.html">8</a>  <a href="chap9_mj.html">9</a>  <a href="chap10_mj.html">10</a>  <a href="chap11_mj.html">11</a>  <a href="chapInd_mj.html">Ind</a>  </div>

<div class="chlinkprevnexttop"> <a href="chap0_mj.html">[Top of Book]</a>   <a href="chap0_mj.html#contents">[Contents]</a>    <a href="chap0_mj.html">[Previous Chapter]</a>    <a href="chap2_mj.html">[Next Chapter]</a>   </div>

<p id="mathjaxlink" class="pcenter"><a href="chap1.html">[MathJax off]</a></p>
<p><a id="X7EA285468533E153" name="X7EA285468533E153"></a></p>
<div class="ChapSects"><a href="chap1_mj.html#X7EA285468533E153">1 <span class="Heading">Tasks</span></a>
<div class="ContSect"><span class="tocline"><span class="nocss"> </span><a href="chap1_mj.html#X8389AD927B74BA4A">1.1 <span class="Heading">Overview</span></a>
</span>
</div>
<div class="ContSect"><span class="tocline"><span class="nocss"> </span><a href="chap1_mj.html#X7C9F2EF384645B8F">1.2 <span class="Heading">Running tasks</span></a>
</span>
<div class="ContSSBlock">
<span class="ContSS"><br /><span class="nocss">  </span><a href="chap1_mj.html#X7DEC1649841E3813">1.2-1 RunTask</a></span>
<span class="ContSS"><br /><span class="nocss">  </span><a href="chap1_mj.html#X7A86AE967D2A9E94">1.2-2 ScheduleTask</a></span>
<span class="ContSS"><br /><span class="nocss">  </span><a href="chap1_mj.html#X85BC2BBC7EF5B22E">1.2-3 DelayTask</a></span>
<span class="ContSS"><br /><span class="nocss">  </span><a href="chap1_mj.html#X856288C27C62B14A">1.2-4 RunAsyncTask</a></span>
<span class="ContSS"><br /><span class="nocss">  </span><a href="chap1_mj.html#X7EAC7A4B86F5F74C">1.2-5 ScheduleAsyncTask</a></span>
<span class="ContSS"><br /><span class="nocss">  </span><a href="chap1_mj.html#X791CA0E07B16E7F9">1.2-6 MakeTaskAsync</a></span>
<span class="ContSS"><br /><span class="nocss">  </span><a href="chap1_mj.html#X84AFD0FA7A4E3633">1.2-7 ImmediateTask</a></span>
<span class="ContSS"><br /><span class="nocss">  </span><a href="chap1_mj.html#X83D2E32C8759FB37">1.2-8 ExecuteTask</a></span>
<span class="ContSS"><br /><span class="nocss">  </span><a href="chap1_mj.html#X861BC1488345C424">1.2-9 WaitTask</a></span>
<span class="ContSS"><br /><span class="nocss">  </span><a href="chap1_mj.html#X81489CD684EA11B6">1.2-10 WaitAnyTask</a></span>
<span class="ContSS"><br /><span class="nocss">  </span><a href="chap1_mj.html#X7A86C732823E04B6">1.2-11 TaskResult</a></span>
<span class="ContSS"><br /><span class="nocss">  </span><a href="chap1_mj.html#X830A82A7847993FF">1.2-12 CullIdleTasks</a></span>
</div></div>
<div class="ContSect"><span class="tocline"><span class="nocss"> </span><a href="chap1_mj.html#X86F8419B7968345B">1.3 <span class="Heading">Information about tasks</span></a>
</span>
<div class="ContSSBlock">
<span class="ContSS"><br /><span class="nocss">  </span><a href="chap1_mj.html#X87BB5EF38415B923">1.3-1 TaskSuccess</a></span>
<span class="ContSS"><br /><span class="nocss">  </span><a href="chap1_mj.html#X85F42F5E7E04F3C2">1.3-2 TaskError</a></span>
<span class="ContSS"><br /><span class="nocss">  </span><a href="chap1_mj.html#X7C0C66E37DB9ACC0">1.3-3 CurrentTask</a></span>
<span class="ContSS"><br /><span class="nocss">  </span><a href="chap1_mj.html#X7DA4E06B792002C7">1.3-4 RunningTasks</a></span>
<span class="ContSS"><br /><span class="nocss">  </span><a href="chap1_mj.html#X7A023A657BB4F17D">1.3-5 TaskStarted</a></span>
<span class="ContSS"><br /><span class="nocss">  </span><a href="chap1_mj.html#X7E7500E17EC1067D">1.3-6 TaskFinished</a></span>
<span class="ContSS"><br /><span class="nocss">  </span><a href="chap1_mj.html#X7B37CED386024A1F">1.3-7 TaskIsAsync</a></span>
</div></div>
<div class="ContSect"><span class="tocline"><span class="nocss"> </span><a href="chap1_mj.html#X7B286945821A3BBA">1.4 <span class="Heading">Cancelling tasks</span></a>
</span>
<div class="ContSSBlock">
<span class="ContSS"><br /><span class="nocss">  </span><a href="chap1_mj.html#X86C26E3081C3C9AA">1.4-1 CancelTask</a></span>
<span class="ContSS"><br /><span class="nocss">  </span><a href="chap1_mj.html#X8431B91487A8A3F1">1.4-2 TaskCancellationRequested</a></span>
<span class="ContSS"><br /><span class="nocss">  </span><a href="chap1_mj.html#X7D61F9C487232DE7">1.4-3 OnTaskCancellation</a></span>
<span class="ContSS"><br /><span class="nocss">  </span><a href="chap1_mj.html#X82D1773F8058CA54">1.4-4 OnTaskCancellationReturn</a></span>
</div></div>
<div class="ContSect"><span class="tocline"><span class="nocss"> </span><a href="chap1_mj.html#X802FC4C284F68696">1.5 <span class="Heading">Conditions</span></a>
</span>
</div>
<div class="ContSect"><span class="tocline"><span class="nocss"> </span><a href="chap1_mj.html#X7EE6DC40842CD74B">1.6 <span class="Heading">Milestones</span></a>
</span>
<div class="ContSSBlock">
<span class="ContSS"><br /><span class="nocss">  </span><a href="chap1_mj.html#X80CB3247854A46E4">1.6-1 NewMilestone</a></span>
<span class="ContSS"><br /><span class="nocss">  </span><a href="chap1_mj.html#X800AE2737CB715C5">1.6-2 ContributeToMilestone</a></span>
<span class="ContSS"><br /><span class="nocss">  </span><a href="chap1_mj.html#X7ACB26D38096CD56">1.6-3 AchieveMilestone</a></span>
<span class="ContSS"><br /><span class="nocss">  </span><a href="chap1_mj.html#X83E7AF007E040FB9">1.6-4 IsMilestoneAchieved</a></span>
</div></div>
</div>

<h3>1 <span class="Heading">Tasks</span></h3>

<p><a id="X8389AD927B74BA4A" name="X8389AD927B74BA4A"></a></p>

<h4>1.1 <span class="Heading">Overview</span></h4>

<p>Tasks provide mid- to high-level functionality for programmers to describe asynchronous workflows. A task is an asynchronously or synchronously executing job; functions exist to create tasks that are executed concurrently, on demand, or in the current thread; to wait for their completion, check their status, and retrieve any results.</p>

<p>Here is a simple example of sorting a list in the background:</p>


<div class="example"><pre>
<span class="GAPprompt">gap></span> <span class="GAPinput">task := RunTask(x -> SortedList(x), [3,2,1]);;</span>
<span class="GAPprompt">gap></span> <span class="GAPinput">WaitTask(task);</span>
<span class="GAPprompt">gap></span> <span class="GAPinput">TaskResult(task);</span>
[ 1, 2, 3 ]
</pre></div>

<p><code class="func">RunTask</code> (<a href="chap1_mj.html#X7DEC1649841E3813"><span class="RefLink">1.2-1</span></a>) dispatches a task to run in the background; a task is described by a function and zero or more arguments that are passed to <code class="func">RunTask</code> (<a href="chap1_mj.html#X7DEC1649841E3813"><span class="RefLink">1.2-1</span></a>). <code class="func">WaitTask</code> (<a href="chap1_mj.html#X861BC1488345C424"><span class="RefLink">1.2-9</span></a>) waits for the task to complete; and <code class="code">TaskResult</code> returns the result of the task.</p>

<p><code class="func">TaskResult</code> (<a href="chap1_mj.html#X7A86C732823E04B6"><span class="RefLink">1.2-11</span></a>) does an implicit <code class="func">WaitTask</code> (<a href="chap1_mj.html#X861BC1488345C424"><span class="RefLink">1.2-9</span></a>), so the second line above can actually be omitted:</p>


<div class="example"><pre>
<span class="GAPprompt">gap></span> <span class="GAPinput">task := RunTask(x -> SortedList(x), [3,2,1]);;</span>
<span class="GAPprompt">gap></span> <span class="GAPinput">TaskResult(task);</span>
[ 1, 2, 3 ]
</pre></div>

<p>It is simple to run two tasks in parallel. Let's compute the factorial of 10000 by splitting the work between two tasks:




<div class="example"><pre>
<span class="GAPprompt">gap></span> <span class="GAPinput">task1 := RunTask(Product, [1..5000]);;</span>
<span class="GAPprompt">gap></span> <span class="GAPinput">task2 := RunTask(Product, [5001..10000]);;</span>
<span class="GAPprompt">gap></span> <span class="GAPinput">TaskResult(task1) * TaskResult(task2) = Factorial(10000);</span>
true
</pre></div>

<p>You can use <code class="func">DelayTask</code> (<a href="chap1_mj.html#X85BC2BBC7EF5B22E"><span class="RefLink">1.2-3</span></a>) to delay executing the task until its result is actually needed.</p>


<div class="example"><pre>
<span class="GAPprompt">gap></span> <span class="GAPinput">task1 := DelayTask(Product, [1..5000]);;</span>
<span class="GAPprompt">gap></span> <span class="GAPinput">task2 := DelayTask(Product, [5001..10000]);;</span>
<span class="GAPprompt">gap></span> <span class="GAPinput">WaitTask(task1, task2);</span>
<span class="GAPprompt">gap></span> <span class="GAPinput">TaskResult(task1) * TaskResult(task2) = Factorial(10000);</span>
true
</pre></div>

<p>Note that <code class="func">WaitTask</code> (<a href="chap1_mj.html#X861BC1488345C424"><span class="RefLink">1.2-9</span></a>) is used here to start execution of both tasks; otherwise, <code class="code">task2</code> would not be started until <code class="code">TaskResult(task1)</code> has been evaluated.</p>

<p>To start execution of a delayed task, you can also use <code class="code">ExecuteTask</code>. This has no effect if a task has already been running.</p>

<p>For convenience, you can also use <code class="func">ImmediateTask</code> (<a href="chap1_mj.html#X84AFD0FA7A4E3633"><span class="RefLink">1.2-7</span></a>) to execute a task synchronously (i.e., the task is started immediately and the call does not return until the task has completed).</p>


<div class="example"><pre>
<span class="GAPprompt">gap></span> <span class="GAPinput">task := ImmediateTask(x -> SortedList(x), [3,2,1]);;</span>
<span class="GAPprompt">gap></span> <span class="GAPinput">TaskResult(task);</span>
[ 1, 2, 3 ]
</pre></div>

<p>This is indistinguishable from calling the function directly, but provides the same interface as normal tasks.</p>

<p>If e.g. you want to call a function only for its side-effects, it can be useful to ignore the result of a task. <code class="func">RunAsyncTask</code> (<a href="chap1_mj.html#X856288C27C62B14A"><span class="RefLink">1.2-4</span></a>) provides the necessary functionality. Such a task cannot be waited for and its result (if any) is ignored.</p>


<div class="example"><pre>
<span class="GAPprompt">gap></span> <span class="GAPinput">RunAsyncTask(function() Print("Hello, world!\n"); end);;</span>
<span class="GAPprompt">gap></span> <span class="GAPinput">!list</span>
--- Thread 0 [0]
--- Thread 5 [5] (pending output)
<span class="GAPprompt">gap></span> <span class="GAPinput">!5</span>
--- Switching to thread 5
[5] Hello, world!
!0
--- Switching to thread 0
gap>
</pre></div>

<p>For more information on the multi-threaded user interface, see Chapter <a href="chap4_mj.html#X7AFF436381C319CD"><span class="RefLink">4</span></a>.</p>

<p>Task arguments are generally copied so that both the task that created them and the task that uses them can access the data concurrently without fear of race conditions. To avoid copying, arguments should be made shared or public (see the relevant parts of section <a href="chap3_mj.html#X87315FA584A37637"><span class="RefLink">3.6</span></a> on migrating objects between regions); shared and public arguments will not be copied.</p>

<p>HPC-GAP currently has multiple implementations of the task API. To use an alternative implementation to the one documented here, set the environment variable <code class="code">GAP_WORKSTEALING</code> to a non-empty value before starting GAP.</p>

<p><a id="X7C9F2EF384645B8F" name="X7C9F2EF384645B8F"></a></p>

<h4>1.2 <span class="Heading">Running tasks</span></h4>

<p><a id="X7DEC1649841E3813" name="X7DEC1649841E3813"></a></p>

<h5>1.2-1 RunTask</h5>

<div class="func"><table class="func" width="100%"><tr><td class="tdleft"><code class="func">‣ RunTask</code>( <var class="Arg">func</var>[, <var class="Arg">arg1</var>, <var class="Arg">...</var>, <var class="Arg">argn</var>] )</td><td class="tdright">( function )</td></tr></table></div>
<p><code class="func">RunTask</code> prepares a task for execution and starts it. The task will call the function <var class="Arg">func</var> with arguments <var class="Arg">arg1</var> through <var class="Arg">argn</var> (if provided). The return value of <var class="Arg">func</var> is the result of the task. The <code class="func">RunTask</code> call itself returns a task object that can be used by functions that expect a task argument.</p>

<p><a id="X7A86AE967D2A9E94" name="X7A86AE967D2A9E94"></a></p>

<h5>1.2-2 ScheduleTask</h5>

<div class="func"><table class="func" width="100%"><tr><td class="tdleft"><code class="func">‣ ScheduleTask</code>( <var class="Arg">condition</var>, <var class="Arg">func</var>[, <var class="Arg">arg1</var>, <var class="Arg">...</var>, <var class="Arg">argn</var>] )</td><td class="tdright">( function )</td></tr></table></div>
<p><code class="func">ScheduleTask</code> prepares a task for execution, but, unlike <code class="func">RunTask</code> (<a href="chap1_mj.html#X7DEC1649841E3813"><span class="RefLink">1.2-1</span></a>) does not start it until <var class="Arg">condition</var> is met. See on how to construct conditions. Simple examples of conditions are individual tasks, where execution occurs after the task completes, or lists of tasks, where execution occurs after all tasks in the list complete.</p>


<div class="example"><pre>
<span class="GAPprompt">gap></span> <span class="GAPinput">t1 := RunTask(x->x*x, 3);;</span>
<span class="GAPprompt">gap></span> <span class="GAPinput">t2 := RunTask(x->x*x, 4);;</span>
<span class="GAPprompt">gap></span> <span class="GAPinput">t := ScheduleTask([t1, t2], function()</span>
<span class="GAPprompt">></span> <span class="GAPinput">          return TaskResult(t1) + TaskResult(t2);</span>
<span class="GAPprompt">></span> <span class="GAPinput">   end);;</span>
<span class="GAPprompt">gap></span> <span class="GAPinput">TaskResult(t);</span>
25
</pre></div>

<p>While the above example could also be achieved with <code class="func">RunTask</code> (<a href="chap1_mj.html#X7DEC1649841E3813"><span class="RefLink">1.2-1</span></a>) in lieu of <code class="func">ScheduleTask</code>, since <code class="func">TaskResult</code> (<a href="chap1_mj.html#X7A86C732823E04B6"><span class="RefLink">1.2-11</span></a>) would wait for <var class="Arg">t1</var> and <var class="Arg">t2</var> to complete, the above implementation does not actually start the final task until the others are complete, making it more efficient, since no additional worker thread needs to be occupied.</p>

<p><a id="X85BC2BBC7EF5B22E" name="X85BC2BBC7EF5B22E"></a></p>

<h5>1.2-3 DelayTask</h5>

<div class="func"><table class="func" width="100%"><tr><td class="tdleft"><code class="func">‣ DelayTask</code>( <var class="Arg">func</var>[, <var class="Arg">arg1</var>, <var class="Arg">...</var>, <var class="Arg">argn</var>] )</td><td class="tdright">( function )</td></tr></table></div>
<p><code class="func">DelayTask</code> works as <code class="func">RunTask</code> (<a href="chap1_mj.html#X7DEC1649841E3813"><span class="RefLink">1.2-1</span></a>), but its start is delayed until it is being waited for (including implicitly by calling <code class="func">TaskResult</code(<a href="chap1_mj.html#X7A86C732823E04B6"><span class="RefLink">1.2-11</span></a>)).</p>

<p><a id="X856288C27C62B14A" name="X856288C27C62B14A"></a></p>

<h5>1.2-4 RunAsyncTask</h5>

<div class="func"><table class="func" width="100%"><tr><td class="tdleft"><code class="func">‣ RunAsyncTask</code>( <var class="Arg">func</var>[, <var class="Arg">arg1</var>, <var class="Arg">...</var>, <var class="Arg">argn</var>] )</td><td class="tdright">( function )</td></tr></table></div>
<p><code class="func">RunAsyncTask</code> creates an asynchronous task. It works like <code class="func">RunTask</code> (<a href="chap1_mj.html#X7DEC1649841E3813"><span class="RefLink">1.2-1</span></a>), except that its result will be ignored.</p>

<p><a id="X7EAC7A4B86F5F74C" name="X7EAC7A4B86F5F74C"></a></p>

<h5>1.2-5 ScheduleAsyncTask</h5>

<div class="func"><table class="func" width="100%"><tr><td class="tdleft"><code class="func">‣ ScheduleAsyncTask</code>( <var class="Arg">condition</var>, <var class="Arg">func</var>[, <var class="Arg">arg1</var>, <var class="Arg">...</var>, <var class="Arg">argn</var>] )</td><td class="tdright">( function )</td></tr></table></div>
<p><code class="func">ScheduleAsyncTask</code> creates an asynchronous task. It works like <code class="func">ScheduleTask</code> (<a href="chap1_mj.html#X7A86AE967D2A9E94"><span class="RefLink">1.2-2</span></a>), except that its result will be ignored.</p>

<p><a id="X791CA0E07B16E7F9" name="X791CA0E07B16E7F9"></a></p>

<h5>1.2-6 MakeTaskAsync</h5>

<div class="func"><table class="func" width="100%"><tr><td class="tdleft"><code class="func">‣ MakeTaskAsync</code>( <var class="Arg">task</var> )</td><td class="tdright">( function )</td></tr></table></div>
<p><code class="func">MakeTaskAsync</code> turns a synchronous task into an asynchronous task that cannot be waited for and whose result will be ignored.</p>

<p><a id="X84AFD0FA7A4E3633" name="X84AFD0FA7A4E3633"></a></p>

<h5>1.2-7 ImmediateTask</h5>

<div class="func"><table class="func" width="100%"><tr><td class="tdleft"><code class="func">‣ ImmediateTask</code>( <var class="Arg">func</var>[, <var class="Arg">arg1</var>, <var class="Arg">...</var>, <var class="Arg">argn</var>] )</td><td class="tdright">( function )</td></tr></table></div>
<p><code class="func">ImmediateTask</code> executes the task specified by its arguments synchronously, usually within the current thread.</p>

<p><a id="X83D2E32C8759FB37" name="X83D2E32C8759FB37"></a></p>

<h5>1.2-8 ExecuteTask</h5>

<div class="func"><table class="func" width="100%"><tr><td class="tdleft"><code class="func">‣ ExecuteTask</code>( <var class="Arg">task</var> )</td><td class="tdright">( function )</td></tr></table></div>
<p><code class="func">ExecuteTask</code> starts <var class="Arg">task</var> if it is not already running. It has only an effect if its argument is a task returned by <code class="func">DelayTask</code> (<a href="chap1_mj.html#X85BC2BBC7EF5B22E"><span class="RefLink">1.2-3</span></a>); otherwise, it is a no-op.</p>

<p><a id="X861BC1488345C424" name="X861BC1488345C424"></a></p>

<h5>1.2-9 WaitTask</h5>

<div class="func"><table class="func" width="100%"><tr><td class="tdleft"><code class="func">‣ WaitTask</code>( <var class="Arg">task1</var>, <var class="Arg">...</var>, <var class="Arg">taskn</var)</td><td class="tdright">( function )</td></tr></table></div>
<div class="func"><table class="func" width="100%"><tr><td class="tdleft"><code class="func">‣ WaitTask</code>( <var class="Arg">condition</var> )</td><td class="tdright">( function )</td></tr></table></div>
<div class="func"><table class="func" width="100%"><tr><td class="tdleft"><code class="func">‣ WaitTasks</code>( <var class="Arg">task1</var>, <var class="Arg">...</var>, <var class="Arg">taskn</var> )</td><td class="tdright">( function )</td></tr></table></div>
<p><code class="func">WaitTask</code> waits until <var class="Arg">task1</var> through <var class="Arg">taskn</var> have completed; after that, it returns. Alternatively, a condition can be passed to <code class="func">WaitTask</code> in order to wait until a condition is met. See on how to construct conditions. <code class="func">WaitTasks</code> is an alias for <code class="func">WaitTask</code>.</p>

<p><a id="X81489CD684EA11B6" name="X81489CD684EA11B6"></a></p>

<h5>1.2-10 WaitAnyTask</h5>

<div class="func"><table class="func" width="100%"><tr><td class="tdleft"><code class="func">‣ WaitAnyTask</code>( <var class="Arg">task1</var>, <var class="Arg">...</var>, <var class="Arg">taskn</var> )</td><td class="tdright">( function )</td></tr></table></div>
<p>The <code class="func">WaitAnyTask</code> function waits for any of its arguments to finish, then returns the number of that task.</p>


<div class="example"><pre>
<span class="GAPprompt">gap></span> <span class="GAPinput">task1 := DelayTask(x->SortedList(x), [3,2,1]);;</span>
<span class="GAPprompt">gap></span> <span class="GAPinput">task2 := DelayTask(x->SortedList(x), [6,5,4]);;</span>
<span class="GAPprompt">gap></span> <span class="GAPinput">which := WaitAnyTask(task1, task2);</span>
2
<span class="GAPprompt">gap></span> <span class="GAPinput">if which = 1 then</span>
<span class="GAPprompt">></span> <span class="GAPinput">     Display(TaskResult(task1));Display(TaskResult(task2));</span>
<span class="GAPprompt">></span> <span class="GAPinput">   else</span>
<span class="GAPprompt">></span> <span class="GAPinput">     Display(TaskResult(task2));Display(TaskResult(task1));</span>
<span class="GAPprompt">></span> <span class="GAPinput">   fi;</span>
[ 4, 5, 6 ]
[ 1, 2, 3 ]
</pre></div>

<p>One can pass a list of tasks to <code class="code">WaitAnyTask</code> as an argument; <code class="code">WaitAnyTask([task1, ..., taskn])</code> behaves identically to <code class="code">WaitAnyTask(task1, ..., taskn)</code>.</p>

<p><a id="X7A86C732823E04B6" name="X7A86C732823E04B6"></a></p>

<h5>1.2-11 TaskResult</h5>

<div class="func"><table class="func" width="100%"><tr><td class="tdleft"><code class="func">‣ TaskResult</code>( <var class="Arg">task</var> )</td><td class="tdright">( function )</td></tr></table></div>
<p>The <code class="func">TaskResult</code> function returns the result of a task. It implicitly calls <code class="func">WaitTask</code> (<a href="chap1_mj.html#X861BC1488345C424"><span class="RefLink">1.2-9</span></a>) if that is necessary. Multiple invocations of <code class="func">TaskResult</code> with the same task argument will not do repeated waits and always return the same value.</p>

<p>If the function executed by <var class="Arg">task</var> encounters an error, <code class="func">TaskResult</code> returns <code class="keyw">fail</code>. Whether <var class="Arg">task</var> encountered an error can be checked via <code class="func">TaskSuccess</code> (<a href="chap1_mj.html#X87BB5EF38415B923"><span class="RefLink">1.3-1</span></a>). In case of an error, the error message can be retrieved via <code class="func">TaskError</code> (<a href="chap1_mj.html#X85F42F5E7E04F3C2"><span class="RefLink">1.3-2</span></a>).</p>

<p><a id="X830A82A7847993FF" name="X830A82A7847993FF"></a></p>

<h5>1.2-12 CullIdleTasks</h5>

<div class="func"><table class="func" width="100%"><tr><td class="tdleft"><code class="func">‣ CullIdleTasks</code>(  )</td><td class="tdright">( function )</td></tr></table></div>
<p>This function terminates unused worker threads.</p>

<p><a id="X86F8419B7968345B" name="X86F8419B7968345B"></a></p>

<h4>1.3 <span class="Heading">Information about tasks</span></h4>

<p><a id="X87BB5EF38415B923" name="X87BB5EF38415B923"></a></p>

<h5>1.3-1 TaskSuccess</h5>

<div class="func"><table class="func" width="100%"><tr><td class="tdleft"><code class="func">‣ TaskSuccess</code>( <var class="Arg">task</var> )</td><td class="tdright">( function )</td></tr></table></div>
<p><code class="func">TaskSuccess</code> waits for <var class="Arg">task</var> and returns <code class="keyw">true</code> if the it finished without encountering an error. Otherwise the function returns <code class="keyw">false</code>.</p>

<p><a id="X85F42F5E7E04F3C2" name="X85F42F5E7E04F3C2"></a></p>

<h5>1.3-2 TaskError</h5>

<div class="func"><table class="func" width="100%"><tr><td class="tdleft"><code class="func">‣ TaskError</code>( <var class="Arg">task</var> )</td><td class="tdright">( function )</td></tr></table></div>
<p><code class="func">TaskError</code> waits for <var class="Arg">task</var> and returns its error message, if it encountered an error. If it did not encounter an error, the function returns <code class="keyw">fail</code>.</p>

<p><a id="X7C0C66E37DB9ACC0" name="X7C0C66E37DB9ACC0"></a></p>

<h5>1.3-3 CurrentTask</h5>

<div class="func"><table class="func" width="100%"><tr><td class="tdleft"><code class="func">‣ CurrentTask</code>(  )</td><td class="tdright">( function )</td></tr></table></div>
<p>The <code class="func">CurrentTask</code> returns the currently running task.</p>

<p><a id="X7DA4E06B792002C7" name="X7DA4E06B792002C7"></a></p>

<h5>1.3-4 RunningTasks</h5>

<div class="func"><table class="func" width="100%"><tr><td class="tdleft"><code class="func">‣ RunningTasks</code>(  )</td><td class="tdright">( function )</td></tr></table></div>
<p>This function returns the number of currently running tasks. Note that it is only an approximation and can change as new tasks are being started by other threads.</p>

<p><a id="X7A023A657BB4F17D" name="X7A023A657BB4F17D"></a></p>

<h5>1.3-5 TaskStarted</h5>

<div class="func"><table class="func" width="100%"><tr><td class="tdleft"><code class="func">‣ TaskStarted</code>( <var class="Arg">task</var> )</td><td class="tdright">( function )</td></tr></table></div>
<p>This function returns true if the task has started executing (i.e., for any non-delayed task), false otherwise.</p>

<p><a id="X7E7500E17EC1067D" name="X7E7500E17EC1067D"></a></p>

<h5>1.3-6 TaskFinished</h5>

<div class="func"><table class="func" width="100%"><tr><td class="tdleft"><code class="func">‣ TaskFinished</code>( <var class="Arg">task</var> )</td><td class="tdright">( function )</td></tr></table></div>
<p>This function returns true if the task has finished executing and its result is available, false otherwise.</p>

<p><a id="X7B37CED386024A1F" name="X7B37CED386024A1F"></a></p>

<h5>1.3-7 TaskIsAsync</h5>

<div class="func"><table class="func" width="100%"><tr><td class="tdleft"><code class="func">‣ TaskIsAsync</code>( <var class="Arg">task</var> )</td><td class="tdright">( function )</td></tr></table></div>
<p>This function returns true if the task is asynchronous, true otherwise.</p>

<p><a id="X7B286945821A3BBA" name="X7B286945821A3BBA"></a></p>

<h4>1.4 <span class="Heading">Cancelling tasks</span></h4>

<p>HPC-GAP uses a cooperative model for task cancellation. A programmer can request the cancellation of another task, but it is up to that other task to actually terminate itself. The tasks library has functions to request cancellation, to test for the cancellation state of a task, and to perform actions in response to cancellation requests.</p>

<p><a id="X86C26E3081C3C9AA" name="X86C26E3081C3C9AA"></a></p>

<h5>1.4-1 CancelTask</h5>

<div class="func"><table class="func" width="100%"><tr><td class="tdleft"><code class="func">‣ CancelTask</code>( <var class="Arg">task</var> )</td><td class="tdright">( function )</td></tr></table></div>
<p><code class="func">CancelTask</code> submits a request that <var class="Arg">task</var> is to be cancelled.</p>

<p><a id="X8431B91487A8A3F1" name="X8431B91487A8A3F1"></a></p>

<h5>1.4-2 TaskCancellationRequested</h5>

<div class="func"><table class="func" width="100%"><tr><td class="tdleft"><code class="func">‣ TaskCancellationRequested</code>( <var class="Arg">task</var> )</td><td class="tdright">( function )</td></tr></table></div>
<p><code class="func">TaskCancellationRequested</code> returns true if <code class="func">CancelTask</code> (<a href="chap1_mj.html#X86C26E3081C3C9AA"><span class="RefLink">1.4-1</span></a>) has been called for <var class="Arg">task</var>, false otherwise.</p>

<p><a id="X7D61F9C487232DE7" name="X7D61F9C487232DE7"></a></p>

<h5>1.4-3 OnTaskCancellation</h5>

<div class="func"><table class="func" width="100%"><tr><td class="tdleft"><code class="func">‣ OnTaskCancellation</code>( <var class="Arg">exit_func</var> )</td><td class="tdright">( function )</td></tr></table></div>
<p><code class="func">OnTaskCancellation</code> tests if cancellation for the current task has been requested. If so, then <var class="Arg">exit_func</var> will be called (as a parameterless function) and the current task will be aborted. The result of the current task will be the value of <var class="Arg">exit_func()</var>.</p>


<div class="example"><pre>
<span class="GAPprompt">gap></span> <span class="GAPinput">task := RunTask(function()</span>
<span class="GAPprompt">></span> <span class="GAPinput">     while true do</span>
<span class="GAPprompt">></span> <span class="GAPinput">       OnTaskCancellation(function() return 314; end);</span>
<span class="GAPprompt">></span> <span class="GAPinput">     od;</span>
<span class="GAPprompt">></span> <span class="GAPinput">   end);;</span>
<span class="GAPprompt">gap></span> <span class="GAPinput">CancelTask(task);</span>
<span class="GAPprompt">gap></span> <span class="GAPinput">TaskResult(task);</span>
314
</pre></div>

<p><a id="X82D1773F8058CA54" name="X82D1773F8058CA54"></a></p>

<h5>1.4-4 OnTaskCancellationReturn</h5>

<div class="func"><table class="func" width="100%"><tr><td class="tdleft"><code class="func">‣ OnTaskCancellationReturn</code>( <var class="Arg">value</var> )</td><td class="tdright">( function )</td></tr></table></div>
<p><code class="func">OnTaskCancellationReturn</code> is a convenience function that does the same as: <code class="code">OnTaskCancellation(function() return value; end);</code></p>

<p><a id="X802FC4C284F68696" name="X802FC4C284F68696"></a></p>

<h4>1.5 <span class="Heading">Conditions</span></h4>

<p><code class="func">ScheduleTask</code> (<a href="chap1_mj.html#X7A86AE967D2A9E94"><span class="RefLink">1.2-2</span></a>) and <code class="func">WaitTask</code> (<a href="chap1_mj.html#X861BC1488345C424"><span class="RefLink">1.2-9</span></a>) can be made to wait on more complex conditions than just tasks. A condition is either a milestone, a task, or a list of milestones and tasks. <code class="func">ScheduleTask</code> (<a href="chap1_mj.html#X7A86AE967D2A9E94"><span class="RefLink">1.2-2</span></a>) starts its task and <code class="func">WaitTask</code> (<a href="chap1_mj.html#X861BC1488345C424"><span class="RefLink">1.2-9</span></a>) returns when the condition has been met. A condition represented by a task is met when the task has completed. A condition represented by a milestone is met when the milestone has been achieved (see below). A condition represented by a list is met when all conditions in the list have been met.</p>

<p><a id="X7EE6DC40842CD74B" name="X7EE6DC40842CD74B"></a></p>

<h4>1.6 <span class="Heading">Milestones</span></h4>

<p>Milestones are a way to represent abstract conditions to which multiple tasks can contribute.</p>

<p><a id="X80CB3247854A46E4" name="X80CB3247854A46E4"></a></p>

<h5>1.6-1 NewMilestone</h5>

<div class="func"><table class="func" width="100%"><tr><td class="tdleft"><code class="func">‣ NewMilestone</code>( [<var class="Arg">list</var>] )</td><td class="tdright">( function )</td></tr></table></div>
<p>The <code class="func">NewMilestone</code> function creates a new milestone. Its argument is a list of targets, which must be a list of integers and/or strings. If omitted, the list defaults to <code class="code">[0]</code>.</p>

<p><a id="X800AE2737CB715C5" name="X800AE2737CB715C5"></a></p>

<h5>1.6-2 ContributeToMilestone</h5>

<div class="func"><table class="func" width="100%"><tr><td class="tdleft"><code class="func">‣ ContributeToMilestone</code>( <var class="Arg">milestone</var>, <var class="Arg">target</var> )</td><td class="tdright">( function )</td></tr></table></div>
<p>The <code class="func">ContributeToMilestone</code> milestone function contributes the specified target to the milestone. Once all targets have been contributed to a milestone, it has been achieved.</p>

<p><a id="X7ACB26D38096CD56" name="X7ACB26D38096CD56"></a></p>

<h5>1.6-3 AchieveMilestone</h5>

<div class="func"><table class="func" width="100%"><tr><td class="tdleft"><code class="func">‣ AchieveMilestone</code>( <var class="Arg">milestone</var> )</td><td class="tdright">( function )</td></tr></table></div>
<p>The <code class="func">AchieveMilestone</code> function allows a program to achieve a milestone in a single step without adding individual targets to it. This is most useful in conjunction with the default value for <code class="func">NewMilestone</code> (<a href="chap1_mj.html#X80CB3247854A46E4"><span class="RefLink">1.6-1</span></a>), e.g.</p>


<div class="example"><pre>
<span class="GAPprompt">gap></span> <span class="GAPinput">m := NewMilestone();;</span>
<span class="GAPprompt">gap></span> <span class="GAPinput">AchieveMilestone(m);</span>
</pre></div>

<p>></p>

<p><a id="X83E7AF007E040FB9" name="X83E7AF007E040FB9"></a></p>

<h5>1.6-4 IsMilestoneAchieved</h5>

<div class="func"><table class="func" width="100%"><tr><td class="tdleft"><code class="func">‣ IsMilestoneAchieved</code>( <var class="Arg">milestone</var> )</td><td class="tdright">( function )</td></tr></table></div>
<p><code class="func">IsMilestoneAchieved</code> tests explicitly if a milestone has been achieved. It returns <code class="keyw">true</code> on success, <code class="keyw">false</code> otherwise.</p>


<div class="example"><pre>
<span class="GAPprompt">gap></span> <span class="GAPinput">m := NewMilestone([1,2]);;</span>
<span class="GAPprompt">gap></span> <span class="GAPinput">ContributeToMilestone(m, 1);</span>
<span class="GAPprompt">gap></span> <span class="GAPinput">IsMilestoneAchieved(m);</span>
false
<span class="GAPprompt">gap></span> <span class="GAPinput">ContributeToMilestone(m, 2);</span>
<span class="GAPprompt">gap></span> <span class="GAPinput">IsMilestoneAchieved(m);</span>
true
</pre></div>


<div class="chlinkprevnextbot"> <a href="chap0_mj.html">[Top of Book]</a>   <a href="chap0_mj.html#contents">[Contents]</a>    <a href="chap0_mj.html">[Previous Chapter]</a>    <a href="chap2_mj.html">[Next Chapter]</a>   </div>


<div class="chlinkbot"><span class="chlink1">Goto Chapter: </span><a href="chap0_mj.html">Top</a>  <a href="chap1_mj.html">1</a>  <a href="chap2_mj.html">2</a>  <a href="chap3_mj.html">3</a>  <a href="chap4_mj.html">4</a>  <a href="chap5_mj.html">5</a>  <a href="chap6_mj.html">6</a>  <a href="chap7_mj.html">7</a>  <a href="chap8_mj.html">8</a>  <a href="chap9_mj.html">9</a>  <a href="chap10_mj.html">10</a>  <a href="chap11_mj.html">11</a>  <a href="chapInd_mj.html">Ind</a>  </div>

<hr />
<p class="foot">generated by <a href="https://www.math.rwth-aachen.de/~Frank.Luebeck/GAPDoc">GAPDoc2HTML</a></p>
</body>
</html>

100%


¤ Dauer der Verarbeitung: 0.20 Sekunden  ¤

*© Formatika GbR, Deutschland






Wurzel

Suchen

Beweissystem der NASA

Beweissystem Isabelle

NIST Cobol Testsuite

Cephes Mathematical Library

Wiener Entwicklungsmethode

Haftungshinweis

Die Informationen auf dieser Webseite wurden nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit, noch Qualität der bereit gestellten Informationen zugesichert.

Bemerkung:

Die farbliche Syntaxdarstellung ist noch experimentell.