deal.II version GIT relicensing-6834-g5b78e6bcdf 2026-10-01 11:20:01+00:00
\(\newcommand{\dealvcentcolon}{\mathrel{\mathop{:}}}\) \(\newcommand{\dealcoloneq}{\dealvcentcolon\mathrel{\mkern-1.2mu}=}\) \(\newcommand{\jump}[1]{\left[\!\left[ #1 \right]\!\right]}\) \(\newcommand{\average}[1]{\left\{\!\left\{ #1 \right\}\!\right\}}\)
Loading...
Searching...
No Matches
Public Member Functions | Private Member Functions | Private Attributes | List of all members
Utilities::MPI::ConsensusAlgorithms::PEX< RequestType, AnswerType > Class Template Reference

#include <deal.II/base/mpi_consensus_algorithms.h>

Detailed Description

template<typename RequestType, typename AnswerType>
class Utilities::MPI::ConsensusAlgorithms::PEX< RequestType, AnswerType >

This class implements a concrete algorithm for the ConsensusAlgorithms::Interface base class, using a two step approach. In the first step the source ranks are determined and in the second step a static sparse data exchange is performed. This algorithm is most suitable for relatively small process counts – say, less than 100.

Note
In contrast to NBX, this class splits the same task into two distinct steps. In the first step, all processes are identified who want to send a request to this process. In the second step, the data is exchanged. However, since - in the second step - now it is clear how many requests have to be answered, i.e. when this process can stop waiting for requests, no IBarrier is needed.
Under the hood, this function uses Utilities::MPI::compute_point_to_point_communication_pattern() to determine the source processes, which itself is based on the NBX-algorithm from [133] that is implemented in the ConsensusAlgorithms::NBX class (a sister class to the current one).
Template Parameters
RequestTypeThe type of the elements of the vector to be sent.
AnswerTypeThe type of the elements of the vector to be received.

Definition at line 456 of file mpi_consensus_algorithms.h.

Inheritance diagram for Utilities::MPI::ConsensusAlgorithms::PEX< RequestType, AnswerType >:
[legend]

Public Member Functions

 PEX ()=default
 
virtual ~PEX ()=default
 
virtual std::vector< unsigned int > run (const std::vector< unsigned int > &targets, const std::function< RequestType(const unsigned int)> &create_request, const std::function< AnswerType(const unsigned int, const RequestType &)> &answer_request, const std::function< void(const unsigned int, const AnswerType &)> &process_answer, const MPI_Comm comm) override
 

Private Member Functions

unsigned int start_communication (const std::vector< unsigned int > &targets, const std::function< RequestType(const unsigned int)> &create_request, const MPI_Comm comm)
 
void answer_one_request (const unsigned int index, const std::function< AnswerType(const unsigned int, const RequestType &)> &answer_request, const MPI_Comm comm)
 
void process_incoming_answers (const unsigned int n_targets, const std::function< void(const unsigned int, const AnswerType &)> &process_answer, const MPI_Comm comm)
 
void clean_up_and_end_communication ()
 

Private Attributes

std::vector< std::vector< char > > send_buffers
 
std::vector< std::vector< char > > recv_buffers
 
std::vector< MPI_Request > send_request_requests
 
std::vector< std::vector< char > > requests_buffers
 
std::vector< MPI_Request > send_answer_requests
 
std::set< unsigned int > requesting_processes
 

Constructor & Destructor Documentation

◆ PEX()

template<typename RequestType , typename AnswerType >
Utilities::MPI::ConsensusAlgorithms::PEX< RequestType, AnswerType >::PEX ( )
default

Default constructor.

◆ ~PEX()

template<typename RequestType , typename AnswerType >
virtual Utilities::MPI::ConsensusAlgorithms::PEX< RequestType, AnswerType >::~PEX ( )
virtualdefault

Destructor.

Member Function Documentation

◆ run()

template<typename RequestType , typename AnswerType >
virtual std::vector< unsigned int > Utilities::MPI::ConsensusAlgorithms::PEX< RequestType, AnswerType >::run ( const std::vector< unsigned int > &  targets,
const std::function< RequestType(const unsigned int)> &  create_request,
const std::function< AnswerType(const unsigned int, const RequestType &)> &  answer_request,
const std::function< void(const unsigned int, const AnswerType &)> &  process_answer,
const MPI_Comm  comm 
)
overridevirtual

Run the consensus algorithm and return a vector of process ranks that have requested answers from the current process.

Parameters
[in]targetsA vector that contains the ranks of processes to which requests should be sent and from which answers need to be received.
[in]create_requestA function object that takes the rank of a target process as argument and returns the message that forms the request to this target.
[in]answer_requestA function that takes as arguments the rank of the process that has sent a request to us, along with the message of the request, and returns the message that forms the answer that should be sent back to the requesting process.
[in]process_answerA function object that takes as argument the rank of a process from which we have received an answer to a previously sent request, along with the message that forms this answer. This function is used to describe what the caller of the consensus algorithm wants to do with the received answer.
[in]commThe MPI communicator on which the whole algorithm is to be performed.

Implements Utilities::MPI::ConsensusAlgorithms::Interface< RequestType, AnswerType >.

◆ start_communication()

template<typename RequestType , typename AnswerType >
unsigned int Utilities::MPI::ConsensusAlgorithms::PEX< RequestType, AnswerType >::start_communication ( const std::vector< unsigned int > &  targets,
const std::function< RequestType(const unsigned int)> &  create_request,
const MPI_Comm  comm 
)
private

Start to send all requests via ISend and post IRecvs for the incoming answer messages.

◆ answer_one_request()

template<typename RequestType , typename AnswerType >
void Utilities::MPI::ConsensusAlgorithms::PEX< RequestType, AnswerType >::answer_one_request ( const unsigned int  index,
const std::function< AnswerType(const unsigned int, const RequestType &)> &  answer_request,
const MPI_Comm  comm 
)
private

The indexth request message from another rank has been received: process the request and send an answer.

◆ process_incoming_answers()

template<typename RequestType , typename AnswerType >
void Utilities::MPI::ConsensusAlgorithms::PEX< RequestType, AnswerType >::process_incoming_answers ( const unsigned int  n_targets,
const std::function< void(const unsigned int, const AnswerType &)> &  process_answer,
const MPI_Comm  comm 
)
private

Receive and process all of the incoming responses to the requests we sent.

◆ clean_up_and_end_communication()

template<typename RequestType , typename AnswerType >
void Utilities::MPI::ConsensusAlgorithms::PEX< RequestType, AnswerType >::clean_up_and_end_communication ( )
private

After all answers have been exchanged, the MPI data structures can be freed and the received answers can be processed.

Member Data Documentation

◆ send_buffers

template<typename RequestType , typename AnswerType >
std::vector<std::vector<char> > Utilities::MPI::ConsensusAlgorithms::PEX< RequestType, AnswerType >::send_buffers
private

Buffers for sending requests.

Definition at line 487 of file mpi_consensus_algorithms.h.

◆ recv_buffers

template<typename RequestType , typename AnswerType >
std::vector<std::vector<char> > Utilities::MPI::ConsensusAlgorithms::PEX< RequestType, AnswerType >::recv_buffers
private

Buffers for receiving answers to requests.

Definition at line 492 of file mpi_consensus_algorithms.h.

◆ send_request_requests

template<typename RequestType , typename AnswerType >
std::vector<MPI_Request> Utilities::MPI::ConsensusAlgorithms::PEX< RequestType, AnswerType >::send_request_requests
private

MPI request objects for sending request messages.

Definition at line 497 of file mpi_consensus_algorithms.h.

◆ requests_buffers

template<typename RequestType , typename AnswerType >
std::vector<std::vector<char> > Utilities::MPI::ConsensusAlgorithms::PEX< RequestType, AnswerType >::requests_buffers
private

Buffers for sending answers to requests.

Definition at line 502 of file mpi_consensus_algorithms.h.

◆ send_answer_requests

template<typename RequestType , typename AnswerType >
std::vector<MPI_Request> Utilities::MPI::ConsensusAlgorithms::PEX< RequestType, AnswerType >::send_answer_requests
private

Requests for sending answers to requests.

Definition at line 507 of file mpi_consensus_algorithms.h.

◆ requesting_processes

template<typename RequestType , typename AnswerType >
std::set<unsigned int> Utilities::MPI::ConsensusAlgorithms::PEX< RequestType, AnswerType >::requesting_processes
private

List of processes who have made a request to this process.

Definition at line 512 of file mpi_consensus_algorithms.h.


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