-
Notifications
You must be signed in to change notification settings - Fork 707
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
Upgrade write_vtu_in_parallel based on mpi large IO update #13673
Merged
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change | ||||
---|---|---|---|---|---|---|
|
@@ -34,6 +34,7 @@ | |||||
#include <deal.II/base/data_out_base.h> | ||||||
#include <deal.II/base/memory_consumption.h> | ||||||
#include <deal.II/base/mpi.h> | ||||||
#include <deal.II/base/mpi_large_count.h> | ||||||
#include <deal.II/base/parameter_handler.h> | ||||||
#include <deal.II/base/thread_management.h> | ||||||
#include <deal.II/base/utilities.h> | ||||||
|
@@ -7673,6 +7674,7 @@ DataOutInterface<dim, spacedim>::write_svg(std::ostream &out) const | |||||
out); | ||||||
} | ||||||
|
||||||
|
||||||
template <int dim, int spacedim> | ||||||
void | ||||||
DataOutInterface<dim, spacedim>::write_vtu_in_parallel( | ||||||
|
@@ -7688,8 +7690,8 @@ DataOutInterface<dim, spacedim>::write_vtu_in_parallel( | |||||
write_vtu(f); | ||||||
#else | ||||||
|
||||||
const int myrank = Utilities::MPI::this_mpi_process(comm); | ||||||
|
||||||
const unsigned int myrank = Utilities::MPI::this_mpi_process(comm); | ||||||
const unsigned int n_ranks = Utilities::MPI::n_mpi_processes(comm); | ||||||
MPI_Info info; | ||||||
int ierr = MPI_Info_create(&info); | ||||||
AssertThrowMPI(ierr); | ||||||
|
@@ -7707,21 +7709,24 @@ DataOutInterface<dim, spacedim>::write_vtu_in_parallel( | |||||
ierr = MPI_Info_free(&info); | ||||||
AssertThrowMPI(ierr); | ||||||
|
||||||
// Define header size so we can broadcast later. | ||||||
unsigned int header_size; | ||||||
std::uint64_t footer_offset; | ||||||
|
||||||
// write header | ||||||
if (myrank == 0) | ||||||
{ | ||||||
std::stringstream ss; | ||||||
DataOutBase::write_vtu_header(ss, vtk_flags); | ||||||
header_size = ss.str().size(); | ||||||
// Write the header on rank 0 and automatically move the | ||||||
// shared file pointer to the location after header; | ||||||
ierr = MPI_File_write_shared( | ||||||
fh, ss.str().c_str(), header_size, MPI_CHAR, MPI_STATUS_IGNORE); | ||||||
// Write the header on rank 0 at the starting of a file, i.e., offset 0. | ||||||
ierr = Utilities::MPI::LargeCount::MPI_File_write_at_c( | ||||||
fh, 0, ss.str().c_str(), header_size, MPI_CHAR, MPI_STATUS_IGNORE); | ||||||
AssertThrowMPI(ierr); | ||||||
} | ||||||
|
||||||
ierr = MPI_Bcast(&header_size, 1, MPI_UNSIGNED, 0, comm); | ||||||
AssertThrowMPI(ierr); | ||||||
pengfej marked this conversation as resolved.
Show resolved
Hide resolved
|
||||||
|
||||||
{ | ||||||
const auto &patches = get_patches(); | ||||||
|
@@ -7741,21 +7746,47 @@ DataOutInterface<dim, spacedim>::write_vtu_in_parallel( | |||||
vtk_flags, | ||||||
ss); | ||||||
|
||||||
ierr = MPI_File_write_ordered( | ||||||
fh, ss.str().c_str(), ss.str().size(), MPI_CHAR, MPI_STATUS_IGNORE); | ||||||
// using prefix sum to find specific offset to write at. | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||
const std::uint64_t size_on_proc = ss.str().size(); | ||||||
std::uint64_t prefix_sum = 0; | ||||||
ierr = | ||||||
MPI_Exscan(&size_on_proc, &prefix_sum, 1, MPI_UINT64_T, MPI_SUM, comm); | ||||||
AssertThrowMPI(ierr); | ||||||
|
||||||
// Locate specific offset for each processor. | ||||||
const MPI_Offset offset = static_cast<MPI_Offset>(header_size) + prefix_sum; | ||||||
|
||||||
ierr = | ||||||
Utilities::MPI::LargeCount::MPI_File_write_at_all_c(fh, | ||||||
offset, | ||||||
ss.str().c_str(), | ||||||
ss.str().size(), | ||||||
MPI_CHAR, | ||||||
MPI_STATUS_IGNORE); | ||||||
AssertThrowMPI(ierr); | ||||||
|
||||||
if (myrank == n_ranks - 1) | ||||||
{ | ||||||
// Locating Footer with offset on last rank. | ||||||
footer_offset = size_on_proc + offset; | ||||||
|
||||||
std::stringstream ss; | ||||||
DataOutBase::write_vtu_footer(ss); | ||||||
const unsigned int footer_size = ss.str().size(); | ||||||
|
||||||
// Writing Footer. | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||
ierr = | ||||||
Utilities::MPI::LargeCount::MPI_File_write_at_c(fh, | ||||||
footer_offset, | ||||||
ss.str().c_str(), | ||||||
footer_size, | ||||||
MPI_CHAR, | ||||||
MPI_STATUS_IGNORE); | ||||||
AssertThrowMPI(ierr); | ||||||
} | ||||||
} | ||||||
|
||||||
// write footer | ||||||
if (myrank == 0) | ||||||
{ | ||||||
std::stringstream ss; | ||||||
DataOutBase::write_vtu_footer(ss); | ||||||
unsigned int footer_size = ss.str().size(); | ||||||
ierr = MPI_File_write_shared( | ||||||
fh, ss.str().c_str(), footer_size, MPI_CHAR, MPI_STATUS_IGNORE); | ||||||
AssertThrowMPI(ierr); | ||||||
} | ||||||
|
||||||
ierr = MPI_File_close(&fh); | ||||||
AssertThrowMPI(ierr); | ||||||
#endif | ||||||
|
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.