ADS
Algorithms and Data Structures
Loading...
Searching...
No Matches
Channels.h File Reference

The channels between the long-lived workers of an executor [see Executor.h], beyond the book: \( p \) workers, each with an inbox, where any worker pushes a batch of messages for another one and the owner of the inbox drains it. More...

#include "ADS/Contract.h"
#include "ADS/concurrent/MPSCInbox.h"
#include "ADS/concurrent/MPSCQueue.h"
#include "ADS/concurrent/SPSCQueue.h"
#include "ADS/parallel/Executor.h"
#include <atomic>
#include <concepts>
#include <cstddef>
#include <memory>
#include <mutex>
#include <span>
#include <utility>
#include <vector>

Go to the source code of this file.

Classes

class  ADS::ChannelPort< C >
 the channels of a family seen by one worker More...
class  ADS::LockedChannels< Msg, Lock >
 the inboxes as vectors under a lock, the portable baseline More...
class  ADS::InboxChannels< Msg >
 the inboxes as stacks of Treiber of batches [see MPSCInbox.h] More...
class  ADS::LaneChannels< Msg, B >
 the inboxes as queues with a lane per sender [see MPSCQueue.h] More...
class  ADS::MeshChannels< Msg >
 the \( p^2 \) bounded queues of the pairs of workers [see SPSCQueue.h] More...
struct  ADS::ChannelsOf< E >
 the family of channels of an executor, as measured by bench/runtime.cpp (see Channels between workers): the mesh on every executor, which won the batches of 1 and of 64 messages and the round trips on the pool, OpenMP and FastFlow, with the trees a tie; a specialization may give an executor a family of its own More...

Namespaces

namespace  ADS

Concepts

concept  ADS::ChannelFamily
 the families of channels among \( p \) workers: tryPush( from , to , m ) pushes a span of messages and returns how many, drain( me , f ) calls \( f \) on the messages of the inbox of me and returns how many, size() is \( p \)

Typedefs

template<class Msg, class E>
using ADS::DefaultChannels = typename ChannelsOf< E >::template type< Msg >
 the family of channels to use on the executor E

Detailed description

The channels between the long-lived workers of an executor [see Executor.h], beyond the book: \( p \) workers, each with an inbox, where any worker pushes a batch of messages for another one and the owner of the inbox drains it.

All the families of channels have one interface, the concept ChannelFamily: tryPush( from , to , m ) pushes the messages of the span \( m \) from the worker from to the inbox of the worker to and returns how many it pushed (all of them but in a bounded family, which pushes those that fit), drain( me , f ) calls f( x ) on each message \( x \) found in the inbox of me, moved, and returns how many, and port( i ) binds both to the worker \( i \). The messages of a worker to another come out in the order in which it pushed them; those of different senders interleave in any order. The families differ in what an inbox is (see Channels between workers):

  • LockedChannels, the portable baseline: an inbox is a vector under a lock, by default the lock of the executor (lock_type), which a push appends to and a drain swaps with an empty one, so that each takes the lock once per batch;
  • InboxChannels: an inbox is an MPSCInbox [see MPSCInbox.h], a stack of Treiber on which a push puts the batch as one cell, by one compare-and-swap, and that a drain takes whole by one exchange;
  • LaneChannels: an inbox is an MPSCQueue [see MPSCQueue.h], with a lane of blocks for each sender, so that the senders never meet;
  • MeshChannels: the \( p^2 \) queues SPSCQueue [see SPSCQueue.h] of each ordered pair of workers, the mesh of the farms and of the all-to-all of FastFlow, bounded, a batch pushed by one store of a tail and a queue drained by one store of a head, the drain scanning the \( p \) queues of its worker.

DefaultChannels< Msg , E > is the family to use on the executor E, chosen by the measures of bench/runtime.cpp (see Channels between workers): the mesh, on every executor measured.

The contracts [see Contract.h]: \( p \ge 1 \) workers, the indices of the workers in \( [ 0 , p ) \); only the worker from pushes as from, and only the worker me drains its inbox; f does not throw. The messages are movable, and default constructible in LaneChannels.

See also
R. K. Treiber, Systems programming: coping with parallelism, Technical Report RJ 5118, IBM Almaden Research Center, 1986
M. Aldinucci, M. Danelutto, P. Kilpatrick, M. Meneghin, M. Torquati, An efficient unbounded lock-free queue for multi-core systems, Euro-Par 2012, LNCS 7484, 662-673, 2012, doi:10.1007/978-3-642-32820-6_65
M. Aldinucci, M. Danelutto, P. Kilpatrick, M. Torquati, FastFlow: high-level and efficient streaming on multicore, in S. Pllana, F. Xhafa (eds.), Programming Multi-core and Many-core Computing Systems, Wiley, 261-280, 2017, doi:10.1002/9781119332015.ch13
Author
Donato Meoli
Dipartimento di Informatica
Università di Pisa