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

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

Parent Directory Parent Directory | Revision Log Revision Log


Revision 474 - (show annotations)
Mon Jan 30 04:23:44 2006 UTC (14 years ago) by jgs
File MIME type: text/plain
File size: 4321 byte(s)
restructure escript source tree
move src/Data/* -> src
remove inc
modify #includes and cpppath settings accordingly

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 #include <iostream>
19 #include <cassert>
20
21 #ifdef _OPENMP
22 #include <omp.h>
23 #endif
24
25 namespace escript {
26
27 /**
28 \brief
29 Taipan array manager, C++ version.
30 Based on TaipanMemManager C module by Lutz Gross.
31
32 Description:
33 Taipan: data-array manager.
34
35 The Taipan data-array manager holds a set of (dim x N) arrays distributed across a number of threads.
36 If a (dim x N) array is requested via the Taipan allocator, the buffer of managed arrays is searched for
37 a free array of this size on the current number of threads. If none is available, a new one is allocated
38 and added to the buffer of managed arrays.
39
40 When a managed array is deallocated, the array is marked as free but not returned to the system as long
41 as at least one array of N is in use. Otherwise all arrays of N are deallocated as it is assumed that
42 these arrays not be used anymore. The exceptions to this strategy are arrays with N=0 or N=1, these
43 arrays are never deallocated, but are kept for possible reuse.
44 */
45
46 class Taipan {
47
48 public:
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(int dim, int 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 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