Skip to content

Commit

Permalink
Change particle postprocessor writer from raw poiters to unique point…
Browse files Browse the repository at this point in the history
…ers.
  • Loading branch information
MFraters committed Jul 9, 2023
1 parent 1971dd6 commit b4e7edd
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 15 deletions.
6 changes: 3 additions & 3 deletions include/aspect/postprocess/particles.h
Original file line number Diff line number Diff line change
Expand Up @@ -289,9 +289,9 @@ namespace aspect
* of these arguments and deletes them at the end of its work.
*/
static
void writer (const std::string filename,
const std::string temporary_filename,
const std::string *file_contents);
void writer (const std::string &filename,
const std::string &temporary_filename,
const std::string &file_contents);

/**
* Write the various master record files. The master files are used by
Expand Down
23 changes: 11 additions & 12 deletions source/postprocess/particles.cc
Original file line number Diff line number Diff line change
Expand Up @@ -192,9 +192,9 @@ namespace aspect

template <int dim>
// We need to pass the arguments by value, as this function can be called on a separate thread:
void Particles<dim>::writer (const std::string filename, //NOLINT(performance-unnecessary-value-param)
const std::string temporary_output_location, //NOLINT(performance-unnecessary-value-param)
const std::string *file_contents)
void Particles<dim>::writer (const std::string &filename, //NOLINT(performance-unnecessary-value-param)
const std::string &temporary_output_location, //NOLINT(performance-unnecessary-value-param)
const std::string &file_contents)
{
std::string tmp_filename = filename;
if (temporary_output_location != "")
Expand Down Expand Up @@ -241,7 +241,7 @@ namespace aspect

// now write and then move the tmp file to its final destination
// if necessary
out << *file_contents;
out << file_contents;
out.close ();

if (tmp_filename != filename)
Expand All @@ -254,9 +254,6 @@ namespace aspect
+ filename + ". On processor "
+ Utilities::int_to_string(Utilities::MPI::this_mpi_process (MPI_COMM_WORLD)) + "."));
}

// destroy the pointer to the data we needed to write
delete file_contents;
}

template <int dim>
Expand Down Expand Up @@ -442,12 +439,12 @@ namespace aspect
{
// Put the content we want to write into a string object that
// we can then write in the background
const std::string *file_contents;
std::unique_ptr<std::string> file_contents;
{
std::ostringstream tmp;

data_out.write (tmp, DataOutBase::parse_output_format(output_format));
file_contents = new std::string (tmp.str());
file_contents = std::make_unique<std::string>(tmp.str());
}

if (write_in_background_thread)
Expand All @@ -459,13 +456,15 @@ namespace aspect

// ...then continue with writing our own data.
background_thread
= std::thread([&]()
= std::thread([ my_filename = std::move(filename),
my_temporary_output_location = temporary_output_location,
my_file_contents = std::move(file_contents)]()
{
writer (filename, temporary_output_location, file_contents);
writer (my_filename, my_temporary_output_location, *my_file_contents);
});
}
else
writer(filename,temporary_output_location,file_contents);
writer(filename,temporary_output_location,*file_contents);
}
// Just write one data file in parallel
else if (group_files == 1)
Expand Down

0 comments on commit b4e7edd

Please sign in to comment.