<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>
<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>
<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>
<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>
<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>
<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>
<div class="func"><table class="func" width="100%"><tr><td class="tdleft"><code class="func">an style='color: green'>8227; 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>
<div class="func"><table class="func" width="100%"><tr><td class="tdleft"><code class="func">an style='color: green'>8227; 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>
<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>
<div class="func"><table class="func" width="100%"><tr><td class="tdleft"><code class="func">an style='color: green'>8227; 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>
<div class="func"><table class="func" width="100%"><tr><td class="tdleft"><code class="func">an style='color: green'>8227; 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>
<div class="func"><table class="func" width="100%"><tr><td class="tdleft"><code class="func">an style='color: green'>8227; 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>
<div class="func"><table class="func" width="100%"><tr><td class="tdleft"><code class="func">an style='color: green'>8227; 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>
<div class="func"><table class="func" width="100%"><tr><td class="tdleft"><code class="func">an style='color: green'>8227; 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>
<div class="func"><table class="func" width="100%"><tr><td class="tdleft"><code class="func">an style='color: green'>8227; 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>
<div class="func"><table class="func" width="100%"><tr><td class="tdleft"><code class="func">an style='color: green'>8227; 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">an style='color: green'>8227; 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">an style='color: green'>8227; 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>
<div class="func"><table class="func" width="100%"><tr><td class="tdleft"><code class="func">an style='color: green'>8227; 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>
<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>
<div class="func"><table class="func" width="100%"><tr><td class="tdleft"><code class="func">an style='color: green'>8227; 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>
<"java.lang.StringIndexOutOfBoundsException: Range [44, 43) out of bounds for length 221
"java.lang.StringIndexOutOfBoundsException: Range [22, 20) out of bounds for length 239
<div class="func"><table class="func" width="100%"><tr><td class="tdleft"><code class="func">an style='color: green'>8227; TaskError</code>( <var class="Arg">task</var> )</td><td class="tdright">( function )</td></tr></table></div>
<code =func"TaskError<code> for <class=Arg"task</> returns error message, if it encountered an error. If it did not encounter an error, the function returns <code class="keyw">fail</code>.</p>
<div class="pan "ContSS"<br><pan =">nbsp&;<s>a href=chap1_mj.#X8431B91487A8A3F11.4-2TaskCancellationRequesteda>/pan>
p><code class"">urrentTask/>returns java.lang.StringIndexOutOfBoundsException: Range [57, 56) out of bounds for length 84
p>< =" =X7DA4E06B792002C7>/a>/>
s class""< >s class=">nbsp;;<span>a href=".#80B3247854A46E4>.61 /a><>
<div class="func"><table class="func" width="100%"><tr><td span ""b >span class=nocss"&bsp;;<span> href="chap1_mjh#7CB26D38096CD56"1.6-3 </>/pan>
<>java.lang.StringIndexOutOfBoundsException: Range [8, 7) out of bounds for length 169
<div class="func"><table class="func" width="100%"><tr><span class="">gapg;/spanspan class="GAPinput">WaitTask(task);</span>
<This trueif task executing its resultjava.lang.StringIndexOutOfBoundsException: Range [100, 82) out of bounds for length 114
iv ="func"<able class=func"width=100%<r<tdclass"">code ="">#8227;TaskIsAsync<code> var ="Arg"><var>)<td> class="(nbsp;&;<td>/>/table>/>
<> function the ,true ./>
<p><a id="X7B286945821A3BBA" name="X7B286945821A3BBA"></java.lang.StringIndexOutOfBoundsException: Index 57 out of bounds for length 0
<h5>1.4-1 CancelTask<s =GAPprompt"gap&t;<s><java.lang.StringIndexOutOfBoundsException: Range [45, 44) out of bounds for length 111
<div class="func"><table class="funcjava.lang.StringIndexOutOfBoundsException: Index 36 out of bounds for length 4
<</var> is to be cancelled<p>
<java.lang.StringIndexOutOfBoundsException: Index 1 out of bounds for length 0
<h5></h5>
<div class="func"><table class="func" width="100%"><tr><<span class"">gap&;</span>span=GAPinput"T()*TaskResult() Factorial(0000)<span>
<>code ""TaskCancellationRequestedcode> true <ode "func"><ode>(a href="chap1_mjhtmlXC26">span "RefLink">.-</pan>/a>) has called < class"rg"task<var> otherwise./>
<p><a id="X7D61F9C487232DE7" name="X7D61F9C487232DE7"java.lang.StringIndexOutOfBoundsException: Index 0 out of bounds for length 0
<h5>1.4-3 OnTaskCancellation</h5>
<div%"><tr<td =tdleft>code class="func"227;OnTaskCancellation</code( <var class=Arg">exit_func/var>)<td>td class"">&;java.lang.StringIndexOutOfBoundsException: Range [203, 202) out of bounds for length 233
<>< class=func"OnTaskCancellation/code>tests cancellation for the current task has been requested. If so, then <var class="Arg">exit_func</var> will be called (as class="APprompt"g;<span><pan "GAPinput"task =ImmediateTaskx-gt;() [,1);/pan>
<divjava.lang.StringIndexOutOfBoundsException: Index 0 out of bounds for length 0
<span class="GAPprompt">gap></span> <span class="
<java.lang.StringIndexOutOfBoundsException: Range [57, 5) out of bounds for length 84
<
< ="&;/span>< class=GAPinput"> java.lang.StringIndexOutOfBoundsException: Range [67, 66) out of bounds for length 74
<span class="GAPprompt">></span> <span class="GAPinput"> end);;</span>
<panclass=GAPprompt>>/pan> sclass="CancelTask(;<span>
<span class="GAPprompt">gap></span> <span java.lang.StringIndexOutOfBoundsException: Index 50 out of bounds for length 33 314
</<div>
<d"82D1773F8058CA54 name=X82D1773F8058CA54"</><>
<java.lang.StringIndexOutOfBoundsException: Range [34, 3) out of bounds for length 39
<div p>HPC-GAPcurrently has implementations of the task API. To use an alternative implementation to the one documented here, set the environment variable <code java.lang.StringIndexOutOfBoundsException: Index 170 out of bounds for length 0
<p><code class="java.lang.StringIndexOutOfBoundsException: Index 20 out of bounds for length 0
<h4>1.5 <span class="Heading"><p><code class="func">RunTask</codea for executionand starts it.The taskwill the < =Arg/ < "Arg><var>through var =A"argn</ar>(if java.lang.StringIndexOutOfBoundsException: Range [234, 233) out of bounds for length 445
<div class="funcppan =GAPprompt"gap>s><span class="GAPinput"();/>
<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>java.lang.StringIndexOutOfBoundsException: Index 0 out of bounds for length 0
<h5>1.6-2 ContributeToMilestone</h5>
<div class="func"><table class="func" width="100%"><tr><td class="tdleft"><code class="func">an style='color: green'>8227; 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>
<div class="func"><table class="func" width="100%"><tr><td class="tdleft"><code class="func">an style='color: green'>8227; 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="func"><table class="func" width="100%"><tr><td class="tdleft"><code class="func">an style='color: green'>8227; 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>
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 und die Messung sind noch experimentell.