![]() |
deal.II version GIT relicensing-6834-g5b78e6bcdf 2026-10-01 11:20:01+00:00
|
#include <deal.II/matrix_free/portable_matrix_free.h>
This class collects all the data that is stored for the matrix free implementation. The storage scheme is tailored towards several loops performed with the same data, i.e., typically doing many matrix-vector products or residual computations on the same mesh.
This class does not implement any operations involving finite element basis functions, i.e., regarding the operation performed on the cells. For these operations, the class FEEvaluation is designed to use the data collected in this class.
This class implements a loop over all cells (cell_loop()). This loop is scheduled in such a way that cells that share degrees of freedom are not worked on simultaneously, which implies that it is possible to write to vectors in parallel without having to explicitly synchronize access to these vectors and matrices. This class does not implement any shape values, all it does is to cache the respective data. To implement finite element operations, use the class Portable::FEEvaluation.
This class traverse the cells in a different order than the usual Triangulation class in deal.II.
Definition at line 197 of file portable_matrix_free.h.
Classes | |
| struct | AdditionalData |
| struct | Data |
| struct | DoFInfo |
| struct | MappingInfo |
| struct | PrecomputedData |
Public Types | |
| using | jacobian_type = Tensor< 2, dim, Tensor< 1, dim, Number > > |
| using | point_type = Point< dim, Number > |
| using | CellFilter = FilteredIterator< typename DoFHandler< dim >::active_cell_iterator > |
| using | LevelCellFilter = FilteredIterator< typename DoFHandler< dim >::level_cell_iterator > |
Public Member Functions | |
| MatrixFree () | |
| unsigned int | get_padding_length () const |
| template<typename IteratorFiltersType > | |
| void | reinit (const Mapping< dim > &mapping, const DoFHandler< dim > &dof_handler, const AffineConstraints< Number > &constraints, const Quadrature< 1 > &quad, const IteratorFiltersType &iterator_filter, const AdditionalData &additional_data=AdditionalData()) |
| void | reinit (const Mapping< dim > &mapping, const DoFHandler< dim > &dof_handler, const AffineConstraints< Number > &constraints, const Quadrature< 1 > &quad, const AdditionalData &additional_data=AdditionalData()) |
| void | reinit (const DoFHandler< dim > &dof_handler, const AffineConstraints< Number > &constraints, const Quadrature< 1 > &quad, const AdditionalData &additional_data=AdditionalData()) |
| template<typename IteratorFiltersType > | |
| void | reinit (const Mapping< dim > &mapping, const std::vector< const DoFHandler< dim > * > &dof_handler, const std::vector< const AffineConstraints< Number > * > &constraints, const Quadrature< 1 > &quad, const IteratorFiltersType &iterator_filter, const AdditionalData &additional_data=AdditionalData()) |
| void | reinit (const Mapping< dim > &mapping, const std::vector< const DoFHandler< dim > * > &dof_handler, const std::vector< const AffineConstraints< Number > * > &constraints, const Quadrature< 1 > &quad, const AdditionalData &additional_data=AdditionalData()) |
| PrecomputedData | get_data (const unsigned int color, const unsigned int dof_handler_index=0) const |
| template<typename Functor , typename VectorType > | |
| void | cell_loop (const Functor &func, const VectorType &src, VectorType &dst) const |
| template<typename Functor > | |
| void | evaluate_coefficients (Functor func) const |
| template<typename VectorType > | |
| void | copy_constrained_values (const VectorType &src, VectorType &dst, const unsigned int dof_handler_index=0) const |
| void | copy_constrained_values (const LinearAlgebra::distributed::BlockVector< Number, MemorySpace::Default > &src, LinearAlgebra::distributed::BlockVector< Number, MemorySpace::Default > &dst) const |
| template<typename VectorType > | |
| void | set_constrained_values (const Number value, VectorType &dst, const unsigned int dof_handler_index=0) const |
| template<typename MemorySpaceType > | |
| void | initialize_dof_vector (LinearAlgebra::distributed::Vector< Number, MemorySpaceType > &vec, const unsigned int dof_handler_index=0) const |
| template<typename MemorySpaceType > | |
| void | initialize_dof_vector (LinearAlgebra::distributed::BlockVector< Number, MemorySpaceType > &vec) const |
| const std::vector< std::vector< CellFilter > > & | get_colored_graph () const |
| const std::vector< std::vector< LevelCellFilter > > & | get_colored_level_graph () const |
| const std::shared_ptr< const Utilities::MPI::Partitioner > & | get_vector_partitioner (const unsigned int dof_handler_index=0) const |
| const DoFHandler< dim > & | get_dof_handler (const unsigned int dof_handler_index=0) const |
| unsigned int | get_mg_level () const |
| DoFHandler< dim >::cell_iterator | get_cell_iterator (const unsigned int color, const unsigned int index, const unsigned int dof_handler_index=0) const |
| unsigned int | n_cells_per_color (const unsigned int color) const |
| bool | use_overlap_communication_computation () const |
| std::size_t | memory_consumption () const |
| template<class Archive > | |
| void | serialize (Archive &ar, const unsigned int version) |
Querying the observer pointers an object has. | |
| unsigned int | n_subscriptions () const |
| template<typename StreamType > | |
| void | list_subscribers (StreamType &stream) const |
| void | list_subscribers () const |
Static Public Member Functions | |
| static ::ExceptionBase & | ExcInUse (int arg1, std::string arg2, std::string arg3) |
| static ::ExceptionBase & | ExcNoSubscriber (std::string arg1, std::string arg2) |
Private Member Functions | |
| template<typename IteratorFiltersType > | |
| void | internal_reinit (const Mapping< dim > &mapping, const std::vector< const DoFHandler< dim > * > &dof_handler, const std::vector< const AffineConstraints< Number > * > &constraints, const Quadrature< 1 > &quad, const IteratorFiltersType &iterator_filter, const std::shared_ptr< const MPI_Comm > &comm, const AdditionalData additional_data) |
| template<typename Functor , typename VectorType > | |
| void | serial_cell_loop (const Functor &func, const VectorType &src, VectorType &dst) const |
| template<typename Functor > | |
| void | distributed_cell_loop (const Functor &func, const LinearAlgebra::distributed::Vector< Number, MemorySpace::Default > &src, LinearAlgebra::distributed::Vector< Number, MemorySpace::Default > &dst) const |
| template<typename Functor > | |
| void | distributed_cell_loop (const Functor &func, const LinearAlgebra::distributed::BlockVector< Number, MemorySpace::Default > &src, LinearAlgebra::distributed::BlockVector< Number, MemorySpace::Default > &dst) const |
EnableObserverPointer functionality | |
Classes derived from EnableObserverPointer provide a facility to subscribe to this object. This is mostly used by the ObserverPointer class. | |
| void | subscribe (std::atomic< bool > *const validity, const std::string &identifier="") const |
| void | unsubscribe (std::atomic< bool > *const validity, const std::string &identifier="") const |
| void | check_no_subscribers () const noexcept |
Private Attributes | |
| int | my_id |
| bool | use_coloring |
| bool | overlap_communication_computation |
| unsigned int | mg_level |
| unsigned int | team_size |
| std::vector< MappingInfo > | mapping_info |
| std::vector< DoFInfo > | dof_handler_data |
| unsigned int | q_points_per_cell |
| unsigned int | n_colors |
| std::vector< unsigned int > | n_cells |
| unsigned int | padding_length |
| std::vector< unsigned int > | row_start |
| std::vector< std::vector< CellFilter > > | graph |
| std::vector< std::vector< LevelCellFilter > > | level_graph |
| std::atomic< unsigned int > | counter |
| std::map< std::string, unsigned int > | counter_map |
| std::vector< std::atomic< bool > * > | validity_pointers |
| const std::type_info * | object_info |
Static Private Attributes | |
| static std::mutex | mutex |
Friends | |
| class | internal::ReinitHelper< dim, Number > |
Related Symbols | |
(Note that these are not member symbols.) | |
| template<int dim, typename Number > | |
| DataHost< dim, Number > | copy_mf_data_to_host (const typename::Portable::MatrixFree< dim, Number >::PrecomputedData &data, const UpdateFlags &update_flags) |
| using Portable::MatrixFree< dim, Number >::jacobian_type = Tensor<2, dim, Tensor<1, dim, Number> > |
Definition at line 200 of file portable_matrix_free.h.
| using Portable::MatrixFree< dim, Number >::point_type = Point<dim, Number> |
Definition at line 201 of file portable_matrix_free.h.
| using Portable::MatrixFree< dim, Number >::CellFilter = FilteredIterator<typename DoFHandler<dim>::active_cell_iterator> |
Definition at line 202 of file portable_matrix_free.h.
| using Portable::MatrixFree< dim, Number >::LevelCellFilter = FilteredIterator<typename DoFHandler<dim>::level_cell_iterator> |
Definition at line 204 of file portable_matrix_free.h.
| Portable::MatrixFree< dim, Number >::MatrixFree | ( | ) |
Default constructor.
| unsigned int Portable::MatrixFree< dim, Number >::get_padding_length | ( | ) | const |
Return the length of the padding.
| void Portable::MatrixFree< dim, Number >::reinit | ( | const Mapping< dim > & | mapping, |
| const DoFHandler< dim > & | dof_handler, | ||
| const AffineConstraints< Number > & | constraints, | ||
| const Quadrature< 1 > & | quad, | ||
| const IteratorFiltersType & | iterator_filter, | ||
| const AdditionalData & | additional_data = AdditionalData() |
||
| ) |
Extracts the information needed to perform loops over cells. The DoFHandler and AffineConstraints objects describe the layout of degrees of freedom, the DoFHandler and the mapping describe the transformation from unit to real cell, and the finite element underlying the DoFHandler together with the quadrature formula describe the local operations. This function takes an IteratorFilters object (predicate) to loop over a subset of the active cells. When using MPI, the predicate should filter out non locally owned cells.
| void Portable::MatrixFree< dim, Number >::reinit | ( | const Mapping< dim > & | mapping, |
| const DoFHandler< dim > & | dof_handler, | ||
| const AffineConstraints< Number > & | constraints, | ||
| const Quadrature< 1 > & | quad, | ||
| const AdditionalData & | additional_data = AdditionalData() |
||
| ) |
Same as above using Iterators::LocallyOwnedCell() as predicate.
| void Portable::MatrixFree< dim, Number >::reinit | ( | const DoFHandler< dim > & | dof_handler, |
| const AffineConstraints< Number > & | constraints, | ||
| const Quadrature< 1 > & | quad, | ||
| const AdditionalData & | additional_data = AdditionalData() |
||
| ) |
Initializes the data structures. Same as above but using a Q1 mapping.
| void Portable::MatrixFree< dim, Number >::reinit | ( | const Mapping< dim > & | mapping, |
| const std::vector< const DoFHandler< dim > * > & | dof_handler, | ||
| const std::vector< const AffineConstraints< Number > * > & | constraints, | ||
| const Quadrature< 1 > & | quad, | ||
| const IteratorFiltersType & | iterator_filter, | ||
| const AdditionalData & | additional_data = AdditionalData() |
||
| ) |
Reinit with a list of DoFHandler objects.
| void Portable::MatrixFree< dim, Number >::reinit | ( | const Mapping< dim > & | mapping, |
| const std::vector< const DoFHandler< dim > * > & | dof_handler, | ||
| const std::vector< const AffineConstraints< Number > * > & | constraints, | ||
| const Quadrature< 1 > & | quad, | ||
| const AdditionalData & | additional_data = AdditionalData() |
||
| ) |
Same as above using Iterators::LocallyOwnedCell() as predicate.
| PrecomputedData Portable::MatrixFree< dim, Number >::get_data | ( | const unsigned int | color, |
| const unsigned int | dof_handler_index = 0 |
||
| ) | const |
Return the Data structure associated with color.
| void Portable::MatrixFree< dim, Number >::cell_loop | ( | const Functor & | func, |
| const VectorType & | src, | ||
| VectorType & | dst | ||
| ) | const |
This method performs a loop over all cells and applies the local operation on each element in parallel. func is a functor which is applied for each color and each cell.
If VectorType is a LinearAlgebra::distributed::Vector, func needs to define
If VectorType is a LinearAlgebra::distributed::BlockVector, func uses BlockDeviceVector instead of DeviceVector for the src and dst arguments.
While src can be left empty, dst must be provided and allocated with a partitioner of one of the DoFHandlers of this MatrixFree object (or a BlockVector with one block for each DoFHandler). If src is provided, it must have the same partitioner as dst.
| void Portable::MatrixFree< dim, Number >::evaluate_coefficients | ( | Functor | func | ) | const |
This method runs the loop over all cells and apply the local operation on each element in parallel. This function is very similar to cell_loop() but it uses a simpler functor.
A typical usage of this function is to fill a Kokkos::View or LinearAlgebra::distributed::Vector with data for every cell or quadrature point. See step-64 for an example.
func needs to define
| void Portable::MatrixFree< dim, Number >::copy_constrained_values | ( | const VectorType & | src, |
| VectorType & | dst, | ||
| const unsigned int | dof_handler_index = 0 |
||
| ) | const |
Copy the values of the constrained entries from src to dst. This is used to impose zero Dirichlet boundary conditions.
dof_handler_index is used to select the DoFHandler object.
| void Portable::MatrixFree< dim, Number >::copy_constrained_values | ( | const LinearAlgebra::distributed::BlockVector< Number, MemorySpace::Default > & | src, |
| LinearAlgebra::distributed::BlockVector< Number, MemorySpace::Default > & | dst | ||
| ) | const |
Copy the values of the constrained entries from src to dst. This is used to impose zero Dirichlet boundary conditions.
This is a specialization for BlockVector and will copy the constrained values for all DoFHandlers. The number of blocks in src and dst must be equal to the number of DoFHandlers of this MatrixFree object.
| void Portable::MatrixFree< dim, Number >::set_constrained_values | ( | const Number | value, |
| VectorType & | dst, | ||
| const unsigned int | dof_handler_index = 0 |
||
| ) | const |
Set the entries in dst corresponding to constrained values to value. The main purpose of this function is to set the constrained entries of the source vector used in cell_loop() to zero.
dof_handler_index is used to select the DoFHandler object.
| void Portable::MatrixFree< dim, Number >::initialize_dof_vector | ( | LinearAlgebra::distributed::Vector< Number, MemorySpaceType > & | vec, |
| const unsigned int | dof_handler_index = 0 |
||
| ) | const |
Initialize a distributed vector. The local elements correspond to the locally owned degrees of freedom and the ghost elements correspond to the (additional) locally relevant dofs.
If the MatrixFree class is initialized with more than one DoFHandler, it can be chosen with dof_handler_index.
| void Portable::MatrixFree< dim, Number >::initialize_dof_vector | ( | LinearAlgebra::distributed::BlockVector< Number, MemorySpaceType > & | vec | ) | const |
Initialize a distributed block vector. The local elements correspond to the locally owned degrees of freedom and the ghost elements correspond to the (additional) locally relevant dofs. This version creates one block for each DoFHandler provided when the MatrixFree class was initialized.
| const std::vector< std::vector< CellFilter > > & Portable::MatrixFree< dim, Number >::get_colored_graph | ( | ) | const |
Return the colored graph of locally owned active cells.
| const std::vector< std::vector< LevelCellFilter > > & Portable::MatrixFree< dim, Number >::get_colored_level_graph | ( | ) | const |
Return the colored graph of locally owned level cells.
| const std::shared_ptr< const Utilities::MPI::Partitioner > & Portable::MatrixFree< dim, Number >::get_vector_partitioner | ( | const unsigned int | dof_handler_index = 0 | ) | const |
Return the partitioner that represents the locally owned data and the ghost indices where access is needed to for the cell loop. The partitioner is constructed from the locally owned dofs and ghost dofs given by the respective fields. If you want to have specific information about these objects, you can query them with the respective access functions. If you just want to initialize a (parallel) vector, you should usually prefer this data structure as the data exchange information can be reused from one vector to another.
| const DoFHandler< dim > & Portable::MatrixFree< dim, Number >::get_dof_handler | ( | const unsigned int | dof_handler_index = 0 | ) | const |
Return the DoFHandler with index dof_handler_index.
| unsigned int Portable::MatrixFree< dim, Number >::get_mg_level | ( | ) | const |
Return the local smoothing multigrid level that this object has been initialized with. The level is numbers::invalid_unsigned_int for active cells.
| DoFHandler< dim >::cell_iterator Portable::MatrixFree< dim, Number >::get_cell_iterator | ( | const unsigned int | color, |
| const unsigned int | index, | ||
| const unsigned int | dof_handler_index = 0 |
||
| ) | const |
Return the cell iterator given the index within the color.
| color | The color index |
| index | The index within the color |
| dof_handler_index | Index of the DoFHandler (default 0) |
| unsigned int Portable::MatrixFree< dim, Number >::n_cells_per_color | ( | const unsigned int | color | ) | const |
Return the entries (cells) per color.
| bool Portable::MatrixFree< dim, Number >::use_overlap_communication_computation | ( | ) | const |
Return the flag indicating whether overlap MPI communication with computation is used as was set by AdditionalData::overlap_communication_computation.
| std::size_t Portable::MatrixFree< dim, Number >::memory_consumption | ( | ) | const |
Return an approximation of the memory consumption of this class in bytes.
|
private |
Initializes the data structures.
|
private |
Helper function. Loop over all the cells and apply the functor on each element in parallel. This function is used when MPI is not used.
|
private |
Helper function. Loop over all the cells and apply the functor on each element in parallel. This function is used when MPI is used.
|
private |
Same as above but for BlockVector.
|
inlineinherited |
Return the present number of subscriptions to this object. This allows to use this class for reference counted lifetime determination where the last one to unsubscribe also deletes the object.
Definition at line 318 of file enable_observer_pointer.h.
|
inlineinherited |
List the subscribers to the input stream.
Definition at line 335 of file enable_observer_pointer.h.
|
inherited |
List the subscribers to deallog.
Definition at line 200 of file enable_observer_pointer.cc.
|
inlineinherited |
Read or write the data of this object to or from a stream for the purpose of serialization using the BOOST serialization library.
This function does not actually serialize any of the member variables of this class. The reason is that what this class stores is only who subscribes to this object, but who does so at the time of storing the contents of this object does not necessarily have anything to do with who subscribes to the object when it is restored. Consequently, we do not want to overwrite the subscribers at the time of restoring, and then there is no reason to write the subscribers out in the first place.
Definition at line 327 of file enable_observer_pointer.h.
|
privateinherited |
Subscribes a user of the object by storing the pointer validity. The subscriber may be identified by text supplied as identifier.
Definition at line 136 of file enable_observer_pointer.cc.
|
privateinherited |
Unsubscribes a user from the object.
identifier and the validity pointer must be the same as the one supplied to subscribe(). Definition at line 154 of file enable_observer_pointer.cc.
|
privatenoexceptinherited |
Check that there are no objects subscribing to this object. If this check passes then it is safe to destroy the current object. It this check fails then this function will either abort or print an error message to deallog (by using the AssertNothrow mechanism), but will not throw an exception.
Definition at line 58 of file enable_observer_pointer.cc.
|
friend |
Definition at line 1078 of file portable_matrix_free.h.
|
related |
Copy data from the device to the host. update_flags should be identical to the one used in MatrixFree::AdditionalData.
Definition at line 1295 of file portable_matrix_free.h.
|
private |
Unique ID associated with the object.
Definition at line 844 of file portable_matrix_free.h.
|
private |
If true, use graph coloring. Otherwise, use atomic operations. Graph coloring ensures bitwise reproducibility but is slower on Pascal and newer architectures.
Definition at line 851 of file portable_matrix_free.h.
|
private |
Overlap MPI communications with computation. This requires device-aware MPI and use_coloring must be false.
Definition at line 857 of file portable_matrix_free.h.
|
private |
Multigrid level for which this MatrixFree object is initialized. If set to numbers::invalid_unsigned_int, this operates on active cells.
Definition at line 863 of file portable_matrix_free.h.
|
private |
The team size used by the underlying kokkos team policy. If -1 is provided then Kokkos::AUTO will be used.
Definition at line 869 of file portable_matrix_free.h.
|
private |
Store information for each quadrature formula / mapping. Currently always exactly size 1.
Definition at line 929 of file portable_matrix_free.h.
|
private |
Store information necessary for each DoFHandler
Definition at line 1039 of file portable_matrix_free.h.
|
private |
Number of quadrature points per cells.
Definition at line 1044 of file portable_matrix_free.h.
|
private |
Number of colors produced by the graph coloring algorithm.
Definition at line 1049 of file portable_matrix_free.h.
|
private |
Number of cells in each color.
Definition at line 1054 of file portable_matrix_free.h.
|
private |
Length of the padding (closest power of two larger than or equal to the number of thread).
Definition at line 1060 of file portable_matrix_free.h.
|
private |
Row start of each color.
Definition at line 1065 of file portable_matrix_free.h.
|
private |
Colored graph of locally owned active cells (used when mg_level == invalid).
Definition at line 1072 of file portable_matrix_free.h.
|
private |
Colored graph of locally owned level cells (used when mg_level != invalid).
Definition at line 1078 of file portable_matrix_free.h.
|
mutableprivateinherited |
Store the number of objects which subscribed to this object. Initially, this number is zero, and upon destruction it shall be zero again (i.e. all objects which subscribed should have unsubscribed again).
The creator (and owner) of an object is counted in the map below if HE manages to supply identification.
We use the mutable keyword in order to allow subscription to constant objects also.
This counter may be read from and written to concurrently in multithreaded code: hence we use the std::atomic class template.
Definition at line 212 of file enable_observer_pointer.h.
|
mutableprivateinherited |
In this map, we count subscriptions for each different identification string supplied to subscribe().
Definition at line 218 of file enable_observer_pointer.h.
|
mutableprivateinherited |
In this vector, we store pointers to the validity bool in the ObserverPointer objects that subscribe to this class.
Definition at line 224 of file enable_observer_pointer.h.
|
mutableprivateinherited |
Pointer to the typeinfo object of this object, from which we can later deduce the class name. Since this information on the derived class is neither available in the destructor, nor in the constructor, we obtain it in between and store it here.
Definition at line 232 of file enable_observer_pointer.h.
|
staticprivateinherited |
A mutex used to ensure data consistency when accessing the mutable members of this class. This lock is used in the subscribe() and unsubscribe() functions, as well as in list_subscribers().
Definition at line 239 of file enable_observer_pointer.h.