source: Sophya/trunk/SophyaLib/TArray/basarr.h@ 894

Last change on this file since 894 was 894, checked in by ansari, 25 years ago

documentation cmv 12/4/00

File size: 9.1 KB
Line 
1// This may look like C code, but it is really -*- C++ -*-
2// Base array class - Memory organisation management
3// R. Ansari, C.Magneville 03/2000
4
5#ifndef BaseArray_SEEN
6#define BaseArray_SEEN
7
8#include "machdefs.h"
9#include <math.h>
10#include <iostream.h>
11#include "anydataobj.h"
12#include "dvlist.h"
13
14
15//! Maximum number of dimensions for an array
16/*! \anchor BASEARRAY_MAXNDIMS */
17#define BASEARRAY_MAXNDIMS 5
18
19namespace SOPHYA {
20
21// ------------ classe template Array -----------
22//! Base class for template arrays
23/*!
24 No data are connected to this class.
25
26 Define base methods, enum and defaults for TArray , TMatrix and TVector.
27*/
28class BaseArray : public AnyDataObj {
29public:
30 //! To define Array or Matrix memory mapping
31 enum MemoryMapping {
32 AutoMemoryMapping = -1, //!< define Auto Memory Mapping
33 SameMemoryMapping = 0, //!< define Same Memory Mapping
34 CMemoryMapping = 1, //!< define C Memory Mapping
35 FortranMemoryMapping = 2 //!< define Fortran Memory Mapping
36 };
37 //! To define Vector type
38 enum VectorType {
39 AutoVectorType = -1, //!< define Auto Vector Type
40 SameVectorType = 0, //!< define Same Vector Type
41 ColumnVector = 1, //!< define Column Vector Type
42 RowVector = 2 //!< define Row Vector Type
43 };
44
45 // threshold for parallel routine call
46 static void SetOpenMPSizeThreshold(uint_8 thr=200000);
47 //! Get Size threshold for parallel routine call
48 static inline uint_8 GetOpenMPSizeThreshold() { return openmp_size_threshold; }
49
50 static void SetMaxPrint(uint_4 nprt=50, uint_4 lev=0);
51 //! Get maximum number of printed elements
52 static inline uint_4 GetMaxPrint() { return max_nprt_; }
53 //! Maximum number of printed elements arint level
54 static inline uint_4 GetPrintLevel() { return prt_lev_; }
55
56 static short SetDefaultMemoryMapping(short mm=CMemoryMapping);
57 //! Get Default Memory Mapping
58 static inline short GetDefaultMemoryMapping() { return default_memory_mapping; }
59 static short SetDefaultVectorType(short vt=ColumnVector);
60 //! Get Default Vector Type
61 static inline short GetDefaultVectorType() { return default_vector_type; }
62
63 // Creator / destructor
64 BaseArray();
65 virtual ~BaseArray();
66
67 // Returns true if ndim and sizes are equal
68 virtual bool CompareSizes(const BaseArray& a);
69
70 // Compacts \b size=1 array dimensions
71 virtual void CompactAllDim(); // suppresses all size==1 dimensions
72 virtual void CompactTrailingDim(); // suppresses size==1 dimensions after the last size>1 dimension
73
74 // Array dimensions
75 //! Return number of dimensions
76 inline uint_4 NbDimensions() const { return( ndim_ ); }
77
78 //! Return total size of the array
79 inline uint_8 Size() const { return(totsize_); }
80 //! Return size along the first dimension
81 inline uint_4 SizeX() const { return(size_[0]); }
82 //! Return size along the second dimension
83 inline uint_4 SizeY() const { return(size_[1]); }
84 //! Return size along the third dimension
85 inline uint_4 SizeZ() const { return(size_[2]); }
86 //! Return size along the \b ka th dimension
87 inline uint_4 Size(int ka) const { return(size_[CheckDI(ka,1)]); }
88
89 uint_4 MaxSizeKA() const ;
90
91 //! Get memory organization
92 inline short GetMemoryMapping() const
93 { return ( (marowi_ == 1) ? CMemoryMapping : FortranMemoryMapping) ; }
94 //! line index dimension
95 inline uint_4 RowsKA() const {return marowi_; }
96 //! line column dimension
97 inline uint_4 ColsKA() const {return macoli_; }
98 //! Index dimension of the elements of a vector
99 inline uint_4 VectKA() const {return veceli_; }
100 void SetMemoryMapping(short mm=AutoMemoryMapping);
101
102 //! Get Vector type ( \b Line or \b Column vector )
103 inline short GetVectorType() const
104 { return((marowi_ == veceli_) ? ColumnVector : RowVector); }
105 void SetVectorType(short vt=AutoVectorType);
106
107 // memory organisation - packing information
108 //! return true if array is packed in memory
109 inline bool IsPacked() const { return(moystep_ == 1); }
110 //! return true if array is packed along the first dimension
111 inline bool IsPackedX() const { return(step_[0] == 1); }
112 //! return true if array is packed along the second dimension
113 inline bool IsPackedY() const { return(step_[1] == 1); }
114 //! return true if array is packed along the third dimension
115 inline bool IsPackedZ() const { return(step_[2] == 1); }
116 //! return true if array is packed along the \b ka th dimension
117 inline bool IsPacked(int ka) const { return(step_[CheckDI(ka,2)] == 1); }
118
119 //! return the minimum step value along all the dimensions
120 inline uint_4 MinStep() const { return(minstep_); }
121 //! return the average step value along all the dimensions
122 inline uint_4 AvgStep() const { return(moystep_); }
123 //! return the step along the first dimension
124 inline uint_4 StepX() const { return(step_[0]); }
125 //! return the step along the second dimension
126 inline uint_4 StepY() const { return(step_[1]); }
127 //! return the step along the third dimension
128 inline uint_4 StepZ() const { return(step_[2]); }
129 //! return the step along the \b ka th dimension
130 inline uint_4 Step(int ka) const { return(step_[CheckDI(ka,3)]); }
131
132 uint_4 MinStepKA() const ;
133
134 // Offset of element ip
135 uint_8 Offset(uint_8 ip=0) const ;
136 // Offset of the i'th vector along axe ka
137 uint_8 Offset(uint_4 ka, uint_8 i) const ;
138 inline uint_8 Offset(uint_4 ix, uint_4 iy, uint_4 iz, uint_4 it=0, uint_4 iu=0) const;
139
140 // an abstract element acces methode
141 virtual double ValueAtPosition(uint_8 ip) const = 0;
142
143 // Impression, I/O, ...
144 void Show(ostream& os, bool si=false) const;
145 //! Show information on \b cout
146 inline void Show() const { Show(cout); }
147 virtual string InfoString() const;
148
149 // DVList info Object
150 DVList& Info();
151
152protected:
153 inline int CheckDI(int ka, int msg) const ;
154 inline void CheckBound(int ix, uint_4 iy, uint_4 iz, uint_4 it, uint_4 iu, int msg) const ;
155 // Changing Sizes/NDim ... return true if OK
156 bool UpdateSizes(uint_4 ndim, const uint_4 * siz, uint_4 step, uint_8 offset, string & exmsg);
157 bool UpdateSizes(uint_4 ndim, const uint_4 * siz, const uint_4 * step, uint_8 offset, string & exmsg);
158 bool UpdateSizes(const BaseArray& a, string & exmsg);
159 static uint_8 ComputeTotalSize(uint_4 ndim, const uint_4 * siz, uint_4 step, uint_8 offset) ;
160 // Organisation memoire
161 static short SelectMemoryMapping(short mm);
162 static short SelectVectorType(short vt);
163 void UpdateMemoryMapping(short mm);
164 void UpdateMemoryMapping(BaseArray const & a, short mm);
165
166 // Pour Extraction de sous-tableau
167 virtual void UpdateSubArraySizes(BaseArray & ra, uint_4 ndim, uint_4 * siz, uint_4 * pos, uint_4 * step) const;
168
169 uint_4 ndim_; //!< number of dimensions of array
170 uint_4 size_[BASEARRAY_MAXNDIMS]; //!< array of the size in each dimension
171 uint_8 totsize_; //!< Total number of elements
172 //! two consecutive elements distance in a given dimension
173 uint_4 step_[BASEARRAY_MAXNDIMS];
174 uint_4 minstep_; //!< minimal step (in any axes)
175 uint_4 moystep_; //!< mean step, if == 0 --\> non regular steps
176 uint_8 offset_; //!< global offset -\> position of elem[0] in DataBlock
177 uint_4 marowi_; //!< For matrices, Row index in dimensions
178 uint_4 macoli_; //!< For matrices, Column index in dimensions
179 uint_4 veceli_; //!< For vectors, dimension index = marowi_/macoli_ (Row/Col vectors)
180 bool ck_memo_vt_; //!< if true, check MemoryOrg./VectorType for CompareSize
181 DVList* mInfo; //!< Infos (variables) attached to the array
182
183 static char * ck_op_msg_[6]; //!< Operation messages for CheckDI() CheckBound()
184 static uint_4 max_nprt_; //!< maximum number of printed elements
185 static uint_4 prt_lev_; //!< Print level
186 static short default_memory_mapping; //!< Default memory mapping
187 static short default_vector_type; //!< Default vector type Row/Column
188 static uint_8 openmp_size_threshold; //!< Size limit for parallel routine calls
189};
190
191// --------------------------------------------------
192// Methodes inline de verification
193// --------------------------------------------------
194//! to verify the compatibility of the dimension index
195inline int BaseArray::CheckDI(int ka, int msg) const
196{
197 if ( (ka < 0) || (ka >= ndim_) ) {
198 string txt = "BaseArray::CheckDimensionIndex/Error "; txt += ck_op_msg_[msg];
199 throw(RangeCheckError(txt));
200 }
201 return(ka);
202}
203
204//! to verify the compatibility of the indexes in all dimensions
205inline void BaseArray::CheckBound(int ix, uint_4 iy, uint_4 iz, uint_4 it, uint_4 iu, int msg) const
206{
207 if ( (ix >= size_[0]) || (iy >= size_[1]) || (iz > size_[2]) ||
208 (it >= size_[3]) || (iu >= size_[4]) ) {
209 string txt = "BaseArray::CheckArrayBound/Error "; txt += ck_op_msg_[msg];
210 throw(RangeCheckError(txt));
211 }
212 return;
213}
214
215
216
217// --------------------------------------------------
218// Position d'un element
219// --------------------------------------------------
220//! Offset of element (ix,iy,iz,it,iu)
221inline uint_8 BaseArray::Offset(uint_4 ix, uint_4 iy, uint_4 iz, uint_4 it, uint_4 iu) const
222{
223#ifdef SO_BOUNDCHECKING
224 CheckBound(ix, iy, iz, it, iu, 4);
225#endif
226 return ( offset_+ ix*step_[0] + iy*step_[1] + iz*step_[2] +
227 it*step_[3] + iu*step_[4] );
228}
229
230
231} // Fin du namespace
232
233#endif
Note: See TracBrowser for help on using the repository browser.