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

Diff of /trunk/escript/src/Taipan.cpp

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

revision 122 by jgs, Thu Jun 9 05:38:05 2005 UTC revision 149 by jgs, Thu Sep 1 03:31:39 2005 UTC
# Line 28  Taipan::Taipan() : Line 28  Taipan::Taipan() :
28    memTable_Root(0),    memTable_Root(0),
29    totalElements(0)    totalElements(0)
30  {  {
31      // create and initialise a new StatTable
32      statTable = new Taipan_StatTable;
33      clear_stats();
34  }  }
35    
36  Taipan::~Taipan() {  Taipan::~Taipan() {
# Line 35  Taipan::~Taipan() { Line 38  Taipan::~Taipan() {
38    Taipan_MemTable *tab;    Taipan_MemTable *tab;
39    Taipan_MemTable *tab_next;    Taipan_MemTable *tab_next;
40    
41      // dump memory usage statistics
42      dump_stats();
43    
44      // deallocate StatTable object
45      delete statTable;
46    
47    // deallocate all managed arrays and the memTable    // deallocate all managed arrays and the memTable
48    tab = memTable_Root;    tab = memTable_Root;
49    while (tab != 0) {    while (tab != 0) {
# Line 57  Taipan::new_array(int dim, int N) { Line 66  Taipan::new_array(int dim, int N) {
66    assert(totalElements >= 0);    assert(totalElements >= 0);
67    
68    int len = 0;    int len = 0;
                                                                                                                                         
69    #ifdef _OPENMP    #ifdef _OPENMP
70    int numThreads = omp_get_num_threads();    int numThreads = omp_get_num_threads();
71    #else    #else
# Line 68  Taipan::new_array(int dim, int N) { Line 76  Taipan::new_array(int dim, int N) {
76    Taipan_MemTable *new_tab;    Taipan_MemTable *new_tab;
77    Taipan_MemTable *tab_prev;    Taipan_MemTable *tab_prev;
78    
79  //  numThreads = omp_get_max_threads();    // increment count of alloc opperations called
80      statTable->allocs++;
81    
82      // numThreads = omp_get_max_threads();
83    
84    // is a suitable array already available?    // is a suitable array already available?
85    if (memTable_Root != 0) {    if (memTable_Root != 0) {
# Line 114  Taipan::new_array(int dim, int N) { Line 125  Taipan::new_array(int dim, int N) {
125    }    }
126    totalElements += len;    totalElements += len;
127    
128      // increment count of arrays allocated
129      statTable->arrays++;
130    
131      // increment count of elements allocated
132      statTable->elements+=len;
133    
134    return new_tab->array;    return new_tab->array;
135  }  }
136    
# Line 148  Taipan::delete_array(double* array) { Line 165  Taipan::delete_array(double* array) {
165        return;        return;
166      }      }
167    
168        // increment count of dealloc opperations called
169        statTable->deallocs++;
170    
171      // are there any N block arrays still in use?      // are there any N block arrays still in use?
172      tab = memTable_Root;      tab = memTable_Root;
173      while (tab != 0) {      while (tab != 0) {
# Line 170  Taipan::delete_array(double* array) { Line 190  Taipan::delete_array(double* array) {
190            memTable_Root = tab->next;            memTable_Root = tab->next;
191          }          }
192          delete tab;          delete tab;
193            // increment count of arrays dealloced
194            statTable->dearrays++;
195        } else {        } else {
196          tab_prev = tab;          tab_prev = tab;
197        }        }
# Line 178  Taipan::delete_array(double* array) { Line 200  Taipan::delete_array(double* array) {
200    
201      totalElements -= len;      totalElements -= len;
202    
203        // increment count of elements dealloced
204        statTable->deelements+=len;
205    
206    } else {    } else {
207      // what to do if no arrays under management?      // what to do if no arrays under management?
208    }    }
# Line 252  Taipan::num_elements() { Line 277  Taipan::num_elements() {
277    return totalElements;    return totalElements;
278  }  }
279    
280    void
281    Taipan::dump_stats() {
282      float elMb=statTable->elements*8.0/1048576;
283      float deelMb=statTable->deelements*8.0/1048576;
284      cout << "========== Mem Stats ==================" << endl;
285      cout << "Total Num allocs:     " << statTable->allocs << endl;
286      cout << "Total Num deallocs:   " << statTable->deallocs << endl;
287      cout << "Total Num arrays:     " << statTable->arrays << endl;
288      cout << "Total Num dearrays:   " << statTable->dearrays << endl;
289      cout << "Total Num elements:   " << statTable->elements << " (" << elMb << " Mb)" << endl;
290      cout << "Total Num deelements: " << statTable->deelements << " (" << deelMb << " Mb)" << endl;
291      cout << "Curr  Num arrays:     " << num_arrays() << endl;
292      cout << "Curr  Num elements:   " << num_elements() << endl;
293      cout << "=======================================" << endl;
294    }
295    
296    void
297    Taipan::clear_stats() {
298      statTable->allocs=0;
299      statTable->deallocs=0;
300      statTable->arrays=0;
301      statTable->dearrays=0;
302      statTable->elements=0;
303      statTable->deelements=0;
304    }
305    
306  }  // end of namespace  }  // end of namespace

Legend:
Removed from v.122  
changed lines
  Added in v.149

  ViewVC Help
Powered by ViewVC 1.1.26