Mar 1, 2014 at 6:30am UTC
Hi,
I have the following working section of code:
const unsigned int arySize = numSteps * numSteps * numZPlanes;
double phase1D[arySize];
blitz::Array<double, 3> phase3D(phase1D, shape(numSteps, numSteps, numZPlanes), blitz::duplicateData);
blitz::Array<blitz::TinyVector<double, 3>, 3> phaseGrad3D(numSteps, numSteps, numSteps);
phaseGrad3D = blitz::grad3Dn(phase3D);
cout << phaseGrad3D.depth() << "\n";
cout << phaseGrad3D(i,j,k) << "\n";
I need to process quite large arrays so have moved to allocating on the heap which means I have changed the above to:
double * phase1D = new double[arySize];
blitz::Array<double, 3> * phase3D = new blitz::Array<double, 3>(numSteps, numSteps, numZPlanes, blitz::duplicateData);
delete[] phase1D;
blitz::Array<blitz::TinyVector<double, 3>, 3> * phaseGrad3D = new blitz::Array<blitz::TinyVector<double, 3>, 3>(numSteps, numSteps, numZPlanes);
But I can't work out what syntax I need for the grad3Dn line and the two cout lines after. Any help would be appreciated.
Regards
Mar 1, 2014 at 7:25am UTC
Blitz++ uses new to allocate memory for arrays.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15
const unsigned int arySize = numSteps * numSteps * numZPlanes;
// double phase1D[arySize];
std::vector<double > phase1D(arySize) ;
// ...
// blitz::Array<> uses new to allocate memory
blitz::Array<double , 3> phase1D( &phase1D.front(), shape(numSteps, numSteps, numZPlanes), blitz::duplicateData);
blitz::Array<blitz::TinyVector<double , 3>, 3> phaseGrad3D(numSteps, numSteps, numSteps);
phaseGrad3D = blitz::grad3Dn(phase3D);
cout << phaseGrad3D.depth() << "\n" ;
cout << phaseGrad3D(i,j,k) << "\n" ;
Or:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16
const unsigned int arySize = numSteps * numSteps * numZPlanes;
// double phase1D[arySize];
double * phase1D = new double [arySize] ;
// ...
// blitz::Array<> uses new to allocate memory
blitz::Array<double , 3> phase1D( phase1D, shape(numSteps, numSteps, numZPlanes), blitz::duplicateData);
delete [] phase1D ;
blitz::Array<blitz::TinyVector<double , 3>, 3> phaseGrad3D(numSteps, numSteps, numSteps);
phaseGrad3D = blitz::grad3Dn(phase3D);
cout << phaseGrad3D.depth() << "\n" ;
cout << phaseGrad3D(i,j,k) << "\n" ;
Or:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15
const unsigned int arySize = numSteps * numSteps * numZPlanes;
// double phase1D[arySize];
static double phase1D[arySize] ;
// ...
// blitz::Array<> uses new to allocate memory
blitz::Array<double , 3> phase1D( phase1D, shape(numSteps, numSteps, numZPlanes), blitz::duplicateData);
blitz::Array<blitz::TinyVector<double , 3>, 3> phaseGrad3D(numSteps, numSteps, numSteps);
phaseGrad3D = blitz::grad3Dn(phase3D);
cout << phaseGrad3D.depth() << "\n" ;
cout << phaseGrad3D(i,j,k) << "\n" ;
Last edited on Mar 1, 2014 at 7:28am UTC