Loading...
Searching...
No Matches
Opm::ElementChunks< GridView, PartitionSet > Class Template Reference

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

`#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 } }

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

- opm/grid/utility/ElementChunks.hpp