https://mooseframework.inl.gov
Loading...
Searching...
No Matches
Public Member Functions | Protected Attributes | Private Attributes | List of all members
SendBuffer< Object, Context > Class Template Reference

#include <SendBuffer.h>

Inheritance diagram for SendBuffer< Object, Context >:
[legend]

Public Member Functions

 SendBuffer (const libMesh::Parallel::Communicator &comm, const Context *const context, const processor_id_type pid, const ParallelStudyMethod &method, const unsigned int min_buffer_size, const unsigned int max_buffer_size, const Real buffer_growth_multiplier, const Real buffer_shrink_multiplier, const Parallel::MessageTag object_buffer_tag)
 
 ~SendBuffer () override
 Destructor: ensures that all send requests have completed.
 
unsigned long int objectsSent () const
 Get the number of objects sent from this buffer.
 
unsigned long int buffersSent () const
 Get the number of buffers sent from this buffer.
 
unsigned long int bufferPoolCreated () const
 Get the number of buffers created in the buffer pool.
 
bool currentlySending () const
 Whether or not messages are currently being sent.
 
bool currentlyBuffered () const
 Whether or not objects are currently waiting to be sent.
 
void moveObject (std::shared_ptr< Object > &object)
 Move an object to the buffer.
 
void forceSend (const bool shrink_current_buffer_size=true)
 Forces a Send for all currently buffered objects.
 
void waitAll ()
 Wait for all requests to finish.
 
void clear ()
 Clear all existing data.
 
void cleanupRequests ()
 Checks to see if any Requests can be finished.
 
const Parallel::Communicator & comm () const
 
processor_id_type n_processors () const
 
processor_id_type processor_id () const
 

Protected Attributes

const Parallel::Communicator & _communicator
 

Private Attributes

const Context *const _context
 The context.
 
const processor_id_type _pid
 The processor ID this buffer will send to.
 
const ParallelStudyMethod_method
 
const unsigned int _min_buffer_size
 Minimum size of the buffer (in objects)
 
const unsigned int _max_buffer_size
 Maximum size of the buffer (in objects)
 
const Real _buffer_growth_multiplier
 Multiplier for the buffer size for growing the buffer.
 
const Real _buffer_shrink_multiplier
 Multiplier for the buffer size for shrinking the buffer.
 
const Parallel::MessageTag _object_buffer_tag
 MessageTag for sending objects.
 
unsigned int _current_buffer_size
 Current size of the buffer (in objects)
 
Real _current_buffer_size_real
 Running buffer size.
 
std::vector< std::shared_ptr< Object > > _buffer
 The buffer.
 
std::size_t _buffer_size_bytes
 The size of the objects in the buffer in bytes.
 
std::list< std::shared_ptr< Parallel::Request > > _requests
 List of Requests.
 
MooseUtils::SharedPool< std::vector< typename Parallel::Packing< std::shared_ptr< Object > >::buffer_type > > _buffer_pool
 Shared pool of buffers.
 
unsigned long int _objects_sent
 Counter for objects sent.
 
unsigned long int _buffers_sent
 Counter for buffers sent.
 

Detailed Description

template<typename Object, typename Context>
class SendBuffer< Object, Context >

Definition at line 26 of file SendBuffer.h.

Constructor & Destructor Documentation

◆ SendBuffer()

template<typename Object , typename Context >
SendBuffer< Object, Context >::SendBuffer ( const libMesh::Parallel::Communicator comm,
const Context *const  context,
const processor_id_type  pid,
const ParallelStudyMethod method,
const unsigned int  min_buffer_size,
const unsigned int  max_buffer_size,
const Real  buffer_growth_multiplier,
const Real  buffer_shrink_multiplier,
const Parallel::MessageTag  object_buffer_tag 
)

Definition at line 139 of file SendBuffer.h.

149 _context(context),
150 _pid(pid),
151 _method(method),
152 _min_buffer_size(min_buffer_size),
153 _max_buffer_size(max_buffer_size),
154 _buffer_growth_multiplier(buffer_growth_multiplier),
155 _buffer_shrink_multiplier(buffer_shrink_multiplier),
156 _object_buffer_tag(object_buffer_tag),
160 _objects_sent(0),
162{
163 _buffer.reserve(max_buffer_size);
164}
unsigned long int _buffers_sent
Counter for buffers sent.
Definition SendBuffer.h:135
const Real _buffer_growth_multiplier
Multiplier for the buffer size for growing the buffer.
Definition SendBuffer.h:107
Real _current_buffer_size_real
Running buffer size.
Definition SendBuffer.h:117
const unsigned int _min_buffer_size
Minimum size of the buffer (in objects)
Definition SendBuffer.h:102
unsigned int _current_buffer_size
Current size of the buffer (in objects)
Definition SendBuffer.h:115
std::vector< std::shared_ptr< Object > > _buffer
The buffer.
Definition SendBuffer.h:120
const processor_id_type _pid
The processor ID this buffer will send to.
Definition SendBuffer.h:97
std::size_t _buffer_size_bytes
The size of the objects in the buffer in bytes.
Definition SendBuffer.h:122
const Real _buffer_shrink_multiplier
Multiplier for the buffer size for shrinking the buffer.
Definition SendBuffer.h:109
const ParallelStudyMethod & _method
Definition SendBuffer.h:99
const unsigned int _max_buffer_size
Maximum size of the buffer (in objects)
Definition SendBuffer.h:104
const Parallel::MessageTag _object_buffer_tag
MessageTag for sending objects.
Definition SendBuffer.h:112
unsigned long int _objects_sent
Counter for objects sent.
Definition SendBuffer.h:133
const Context *const _context
The context.
Definition SendBuffer.h:95
ParallelObject(const Parallel::Communicator &comm_in)
const Parallel::Communicator & comm() const

