16#ifndef dealii_mpi_consensus_algorithm_h
17#define dealii_mpi_consensus_algorithm_h
22#include <deal.II/base/mpi.templates.h>
37 namespace ConsensusAlgorithms
61 template <
typename T1,
typename T2>
76 virtual std::vector<unsigned int>
90 std::vector<T1> & send_buffer);
104 std::vector<T2> & recv_buffer);
120 const std::vector<T1> &buffer_recv,
121 std::vector<T2> & request_buffer);
132 const std::vector<T2> &recv_buffer);
165 template <
typename T1,
typename T2>
179 virtual std::vector<unsigned int>
224 template <
typename T1,
typename T2>
244 virtual std::vector<unsigned int>
248#ifdef DEAL_II_WITH_MPI
358 template <
typename T1,
typename T2>
378 virtual std::vector<unsigned int>
382#ifdef DEAL_II_WITH_MPI
451 template <
typename T1,
typename T2>
466 virtual std::vector<unsigned int>
480 template <
typename T1,
typename T2>
502 virtual std::vector<unsigned int>
516 template <
typename T1,
typename T2>
532 const std::function<std::vector<unsigned int>()>
534 const std::function<
void(
const unsigned int, std::vector<T1> &)>
536 [](
const unsigned int, std::vector<T1> &) {},
537 const std::function<void(
const unsigned int,
538 const std::vector<T1> &,
541 const std::vector<T1> &,
542 std::vector<T2> &) {},
543 const std::function<void(
const unsigned int, std::vector<T2> &)>
545 [](
const unsigned int, std::vector<T2> &) {},
546 const std::function<void(
const unsigned int,
const std::vector<T2> &)>
548 [](
const unsigned int,
const std::vector<T2> &) {});
553 std::vector<unsigned int>
561 std::vector<T1> & send_buffer)
override;
568 const std::vector<T1> &buffer_recv,
569 std::vector<T2> & request_buffer)
override;
576 std::vector<T2> & recv_buffer)
override;
583 const std::vector<T2> &recv_buffer)
override;
586 const std::function<std::vector<unsigned int>()>
588 const std::function<void(
const int, std::vector<T1> &)>
591 void(
const unsigned int,
const std::vector<T1> &, std::vector<T2> &)>
593 const std::function<void(
const int, std::vector<T2> &)>
595 const std::function<void(
const int,
const std::vector<T2> &)>
601 template <
typename T1,
typename T2>
603 const std::function<std::vector<unsigned int>()>
604 &function_compute_targets,
605 const std::function<
void(
const unsigned int, std::vector<T1> &)>
606 & function_create_request,
607 const std::function<
void(
const unsigned int,
608 const std::vector<T1> &,
609 std::vector<T2> &)> &function_answer_request,
610 const std::function<
void(
const unsigned int, std::vector<T2> &)>
611 &function_prepare_buffer_for_answer,
612 const std::function<
void(
const unsigned int,
const std::vector<T2> &)>
613 &function_read_answer)
614 : function_compute_targets(function_compute_targets)
615 , function_create_request(function_create_request)
616 , function_answer_request(function_answer_request)
617 , function_prepare_buffer_for_answer(function_prepare_buffer_for_answer)
618 , function_read_answer(function_read_answer)
623 template <
typename T1,
typename T2>
624 std::vector<unsigned int>
627 return function_compute_targets();
632 template <
typename T1,
typename T2>
635 std::vector<T1> & send_buffer)
637 function_create_request(other_rank, send_buffer);
642 template <
typename T1,
typename T2>
645 const unsigned int other_rank,
646 const std::vector<T1> &buffer_recv,
647 std::vector<T2> & request_buffer)
649 function_answer_request(other_rank, buffer_recv, request_buffer);
654 template <
typename T1,
typename T2>
657 const unsigned int other_rank,
658 std::vector<T2> & recv_buffer)
660 function_prepare_buffer_for_answer(other_rank, recv_buffer);
665 template <
typename T1,
typename T2>
668 const std::vector<T2> &recv_buffer)
670 function_read_answer(other_rank, recv_buffer);
const std::function< std::vector< unsigned int >()> function_compute_targets
std::vector< unsigned int > compute_targets() override
const std::function< void(const unsigned int, const std::vector< T1 > &, std::vector< T2 > &)> function_answer_request
void prepare_buffer_for_answer(const unsigned int other_rank, std::vector< T2 > &recv_buffer) override
const std::function< void(const int, std::vector< T1 > &)> function_create_request
void answer_request(const unsigned int other_rank, const std::vector< T1 > &buffer_recv, std::vector< T2 > &request_buffer) override
void read_answer(const unsigned int other_rank, const std::vector< T2 > &recv_buffer) override
void create_request(const unsigned int other_rank, std::vector< T1 > &send_buffer) override
const std::function< void(const int, std::vector< T2 > &)> function_prepare_buffer_for_answer
AnonymousProcess(const std::function< std::vector< unsigned int >()> &function_compute_targets, const std::function< void(const unsigned int, std::vector< T1 > &)> &function_create_request=[](const unsigned int, std::vector< T1 > &) {}, const std::function< void(const unsigned int, const std::vector< T1 > &, std::vector< T2 > &)> &function_answer_request=[](const unsigned int, const std::vector< T1 > &, std::vector< T2 > &) {}, const std::function< void(const unsigned int, std::vector< T2 > &)> &function_prepare_buffer_for_answer=[](const unsigned int, std::vector< T2 > &) {}, const std::function< void(const unsigned int, const std::vector< T2 > &)> &function_read_answer=[](const unsigned int, const std::vector< T2 > &) {})
const std::function< void(const int, const std::vector< T2 > &)> function_read_answer
const unsigned int my_rank
virtual ~Interface()=default
const bool job_supports_mpi
Interface(Process< T1, T2 > &process, const MPI_Comm &comm)
const unsigned int n_procs
Process< T1, T2 > & process
virtual std::vector< unsigned int > run()=0
std::vector< std::vector< T2 > > recv_buffers
std::vector< MPI_Request > recv_requests
NBX(Process< T1, T2 > &process, const MPI_Comm &comm)
void start_communication()
std::set< unsigned int > requesting_processes
std::vector< unsigned int > targets
virtual std::vector< unsigned int > run() override
std::vector< std::unique_ptr< std::vector< T2 > > > request_buffers
bool check_global_state()
std::vector< std::unique_ptr< MPI_Request > > request_requests
std::vector< MPI_Request > send_requests
std::vector< std::vector< T1 > > send_buffers
void clean_up_and_end_communication()
MPI_Request barrier_request
std::vector< MPI_Request > send_and_recv_buffers
std::vector< unsigned int > targets
virtual std::vector< unsigned int > run() override
std::set< unsigned int > requesting_processes
void clean_up_and_end_communication()
unsigned int start_communication()
std::vector< std::vector< T2 > > recv_buffers
std::vector< unsigned int > sources
PEX(Process< T1, T2 > &process, const MPI_Comm &comm)
std::vector< std::vector< T1 > > send_buffers
std::vector< std::vector< T2 > > requests_buffers
void answer_requests(int index)
std::vector< MPI_Request > requests_answers
virtual void create_request(const unsigned int other_rank, std::vector< T1 > &send_buffer)
virtual void read_answer(const unsigned int other_rank, const std::vector< T2 > &recv_buffer)
virtual ~Process()=default
virtual void answer_request(const unsigned int other_rank, const std::vector< T1 > &buffer_recv, std::vector< T2 > &request_buffer)
virtual std::vector< unsigned int > compute_targets()=0
virtual void prepare_buffer_for_answer(const unsigned int other_rank, std::vector< T2 > &recv_buffer)
std::shared_ptr< Interface< T1, T2 > > consensus_algo
virtual std::vector< unsigned int > run() override
virtual ~Selector()=default
Selector(Process< T1, T2 > &process, const MPI_Comm &comm)
Serial(Process< T1, T2 > &process, const MPI_Comm &comm)
virtual std::vector< unsigned int > run() override
#define DEAL_II_NAMESPACE_OPEN
#define DEAL_II_NAMESPACE_CLOSE