VAPOR3 3.9.4
WaveCodecIO.h
Go to the documentation of this file.
1//
2// $Id$
3//
4#ifndef _WaveCodeIO_h_
5#define _WaveCodeIO_h_
6
7#include <vapor/VDFIOBase.h>
9#include <vapor/Compressor.h>
10#include <vapor/EasyThreads.h>
11#include <vapor/NCBuf.h>
12
13#ifdef PARALLEL
14 #include <mpi.h>
15#endif
16
17namespace VAPoR {
18
19//
37//
38class VDF_API WaveCodecIO : public VDFIOBase, protected Wasp::EasyThreads {
39public:
46 //
47 WaveCodecIO(const MetadataVDC &metadata, int nthreads = 0);
48
55 //
56 WaveCodecIO(const string &metafile, int nthreads = 0);
57
58#ifdef VAPOR3_0_0_ALPHA
59 WaveCodecIO(const size_t dim[3], const size_t bs[3], int numTransforms, const vector<size_t> cratios, const string &wname, const string &filebase);
60
61 WaveCodecIO(const vector<string> &files);
62#endif
63
64 virtual ~WaveCodecIO();
65
100 virtual int OpenVariableRead(size_t timestep, const char *varname, int reflevel = 0, int lod = 0);
101
123 virtual int OpenVariableWrite(size_t timestep, const char *varname, int reflevel = -1 /*ignored*/, int lod = -1);
124
128 //
129 virtual int CloseVariable();
130
152 //
153 virtual int BlockReadRegion(const size_t bmin[3], const size_t bmax[3], float *region, bool unblock = true);
154
177 //
178 virtual int ReadRegion(const size_t min[3], const size_t max[3], float *region);
179
180 virtual int ReadRegion(float *region);
181
203 //
204 virtual int ReadSlice(float *slice);
205
229 //
230 virtual int BlockWriteRegion(const float *region, const size_t bmin[3], const size_t bmax[3], bool block = true);
231
258 virtual int WriteRegion(const float *region, const size_t min[3], const size_t max[3]);
259
260 virtual int WriteRegion(const float *region);
261
278 virtual int WriteSlice(const float *slice);
279
292 virtual void SetBoundaryPadOnOff(bool pad) { _pad = pad; };
293
307 //
308 const float *GetDataRange() const { return (_dataRange); }
309
326 void GetValidRegion(size_t min[3], size_t max[3], int reflevel) const;
327
341 //
342 virtual int VariableExists(size_t ts, const char *varname, int reflevel = 0, int lod = 0) const;
343
361 static size_t GetMaxCRatio(const size_t bs[3], string wavename, string wmode);
362
364 //
365 virtual int GetNumTransforms() const;
366
368 //
369 virtual void GetBlockSize(size_t bs[3], int reflevel) const;
370#ifdef PARALLEL
371 void SetIOComm(MPI_Comm NewIOComm) { _IO_Comm = NewIOComm; };
372#endif
373 void SetCollectiveIO(bool newCollectiveIO) { _collectiveIO = newCollectiveIO; };
374 friend void *RunBlockReadRegionThread(void *object);
375 friend void *RunBlockWriteRegionThread(void *object);
376
377private:
378#ifdef PARALLEL
379 MPI_Comm _IO_Comm;
380#endif
381 bool _collectiveIO;
382 double _xformMPI;
383 double _methodTimer;
384 double _methodThreadTimer;
385 double _ioMPI;
386 //
387 // Threaded read object for parallel inverse transforms
388 // (data reconstruction)
389 //
390 class ReadWriteThreadObj {
391 public:
392 ReadWriteThreadObj(WaveCodecIO *wc, int id, float *region, const size_t bmin_p[3], const size_t bmax_p[3], const size_t bdim_p[3], const size_t dim_p[3], const size_t bs_p[3], bool reblock,
393 bool pad);
394 void BlockReadRegionThread();
395 void BlockWriteRegionThread();
396 const float *GetDataRange() const { return (_dataRange); }
397
398 private:
399 WaveCodecIO * _wc;
400 int _id; // thread id
401 float * _region; // destination buffer for read
402 const size_t *_bmin_p;
403 const size_t *_bmax_p; // block coordinates of data
404 const size_t *_bdim_p;
405 const size_t *_dim_p;
406 const size_t *_bs_p; // dimensions of block
407 float _dataRange[2];
408 bool _reblock;
409 bool _pad;
410 int _FetchBlock(size_t bx, size_t by, size_t bz);
411 int _WriteBlock(size_t bx, size_t by, size_t bz);
412 };
413
414public:
415 int _nthreads; // num execution threads
416 int getNumThread() { return _nthreads; }
417 void EnableBuffering(size_t count[3], size_t divisor, int rank);
418
419private:
420 int _next_block;
421 int _threadStatus;
422 size_t _NC_BUF_SIZE; // buffering disabled by default
423 ReadWriteThreadObj ** _rw_thread_objs;
424 vector<vector<SignificanceMap>> _sigmapsThread; // one set for each thread
425 vector<size_t> _sigmapsizes; // size of each encoded sig map
426 Compressor * _compressor3D; // 3D compressor
427 Compressor * _compressor2DXY;
428 Compressor * _compressor2DXZ;
429 Compressor * _compressor2DYZ;
430 Compressor * _compressor; // compressor for currently opened variable
431 vector<Compressor *> _compressorThread3D;
432 vector<Compressor *> _compressorThread2DXY;
433 vector<Compressor *> _compressorThread2DXZ;
434 vector<Compressor *> _compressorThread2DYZ;
435 vector<Compressor *> _compressorThread; // current compressor threads
436 vector<NCBuf *> _ncbufs;
437
438 VarType_T _vtype; // Type (2d, or 3d) of currently opened variable
439 VarType_T _compressorType; // Type (2d, or 3d) of current _compressor
440 int _lod; // compression level of currently opened file
441 int _reflevel; // current refinement level
442 size_t _validRegMin[3]; // min region bounds of current file
443 size_t _validRegMax[3]; // max region bounds of current file
444 bool _writeMode; // true if opened for writes
445 bool _isOpen; // true if a file is opened
446 size_t _timeStep; // currently opened time step
447 string _varName; // Currently opened variable
448 vector<string> _ncpaths;
449 vector<int> _ncids;
450 vector<int> _nc_sig_vars; // ncdf ids for wave and sig vars
451 vector<int> _nc_wave_vars;
452 float * _cvector; // storage for wavelet coefficients
453 size_t _cvectorsize; // amount of space allocated to _cvector
454 vector<float *> _cvectorThread;
455 unsigned char * _svector; // storage for encoded signficance map
456 size_t _svectorsize; // amount of space allocated to _svector
457 vector<unsigned char *> _svectorThread;
458 float * _block; // storage for a block
459 vector<float *> _blockThread;
460 float * _blockReg; // more storage
461 float _dataRange[2];
462 vector<size_t> _ncoeffs; // num wave coeff. at each compression level
463 vector<size_t> _cratios3D; // 3D compression ratios
464 vector<size_t> _cratios2D; // 2D compression ratios
465 vector<size_t> _cratios; // compression ratios for currently opened file
466
467 float *_sliceBuffer;
468 size_t _sliceBufferSize; // size of slice buffer in elements
469 int _sliceCount; // num slices written
470
471 bool _pad; // Padding enabled?
472
473 int _OpenVarWrite(const string &basename);
474 int _OpenVarRead(const string &basename);
475 int _WaveCodecIO(int nthreads);
476 int _SetupCompressor();
477
478 void _UnpackCoord(VarType_T vtype, const size_t src[3], size_t dst[3], size_t fill) const;
479
480 void _PackCoord(VarType_T vtype, const size_t src[3], size_t dst[3], size_t fill) const;
481
482 void _FillPackedCoord(VarType_T vtype, const size_t src[3], size_t dst[3], size_t fill) const;
483};
484}; // namespace VAPoR
485
486#endif // _WaveCodeIO_h_
A class for managing data set metadata.
Definition: Compressor.h:28
A sub-region reader for VDF files.
Definition: WaveCodecIO.h:38
void GetValidRegion(size_t min[3], size_t max[3], int reflevel) const
static size_t GetMaxCRatio(const size_t bs[3], string wavename, string wmode)
void EnableBuffering(size_t count[3], size_t divisor, int rank)
virtual int WriteRegion(const float *region)
friend void * RunBlockReadRegionThread(void *object)
WaveCodecIO(const MetadataVDC &metadata, int nthreads=0)
virtual int VariableExists(size_t ts, const char *varname, int reflevel=0, int lod=0) const
virtual void GetBlockSize(size_t bs[3], int reflevel) const
virtual int ReadRegion(const size_t min[3], const size_t max[3], float *region)
virtual int ReadRegion(float *region)
virtual int WriteRegion(const float *region, const size_t min[3], const size_t max[3])
const float * GetDataRange() const
Definition: WaveCodecIO.h:308
virtual int OpenVariableWrite(size_t timestep, const char *varname, int reflevel=-1, int lod=-1)
virtual int ReadSlice(float *slice)
virtual int WriteSlice(const float *slice)
virtual ~WaveCodecIO()
WaveCodecIO(const string &metafile, int nthreads=0)
virtual int BlockReadRegion(const size_t bmin[3], const size_t bmax[3], float *region, bool unblock=true)
virtual int OpenVariableRead(size_t timestep, const char *varname, int reflevel=0, int lod=0)
friend void * RunBlockWriteRegionThread(void *object)
virtual int GetNumTransforms() const
virtual int BlockWriteRegion(const float *region, const size_t bmin[3], const size_t bmax[3], bool block=true)
virtual void SetBoundaryPadOnOff(bool pad)
Definition: WaveCodecIO.h:292
void SetCollectiveIO(bool newCollectiveIO)
Definition: WaveCodecIO.h:373
virtual int CloseVariable()
#define VDF_API
Definition: common.h:73