Line data Source code
1 : //
2 : // Buffers.cpp
3 : // Interface for globally accessible buffer factory for communication
4 : //
5 : // Data sent between MPI ranks has to be stored in a buffer for sending and receiving.
6 : // To reduce the number of times memory has to be allocated and freed, the buffer
7 : // factory interface allows buffers to be reused. This is especially relevant on
8 : // GPUs, as Cuda allocation calls are expensive. To avoid reallocating the buffers
9 : // in the case that the amount of data to be exchanged increases, when a new buffer
10 : // is created, an amount of memory greater than the requested size is allocated
11 : // for the new buffer. The factor by which memory is overallocated is determined by
12 : // a data member in Communicator, which can be set and queried at runtime. Only new
13 : // buffers are overallocated. If a buffer is requested with the same ID as a buffer
14 : // that has been previously allocated, the same buffer will be used. If the requested
15 : // size exceeds the buffer size, that buffer will be resized to have exactly
16 : // the requested size.
17 : //
18 : // Currently, the buffer factory is used for application of periodic boundary
19 : // conditions; halo cell exchange along faces, edges, and vertices; as well as
20 : // exchanging particle data between ranks.
21 : //
22 :
23 : #include "Ippl.h"
24 :
25 : #include "Communicator.h"
26 :
27 : namespace ippl {
28 : namespace mpi {
29 :
30 0 : void Communicator::setDefaultOverallocation(double factor) {
31 0 : defaultOveralloc_m = factor;
32 0 : }
33 :
34 44 : void Communicator::deleteAllBuffers() {
35 44 : buffer_handlers_m.forAll([]<typename BufferHandler>(BufferHandler&& bh) {
36 44 : bh.deleteAllBuffers();
37 44 : });
38 44 : }
39 :
40 632 : void Communicator::freeAllBuffers() {
41 632 : buffer_handlers_m.forAll([]<typename BufferHandler>(BufferHandler&& bh) {
42 632 : bh.freeAllBuffers();
43 632 : });
44 632 : }
45 :
46 : } // namespace mpi
47 : } // namespace ippl
|