ADS
Algorithms and Data Structures
Toggle main menu visibility
Loading...
Searching...
No Matches
BoostMPI.h
Go to the documentation of this file.
1
/*--------------------------------------------------------------------------*/
2
/*---------------------------- File BoostMPI.h -----------------------------*/
3
/*--------------------------------------------------------------------------*/
38
/*--------------------------------------------------------------------------*/
39
/*----------------------------- DEFINITIONS --------------------------------*/
40
/*--------------------------------------------------------------------------*/
41
42
#ifndef __ADS_BoostMPI
43
#define __ADS_BoostMPI
44
/* self-identification: #endif constant */
45
46
#if defined( ADS_WITH_MPI ) && \
47
( defined( ADS_WITH_BOOST_MPI ) || __has_include( <boost/mpi.hpp> ) )
48
49
/*--------------------------------------------------------------------------*/
50
/*------------------------------ INCLUDES ----------------------------------*/
51
/*--------------------------------------------------------------------------*/
52
53
#include "
ADS/distributed/MPIExecutor.h
"
54
#include "
ADS/distributed/MPIMailbox.h
"
55
56
#include <boost/mpi/communicator.hpp>
57
#include <boost/mpi/packed_iarchive.hpp>
58
#include <boost/mpi/packed_oarchive.hpp>
59
60
#include <concepts>
61
#include <cstddef>
62
#include <cstring>
63
#include <span>
64
#include <vector>
65
66
/*--------------------------------------------------------------------------*/
67
/*--------------------------- NAMESPACE ------------------------------------*/
68
/*--------------------------------------------------------------------------*/
69
70
namespace
ADS
71
{
72
73
/*--------------------------------------------------------------------------*/
74
/*------------------------- CLASS BoostMPICodec ----------------------------*/
75
/*--------------------------------------------------------------------------*/
76
79
template
< std::default_initializable Msg >
80
struct
BoostMPICodec
81
{
83
static
void
encode
(
const
Msg & x , std::vector< std::byte > & out ) {
84
boost::mpi::communicator world;
85
boost::mpi::packed_oarchive::buffer_type buffer;
86
boost::mpi::packed_oarchive archive( world , buffer );
87
archive << x;
88
const
std::size_t at = out.size();
89
out.resize( at + buffer.size() );
90
if
( ! buffer.empty() )
91
std::memcpy( out.data() + at , buffer.data() , buffer.size() );
92
}
93
95
static
Msg
decode
( std::span< const std::byte > b ) {
96
boost::mpi::communicator world;
97
boost::mpi::packed_iarchive::buffer_type buffer( b.size() );
98
if
( ! b.empty() )
99
std::memcpy( buffer.data() , b.data() , b.size() );
100
boost::mpi::packed_iarchive archive( world , buffer );
101
Msg x;
102
archive >> x;
103
return
( x );
104
}
105
};
// end( struct BoostMPICodec )
106
107
/*--------------------------------------------------------------------------*/
108
109
}
// end( namespace ADS )
110
111
#endif
/* ADS_WITH_MPI and Boost.MPI */
112
113
/*--------------------------------------------------------------------------*/
114
115
#endif
/* BoostMPI.h included */
116
117
/*--------------------------------------------------------------------------*/
118
/*-------------------------- End File BoostMPI.h ---------------------------*/
119
/*--------------------------------------------------------------------------*/
MPIExecutor.h
The processes of MPI as the workers of a distributed computation, beyond the book,...
MPIMailbox.h
The mailbox of the processes of MPI, beyond the book, compiled only with ADS_WITH_MPI: the mailbox of...
ADS
Definition
ADT.h:96
ADS::BoostMPICodec
the bytes of a message by Boost.Serialization, in the packed archives of Boost.MPI,...
Definition
BoostMPI.h:81
ADS::BoostMPICodec::encode
static void encode(const Msg &x, std::vector< std::byte > &out)
the bytes of the packed archive of appended to out
Definition
BoostMPI.h:83
ADS::BoostMPICodec::decode
static Msg decode(std::span< const std::byte > b)
the message of the bytes of a packed archive
Definition
BoostMPI.h:95
ADS
distributed
BoostMPI.h
Generated by
1.17.0