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