Opm::ElementChunks< GridView, PartitionSet > Class Template Reference

#include <ElementChunks.hpp>

Classes

struct  Chunk
 
struct  ChunkIterator
 

Public Member Functions

 ElementChunks (const GridView &gv, const PartitionSet included_partition, const std::size_t num_chunks)
 
auto begin () const
 
auto end () const
 
auto size () const
 
Chunk operator[] (std::size_t i) const
 

Detailed Description

template<class GridView, class PartitionSet>
class Opm::ElementChunks< GridView, PartitionSet >

Class to simplify creating parallel yet performant threaded loops over a grid.

The basic problem is that iteration over a Dune grid is not random-access, and therefore not amenable to typical OpenMP pragmas. The ThreadedEntityIterator class provided in opm-simulators is a possibility, but it uses locking, and is therefore not very efficient. The iteration over chunks facilitated by this class is significantly faster in many cases.

Typical loop over grid without this facility: for (const auto& elem : elements(gridview)) { // Do something with elem }

Typical OpenMP-threaded loop over grid using this class: ElementChunks chunks(gridview, Dune::Partitions::all, num_threads); #pragma omp parallel for for (std::size_t ci = 0; ci < chunks.size(); ++ci) { for (const auto& elem : chunks[ci]) { // Do something with elem } }

The loop over the chunks is index-based: OpenMP accepts a range-based for loop after the pragma only from version 5.0 on, while the index-based form needs only version 3.0.

The ElementChunks object stores a vector of iterators, so create it once and reuse it when several loops run over the same chunks.

Constructor & Destructor Documentation

◆ ElementChunks()

template<class GridView , class PartitionSet >
Opm::ElementChunks< GridView, PartitionSet >::ElementChunks ( const GridView &  gv,
const PartitionSet  included_partition,
const std::size_t  num_chunks 
)
inline

Member Function Documentation

◆ begin()

template<class GridView , class PartitionSet >
auto Opm::ElementChunks< GridView, PartitionSet >::begin ( ) const
inline

◆ end()

template<class GridView , class PartitionSet >
auto Opm::ElementChunks< GridView, PartitionSet >::end ( ) const
inline

◆ operator[]()

template<class GridView , class PartitionSet >
Chunk Opm::ElementChunks< GridView, PartitionSet >::operator[] ( std::size_t  i) const
inline

Chunk number i, for i < size(): the same chunk as *std::next(begin(), i).

◆ size()

template<class GridView , class PartitionSet >
auto Opm::ElementChunks< GridView, PartitionSet >::size ( ) const
inline

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