From 89cff94a9d025a62a6a72af747af8be3a48fa76b Mon Sep 17 00:00:00 2001 From: Wolfgang Bangerth Date: Tue, 29 Nov 2022 10:20:06 -0700 Subject: [PATCH] Remove a dependency in writing VTU files. Previously, one of the lambda functions that write parts updated a variable outside the lambda function that was later checked. This works when running everything sequentially, but introduces a race condition when we want to run things in parallel. Move the updating code out of the lambda function, and so effectively make it 'const' in the sense that it no longer writes into variables outside of the lambda function. --- source/base/data_out_base.cc | 15 ++++++++------- 1 file changed, 8 insertions(+), 7 deletions(-) diff --git a/source/base/data_out_base.cc b/source/base/data_out_base.cc index f0c05d9484..e303b1bfc7 100644 --- a/source/base/data_out_base.cc +++ b/source/base/data_out_base.cc @@ -6494,7 +6494,6 @@ namespace DataOutBase // place const Table<2, float> data_vectors = std::move(*create_global_data_table_task.return_value()); - std::vector data_set_written(n_data_sets, false); // then write data. the 'POINT_DATA' means: node data (as opposed to cell // data, which we do not support explicitly here). all following data sets @@ -6502,7 +6501,6 @@ namespace DataOutBase out << " \n"; const auto stringize_nonscalar_data_range = [&flags, - &data_set_written, &data_names, &data_vectors, ascii_or_binary, @@ -6539,10 +6537,6 @@ namespace DataOutBase "in VTK/VTU format.")); } - // mark these components as already written: - for (unsigned int i = first_component; i <= last_component; ++i) - data_set_written[i] = true; - // write the header. concatenate all the component names with double // underscores unless a vector name has been specified o << " data_set_handled(n_data_sets, false); for (const auto &range : nonscalar_data_ranges) { + // Mark these components as already handled: + const auto first_component = std::get<0>(range); + const auto last_component = std::get<1>(range); + for (unsigned int i = first_component; i <= last_component; ++i) + data_set_handled[i] = true; + out << stringize_nonscalar_data_range(range); } // Now do the left over scalar data sets for (unsigned int data_set = 0; data_set < n_data_sets; ++data_set) - if (data_set_written[data_set] == false) + if (data_set_handled[data_set] == false) { out << stringize_scalar_data_set(data_set); } -- 2.39.5