Skip to main content
QUICK REVIEW

[Paper Review] The interface for functions in the dune-functions module

Christian Engwer, Carsten Gräser|arXiv (Cornell University)|Dec 18, 2015
Distributed and Parallel Computing SystemsComputer Science1 references7 citations
TL;DR

This paper proposes a new C++-based function interface for the Dune finite element framework that replaces legacy reference-based evaluation with return-by-value using operator() overloading and type erasure via std::function. The new design improves code readability and supports modern C++ features like lambdas, while performance measurements show no runtime penalty when using modern compiler optimizations, making it as efficient as the previous interface.

ABSTRACT

The dune-functions Dune module introduces a new programmer interface for discrete and non-discrete functions. Unlike the previous interfaces considered in the existing Dune modules, it is based on overloading operator(), and returning values by-value. This makes user code much more readable, and allows the incorporation of newer C++ features such as lambda expressions. Run-time polymorphism is implemented not by inheritance, but by type erasure, generalizing the ideas of the std::function class from the C++11 standard library. We describe the new interface, show its possibilities, and measure the performance impact of type erasure and return-by-value.

Motivation & Objective

  • To address the poor code readability of Dune's legacy function interface, which required by-reference evaluation and complex syntax.
  • To modernize Dune's function interface by adopting C++11 features such as lambdas and return-by-value semantics.
  • To enable dynamic polymorphism without virtual inheritance by using type erasure, inspired by std::function.
  • To evaluate whether the performance of the new interface is comparable to the old one, especially regarding return-by-value and type erasure.
  • To extend the interface to support differentiable functions and grid-based functions using local coordinate systems.

Proposed method

  • Design a new function interface based on callable objects with operator() overloading and return-by-value semantics.
  • Use concept checking via static_assert to enforce interface contracts and improve error messages.
  • Implement type erasure using std::function-like wrappers for dynamic polymorphism, avoiding virtual inheritance.
  • Introduce LocalFunction and GridViewFunction templates to support grid-based evaluation in local coordinates.
  • Support derivatives through a generic DerivativeTraits template parameter, enabling differentiation for various function types.
  • Benchmark the new interface against the legacy one using composite midpoint rule integration with varying return value sizes and dispatch strategies.

Experimental results

Research questions

  • RQ1Does returning function results by value in C++ incur a measurable performance penalty compared to by-reference evaluation?
  • RQ2Can modern compilers eliminate the overhead of return-by-value through return value optimization (RVO)?
  • RQ3Is the performance of type erasure via std::function comparable to virtual function dispatch in the context of finite element functions?
  • RQ4Can the new interface support differentiable functions and grid-based functions while maintaining efficiency?
  • RQ5Does the use of profile-guided optimization (PGO) close the performance gap between std::function and virtual function dispatch?

Key findings

  • Return-by-value with static dispatch incurs no runtime overhead compared to by-reference evaluation, as modern compilers eliminate temporary object creation via RVO.
  • For dynamic dispatch, the performance of std::function-based type erasure is initially slower than virtual function dispatch for small return types, but this gap is closed with profile-guided optimization (PGO).
  • With PGO, the std::function-based interface performs as well as or slightly better than virtual function dispatch, demonstrating that type erasure does not impose a fundamental performance penalty.
  • The new interface enables more readable and idiomatic C++ code, such as natural expression of mathematical functions using lambda expressions and operator() calls.
  • The performance of the new interface is on par with the legacy interface when using modern compiler optimizations, validating its practicality for high-performance scientific computing.
  • The design successfully extends to differentiable functions and grid-based functions through LocalFunction and GridViewFunction templates, maintaining both expressiveness and efficiency.

Read this paper

Open the full text in the Nubint reader and ask about any passage as you read.

Read this paper on Nubint

This review was generated by AI from the original paper. Please check the paper before citing it.