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
 

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: #pragma omp parallel for for (const auto& chunk : ElementChunks(gridview, num_threads)) { for (const auto& elem : chunk) { // Do something with elem } }

The ElementChunks object stores a vector of iterators, so if you have several such loops it can be a good idea to create the object once instead of once per loop: ElementChunks chunks(gridview, num_threads) // First loop #pragma omp parallel for for (const auto& chunk : chunks) { for (const auto& elem : chunk) { // Do something with elem } } // ... // Second loop #pragma omp parallel for for (const auto& chunk : chunks) { for (const auto& elem : chunk) { // Do something else with elem } }

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

◆ 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: