https://mooseframework.inl.gov
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. More...
 
unsigned long int objectsSent () const
 Get the number of objects sent from this buffer. More...
 
unsigned long int buffersSent () const
 Get the number of buffers sent from this buffer. More...
 
unsigned long int bufferPoolCreated () const
 Get the number of buffers created in the buffer pool. More...
 
bool currentlySending () const
 Whether or not messages are currently being sent. More...
 
bool currentlyBuffered () const
 Whether or not objects are currently waiting to be sent. More...
 
void moveObject (std::shared_ptr< Object > &object)
 Move an object to the buffer. More...
 
void forceSend (const bool shrink_current_buffer_size=true)
 Forces a Send for all currently buffered objects. More...
 
void waitAll ()
 Wait for all requests to finish. More...
 
void clear ()
 Clear all existing data. More...
 
void cleanupRequests ()
 Checks to see if any Requests can be finished. More...
 
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. More...
 
const processor_id_type _pid
 The processor ID this buffer will send to. More...
 
const ParallelStudyMethod_method
 
const unsigned int _min_buffer_size
 Minimum size of the buffer (in objects) More...
 
const unsigned int _max_buffer_size
 Maximum size of the buffer (in objects) More...
 
const Real _buffer_growth_multiplier
 Multiplier for the buffer size for growing the buffer. More...
 
const Real _buffer_shrink_multiplier
 Multiplier for the buffer size for shrinking the buffer. More...
 
const Parallel::MessageTag _object_buffer_tag
 MessageTag for sending objects. More...
 
unsigned int _current_buffer_size
 Current size of the buffer (in objects) More...
 
Real _current_buffer_size_real
 Running buffer size. More...
 
std::vector< std::shared_ptr< Object > > _buffer
 The buffer. More...
 
std::size_t _buffer_size_bytes
 The size of the objects in the buffer in bytes. More...
 
std::list< std::shared_ptr< Parallel::Request > > _requests
 List of Requests. More...
 
MooseUtils::SharedPool< std::vector< typename Parallel::Packing< std::shared_ptr< Object > >::buffer_type > > _buffer_pool
 Shared pool of buffers. More...
 
unsigned long int _objects_sent
 Counter for objects sent. More...
 
unsigned long int _buffers_sent
 Counter for buffers sent. More...
 

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.

148  : ParallelObject(comm),
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),
161  _buffers_sent(0)
162 {
163  _buffer.reserve(max_buffer_size);
164 }
ParallelObject(const Parallel::Communicator &comm_in)
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
unsigned int _current_buffer_size
Current size of the buffer (in objects)
Definition: SendBuffer.h:115
const unsigned int _max_buffer_size
Maximum size of the buffer (in objects)
Definition: SendBuffer.h:104
const Parallel::Communicator & comm() const
const Real _buffer_shrink_multiplier
Multiplier for the buffer size for shrinking the buffer.
Definition: SendBuffer.h:109
Real _current_buffer_size_real
Running buffer size.
Definition: SendBuffer.h:117
const Real _buffer_growth_multiplier
Multiplier for the buffer size for growing the buffer.
Definition: SendBuffer.h:107
const unsigned int _min_buffer_size
Minimum size of the buffer (in objects)
Definition: SendBuffer.h:102
const ParallelStudyMethod & _method
Definition: SendBuffer.h:99
std::size_t _buffer_size_bytes
The size of the objects in the buffer in bytes.
Definition: SendBuffer.h:122
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
unsigned long int _buffers_sent
Counter for buffers sent.
Definition: SendBuffer.h:135

◆ ~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();
170  cleanupRequests();
171 }
void waitAll()
Wait for all requests to finish.
Definition: SendBuffer.h:263
void cleanupRequests()
Checks to see if any Requests can be finished.
Definition: SendBuffer.h:246

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; }
unsigned long int _buffers_sent
Counter for buffers sent.
Definition: SendBuffer.h:135

