-
Notifications
You must be signed in to change notification settings - Fork 10
Quick Start: Execution
ZPC offers parallel execution policy classes with a consistent interface, each corresponding to a certain compute back-end marked by execspace_e. Currently there are execspace_e::host, execspace_e::cuda, execspace_e::openmp for parallel executions on CPU and GPUs.
Every execution policy class should provide implementations for the following parallel primitives:
- for_each
- reduce
- scan (exclusive and inclusive)
- radix_sort (and its variant radix_sort_pair)
- merge_sort (and its variant merge_sort_pair)
A policy class object can be configured at runtime. Common settings include:
- sync(bool): specifies whether its execution is synchronous to the host thread that issues the execution when complete.
- profile(bool): specifies whether to profile and print the timings of the executions issues.
For cuda execution policy, additional settings include device(ProcID), etc.
Note that currently host-side radix sort does not support floating points yet.
To utilize the execution policy for fast and convenient parallel execution,
#include "zensim/execution/ExecutionPolicy.hpp"
// or #include "zensim/cuda/execution/ExecutionPolicy.cuh"
// or #include "zensim/omp/execution/ExecutionPolicy.hpp"
Vector<T> someContainer{...};
constexpr execspace_e space = ...;
auto execPol = par_exec(tag<space>);
execPol.sync(true).profile(true); // these are the default options
// 1
execPol(someContainer, []ZS_LAMBDA(T &v) {
// operator on v
});
// 2
execPol(range(someContainer.size()), [vec = proxy<space>(someContainer)]ZS_LAMBDA(int i) {
// operator on vec(i)
});
// 3
for_each(execPol, someContainer, []ZS_LAMBDA(T &v) {
// operator on v
});
All host-side computations expects programmers to use try-catch idiom to handle exceptions thrown from the execution of the functor. Therefore it is programmer's responsibility to handle it manually.
All device(cuda)-side execution errors are dealt by giving back error codes, which is automatically handled by ZPC.
to be done.