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

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

documentation cmv 12/4/00

File size: 9.1 KB
RevLine 
[787]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
[894]15//! Maximum number of dimensions for an array
16/*! \anchor BASEARRAY_MAXNDIMS */
[787]17#define BASEARRAY_MAXNDIMS 5
18
19namespace SOPHYA {
20
21// ------------ classe template Array -----------
[890]22//! Base class for template arrays
23/*!
[894]24 No data are connected to this class.
25
26 Define base methods, enum and defaults for TArray , TMatrix and TVector.
[890]27*/
[787]28class BaseArray : public AnyDataObj {
29public:
[890]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 };
[804]44
[890]45 // threshold for parallel routine call
[813]46 static void SetOpenMPSizeThreshold(uint_8 thr=200000);
[890]47 //! Get Size threshold for parallel routine call
[813]48 static inline uint_8 GetOpenMPSizeThreshold() { return openmp_size_threshold; }
[890]49
[813]50 static void SetMaxPrint(uint_4 nprt=50, uint_4 lev=0);
[890]51 //! Get maximum number of printed elements
[813]52 static inline uint_4 GetMaxPrint() { return max_nprt_; }
[890]53 //! Maximum number of printed elements arint level
[813]54 static inline uint_4 GetPrintLevel() { return prt_lev_; }
55
[804]56 static short SetDefaultMemoryMapping(short mm=CMemoryMapping);
[890]57 //! Get Default Memory Mapping
[804]58 static inline short GetDefaultMemoryMapping() { return default_memory_mapping; }
[813]59 static short SetDefaultVectorType(short vt=ColumnVector);
[890]60 //! Get Default Vector Type
[813]61 static inline short GetDefaultVectorType() { return default_vector_type; }
[804]62
[890]63 // Creator / destructor
[787]64 BaseArray();
65 virtual ~BaseArray();
66
67 // Returns true if ndim and sizes are equal
68 virtual bool CompareSizes(const BaseArray& a);
69
[890]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
[787]73
74 // Array dimensions
[890]75 //! Return number of dimensions
[787]76 inline uint_4 NbDimensions() const { return( ndim_ ); }
77
[890]78 //! Return total size of the array
[787]79 inline uint_8 Size() const { return(totsize_); }
[890]80 //! Return size along the first dimension
[787]81 inline uint_4 SizeX() const { return(size_[0]); }
[890]82 //! Return size along the second dimension
[787]83 inline uint_4 SizeY() const { return(size_[1]); }
[890]84 //! Return size along the third dimension
[787]85 inline uint_4 SizeZ() const { return(size_[2]); }
[890]86 //! Return size along the \b ka th dimension
[787]87 inline uint_4 Size(int ka) const { return(size_[CheckDI(ka,1)]); }
88
89 uint_4 MaxSizeKA() const ;
90
[890]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_; }
[813]100 void SetMemoryMapping(short mm=AutoMemoryMapping);
[804]101
[890]102 //! Get Vector type ( \b Line or \b Column vector )
[813]103 inline short GetVectorType() const
104 { return((marowi_ == veceli_) ? ColumnVector : RowVector); }
[890]105 void SetVectorType(short vt=AutoVectorType);
[813]106
[890]107 // memory organisation - packing information
108 //! return true if array is packed in memory
[787]109 inline bool IsPacked() const { return(moystep_ == 1); }
[890]110 //! return true if array is packed along the first dimension
[787]111 inline bool IsPackedX() const { return(step_[0] == 1); }
[890]112 //! return true if array is packed along the second dimension
[787]113 inline bool IsPackedY() const { return(step_[1] == 1); }
[890]114 //! return true if array is packed along the third dimension
[787]115 inline bool IsPackedZ() const { return(step_[2] == 1); }
[890]116 //! return true if array is packed along the \b ka th dimension
[787]117 inline bool IsPacked(int ka) const { return(step_[CheckDI(ka,2)] == 1); }
118
[890]119 //! return the minimum step value along all the dimensions
[787]120 inline uint_4 MinStep() const { return(minstep_); }
[890]121 //! return the average step value along all the dimensions
[787]122 inline uint_4 AvgStep() const { return(moystep_); }
[890]123 //! return the step along the first dimension
[787]124 inline uint_4 StepX() const { return(step_[0]); }
[890]125 //! return the step along the second dimension
[787]126 inline uint_4 StepY() const { return(step_[1]); }
[890]127 //! return the step along the third dimension
[787]128 inline uint_4 StepZ() const { return(step_[2]); }
[890]129 //! return the step along the \b ka th dimension
[787]130 inline uint_4 Step(int ka) const { return(step_[CheckDI(ka,3)]); }
131
132 uint_4 MinStepKA() const ;
133
[813]134 // Offset of element ip
[787]135 uint_8 Offset(uint_8 ip=0) const ;
[813]136 // Offset of the i'th vector along axe ka
137 uint_8 Offset(uint_4 ka, uint_8 i) const ;
[787]138 inline uint_8 Offset(uint_4 ix, uint_4 iy, uint_4 iz, uint_4 it=0, uint_4 iu=0) const;
139
[890]140 // an abstract element acces methode
[787]141 virtual double ValueAtPosition(uint_8 ip) const = 0;
142
[890]143 // Impression, I/O, ...
[804]144 void Show(ostream& os, bool si=false) const;
[890]145 //! Show information on \b cout
[804]146 inline void Show() const { Show(cout); }
[813]147 virtual string InfoString() const;
[787]148
[894]149 // DVList info Object
150 DVList& Info();
[787]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);
[804]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);
[813]162 static short SelectVectorType(short vt);
163 void UpdateMemoryMapping(short mm);
[804]164 void UpdateMemoryMapping(BaseArray const & a, short mm);
[787]165
[804]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
[894]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
[890]172 //! two consecutive elements distance in a given dimension
173 uint_4 step_[BASEARRAY_MAXNDIMS];
[894]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
[787]182
[894]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
[787]189};
190
191// --------------------------------------------------
192// Methodes inline de verification
193// --------------------------------------------------
[890]194//! to verify the compatibility of the dimension index
[787]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];
[813]199 throw(RangeCheckError(txt));
[787]200 }
201 return(ka);
202}
203
[890]204//! to verify the compatibility of the indexes in all dimensions
[787]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];
[813]210 throw(RangeCheckError(txt));
[787]211 }
212 return;
213}
214
215
[813]216
[787]217// --------------------------------------------------
218// Position d'un element
219// --------------------------------------------------
[890]220//! Offset of element (ix,iy,iz,it,iu)
[787]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.