dune-assembler 2.12
Loading...
Searching...
No Matches
Dune::Assembler::Experimental::ColoredRangeExecutor< ColoredRange > Class Template Reference

Utility for implementing parallel algorithms based on colored ranges. More...

#include <dune/assembler/parallel/coloredrangeexecutor.hh>

Public Member Functions

 ColoredRangeExecutor (ColoredRange &coloredRange, std::size_t threadCount, bool useWorkStealing=true)
 
template<class ThreadImpl >
void operator() (ThreadImpl &&threadImpl) const
 

Static Public Attributes

static constexpr bool isParallel = true
 

Detailed Description

template<class ColoredRange>
class Dune::Assembler::Experimental::ColoredRangeExecutor< ColoredRange >

Utility for implementing parallel algorithms based on colored ranges.

Template Parameters
ColoredRangeType of the colored range

This allows to execute algorithms containing loops of the underlying range. The algorithm is executed in parallel threads while forEach loops over the range internally the coloring.

This requires that the colored range passed is overlap-free with respect to the given algorithm, in the sense that the parallel thread do not produce race conditions when processing the values stored in a color concurrently. Furthermore the additional code in the threads must also not contain race conditions.

Attention: Data that should be thread-local must be captured by value in the algorithm callback passed to the executor. Otherwise concurrent threads will access a single instance of this data.

Example: Assume that accessElementData(entity) writes some date associated to the entity and that the partition is overlap-free wrt this function. Then a parallel algorithm can e.g. take the form

auto executor = ColoredRangeExecutor(coloredRange, threadCount);

executor([&, threadLocalData](auto&& context) { doSomeSetupForThisThread(); context.forEach(range, [&](const auto& entity) { accessElementData(entity); }); context.barrier().arrive_and_wait(); if (context.threadIndex() == 1) std::cout << "Hello from thread 1!" << std::endl; context.barrier().arrive_and_wait(); doSomeParallelComputation(); context.barrier().arrive_and_wait(); doSomeMoreParallelComputation(); });

Constructor & Destructor Documentation

◆ ColoredRangeExecutor()

template<class ColoredRange >
Dune::Assembler::Experimental::ColoredRangeExecutor< ColoredRange >::ColoredRangeExecutor ( ColoredRange &  coloredRange,
std::size_t  threadCount,
bool  useWorkStealing = true 
)
inline

Member Function Documentation

◆ operator()()

template<class ColoredRange >
template<class ThreadImpl >
void Dune::Assembler::Experimental::ColoredRangeExecutor< ColoredRange >::operator() ( ThreadImpl &&  threadImpl) const
inline

Member Data Documentation

◆ isParallel


The documentation for this class was generated from the following file: