QMCPACK
PointerPool.h
Go to the documentation of this file.
1 //////////////////////////////////////////////////////////////////////////////////////
2 // This file is distributed under the University of Illinois/NCSA Open Source License.
3 // See LICENSE file in top directory for details.
4 //
5 // Copyright (c) 2016 Jeongnim Kim and QMCPACK developers.
6 //
7 // File developed by: Ken Esler, kpesler@gmail.com, University of Illinois at Urbana-Champaign
8 // Jeremy McMinnis, jmcminis@gmail.com, University of Illinois at Urbana-Champaign
9 // Mark A. Berrill, berrillma@ornl.gov, Oak Ridge National Laboratory
10 //
11 // File created by: Ken Esler, kpesler@gmail.com, University of Illinois at Urbana-Champaign
12 //////////////////////////////////////////////////////////////////////////////////////
13 
14 
15 #ifndef POINTER_POOL_H
16 #define POINTER_POOL_H
17 
18 #include <vector>
19 
20 template<typename CONT>
22 {
23 public:
24  using buffer_type = CONT;
25  using pointer = typename CONT::pointer;
26 
27  // Local data routines
28  pointer getPointer(int index, buffer_type& buffer) { return &(buffer[offsets[index]]); }
29 
30  void allocate(buffer_type& buffer) { buffer.resize(totalSize); }
31 
32  // Shared-data routines
33 
34  // Reserves size elements and returns the offset to the member
35  // in the buffer
36  size_t reserve(size_t size)
37  {
38  if (size % 32)
39  {
40  std::cerr << "Unaligned reservation in PointerPool. size = " << size << std::endl;
41  size += 32 - (size % 32);
42  }
43  size_t off = totalSize;
44  offsets.push_back(off);
45  totalSize += size;
46  return off;
47  }
48 
49  void reset()
50  {
51  offsets.resize(0);
52  totalSize = 0;
53  }
54 
55  size_t getTotalSize() { return totalSize; }
56 
58 
59 protected:
60  size_t totalSize;
61  std::vector<size_t> offsets;
62 };
63 
64 #endif
pointer getPointer(int index, buffer_type &buffer)
Definition: PointerPool.h:28
typename CONT::pointer pointer
Definition: PointerPool.h:25
std::vector< size_t > offsets
Definition: PointerPool.h:61
void reset()
Definition: PointerPool.h:49
CONT buffer_type
Definition: PointerPool.h:24
void allocate(buffer_type &buffer)
Definition: PointerPool.h:30
size_t totalSize
Definition: PointerPool.h:60
size_t reserve(size_t size)
Definition: PointerPool.h:36
size_t getTotalSize()
Definition: PointerPool.h:55