Dendro  5.01
Dendro in Greek language means tree. The Dendro library is a large scale (262K cores on ORNL's Titan) distributed memory adaptive octree framework. The main goal of Dendro is to perform large scale multiphysics simulations efficeiently in mordern supercomputers. Dendro consists of efficient parallel data structures and algorithms to perform variational ( finite element) methods and finite difference mthods on 2:1 balanced arbitary adaptive octrees which enables the users to perform simulations raning from black holes (binary black hole mergers) to blood flow in human body, where applications ranging from relativity, astrophysics to biomedical engineering.
memory_pool.h
1 /*
2  * Copyright (c) 2017 Hari Sundar <hari@cs.utah.edu>
3  *
4  * Permission is hereby granted, free of charge, to any person
5  * obtaining a copy of this software and associated documentation
6  * files (the "Software"), to deal in the Software without
7  * restriction, including without limitation the rights to use,
8  * copy, modify, merge, publish, distribute, sublicense, and/or sell
9  * copies of the Software, and to permit persons to whom the
10  * Software is furnished to do so, subject to the following
11  * conditions:
12  *
13  * The above copyright notice and this permission notice shall be
14  * included in all copies or substantial portions of the Software.
15  *
16  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17  * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
18  * OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
19  * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
20  * HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
21  * WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
22  * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
23  * OTHER DEALINGS IN THE SOFTWARE.
24  *
25  */
26 
27 #ifndef MEMORY_POOL_H
28 #define MEMORY_POOL_H
29 
30 
31 #include <vector>
32 
33 struct mem_blk {
34 public:
35  unsigned int size;
36  bool free;
37  double* data;
38 
39  mem_blk(unsigned int sz) {
40  size = sz;
41  free = true;
42  data = NULL;
43  }
44 
45  ~mem_blk() {
46  if (data != NULL) {
47  delete [] data;
48  data = NULL;
49  }
50  }
51 };
52 
54 {
55 private:
56  unsigned long m_ulCount;
57 
58  unsigned int m_uiAlignment;
59  unsigned int m_uiPadding;
60 
61  // for the entries ...
62  // need, address, size, is_available.
63  std::vector<mem_blk> m_vecBlocks;
64 
65 
66 public:
67  memory_pool(unsigned int pad = 3, unsigned int align = 32);
68 
69  ~memory_pool();
70 
71  // basic ops. block based only. of size (sz +2*pad)^3
72  double* allocate(unsigned int sz);
73  void free(double* buf);
74 
75  // how much memory is currently used by the pool
76  unsigned long used();
77 
78  // delete all allocated blocks.
79  void purge();
80 };
81 
82 #endif // MEMORY_POOL_H
Definition: memory_pool.h:53
Definition: memory_pool.h:33