◆ ~SendBuffer()

template<typename Object , typename Context >
SendBuffer< Object, Context >::~SendBuffer ( )
override

Destructor: ensures that all send requests have completed.

Definition at line 167 of file SendBuffer.h.

168{
169 waitAll();
171}
void cleanupRequests()
Checks to see if any Requests can be finished.
Definition SendBuffer.h:246
void waitAll()
Wait for all requests to finish.
Definition SendBuffer.h:263

Member Function Documentation

◆ bufferPoolCreated()

template<typename Object , typename Context >
unsigned long int SendBuffer< Object, Context >::bufferPoolCreated ( ) const
inline

Get the number of buffers created in the buffer pool.

Definition at line 55 of file SendBuffer.h.

55{ return _buffer_pool.num_created(); }
size_t num_created() const
MooseUtils::SharedPool< std::vector< typename Parallel::Packing< std::shared_ptr< Object > >::buffer_type > > _buffer_pool
Shared pool of buffers.
Definition SendBuffer.h:130

◆ buffersSent()

template<typename Object , typename Context >
unsigned long int SendBuffer< Object, Context >::buffersSent ( ) const
inline

Get the number of buffers sent from this buffer.

Definition at line 51 of file SendBuffer.h.

51{ return _buffers_sent; }

◆ cleanupRequests()

template<typename Object , typename Context >
void SendBuffer< Object, Context >::cleanupRequests ( )

Checks to see if any Requests can be finished.

Definition at line 246 of file SendBuffer.h.

247{
248 _requests.remove_if(
249 [](std::shared_ptr<Parallel::Request> & req)
250 {
251 if (req->test())
252 {
253 req->wait(); // MUST call wait() to do post_wait_work
254 return true;
255 }
256 else
257 return false;
258 });
259}
std::list< std::shared_ptr< Parallel::Request > > _requests
List of Requests.
Definition SendBuffer.h:125

◆ clear()

template<typename Object , typename Context >
void SendBuffer< Object, Context >::clear ( )

Clear all existing data.

Definition at line 235 of file SendBuffer.h.

236{
237 _buffer.clear();
238 _requests.clear();
239
240 _objects_sent = 0;
241 _buffers_sent = 0;
242}

◆ currentlyBuffered()

template<typename Object , typename Context >
bool SendBuffer< Object, Context >::currentlyBuffered ( ) const
inline

Whether or not objects are currently waiting to be sent.

Definition at line 64 of file SendBuffer.h.

64{ return _buffer.size(); }

◆ currentlySending()

template<typename Object , typename Context >
bool SendBuffer< Object, Context >::currentlySending ( ) const
inline

Whether or not messages are currently being sent.

Definition at line 60 of file SendBuffer.h.

60{ return _requests.size(); }

◆ forceSend()

template<typename Object , typename Context >
void SendBuffer< Object, Context >::forceSend ( const bool  shrink_current_buffer_size = true)

Forces a Send for all currently buffered objects.

Definition at line 199 of file SendBuffer.h.

200{
201 if (!_buffer.empty())
202 {
203 auto req = std::make_shared<Parallel::Request>();
204
205 _requests.push_back(req);
206
208 _objects_sent += _buffer.size();
210
211 std::shared_ptr<std::vector<typename Parallel::Packing<std::shared_ptr<Object>>::buffer_type>>
212 buffer = _buffer_pool.acquire();
213
215 _pid, _context, _buffer.begin(), _buffer.end(), *req, buffer, _object_buffer_tag);
216
217 _buffer.clear();
218 _buffer.reserve(_max_buffer_size);
219
220 if (_method == ParallelStudyMethod::SMART && shrink_current_buffer_size)
221 {
224
227 }
228 }
229
231}
PtrType acquire(Args &&... args)
void nonblocking_send_packed_range(const unsigned int dest_processor_id, const Context *context, Iter range_begin, const Iter range_end, Request &req, const MessageTag &tag=no_tag) const

◆ moveObject()

template<typename Object , typename Context >
void SendBuffer< Object, Context >::moveObject ( std::shared_ptr< Object > &  object)

Move an object to the buffer.

May cause the buffer to be communicated.

This DOES call std::move on the object

Definition at line 175 of file SendBuffer.h.

