[vtkusers] p-threading an app in VTK
Randall Hand
randall.hand at gmail.com
Tue Oct 4 15:15:14 EDT 2005
I have a VTK app that is extremely slow due to some setup/cleanup work, and
I'ld like to multiprocess those steps, as they should be very trivial. Can
someone show me how this is done with VTK?
My setup code is like the following:
(first setup a vtkDataSetReader & load the data)
if ((data = (double*)malloc(sizeof(double)*bins*bins*bins)) == NULL) {
perror("Unable to allocate memory!\n\t");
return -1;
}
vtkDoubleArray *velarray = static_cast<vtkDoubleArray *>
(reader->GetOutput()->GetPointData()->GetArray("Velocity"));
printf("Using array: %s\n", velarray->GetName());
for(id=0; id < reader->GetOutput()->GetNumberOfPoints(); id++) {
velarray->GetTupleValue(id, velocity);
data[id] = velocity[0];
}
reader->Delete();
vtkDoubleArray *ucPointer = vtkDoubleArray::New();
ucPointer->SetNumberOfComponents(1);
ucPointer->SetArray(data, bins*bins*bins, 1);
ucPointer->SetName("Velocity");
vtkImageData *image = vtkImageData::New();
image->Initialize();
image->SetDimensions(bins,bins,bins);
image->SetExtent(1, bins, 1, bins, 1, bins);
image->SetScalarTypeToDouble();
image->SetNumberOfScalarComponents(1);
image->GetPointData()->SetScalars(ucPointer);
ucPointer->Delete();
Essentially, I just create a vtkImageData of the 1 field from the dataset
that I want.
Then I do all my computations, and at the end:
vtkDoubleArray *fftMag = static_cast<vtkDoubleArray *>
(fft->GetOutput()->GetPointData()->GetArray("Velocity"));
for(id=0; id < fft->GetOutput()->GetNumberOfPoints(); id++) {
fft->GetOutput()->GetPoint(id, xyz);
xpos = xyz[0];
if ((xyz[1] <= halfbins) && (xyz[0] <= halfbins)) {
fftMag->GetTupleValue(id, val);
sums[xpos] += ((val[0]*val[0]) + (val[1]*val[1]));
}
}
Here I take the output of all the FFT & computational stuff, and create a
simple 1-D array which is written to a text file on disk later.
Both of these should be prime candidates for multithreading. Any
suggestions?
--
Randall Hand
Visualization Scientist,
ERDC-MSRC Vicksburg, MS
Homepage: http://www.yeraze.com
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://www.vtk.org/pipermail/vtkusers/attachments/20051004/e2b1278f/attachment.htm>
More information about the vtkusers
mailing list