#ifndef EW_NODE_H #define EW_NODE_H #include #define CHKRET( x ) if( (x) == NULL ) return 1; typedef float Float[MAX_VARS_PER_NODE]; class CNode { public: virtual ~CNode() {}; virtual float& operator()( const int idx1, const int idx2 ) = 0; virtual int mallocMem() = 0; virtual int copyToGPU() = 0; virtual int copyFromGPU() = 0; virtual int copyIntermediate() = 0; virtual int copyPOIs() = 0; virtual int freeMem() = 0; virtual int run() = 0; }; class CStructNode : public CNode { public: Float *node; public: inline float& operator()( const int idx1, const int idx2 ) { return node[idx1][idx2]; } int mallocMem() { CHKRET( this->node = (Float*) malloc( sizeof(Float) * NLon * NLat) ); /* FIXME: remove global variables */ CHKRET( R6 = (float*) malloc( sizeof(float) * (NLat+1) ) ); CHKRET( C1 = (float*) malloc( sizeof(float) * (NLon+1) ) ); CHKRET( C3 = (float*) malloc( sizeof(float) * (NLon+1) ) ); CHKRET( C2 = (float*) malloc( sizeof(float) * (NLat+1) ) ); CHKRET( C4 = (float*) malloc( sizeof(float) * (NLat+1) ) ); return 0; } int freeMem() { free( this->node ); free( R6 ); free( C1 ); free( C2 ); free( C3 ); free( C4 ); return 0; } int run() { if( Par.coriolis ) return ewStepCor(); return ewStep(); } int copyToGPU() { return 0; } int copyFromGPU() { return 0; } int copyIntermediate() { return 0; } int copyPOIs() { return 0; } }; #pragma pack(push, 1) class CArrayNode : public CNode { protected: float *d; float *h; float *hMax; float *fM; float *fN; float *cR1; float *cR2; float *cR3; float *cR4; float *cR5; float *tArr; float *topo; public: virtual float& operator()( const int idx1, const int idx2 ) { return ((float**)&d)[idx2][idx1]; } virtual int mallocMem() { CHKRET( this->d = (float*) malloc( sizeof(float) * NLon * NLat ) ); CHKRET( this->h = (float*) malloc( sizeof(float) * NLon * NLat ) ); CHKRET( this->hMax = (float*) malloc( sizeof(float) * NLon * NLat ) ); CHKRET( this->fM = (float*) malloc( sizeof(float) * NLon * NLat ) ); CHKRET( this->fN = (float*) malloc( sizeof(float) * NLon * NLat ) ); CHKRET( this->cR1 = (float*) malloc( sizeof(float) * NLon * NLat ) ); CHKRET( this->cR2 = (float*) malloc( sizeof(float) * NLon * NLat ) ); CHKRET( this->cR3 = (float*) malloc( sizeof(float) * NLon * NLat ) ); CHKRET( this->cR4 = (float*) malloc( sizeof(float) * NLon * NLat ) ); CHKRET( this->cR5 = (float*) malloc( sizeof(float) * NLon * NLat ) ); CHKRET( this->tArr = (float*) malloc( sizeof(float) * NLon * NLat ) ); CHKRET( this->topo = (float*) malloc( sizeof(float) * NLon * NLat ) ); /* FIXME: remove global variables */ CHKRET( R6 = (float*) malloc( sizeof(float) * (NLat+1) ) ); CHKRET( C1 = (float*) malloc( sizeof(float) * (NLon+1) ) ); CHKRET( C3 = (float*) malloc( sizeof(float) * (NLon+1) ) ); CHKRET( C2 = (float*) malloc( sizeof(float) * (NLat+1) ) ); CHKRET( C4 = (float*) malloc( sizeof(float) * (NLat+1) ) ); return 0; } virtual int freeMem() { free( this->d ); free( this->h ); free( this->hMax ); free( this->fM ); free( this->fN ); free( this->cR1 ); free( this->cR2 ); free( this->cR3 ); free( this->cR4 ); free( this->cR5 ); free( this->tArr ); free( this->topo ); free( R6 ); free( C1 ); free( C2 ); free( C3 ); free( C4 ); return 0; } virtual int run() { if( Par.coriolis ) return ewStepCor(); return ewStep(); } virtual int copyToGPU() { return 0; } virtual int copyFromGPU() { return 0; } virtual int copyIntermediate() { return 0; } virtual int copyPOIs() { return 0; } }; #pragma pack(pop) #endif /* EW_NODE_H */