Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Change particle postprocessor writer from raw pointers to unique pointers #5223

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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