ADS
Algorithms and Data Structures
Toggle main menu visibility
Loading...
Searching...
No Matches
SenderExecutor.h
Go to the documentation of this file.
1
/*--------------------------------------------------------------------------*/
2
/*------------------------- File SenderExecutor.h --------------------------*/
3
/*--------------------------------------------------------------------------*/
51
/*--------------------------------------------------------------------------*/
52
/*----------------------------- DEFINITIONS --------------------------------*/
53
/*--------------------------------------------------------------------------*/
54
55
#ifndef __ADS_SenderExecutor
56
#define __ADS_SenderExecutor
57
/* self-identification: #endif constant */
58
59
#if defined( ADS_WITH_STDEXEC ) || __has_include( <stdexec/execution.hpp> )
60
61
/*--------------------------------------------------------------------------*/
62
/*------------------------------ INCLUDES ----------------------------------*/
63
/*--------------------------------------------------------------------------*/
64
65
#include "
ADS/Contract.h
"
66
#include "
ADS/parallel/Executor.h
"
67
68
#include <stdexec/execution.hpp>
69
70
#include <cstddef>
71
#include <utility>
72
73
/*--------------------------------------------------------------------------*/
74
/*--------------------------- NAMESPACE ------------------------------------*/
75
/*--------------------------------------------------------------------------*/
76
77
namespace
ADS
78
{
79
80
/*--------------------------------------------------------------------------*/
81
/*------------------------- CLASS SenderExecutor ---------------------------*/
82
/*--------------------------------------------------------------------------*/
83
85
template
< stdexec::scheduler Sch >
86
class
SenderExecutor
87
{
88
89
/*--------------------------------------------------------------------------*/
90
public
:
94
SenderExecutor
( Sch s , std::size_t p ) : f_s( std::move( s ) ) , f_p( p ) {
95
ADS_PRE
( p >= 1 );
96
}
97
99
[[nodiscard]] std::size_t
concurrency
(
void
)
const
{
return
( f_p ); }
100
102
[[nodiscard]]
const
Sch &
scheduler
(
void
)
const
{
return
( f_s ); }
103
121
template
<
class
F >
122
void
bulk
( std::size_t n , F && f ) {
123
if
( ( n <= 1 ) || ( f_p == 1 ) || Inside::active() ) {
124
for
( std::size_t i = 0 ; i < n ; ++i )
125
f( i );
126
return
;
127
}
128
detail::FirstError error;
129
auto
body = [ & ]( std::size_t i )
noexcept
{
130
if
( error.failed() )
131
return
;
132
Inside mark;
133
try
{
134
f( i );
135
}
136
catch
( ... ) {
137
error.keep();
138
}
139
};
140
stdexec::sync_wait( stdexec::schedule( f_s ) |
141
stdexec::bulk( stdexec::par , n , body ) );
142
error.rethrow();
143
}
144
145
/*--------------------------------------------------------------------------*/
146
private
:
147
struct
Tag;
148
using
Inside = detail::InsideCall< Tag >;
149
150
Sch f_s;
151
std::size_t f_p;
152
};
// end( class SenderExecutor )
153
154
/*--------------------------------------------------------------------------*/
155
156
}
// end( namespace ADS )
157
158
#endif
/* ADS_WITH_STDEXEC */
159
160
/*--------------------------------------------------------------------------*/
161
162
#endif
/* SenderExecutor.h included */
163
164
/*--------------------------------------------------------------------------*/
165
/*----------------------- End File SenderExecutor.h ------------------------*/
166
/*--------------------------------------------------------------------------*/
Contract.h
The contracts of ADS: the preconditions, the postconditions and the invariants of the operations,...
Executor.h
The layer of execution of the parallel algorithms of ADS, beyond the book: an executor runs the calls...
ADS::SenderExecutor::bulk
void bulk(std::size_t n, F &&f)
the calls by a bulk sender on the scheduler, in order on the calling thread inside a call
Definition
SenderExecutor.h:122
ADS::SenderExecutor::concurrency
std::size_t concurrency(void) const
the number of threads given to the constructor
Definition
SenderExecutor.h:99
ADS::SenderExecutor::SenderExecutor
SenderExecutor(Sch s, std::size_t p)
the executor of the scheduler , which tells the algorithms of ADS that it has threads
Definition
SenderExecutor.h:94
ADS::SenderExecutor::scheduler
const Sch & scheduler(void) const
the scheduler
Definition
SenderExecutor.h:102
ADS_PRE
#define ADS_PRE(cond)
[check]
Definition
Contract.h:121
ADS
Definition
ADT.h:96
ADS
interop
parallel
SenderExecutor.h
Generated by
1.17.0