From: Timo Heister Date: Sun, 12 Jan 2020 16:32:36 +0000 (-0500) Subject: fix write_vtu_in_parallel invalid file if partly empty X-Git-Tag: v9.2.0-rc1~696^2 X-Git-Url: https://gitweb.dealii.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=refs%2Fpull%2F9290%2Fhead;p=dealii.git fix write_vtu_in_parallel invalid file if partly empty 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. --- diff --git a/doc/news/changes/minor/20200112TimoHeister b/doc/news/changes/minor/20200112TimoHeister new file mode 100644 index 0000000000..378d89dac1 --- /dev/null +++ b/doc/news/changes/minor/20200112TimoHeister @@ -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. +
(Timo Heister, 2020/01/12) diff --git a/source/base/data_out_base.cc b/source/base/data_out_base.cc index 2c2f36249b..32f832dfb4 100644 --- a/source/base/data_out_base.cc +++ b/source/base/data_out_base.cc @@ -7499,12 +7499,23 @@ DataOutInterface::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(), diff --git a/tests/mpi/parallel_vtu_01.with_trilinos=true.mpirun=3.with_zlib=on.with_p4est=true.output b/tests/mpi/parallel_vtu_01.with_trilinos=true.mpirun=3.with_zlib=on.with_p4est=true.output index 953962a849..85f57cf567 100644 --- a/tests/mpi/parallel_vtu_01.with_trilinos=true.mpirun=3.with_zlib=on.with_p4est=true.output +++ b/tests/mpi/parallel_vtu_01.with_trilinos=true.mpirun=3.with_zlib=on.with_p4est=true.output @@ -7,22 +7,6 @@ DEAL:0::hyper_cube --> - - - - - - - - - - - - - - - -