Detailed Description
The primary way Agency programs create execution is by invoking a control structure. Control structures are functions invoked via composition with an execution policy. Execution policies parameterize control structures by describing the properties of the requested execution.
For example, the following code snipped uses the bulk_invoke() control structure with the par execution policy to require the parallel execution of ten invocations of a lambda function:
Functions | |
template<class ExecutionPolicy , class Function , class... Args> | |
see_below | agency::bulk_async (ExecutionPolicy &&policy, Function f, Args &&...args) |
Creates a bulk asynchronous invocation. More... | |
template<class ExecutionPolicy , class Function , class... Args> | |
see_below | agency::bulk_invoke (ExecutionPolicy &&policy, Function f, Args &&...args) |
Creates a bulk synchronous invocation. More... | |
template<class ExecutionPolicy , class Function , class Future , class... Args> | |
see_below | agency::bulk_then (ExecutionPolicy &&policy, Function f, Future &predecessor, Args &&...args) |
Creates a bulk continuation. More... | |
Function Documentation
see_below agency::bulk_async | ( | ExecutionPolicy && | policy, |
Function | f, | ||
Args &&... | args | ||
) |
bulk_async
is a control structure which asynchronously creates a group of function invocations with forward progress ordering as required by an execution policy. The results of these invocations, if any, are collected into a container and returned as bulk_async
's asynchronous result. A future object corresponding to the eventual availability of this container is returned as bulk_async
's result.
bulk_async
asynchronously creates a group of function invocations of size N
, and each invocation i in [0,N)
has the following form:
result_i = f(agent_i, arg_i_1, arg_i_2, ..., arg_i_M)
agent_i
is a reference to an execution agent which identifies the ith invocation within the group. The parameter arg_i_j
depends on the M
arguments arg_j
passed to bulk_async
:
- If
arg_j
is a shared parameter, then it is a reference to an object shared among all execution agents inagent_i
's group. - Otherwise,
arg_i_j
is a copy of argumentarg_j
.
If the invocations of f
do not return void
, these results are collected and returned in a container results
, whose type is implementation-defined. If invocation i returns result_i
, and this invocation's agent_i
has index idx_i
, then results[idx_i]
yields result_i
.
- Parameters
-
policy An execution policy describing the requirements of the execution agents created by this call to bulk_async
.f A function defining the work to be performed by execution agents. args Additional arguments to pass to f
when it is invoked.
- Returns
- A
void
future object, iff
has no result; otherwise, a future object corresponding to the eventually available container off
's results indexed by the execution agent which produced them.
- Note
- The type of future object returned by
bulk_async
is a property of the type ofExecutionPolicy
used as a parameter.
- Template Parameters
-
ExecutionPolicy This type must fulfill the requirements of ExecutionPolicy
.Function Function
's first parameter type must beExecutionPolicy::execution_agent_type&
. The types of its additional parameters must matchArgs...
.Args Each type in Args...
must match the type of the corresponding parameter ofFunction
.
The following example demonstrates how to use bulk_async
to create tasks which execute asynchronously with the caller.
Messages from the agents in the two asynchronous tasks are printed while the main thread sleeps:
- See also
- bulk_invoke
- bulk_then
see_below agency::bulk_invoke | ( | ExecutionPolicy && | policy, |
Function | f, | ||
Args &&... | args | ||
) |
bulk_invoke
is a control structure which creates a group of function invocations with forward progress ordering as required by an execution policy. The results of these invocations, if any, are collected into a container and returned as bulk_invoke's result.
bulk_invoke
creates a group of function invocations of size N
, and each invocation i in [0,N)
has the following form:
result_i = f(agent_i, arg_i_1, arg_i_2, ..., arg_i_M)
agent_i
is a reference to an execution agent which identifies the ith invocation within the group. The parameter arg_i_j
depends on the M
arguments arg_j
passed to bulk_invoke
:
- If
arg_j
is a shared parameter, then it is a reference to an object shared among all execution agents inagent_i
's group. - Otherwise,
arg_i_j
is a copy of argumentarg_j
.
If the invocations of f
do not return void
, these results are collected and returned in a container results
, whose type is implementation-defined. If invocation i returns result_i
, and this invocation's agent_i
has index idx_i
, then results[idx_i]
yields result_i
.
- Parameters
-
policy An execution policy describing the requirements of the execution agents created by this call to bulk_invoke
.f A function defining the work to be performed by execution agents. args Additional arguments to pass to f
when it is invoked.
- Returns
void
, iff
has no result; otherwise, a container off
's results indexed by the execution agent which produced them.
- Template Parameters
-
ExecutionPolicy This type must fulfill the requirements of ExecutionPolicy
.Function Function
's first parameter type must beExecutionPolicy::execution_agent_type&
. The types of its additional parameters must matchArgs...
.Args Each type in Args...
must match the type of the corresponding parameter ofFunction
.
The following example demonstrates how to use bulk_invoke
to print 10 "Hello, world" messages in sequence.
Messages from agents 0 through 9 are printed in sequential order:
Changing the execution policy used in the call to bulk_invoke
changes how and where the execution agents will execute the provided function. This example demonstrates how to use bulk_invoke
with par
to execute the SAXPY operation in parallel:
Remember to include optimization (-O3
, in this example) to execute fast:
$ clang -std=c++11 -I. -lstdc++ -pthread -O3 examples/saxpy.cpp -o saxpy $ ./saxpy OK
- See also
- bulk_async
- bulk_then
see_below agency::bulk_then | ( | ExecutionPolicy && | policy, |
Function | f, | ||
Future & | predecessor, | ||
Args &&... | args | ||
) |
bulk_then
is a control structure which asynchronously creates a group of function invocations with forward progress ordering as required by an execution policy. These invocations are a bulk continuation to a predecessor bulk asynchronous invocation. The predecessor bulk asynchronous invocation is represented by a future object, and the continuation will not execute until the predecessor's future object becomes ready. The results of the continuation's invocations, if any, are collected into a container and returned as bulk_then
's asynchronous result. A future object corresponding to the eventual availability of this container is returned as bulk_then
's result.
bulk_then
asynchronously creates a group of function invocations of size N
, and each invocation i in [0,N)
has the following form:
result_i = f(agent_i, predecessor_arg, arg_i_1, arg_i_2, ..., arg_i_M)
agent_i
is a reference to an execution agent which identifies the ith invocation within the group. The parameter predecessor_arg
is a reference to the value of the future object used as a parameter to bulk_then
. If this future object has a void
value, then this parameter is omitted. The parameter arg_i_j
depends on the M
arguments arg_j
passed to bulk_invoke
:
- If
arg_j
is a shared parameter, then it is a reference to an object shared among all execution agents inagent_i
's group. - Otherwise,
arg_i_j
is a copy of argumentarg_j
.
If the invocations of f
do not return void
, these results are collected and returned in a container results
, whose type is implementation-defined. If invocation i returns result_i
, and this invocation's agent_i
has index idx_i
, then results[idx_i]
yields result_i
.
- Parameters
-
policy An execution policy describing the requirements of the execution agents created by this call to bulk_then
.f A function defining the work to be performed by execution agents. predecessor A future object representing the predecessor task. Its future value, if it has one, is passed to f
as an argument whenf
is invoked. Afterbulk_then
returns,predecessor
is invalid if it is not a shared future.args Additional arguments to pass to f
when it is invoked.
- Returns
void
, iff
has no result; otherwise, a container off
's results indexed by the execution agent which produced them.
- Template Parameters
-
ExecutionPolicy This type must fulfill the requirements of ExecutionPolicy
.Function Function
's first parameter type must beExecutionPolicy::execution_agent_type&
. The types of its additional parameters must matchArgs...
.Future This type must fulfill the requirements of Future
. If the value type of thisFuture
is notvoid
, this type must match the type of the second parameter ofFunction
.Args Each type in Args...
must match the type of the corresponding parameter ofFunction
.
The following example demonstrates how to use bulk_then
to sequence a continuation after a predecessor task:
Messages from agents in the predecessor task are guaranteed to be output before messages from the continuation:
- See also
- bulk_invoke
- bulk_async