/[escript]/branches/arrexp_2137_win_merge/escript/src/Taipan.h
ViewVC logotype

Contents of /branches/arrexp_2137_win_merge/escript/src/Taipan.h

Parent Directory Parent Directory | Revision Log Revision Log


Revision 2213 - (show annotations)
Wed Jan 14 00:23:39 2009 UTC (10 years, 6 months ago) by jfenwick
File MIME type: text/plain
File size: 4037 byte(s)
In preparation for merging to trunk

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

Properties

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

  ViewVC Help
Powered by ViewVC 1.1.26