Minimum of dealii:Vector in MPI parallel application

40 views
Skip to first unread message

maurice rohracker

unread,
Jul 26, 2023, 4:59:20 AM7/26/23
to deal.II User Group
Dear all,

In a parallel distributed code, similar to step-42, we use a dealii::Vector of n_active_cells() to compute the error indicators of the locally owned cells. (This can easily be used in e.g. dealii::parallel::distributed::GridRefinement::
refine_and_coarsen_fixed_number()
)
As we want to add an additional criterion based on the minimum and maximum error indicator to mark cells, we need the global minimum and maximum value.
Is there a smart way to get the global minimum based on the minimum of all processes of all locally owned cells? Using std::min_element does not care about locally owned cells and so the results are wrong.

Thanks and best regards,
Maurice

Wolfgang Bangerth

unread,
Jul 26, 2023, 3:00:13 PM7/26/23
to dea...@googlegroups.com
On 7/26/23 02:59, 'maurice rohracker' via deal.II User Group wrote:
>
> In a parallel distributed code, similar to step-42, we use a/dealii::Vector/
> of /n_active_cells()/ to compute the error indicators of the locally owned
> cells. (This can easily be used in e.g.
> /dealii::parallel::distributed::GridRefinement::
> refine_and_coarsen_fixed_number()/)
> As we want to add an additional criterion based on the minimum and maximum
> error indicator to mark cells, we need the global minimum and maximum value.
> Is there a smart way to get the global minimum based on the minimum of all
> processes of all locally owned cells? Using /std::min_element/ does not care
> about locally owned cells and so the results are wrong.

You can get the local min/max via a loop of the form

double min=std::numeric_limits<double>::max(),
max=std::numeric_limits<double>::smallest(),
for (auto &cell : triangulation.active_cell_iterators())
if (cell->is_locally_owned())
min = std::min (min, vec(cell->active_cell_index()));
...same for max...

and then compute the global min and max via Utilities::min()/max().

Best
W.

--
------------------------------------------------------------------------
Wolfgang Bangerth email: bang...@colostate.edu
www: http://www.math.colostate.edu/~bangerth/


Reply all
Reply to author
Forward
0 new messages