[vtkusers] [MPI][Parallel writer] How to use them?

Adrien Suau agpsuau at gmail.com
Sun Jan 7 16:57:33 EST 2018


Hi,

I'm currently trying to find a correct documentation on how to use
parallel writers provided by VTK with MPI. After something like 2h of
research on the web, here I am! Either I really don't know how to search
information, or there is no documentation at all about how to use the
parallel reader/writers of VTK...

My problem: I have several MPI processes (for the moment on my machine,
in local, but they will be distributed on several machines after). Each
of them owns data (points on a cubic region) I want to gather and plot
on a single graph.

What I tried: Assuming all the code presented below is executed on each
MPI process, and the local data of the current process is stored in
"vtkSmartPointer<vtkPolyData> data":

  * Something I found in this test file from VTK
    <https://www.vtk.org/gitweb?p=VTK.git;a=blob;f=Filters/ParallelMPI/Testing/Cxx/TestImplicitConnectivity.cxx>
    (but seems out of date as I don't have the method SetWriteMetaFile).
        vtkSmartPointer<vtkXMLPPolyDataWriter> pwriter =
    vtkSmartPointer<vtkXMLPPolyDataWriter>::New();
        std::string parallel_filename = std::string("Dataset_") +
    std::to_string(m_dataset_index) + std::string(".pvtp");

        pwriter->SetFileName(parallel_filename.c_str());
        pwriter->SetInputData(data);
        pwriter->Write();
  * Something I guessed from this blog
    <https://gerstrong.github.io/blog/2016/08/20/hacking-vtk-for-parallelisation>.
        // And we can save it on each process
        std::string filename = std::string("Dataset_") +
    std::to_string(m_dataset_index) + std::string("_")
                               + std::to_string(m_rank) +
    std::string(".vtp");
        writer->SetFileName(filename.c_str());
    #if VTK_MAJOR_VERSION <= 5
        writer->SetInput(data);
    #else
        writer->SetInputData(data);
    #endif
        writer->Write();
        if(m_rank == 0) {
            std::string parallel_filename = std::string("Dataset_") +
    std::to_string(m_dataset_index) + std::string(".pvtp");
            vtkSmartPointer<vtkXMLPPolyDataWriter> pwriter =
    vtkSmartPointer<vtkXMLPPolyDataWriter>::New();
            pwriter->SetFileName(parallel_filename.c_str());
            pwriter->SetNumberOfPieces(m_size);
            pwriter->SetStartPiece(0);
            pwriter->SetEndPiece(m_size-1);
    #if VTK_MAJOR_VERSION <= 5
            pwriter->SetInput(data);
    #else
            pwriter->SetInputData(data);
    #endif
            pwriter->Update();
        }

None of them worked: the first one only create the .vtp file for process
0 (and the .ptvp file also), and the second one create 4 identical .tvp
files (and I checked, the processes don't have the same data).

So here my question: What is the correct way to use the parallel writers
of VTK?

Thanks for your time, I hope this was not a stupid question easily
answered by something I didn't found on the internet...

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://vtk.org/pipermail/vtkusers/attachments/20180107/2d8d5201/attachment.html>


More information about the vtkusers mailing list