how to use const std::function< T(const T &, const T &)> & combiner

21 views
Skip to first unread message

ztdep...@gmail.com

unread,
Nov 2, 2023, 9:03:38 AM11/2/23
to deal.II User Group
I want to use the mpi::all_reduce to add some values from every processes. 
but i don't know how to set the "const std::function< T(const T &, const T &)> &   combiner". 
Could you please give me some help about it?

 Utilities::MPI::all_reduce ( const T &   local_value,
const MPI_Comm &   comm,
const std::function< T(const T &, const T &)> &   combiner
)

const std::function< T(const T &, const T &)> &   combiner 

Daniel Arndt

unread,
Nov 2, 2023, 9:31:06 AM11/2/23
to dea...@googlegroups.com
It's simply a function that takes two arguments of the same type by reference and returns a new value of that type.
For a sum reduction using doubles, you could pass in in a lambda, for example:

[](const double& a, const double& b) {return a+b;}

Best,
Daniel

--
The deal.II project is located at http://www.dealii.org/
For mailing list/forum options, see https://groups.google.com/d/forum/dealii?hl=en
---
You received this message because you are subscribed to the Google Groups "deal.II User Group" group.
To unsubscribe from this group and stop receiving emails from it, send an email to dealii+un...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/dealii/801ac1c2-cc05-490d-8683-e55613e655fen%40googlegroups.com.
Reply all
Reply to author
Forward
0 new messages