176{
178 Parallel::Packing<std::shared_ptr<Object>>::packable_size(object, _context) *
179 sizeof(typename Parallel::Packing<std::shared_ptr<Object>>::buffer_type);
180 _buffer.emplace_back(std::move(object));
181
182 // Force a send with SMART if we find it appropriate
184 (_buffer.size() >= _current_buffer_size || _buffer.size() == _max_buffer_size)) ||
185 (_buffer_size_bytes > 1048576)) // 1 MB
186 {
189
192
193 forceSend(false);
194 }
195}
void forceSend(const bool shrink_current_buffer_size=true)
Forces a Send for all currently buffered objects.
Definition SendBuffer.h:199

◆ objectsSent()

template<typename Object , typename Context >
unsigned long int SendBuffer< Object, Context >::objectsSent ( ) const
inline

Get the number of objects sent from this buffer.

Definition at line 47 of file SendBuffer.h.

47{ return _objects_sent; }

◆ waitAll()

template<typename Object , typename Context >
void SendBuffer< Object, Context >::waitAll ( )

Wait for all requests to finish.

Definition at line 263 of file SendBuffer.h.

264{
265 std::for_each(_requests.begin(), _requests.end(), [](auto & request) { request->wait(); });
266}

Member Data Documentation

◆ _buffer

template<typename Object , typename Context >
std::vector<std::shared_ptr<Object> > SendBuffer< Object, Context >::_buffer
private

◆ _buffer_growth_multiplier

template<typename Object , typename Context >
const Real SendBuffer< Object, Context >::_buffer_growth_multiplier
private

Multiplier for the buffer size for growing the buffer.

Definition at line 107 of file SendBuffer.h.

◆ _buffer_pool

template<typename Object , typename Context >
MooseUtils::SharedPool< std::vector<typename Parallel::Packing<std::shared_ptr<Object> >::buffer_type> > SendBuffer< Object, Context >::_buffer_pool
private

Shared pool of buffers.

Definition at line 130 of file SendBuffer.h.

Referenced by SendBuffer< Object, Context >::bufferPoolCreated().

◆ _buffer_shrink_multiplier

template<typename Object , typename Context >
const Real SendBuffer< Object, Context >::_buffer_shrink_multiplier
private

Multiplier for the buffer size for shrinking the buffer.

Definition at line 109 of file SendBuffer.h.

◆ _buffer_size_bytes

template<typename Object , typename Context >
std::size_t SendBuffer< Object, Context >::_buffer_size_bytes
private

The size of the objects in the buffer in bytes.

Definition at line 122 of file SendBuffer.h.

◆ _buffers_sent

template<typename Object , typename Context >
unsigned long int SendBuffer< Object, Context >::_buffers_sent
private

Counter for buffers sent.

Definition at line 135 of file SendBuffer.h.

Referenced by SendBuffer< Object, Context >::buffersSent().

◆ _context

template<typename Object , typename Context >
const Context* const SendBuffer< Object, Context >::_context
private

The context.

Definition at line 95 of file SendBuffer.h.

◆ _current_buffer_size

template<typename Object , typename Context >
unsigned int SendBuffer< Object, Context >::_current_buffer_size
private

Current size of the buffer (in objects)

Definition at line 115 of file SendBuffer.h.

◆ _current_buffer_size_real

template<typename Object , typename Context >
Real SendBuffer< Object, Context >::_current_buffer_size_real
private

Running buffer size.

Definition at line 117 of file SendBuffer.h.

◆ _max_buffer_size

template<typename Object , typename Context >
const unsigned int SendBuffer< Object, Context >::_max_buffer_size
private

Maximum size of the buffer (in objects)

Definition at line 104 of file SendBuffer.h.

◆ _method

template<typename Object , typename Context >
const ParallelStudyMethod& SendBuffer< Object, Context >::_method
private

Definition at line 99 of file SendBuffer.h.

◆ _min_buffer_size

template<typename Object , typename Context >
const unsigned int SendBuffer< Object, Context >::_min_buffer_size
private

Minimum size of the buffer (in objects)

Definition at line 102 of file SendBuffer.h.

◆ _object_buffer_tag

template<typename Object , typename Context >
const Parallel::MessageTag SendBuffer< Object, Context >::_object_buffer_tag
private

MessageTag for sending objects.

Definition at line 112 of file SendBuffer.h.

◆ _objects_sent

template<typename Object , typename Context >
unsigned long int SendBuffer< Object, Context >::_objects_sent
private

Counter for objects sent.

Definition at line 133 of file SendBuffer.h.

Referenced by SendBuffer< Object, Context >::objectsSent().

◆ _pid

template<typename Object , typename Context >
const processor_id_type SendBuffer< Object, Context >::_pid
private

The processor ID this buffer will send to.

Definition at line 97 of file SendBuffer.h.

◆ _requests

template<typename Object , typename Context >
std::list<std::shared_ptr<Parallel::Request> > SendBuffer< Object, Context >::_requests
private

List of Requests.

Definition at line 125 of file SendBuffer.h.

Referenced by SendBuffer< Object, Context >::currentlySending().


The documentation for this class was generated from the following file: