Syntax problem using heap allocation

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


I see, that blitz::grad3Dn is a static class method.
So your lime should be: *phaseGrad3D = blitz::grad3Dn(*phase3D); (I really hope that grad3Dn takes arguments by reference)
And changes on the next two lines:
1
2
phaseGrad3D->depth() 
(*phaseGrad3D)(i,j,k)
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
Many thanks.
Topic archived. No new replies allowed.