]> https://gitweb.dealii.org/ - dealii.git/commitdiff
fix write_vtu_in_parallel invalid file if partly empty 9290/head
authorTimo Heister <timo.heister@gmail.com>
Sun, 12 Jan 2020 16:32:36 +0000 (11:32 -0500)
committerTimo Heister <timo.heister@gmail.com>
Sun, 12 Jan 2020 16:50:38 +0000 (11:50 -0500)
Fix generating an invalid vtu file when the first piece written is empty
(this will crash paraview). There is no reason to write empty pieces
anyway, so just skip them.

doc/news/changes/minor/20200112TimoHeister [new file with mode: 0644]
source/base/data_out_base.cc
tests/mpi/parallel_vtu_01.with_trilinos=true.mpirun=3.with_zlib=on.with_p4est=true.output

diff --git a/doc/news/changes/minor/20200112TimoHeister b/doc/news/changes/minor/20200112TimoHeister
new file mode 100644 (file)
index 0000000..378d89d
--- /dev/null
@@ -0,0 +1,3 @@
+Fixed: DataOut::write_vtu_in_parallel() used to generate invalid .vtu files if
+some processors had 0 patches to write. This is now fixed.
+<br> (Timo Heister, 2020/01/12)
index 2c2f36249bf189209a5b7736e8ef7f198452b698..32f832dfb4811511b36a003fd544977853caf0b9 100644 (file)
@@ -7499,12 +7499,23 @@ DataOutInterface<dim, spacedim>::write_vtu_in_parallel(
   ierr = MPI_File_seek_shared(fh, header_size, MPI_SEEK_SET);
   AssertThrowMPI(ierr);
   {
+    const auto &patches = get_patches();
+    const types::global_dof_index my_n_patches = patches.size();
+    const types::global_dof_index global_n_patches =
+      Utilities::MPI::sum(my_n_patches, comm);
+
+    // Do not write pieces with 0 cells as this will crash paraview if this is
+    // the first piece written. But if nobody has any pieces to write (file is
+    // empty), let processor 0 write their empty data, otherwise the vtk file is
+    // invalid.
     std::stringstream ss;
-    DataOutBase::write_vtu_main(get_patches(),
-                                get_dataset_names(),
-                                get_nonscalar_data_ranges(),
-                                vtk_flags,
-                                ss);
+    if (my_n_patches > 0 || (global_n_patches == 0 && myrank == 0))
+      DataOutBase::write_vtu_main(patches,
+                                  get_dataset_names(),
+                                  get_nonscalar_data_ranges(),
+                                  vtk_flags,
+                                  ss);
+
     ierr = MPI_File_write_ordered(fh,
                                   DEAL_II_MPI_CONST_CAST(ss.str().c_str()),
                                   ss.str().size(),
index 953962a849a4151fde7c997f309db2a3261d54bd..85f57cf567fd4dc190eb24f17cf3964d6091061c 100644 (file)
@@ -7,22 +7,6 @@ DEAL:0::hyper_cube
 -->
 <VTKFile type="UnstructuredGrid" version="0.1" compressor="vtkZLibDataCompressor" byte_order="LittleEndian">
 <UnstructuredGrid>
-<Piece NumberOfPoints="0" NumberOfCells="0" >
-<Cells>
-<DataArray type="UInt8" Name="types"></DataArray>
-</Cells>
-  <PointData Scalars="scalars">
-    <DataArray type="Float32" Name="x"></DataArray>
-  </PointData>
-</Piece>
-<Piece NumberOfPoints="0" NumberOfCells="0" >
-<Cells>
-<DataArray type="UInt8" Name="types"></DataArray>
-</Cells>
-  <PointData Scalars="scalars">
-    <DataArray type="Float32" Name="x"></DataArray>
-  </PointData>
-</Piece>
 <Piece NumberOfPoints="4" NumberOfCells="1" >
   <Points>
     <DataArray type="Float32" NumberOfComponents="3" format="binary">

In the beginning the Universe was created. This has made a lot of people very angry and has been widely regarded as a bad move.

Douglas Adams


Typeset in Trocchi and Trocchi Bold Sans Serif.