[vtkusers] vtkXMLPMultiBlockDataWriter crashing

Crni Gorac cgorac at gmail.com
Sun Oct 21 17:42:50 EDT 2012


Test program is attached.  I'm trying to write two uniform grid data
blocks, from two different MPI processes and using
vtkXMLPMultiBlockDataWriter, but the program is crashing.  I'm using VTK
5.10.1 installed from source into /opt/vtk, and I've built the code
through:
  mpicxx -g -I/opt/vtk/include/vtk-5.10 -o foo foo.cpp \
    -L/opt/vtk/lib/vtk-5.10 -lvtkCommon -lvtkFiltering -lvtkIO -lvtkParallel
I'm running the program through:
  LD_LIBRARY_PATH=/opt/vtk/lib/vtk-5.10 mpirun -np 2 foo

On the other side, if I try to replace vtkXMLPMultiBlockDataWriter with
vtkXMLMultiBlockDataWriter (if I understood it properly, according to
http://paraview.org/Bug/view.php?id=6698 vtkXMLMultiBlockDataWriter
should work in parallel too), and remove "-lvtkParallel" from the
command line, data seem to be properly written into two output files,
however master file is referencing only one of these two files.

So - how to use vtkXMLPMultiBlockDataWriter properly?

Thanks.
-------------- next part --------------
#include <mpi.h>
#include <vtkCellData.h>
#include <vtkFloatArray.h>
#include <vtkMultiBlockDataSet.h>
#include <vtkUniformGrid.h>
#include <vtkXMLPMultiBlockDataWriter.h>

#define X0 0
#define Y0 0
#define Z0 0
#define X1 1
#define Y1 1
#define Z1 1
#define NX 100
#define NY 100
#define NZ 100
#define FILENAME "bar.vtmb"

static float f(const float x, const float y, const float z)
{
    return x + y * y + z * z * z;
}

int main(int argc, char **argv)
{
    MPI_Init(&argc, &argv);

    int size;
    int rank;
    MPI_Comm_size(MPI_COMM_WORLD, &size);
    MPI_Comm_rank(MPI_COMM_WORLD, &rank);

    int z_lo = NZ * rank / size;
    int nz = NZ * (rank + 1) / size - z_lo;
    float dx = (float) (X1 - X0) / NX;
    float dy = (float) (Y1 - Y0) / NY;
    float dz = (float) (Z1 - Z0) / NZ;

    vtkFloatArray *array = vtkFloatArray::New();
    array->SetNumberOfValues(nz * NY * NX);
    for (int i = 0; i < nz; ++i)
        for (int j = 0; j < NY; ++j)
            for (int k = 0; k < NX; ++k)
                array->SetValue(i * NY * NX + j * NX + k, f(X0 + dx / 2 + k * dx, Y0 + dy / 2 + j * dy, Z0 + z_lo * dz + dz / 2 + i * dz));

    vtkUniformGrid *grid = vtkUniformGrid::New();
    grid->SetDimensions(NX + 1, NY + 1, nz + 1);
    grid->SetOrigin(X0, Y0, Z0 + z_lo * dz);
    grid->SetSpacing(dx, dy, dz);
    grid->GetCellData()->SetScalars(array);

    vtkMultiBlockDataSet *multiblock = vtkMultiBlockDataSet::New();
    multiblock->SetNumberOfBlocks(size);
    multiblock->SetBlock(rank, grid);

    vtkXMLPMultiBlockDataWriter *writer = vtkXMLPMultiBlockDataWriter::New();
    writer->SetInput(multiblock);
    writer->SetFileName(FILENAME);
    writer->Write();

    array->Delete();
    grid->Delete();
    multiblock->Delete();
    writer->Delete();

    MPI_Finalize();
}

// Local Variables:
// c-basic-offset: 4
// End:


More information about the vtkusers mailing list