◆ 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 }
unsigned long int _objects_sent
Counter for objects sent.
Definition: SendBuffer.h:133
std::list< std::shared_ptr< Parallel::Request > > _requests
List of Requests.
Definition: SendBuffer.h:125
std::vector< std::shared_ptr< Object > > _buffer
The buffer.
Definition: SendBuffer.h:120
unsigned long int _buffers_sent
Counter for buffers sent.
Definition: SendBuffer.h:135

◆ 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(); }
std::vector< std::shared_ptr< Object > > _buffer
The buffer.
Definition: SendBuffer.h:120

◆ 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(); }
std::list< std::shared_ptr< Parallel::Request > > _requests
List of Requests.
Definition: SendBuffer.h:125

◆ 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 
207  _buffer_size_bytes = 0;
208  _objects_sent += _buffer.size();
209  _buffers_sent++;
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 
225  if (_current_buffer_size != (unsigned int)_current_buffer_size_real)
227  }
228  }
229 
230  cleanupRequests();
231 }
const Parallel::MessageTag _object_buffer_tag
MessageTag for sending objects.
Definition: SendBuffer.h:112
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
unsigned long int _objects_sent
Counter for objects sent.
Definition: SendBuffer.h:133
const Context *const _context
The context.
Definition: SendBuffer.h:95
unsigned int _current_buffer_size
Current size of the buffer (in objects)
Definition: SendBuffer.h:115
const unsigned int _max_buffer_size
Maximum size of the buffer (in objects)
Definition: SendBuffer.h:104
const Parallel::Communicator & comm() const
const Real _buffer_shrink_multiplier
Multiplier for the buffer size for shrinking the buffer.
Definition: SendBuffer.h:109
std::list< std::shared_ptr< Parallel::Request > > _requests
List of Requests.
Definition: SendBuffer.h:125
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
const ParallelStudyMethod & _method
Definition: SendBuffer.h:99
std::size_t _buffer_size_bytes
The size of the objects in the buffer in bytes.
Definition: SendBuffer.h:122
std::vector< std::shared_ptr< Object > > _buffer
The buffer.
Definition: SendBuffer.h:120
void cleanupRequests()
Checks to see if any Requests can be finished.
Definition: SendBuffer.h:246
const processor_id_type _pid
The processor ID this buffer will send to.
Definition: SendBuffer.h:97
unsigned long int _buffers_sent
Counter for buffers sent.
Definition: SendBuffer.h:135
MooseUtils::SharedPool< std::vector< typename Parallel::Packing< std::shared_ptr< Object > >::buffer_type > > _buffer_pool
Shared pool of buffers.
Definition: SendBuffer.h:130
PtrType acquire(Args &&... args)

◆ 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 
190  if (_current_buffer_size != (unsigned int)_current_buffer_size_real)
192 
193  forceSend(false);
194  }
195 }
const Context *const _context
The context.
Definition: SendBuffer.h:95
unsigned int _current_buffer_size
Current size of the buffer (in objects)
Definition: SendBuffer.h:115
const unsigned int _max_buffer_size
Maximum size of the buffer (in objects)
Definition: SendBuffer.h:104
Real _current_buffer_size_real
Running buffer size.
Definition: SendBuffer.h:117
void forceSend(const bool shrink_current_buffer_size=true)
Forces a Send for all currently buffered objects.
Definition: SendBuffer.h:199
const Real _buffer_growth_multiplier
Multiplier for the buffer size for growing the buffer.
Definition: SendBuffer.h:107
const ParallelStudyMethod & _method
Definition: SendBuffer.h:99
std::size_t _buffer_size_bytes
The size of the objects in the buffer in bytes.
Definition: SendBuffer.h:122
std::vector< std::shared_ptr< Object > > _buffer
The buffer.
Definition: SendBuffer.h:120

◆ 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; }
unsigned long int _objects_sent
Counter for objects sent.
Definition: SendBuffer.h:133

◆ 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 }
MPI_Request request
std::list< std::shared_ptr< Parallel::Request > > _requests
List of Requests.
Definition: SendBuffer.h:125

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: