/[escript]/branches/subworld2/escriptcore/src/Taipan.h
ViewVC logotype

Contents of /branches/subworld2/escriptcore/src/Taipan.h

Parent Directory Parent Directory | Revision Log Revision Log


Revision 5504 - (show annotations)
Wed Mar 4 22:58:13 2015 UTC (4 years, 1 month ago) by jfenwick
File MIME type: text/plain
File size: 4411 byte(s)
Again with a more up to date copy


1
2 /*****************************************************************************
3 *
4 * Copyright (c) 2003-2015 by University of Queensland
5 * http://www.uq.edu.au
6 *
7 * Primary Business: Queensland, Australia
8 * Licensed under the Open Software License version 3.0
9 * http://www.opensource.org/licenses/osl-3.0.php
10 *
11 * Development until 2012 by Earth Systems Science Computational Center (ESSCC)
12 * Development 2012-2013 by School of Earth Sciences
13 * Development from 2014 by Centre for Geoscience Computing (GeoComp)
14 *
15 *****************************************************************************/
16
17
18 #if !defined escript_Taipan_20050427_H
19 #define escript_Taipan_20050427_H
20 #include "system_dep.h"
21
22 namespace escript {
23
24 /**
25 \brief
26 Taipan array manager, C++ version.
27 Based on TaipanMemManager C module by Lutz Gross.
28
29 Description:
30 Taipan: data-array manager.
31
32 The Taipan data-array manager holds a set of (dim x N) arrays distributed across a number of threads.
33 If a (dim x N) array is requested via the Taipan allocator, the buffer of managed arrays is searched for
34 a free array of this size on the current number of threads. If none is available, a new one is allocated
35 and added to the buffer of managed arrays.
36
37 When a managed array is deallocated, the array is marked as free but not returned to the system as long
38 as at least one array of N is in use. Otherwise all arrays of N are deallocated as it is assumed that
39 these arrays not be used anymore. The exceptions to this strategy are arrays with N=0 or N=1, these
40 arrays are never deallocated, but are kept for possible reuse.
41 */
42
43 class ESCRIPT_DLL_API Taipan {
44
45 public:
46
47 typedef long size_type; // needs to be parallelised by openmp. It should not take negative values.
48 // do not assume that it is unsigned though
49
50 /**
51 \brief
52 Default constructor for Taipan data-array manager.
53
54 Description:
55 Default constructor for Taipan data-array manager.
56
57 Preconditions:
58 Describe any preconditions
59
60 Throws:
61 Describe any exceptions thrown
62 */
63 Taipan();
64
65 /**
66 \brief
67 Default destructor for Taipan data-array manager.
68
69 Description:
70 Default destructor for Taipan data-array manager.
71
72 Preconditions:
73 Describe any preconditions
74
75 Throws:
76 Describe any exceptions thrown
77 */
78 ~Taipan();
79
80 /**
81 \brief
82 Taipan data-array allocator.
83
84 The parameter "dim" defines the contiguous "blocksize" within the array.
85 Where the array is allocated accross multiple threads, it will be split
86 on block boundaries only. N defines the number of "blocks" in the array.
87 */
88 double*
89 new_array(size_type dim, size_type N);
90
91 /**
92 \brief
93 Taipan data-array deallocator.
94
95 The parameter "array" should be an array object that was returned by Taipan::new_array.
96 */
97 void
98 delete_array(double* array);
99
100 /**
101 \brief
102 frees all arrays that are currently unused.
103
104 */
105 void
106 release_unused_arrays();
107
108 /**
109 \brief
110 Calculate the total number of arrays currently under management.
111 */
112 int
113 num_arrays();
114
115 /**
116 \brief
117 Calculate the total number of arrays of N blocks currently under management.
118 */
119 int
120 num_arrays(size_type N);
121
122 /**
123 \brief
124 Calculate the total number of free arrays of N blocks currently under management.
125 */
126 int
127 num_free(size_type N);
128
129 /**
130 \brief
131 Return the total number of array elements currently under management.
132 */
133 long
134 num_elements();
135
136 /**
137 \brief
138 Print out statistics on the memory under management.
139 */
140 void
141 dump_stats();
142
143 /**
144 \brief
145 Clear record of statistics on the memory under management.
146 */
147 void
148 clear_stats();
149
150 protected:
151
152 private:
153 /**
154 Declared (private) as a precaution to ensure that noone tries to copy instances.
155 */
156 void operator=(const Taipan& c){}
157
158 typedef struct Taipan_StatTable {
159 int requests;
160 int frees;
161 int allocations;
162 int deallocations;
163 long allocated_elements;
164 long deallocated_elements;
165 long max_tab_size;
166 } Taipan_StatTable;
167
168 Taipan_StatTable* statTable;
169
170 typedef struct Taipan_MemTable {
171 double* array;
172 size_type dim;
173 size_type N;
174 int numThreads;
175 bool free;
176 struct Taipan_MemTable* next;
177 } Taipan_MemTable;
178
179 Taipan_MemTable* memTable_Root;
180
181 long totalElements;
182
183 };
184
185 } // end of namespace
186
187 #endif

Properties

Name Value
svn:eol-style native
svn:keywords Author Date Id Revision

  ViewVC Help
Powered by ViewVC 1.1.26