ADS
Algorithms and Data Structures
Loading...
Searching...
No Matches
MPIMailbox.h
Go to the documentation of this file.
1/*--------------------------------------------------------------------------*/
2/*--------------------------- File MPIMailbox.h ----------------------------*/
3/*--------------------------------------------------------------------------*/
93/*--------------------------------------------------------------------------*/
94/*----------------------------- DEFINITIONS --------------------------------*/
95/*--------------------------------------------------------------------------*/
96
97#ifndef __ADS_MPIMailbox
98 #define __ADS_MPIMailbox
99/* self-identification: #endif constant */
100
101#if defined( ADS_WITH_MPI )
102
103/*--------------------------------------------------------------------------*/
104/*------------------------------ INCLUDES ----------------------------------*/
105/*--------------------------------------------------------------------------*/
106
107#include "ADS/Contract.h"
109#include "ADS/parallel/Mailbox.h"
110
111#include <concepts>
112#include <cstddef>
113#include <cstdint>
114#include <cstring>
115#include <span>
116#include <string>
117#include <type_traits>
118#include <utility>
119#include <vector>
120
121/*--------------------------------------------------------------------------*/
122/*--------------------------- NAMESPACE ------------------------------------*/
123/*--------------------------------------------------------------------------*/
124
125namespace ADS
126{
127
136template< class Msg >
137struct MPICodec;
138
140template<>
141struct MPICodec< std::string >
142{
144 static void encode( const std::string & x , std::vector< std::byte > & out ) {
145 const auto * b = reinterpret_cast< const std::byte * >( x.data() );
146 out.insert( out.end() , b , b + x.size() );
147 }
148
149 static std::string decode( std::span< const std::byte > b ) {
150 return(
151 std::string( reinterpret_cast< const char * >( b.data() ) , b.size() ) );
152 }
153 };
154
156template< class T >
157 requires std::is_trivially_copyable_v< T >
158struct MPICodec< std::vector< T > >
159{
161 static void encode( const std::vector< T > & x ,
162 std::vector< std::byte > & out ) {
163 const std::size_t at = out.size();
164 out.resize( at + x.size() * sizeof( T ) );
165 if( ! x.empty() )
166 std::memcpy( out.data() + at , x.data() , x.size() * sizeof( T ) );
167 }
168
169 static std::vector< T > decode( std::span< const std::byte > b ) {
170 std::vector< T > x( b.size() / sizeof( T ) );
171 if( ! x.empty() )
172 std::memcpy( x.data() , b.data() , x.size() * sizeof( T ) );
173 return( x );
174 }
175 };
176
177namespace detail
178{
179
180/*--------------------------------------------------------------------------*/
181/*-------------------------- CLASS MPIMailboxCore --------------------------*/
182/*--------------------------------------------------------------------------*/
183
188template< class B >
189class MPIMailboxCore
190{
191
192/*--------------------------------------------------------------------------*/
193 public:
195 MPIMailboxCore( const MPIMailboxCore & ) = delete;
197 MPIMailboxCore & operator=( const MPIMailboxCore & ) = delete;
198
200 [[nodiscard]] std::size_t rank( void ) const {
201 return( std::size_t( f_rank ) );
202 }
203
205 [[nodiscard]] std::size_t size( void ) const {
206 return( std::size_t( f_size ) );
207 }
208
211 [[nodiscard]] bool terminated( void ) const { return( f_done ); }
212
215 [[nodiscard]] bool stopped( void ) const { return( f_stopped ); }
216
224 void stop( void ) {
225 if( f_done || f_stopped )
226 return;
227 f_stopped = true;
228 for( int q = 0 ; q < f_size ; ++q )
229 if( q != f_rank ) {
230 f_buf.emplace_back();
231 f_req.push_back( MPI_REQUEST_NULL );
232 detail::mpiCheck(
233 MPI_Isend( nullptr , 0 , MPI_BYTE , q , kTag , f_comm , &f_req.back() ) ,
234 "MPI_Isend" );
235 ++f_to[ 2 * std::size_t( q ) + 1 ];
236 }
237 }
238
240 [[nodiscard]] std::uint64_t sent( void ) const { return( f_sent ); }
241
243 [[nodiscard]] std::uint64_t batches( void ) const { return( f_batches ); }
244
246 [[nodiscard]] std::uint64_t received( void ) const { return( f_received ); }
247
249 [[nodiscard]] std::uint64_t waves( void ) const { return( f_waves ); }
250
252 [[nodiscard]] MPI_Comm comm( void ) const { return( f_comm ); }
253
254/*--------------------------------------------------------------------------*/
255 protected:
257 static constexpr int kTag = 1;
258
260 explicit MPIMailboxCore( MPI_Comm comm ) {
261 detail::mpiCheck( MPI_Comm_dup( comm , &f_comm ) , "MPI_Comm_dup" );
262 detail::mpiCheck( MPI_Comm_rank( f_comm , &f_rank ) , "MPI_Comm_rank" );
263 detail::mpiCheck( MPI_Comm_size( f_comm , &f_size ) , "MPI_Comm_size" );
264 f_to.assign( 2 * std::size_t( f_size ) , 0 );
265 }
266
269 ~MPIMailboxCore() {
270 if( ! f_req.empty() )
271 MPI_Waitall( int( f_req.size() ) , f_req.data() , MPI_STATUSES_IGNORE );
272 if( f_waving )
273 MPI_Wait( &f_wave , MPI_STATUS_IGNORE );
274 MPI_Comm_free( &f_comm );
275 }
276
279 void isend( std::vector< B > && b , std::size_t to , std::uint64_t k ) {
280 f_buf.push_back( std::move( b ) );
281 const auto & x = f_buf.back();
282 f_req.push_back( MPI_REQUEST_NULL );
283 detail::mpiCheck( MPI_Isend( x.data() , int( x.size() * sizeof( B ) ) ,
284 MPI_BYTE , int( to ) , kTag , f_comm ,
285 &f_req.back() ) ,
286 "MPI_Isend" );
287 f_to[ 2 * to ] += k;
288 ++f_batches;
289 }
290
293 template< class T >
294 std::size_t receive( T && take ) {
295 std::size_t n = 0;
296 for( int batches = 0 ; batches < 64 ; ++batches ) {
297 int flag = 0;
298 MPI_Status st;
299 detail::mpiCheck( MPI_Iprobe( MPI_ANY_SOURCE , kTag , f_comm , &flag ,
300 &st ) ,
301 "MPI_Iprobe" );
302 if( ! flag )
303 break;
304 const std::size_t k = receiveOne( st , take );
305 if( k == 0 ) { // the note of a stop
306 f_stopped = true;
307 break;
308 }
309 n += k;
310 }
311 f_received += n;
312 return( n );
313 }
314
316 void progress( void ) {
317 if( f_req.empty() )
318 return;
319 int done = 0;
320 f_index.resize( f_req.size() );
321 detail::mpiCheck( MPI_Testsome( int( f_req.size() ) , f_req.data() , &done ,
322 f_index.data() , MPI_STATUSES_IGNORE ) ,
323 "MPI_Testsome" );
324 if( ( done == MPI_UNDEFINED ) || ( done == 0 ) )
325 return;
326 // the requests completed are now MPI_REQUEST_NULL: keep the others
327 std::size_t keep = 0;
328 for( std::size_t i = 0 ; i < f_req.size() ; ++i )
329 if( f_req[ i ] != MPI_REQUEST_NULL ) {
330 if( keep != i ) {
331 f_req[ keep ] = f_req[ i ];
332 f_buf[ keep ] = std::move( f_buf[ i ] );
333 }
334 ++keep;
335 }
336 f_req.resize( keep );
337 f_buf.resize( keep );
338 }
339
342 bool wave( void ) {
343 if( f_done )
344 return( true );
345 progress();
346 if( f_waving ) {
347 int flag = 0;
348 detail::mpiCheck( MPI_Test( &f_wave , &flag , MPI_STATUS_IGNORE ) ,
349 "MPI_Test" );
350 if( ! flag )
351 return( false );
352 f_waving = false;
353 ++f_waves;
354 if( f_sums[ 2 ] == std::uint64_t( f_size ) )
355 return( f_done = true ); // all stopped
356 if( f_waves > 1 && ( f_sums[ 0 ] == f_lastR ) )
357 return( f_done = true );
358 f_lastR = f_sums[ 1 ];
359 }
360 f_mine[ 0 ] = f_sent;
361 f_mine[ 1 ] = f_received;
362 f_mine[ 2 ] = f_stopped ? 1 : 0;
363 detail::mpiCheck( MPI_Iallreduce( f_mine , f_sums , 3 , MPI_UINT64_T ,
364 MPI_SUM ,
365 f_comm , &f_wave ) ,
366 "MPI_Iallreduce" );
367 f_waving = true;
368 return( false );
369 }
370
375 template< class T >
376 std::size_t close( T && take ) {
377 if( f_closed )
378 return( 0 );
379 f_closed = true;
380 std::uint64_t in[ 2 ] = { 0 , 0 };
381 detail::mpiCheck( MPI_Reduce_scatter_block( f_to.data() , in , 2 ,
382 MPI_UINT64_T ,
383 MPI_SUM , f_comm ) ,
384 "MPI_Reduce_scatter_block" );
385 std::size_t n = 0;
386 while( ( f_inMsgs < in[ 0 ] ) || ( f_inNotes < in[ 1 ] ) ) {
387 MPI_Status st;
388 detail::mpiCheck( MPI_Probe( MPI_ANY_SOURCE , kTag , f_comm , &st ) ,
389 "MPI_Probe" );
390 n += receiveOne( st , take );
391 }
392 if( ! f_req.empty() )
393 detail::mpiCheck(
394 MPI_Waitall( int( f_req.size() ) , f_req.data() , MPI_STATUSES_IGNORE ) ,
395 "MPI_Waitall" );
396 f_req.clear();
397 f_buf.clear();
398 return( n );
399 }
400
402 [[nodiscard]] bool closed( void ) const { return( f_closed ); }
403
405 void countSent( std::uint64_t k ) { f_sent += k; }
406
408 void countSelf( std::uint64_t k ) { f_received += k; }
409
410/*--------------------------------------------------------------------------*/
411 private:
414 template< class T >
415 std::size_t receiveOne( const MPI_Status & st , T & take ) {
416 int bytes = 0;
417 detail::mpiCheck( MPI_Get_count( &st , MPI_BYTE , &bytes ) ,
418 "MPI_Get_count" );
419 f_in.resize( std::size_t( bytes ) / sizeof( B ) );
420 detail::mpiCheck( MPI_Recv( f_in.data() , bytes , MPI_BYTE , st.MPI_SOURCE ,
421 kTag , f_comm , MPI_STATUS_IGNORE ) ,
422 "MPI_Recv" );
423 if( bytes == 0 ) {
424 ++f_inNotes;
425 return( 0 );
426 }
427 const std::size_t k = take( std::span< const B >( f_in ) );
428 f_inMsgs += k;
429 return( k );
430 }
431
432 MPI_Comm f_comm = MPI_COMM_NULL;
433 int f_rank = 0;
434 int f_size = 1;
435 std::vector< B > f_in;
436 std::vector< MPI_Request > f_req;
437 std::vector< std::vector< B > > f_buf;
438 std::vector< int > f_index;
440 std::vector< std::uint64_t > f_to;
441 std::uint64_t f_inMsgs = 0;
442 std::uint64_t f_inNotes = 0;
443 std::uint64_t f_sent = 0;
444 std::uint64_t f_batches = 0;
445 std::uint64_t f_received = 0;
446 MPI_Request f_wave = MPI_REQUEST_NULL;
447 bool f_waving = false;
448 std::uint64_t f_mine[ 3 ] = { 0 , 0 , 0 };
449 std::uint64_t f_sums[ 3 ] = { 0 , 0 , 0 };
450 std::uint64_t f_lastR = 0;
451 std::uint64_t f_waves = 0;
452 bool f_stopped = false;
453 bool f_done = false;
454 bool f_closed = false;
455 }; // end( class MPIMailboxCore )
456
457} // end( namespace detail )
458
459/*--------------------------------------------------------------------------*/
460/*-------------------------- CLASS MPIByteMailbox --------------------------*/
461/*--------------------------------------------------------------------------*/
462
465class MPIByteMailbox : public detail::MPIMailboxCore< std::byte >
466{
467
468 using Core = detail::MPIMailboxCore< std::byte >;
469
470/*--------------------------------------------------------------------------*/
471 public:
475 explicit MPIByteMailbox( MPI_Comm comm = MPI_COMM_WORLD ,
476 std::size_t batch = 65536 )
477 : Core( comm ) , f_batch( batch ) {
478 ADS_PRE( batch >= 1 );
479 f_out.resize( size() );
480 f_count.assign( size() , 0 );
481 }
482
486 if( terminated() && ! closed() )
487 try {
488 close( []( std::span< const std::byte > b ) { return( records( b ) ); } );
489 }
490 catch( ... ) { // a destructor does not throw
491 }
492 }
493
509 void send( std::size_t to , std::uint32_t t ,
510 std::span< const std::byte > b ) {
511 ADS_PRE( ( to < size() ) && ( b.size() <= 0xFFFFFFFFull ) );
512 auto & o = f_out[ to ];
513 const std::uint32_t head[ 2 ] = { t , std::uint32_t( b.size() ) };
514 const std::size_t at = o.size();
515 o.resize( at + sizeof( head ) + padded( b.size() ) );
516 std::memcpy( o.data() + at , head , sizeof( head ) );
517 if( ! b.empty() )
518 std::memcpy( o.data() + at + sizeof( head ) , b.data() , b.size() );
519 ++f_count[ to ];
520 if( ( o.size() >= f_batch ) && ! stopped() )
521 post( to );
522 }
523
525 void flush( void ) {
526 if( stopped() )
527 return;
528 for( std::size_t to = 0 ; to < f_out.size() ; ++to )
529 if( ! f_out[ to ].empty() )
530 post( to );
531 }
532
557 template< class F >
558 std::size_t poll( F && f ) {
559 if( stopped() )
560 return( 0 );
561 progress();
562 std::size_t n = 0;
563 if( ! f_self.empty() ) {
564 std::swap( f_self , f_selfTaken );
565 n = forEach( f_selfTaken , f );
566 f_selfTaken.clear();
567 countSelf( n );
568 }
569 return( n + receive( [ & ]( std::span< const std::byte > b ) {
570 return( forEach( b , f ) );
571 } ) );
572 }
573
576 bool quiescent( void ) {
577 if( terminated() )
578 return( true );
579 flush();
580 return( wave() );
581 }
582
589 template< class F >
590 std::size_t leftovers( F && f ) {
591 ADS_PRE( terminated() );
592 std::size_t n = close(
593 [ & ]( std::span< const std::byte > b ) { return( forEach( b , f ) ); } );
594 n += forEach( f_self , f );
595 f_self.clear();
596 for( auto & o : f_out ) {
597 n += forEach( o , f );
598 o.clear();
599 }
600 return( n );
601 }
602
603/*--------------------------------------------------------------------------*/
604 private:
606 static std::size_t padded( std::size_t k ) { return( ( k + 7 ) & ~7ull ); }
607
609 template< class F >
610 static std::size_t forEach( std::span< const std::byte > x , F & f ) {
611 std::size_t n = 0;
612 for( std::size_t at = 0 ; at < x.size() ; ++n ) {
613 std::uint32_t head[ 2 ];
614 std::memcpy( head , x.data() + at , sizeof( head ) );
615 at += sizeof( head );
616 f( head[ 0 ] , x.subspan( at , head[ 1 ] ) );
617 at += padded( head[ 1 ] );
618 }
619 return( n );
620 }
621
623 static std::size_t records( std::span< const std::byte > x ) {
624 auto none = []( std::uint32_t , std::span< const std::byte > ) { };
625 return( forEach( x , none ) );
626 }
627
629 void post( std::size_t to ) {
630 auto & o = f_out[ to ];
631 countSent( f_count[ to ] );
632 if( to == rank() )
633 f_self.insert( f_self.end() , o.begin() , o.end() );
634 else {
635 std::vector< std::byte > b;
636 b.reserve( f_batch + 64 );
637 std::swap( b , o );
638 isend( std::move( b ) , to , f_count[ to ] );
639 }
640 o.clear();
641 f_count[ to ] = 0;
642 }
643
644 std::size_t f_batch;
645 std::vector< std::vector< std::byte > > f_out;
646 std::vector< std::uint64_t > f_count;
647 std::vector< std::byte > f_self;
648 std::vector< std::byte > f_selfTaken;
649 }; // end( class MPIByteMailbox )
650
651/*--------------------------------------------------------------------------*/
652/*---------------------------- CLASS MPIMailbox ----------------------------*/
653/*--------------------------------------------------------------------------*/
654
660template< class Msg , bool = std::is_trivially_copyable_v< Msg > >
661class MPIMailbox : public detail::MPIMailboxCore< Msg >
662{
663
664 using Core = detail::MPIMailboxCore< Msg >;
665
666/*--------------------------------------------------------------------------*/
667 public:
668 using Message = Msg;
669
673 explicit MPIMailbox( MPI_Comm comm = MPI_COMM_WORLD ,
674 std::size_t batch = 256 )
675 : Core( comm ) , f_batch( batch ) {
676 ADS_PRE( batch >= 1 );
677 f_out.resize( this->size() );
678 }
679
683 if( this->terminated() && ! this->closed() )
684 try {
685 this->close( []( std::span< const Msg > b ) { return( b.size() ); } );
686 }
687 catch( ... ) { // a destructor does not throw
688 }
689 }
690
704 void send( std::size_t to , const Msg & x ) {
705 ADS_PRE( to < this->size() );
706 auto & o = f_out[ to ];
707 o.push_back( x );
708 if( ( o.size() >= f_batch ) && ! this->stopped() )
709 post( to );
710 }
711
731 void flush( void ) {
732 if( this->stopped() )
733 return;
734 for( std::size_t to = 0 ; to < f_out.size() ; ++to )
735 if( ! f_out[ to ].empty() )
736 post( to );
737 }
738
773 template< class F >
774 std::size_t poll( F && f ) {
775 if( this->stopped() )
776 return( 0 );
777 this->progress();
778 std::size_t n = 0;
779 if( ! f_self.empty() ) {
780 std::swap( f_self , f_selfTaken );
781 for( const auto & x : f_selfTaken )
782 f( x );
783 n += f_selfTaken.size();
784 f_selfTaken.clear();
785 this->countSelf( n );
786 }
787 return( n + this->receive( [ & ]( std::span< const Msg > b ) {
788 for( const auto & x : b )
789 f( x );
790 return( b.size() );
791 } ) );
792 }
793
818 bool quiescent( void ) {
819 if( this->terminated() )
820 return( true );
821 flush();
822 return( this->wave() );
823 }
824
848 template< class F >
849 std::size_t leftovers( F && f ) {
850 ADS_PRE( this->terminated() );
851 std::size_t n = this->close( [ & ]( std::span< const Msg > b ) {
852 for( const auto & x : b )
853 f( x );
854 return( b.size() );
855 } );
856 for( auto * v : { &f_self , &f_selfTaken } ) {
857 for( const auto & x : *v )
858 f( x );
859 n += v->size();
860 v->clear();
861 }
862 for( auto & o : f_out ) {
863 for( const auto & x : o )
864 f( x );
865 n += o.size();
866 o.clear();
867 }
868 return( n );
869 }
870
871/*--------------------------------------------------------------------------*/
872 private:
874 void post( std::size_t to ) {
875 auto & o = f_out[ to ];
876 this->countSent( o.size() );
877 if( to == this->rank() ) {
878 f_self.insert( f_self.end() , o.begin() , o.end() );
879 o.clear();
880 return;
881 }
882 const std::uint64_t k = o.size();
883 std::vector< Msg > b;
884 b.reserve( f_batch );
885 std::swap( b , o );
886 this->isend( std::move( b ) , to , k );
887 }
888
889 std::size_t f_batch;
890 std::vector< std::vector< Msg > > f_out;
891 std::vector< Msg > f_self;
892 std::vector< Msg > f_selfTaken;
893 }; // end( class MPIMailbox )
894
895/*--------------------------------------------------------------------------*/
896/*--------------------- CLASS MPIMailbox< Msg , false > --------------------*/
897/*--------------------------------------------------------------------------*/
898
903template< class Msg >
904class MPIMailbox< Msg , false >
905{
906
907 static_assert(
908 requires( const Msg & x , std::vector< std::byte > & out ,
909 std::span< const std::byte > b ) {
910 MPICodec< Msg >::encode( x , out );
911 { MPICodec< Msg >::decode( b ) } -> std::convertible_to< Msg >;
912 } ,
913 "a message that is not trivially copyable needs MPICodec< Msg >" );
914
915/*--------------------------------------------------------------------------*/
916 public:
917 using Message = Msg;
918
922 explicit MPIMailbox( MPI_Comm comm = MPI_COMM_WORLD ,
923 std::size_t batch = 65536 )
924 : f_box( comm , batch ) { }
925
927 [[nodiscard]] std::size_t rank( void ) const { return( f_box.rank() ); }
929 [[nodiscard]] std::size_t size( void ) const { return( f_box.size() ); }
930
934 void send( std::size_t to , const Msg & x ) {
935 f_bytes.clear();
936 MPICodec< Msg >::encode( x , f_bytes );
937 f_box.send( to , 0 , f_bytes );
938 }
939
941 void flush( void ) { f_box.flush(); }
942
944 template< class F >
945 std::size_t poll( F && f ) {
946 return( f_box.poll( [ & ]( std::uint32_t , std::span< const std::byte > b ) {
947 f( MPICodec< Msg >::decode( b ) );
948 } ) );
949 }
950
952 bool quiescent( void ) { return( f_box.quiescent() ); }
953
956 template< class F >
957 std::size_t leftovers( F && f ) {
958 return(
959 f_box.leftovers( [ & ]( std::uint32_t , std::span< const std::byte > b ) {
960 f( MPICodec< Msg >::decode( b ) );
961 } ) );
962 }
963
965 void stop( void ) { f_box.stop(); }
967 [[nodiscard]] bool stopped( void ) const { return( f_box.stopped() ); }
969 [[nodiscard]] bool terminated( void ) const { return( f_box.terminated() ); }
971 [[nodiscard]] std::uint64_t sent( void ) const { return( f_box.sent() ); }
973 [[nodiscard]] std::uint64_t batches( void ) const {
974 return( f_box.batches() );
975 }
976
977 [[nodiscard]] std::uint64_t received( void ) const {
978 return( f_box.received() );
979 }
980
981 [[nodiscard]] std::uint64_t waves( void ) const { return( f_box.waves() ); }
983 [[nodiscard]] MPI_Comm comm( void ) const { return( f_box.comm() ); }
984
985/*--------------------------------------------------------------------------*/
986 private:
987 MPIByteMailbox f_box;
988 std::vector< std::byte > f_bytes;
989 }; // end( class MPIMailbox< Msg , false > )
990
991/*--------------------------------------------------------------------------*/
992
993} // end( namespace ADS )
994
995#endif /* ADS_WITH_MPI */
996
997/*--------------------------------------------------------------------------*/
998
999#endif /* MPIMailbox.h included */
1000
1001/*--------------------------------------------------------------------------*/
1002/*------------------------- End File MPIMailbox.h --------------------------*/
1003/*--------------------------------------------------------------------------*/
The contracts of ADS: the preconditions, the postconditions and the invariants of the operations,...
The processes of MPI as the workers of a distributed computation, beyond the book,...
The mailbox of the long-lived workers of an executor [see Executor.h], beyond the book,...
the mailbox of the processes of a communicator for messages of bytes, each with a tag of its own,...
Definition MPIMailbox.h:466
std::size_t leftovers(F &&f)
the calls f( t , b ) on the messages left to this process, those on their way to it,...
Definition MPIMailbox.h:590
std::size_t poll(F &&f)
the calls f( t , b ) on the messages received, of tag and bytes (valid during the call,...
Definition MPIMailbox.h:558
~MPIByteMailbox()
the closing, if leftovers() did not do it, its messages dropped; a collective operation
Definition MPIMailbox.h:485
bool quiescent(void)
true if the computation has ended, or its stop; called with no work left, it sends the outboxes (unle...
Definition MPIMailbox.h:576
MPIByteMailbox(MPI_Comm comm=MPI_COMM_WORLD, std::size_t batch=65536)
the mailbox of the processes of comm, which sends an outbox when it holds batch bytes; a collective o...
Definition MPIMailbox.h:475
void send(std::size_t to, std::uint32_t t, std::span< const std::byte > b)
the message of the bytes and of the tag appended to the outbox for to, which is sent when it holds ...
Definition MPIMailbox.h:509
void flush(void)
the outboxes sent, unless stopped
Definition MPIMailbox.h:525
bool quiescent(void)
as MPIByteMailbox::quiescent()
Definition MPIMailbox.h:952
MPI_Comm comm(void) const
the communicator of the mailbox
Definition MPIMailbox.h:983
std::size_t rank(void) const
the rank of this process
Definition MPIMailbox.h:927
Msg Message
the type of the messages
Definition MPIMailbox.h:917
void send(std::size_t to, const Msg &x)
the bytes of appended to the outbox for to, as MPIByteMailbox::send()
Definition MPIMailbox.h:934
void stop(void)
as MPIByteMailbox::stop()
Definition MPIMailbox.h:965
bool terminated(void) const
true once quiescent() has seen the end
Definition MPIMailbox.h:969
std::size_t leftovers(F &&f)
as MPIByteMailbox::leftovers(), the messages rebuilt
Definition MPIMailbox.h:957
std::uint64_t waves(void) const
the waves completed so far
Definition MPIMailbox.h:981
std::uint64_t sent(void) const
the messages sent by this process so far
Definition MPIMailbox.h:971
MPIMailbox(MPI_Comm comm=MPI_COMM_WORLD, std::size_t batch=65536)
the mailbox of the processes of comm, which sends an outbox when it holds batch bytes; a collective o...
Definition MPIMailbox.h:922
std::size_t poll(F &&f)
the calls f( x ) on the messages received, rebuilt, and their number
Definition MPIMailbox.h:945
void flush(void)
the outboxes sent, unless stopped
Definition MPIMailbox.h:941
std::size_t size(void) const
the number of the processes
Definition MPIMailbox.h:929
bool stopped(void) const
true once this process has stopped
Definition MPIMailbox.h:967
std::uint64_t batches(void) const
the batches sent by MPI so far
Definition MPIMailbox.h:973
std::uint64_t received(void) const
the messages received by this process so far
Definition MPIMailbox.h:977
std::size_t poll(F &&f)
the calls f( x ) on the messages received, and their number; nothing after the stop
Definition MPIMailbox.h:774
std::size_t leftovers(F &&f)
the calls f( x ) on the messages left to this process, those on their way to it, those to itself and ...
Definition MPIMailbox.h:849
bool quiescent(void)
true if the computation has ended, or its stop; called with no work left, it sends the outboxes (unle...
Definition MPIMailbox.h:818
MPIMailbox(MPI_Comm comm=MPI_COMM_WORLD, std::size_t batch=256)
the mailbox of the processes of comm, which sends batches of batch messages; a collective operation
Definition MPIMailbox.h:673
void send(std::size_t to, const Msg &x)
appended to the outbox for to, which is sent when it holds a batch; never waits, and after the stop o...
Definition MPIMailbox.h:704
void flush(void)
the outboxes sent, unless stopped
Definition MPIMailbox.h:731
Msg Message
the type of the messages
Definition MPIMailbox.h:668
~MPIMailbox()
the closing, if leftovers() did not do it, its messages dropped; a collective operation
Definition MPIMailbox.h:682
@ none
Definition Capabilities.h:553
#define ADS_PRE(cond)
[check]
Definition Contract.h:121
Batch< S > batch(S &s)
a batch on the structure , open while it lives: its events are collected, and the outermost batch sen...
Definition Modification.h:2150
Definition ADT.h:96
static void encode(const std::string &x, std::vector< std::byte > &out)
the characters appended to out
Definition MPIMailbox.h:144
static std::string decode(std::span< const std::byte > b)
the string of the bytes
Definition MPIMailbox.h:149
static std::vector< T > decode(std::span< const std::byte > b)
the vector of the bytes
Definition MPIMailbox.h:169
static void encode(const std::vector< T > &x, std::vector< std::byte > &out)
the bytes of the items appended to out
Definition MPIMailbox.h:161
the customization point of the messages that are not trivially copyable for MPIMailbox: a specializat...
Definition MPIMailbox.h:137