/[escript]/trunk/escript/src/Taipan.h
ViewVC logotype

Contents of /trunk/escript/src/Taipan.h

Parent Directory Parent Directory | Revision Log Revision Log


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

Properties

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

  ViewVC Help
Powered by ViewVC 1.1.26