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

Print global number of cells and dofs #1865

Merged
merged 25 commits into from
Jun 7, 2024

Conversation

benegee
Copy link
Contributor

@benegee benegee commented Mar 7, 2024

Resolves #1616

Copy link
Contributor

github-actions bot commented Mar 7, 2024

Review checklist

This checklist is meant to assist creators of PRs (to let them know what reviewers will typically look for) and reviewers (to guide them in a structured review process). Items do not need to be checked explicitly for a PR to be eligible for merging.

Purpose and scope

  • The PR has a single goal that is clear from the PR title and/or description.
  • All code changes represent a single set of modifications that logically belong together.
  • No more than 500 lines of code are changed or there is no obvious way to split the PR into multiple PRs.

Code quality

  • The code can be understood easily.
  • Newly introduced names for variables etc. are self-descriptive and consistent with existing naming conventions.
  • There are no redundancies that can be removed by simple modularization/refactoring.
  • There are no leftover debug statements or commented code sections.
  • The code adheres to our conventions and style guide, and to the Julia guidelines.

Documentation

  • New functions and types are documented with a docstring or top-level comment.
  • Relevant publications are referenced in docstrings (see example for formatting).
  • Inline comments are used to document longer or unusual code sections.
  • Comments describe intent ("why?") and not just functionality ("what?").
  • If the PR introduces a significant change or new feature, it is documented in NEWS.md.

Testing

  • The PR passes all tests.
  • New or modified lines of code are covered by tests.
  • New or modified tests run in less then 10 seconds.

Performance

  • There are no type instabilities or memory allocations in performance-critical parts.
  • If the PR intent is to improve performance, before/after time measurements are posted in the PR.

Verification

  • The correctness of the code was verified using appropriate tests.
  • If new equations/methods are added, a convergence test has been run and the results
    are posted in the PR.

Created with ❤️ by the Trixi.jl community.

Copy link

codecov bot commented Mar 7, 2024

Codecov Report

Attention: Patch coverage is 93.88464% with 88 lines in your changes are missing coverage. Please review.

Project coverage is 96.11%. Comparing base (909abb4) to head (bded959).
Report is 58 commits behind head on main.

Files Patch % Lines
...ation/paired_explicit_runge_kutta/methods_PERK2.jl 85.44% 23 Missing ⚠️
src/callbacks_step/analysis_surface_integral_2d.jl 91.04% 12 Missing ⚠️
src/equations/linearized_euler_1d.jl 76.60% 11 Missing ⚠️
src/equations/linearized_euler_3d.jl 94.74% 5 Missing ⚠️
src/Trixi.jl 0.00% 4 Missing ⚠️
src/meshes/structured_mesh_view.jl 91.30% 4 Missing ⚠️
src/meshes/t8code_mesh.jl 96.04% 4 Missing ⚠️
src/solvers/dgsem_tree/subcell_limiters.jl 88.89% 4 Missing ⚠️
src/callbacks_step/analysis.jl 86.96% 3 Missing ⚠️
...em/elixir_linearizedeuler_characteristic_system.jl 93.10% 2 Missing ⚠️
... and 10 more
Additional details and impacted files
@@            Coverage Diff             @@
##             main    #1865      +/-   ##
==========================================
- Coverage   96.30%   96.11%   -0.19%     
==========================================
  Files         440      460      +20     
  Lines       35793    36913    +1120     
==========================================
+ Hits        34470    35478    +1008     
- Misses       1323     1435     +112     
Flag Coverage Δ
unittests 96.11% <93.88%> (-0.19%) ⬇️

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

benegee and others added 2 commits March 7, 2024 17:56
ncells was used elsewhere and has to be the local number
@benegee benegee marked this pull request as ready for review March 7, 2024 16:57
Copy link
Member

@ranocha ranocha left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks! In #1616, you mentioned that the analysis callback also prints only the local information. Does this PR fix this as well?

src/semidiscretization/semidiscretization.jl Outdated Show resolved Hide resolved
src/semidiscretization/semidiscretization.jl Outdated Show resolved Hide resolved
@DanielDoehring DanielDoehring added the parallelization Related to MPI, threading, tasks etc. label Mar 12, 2024
@JoshuaLampert
Copy link
Member

What about other mesh types like the TreeMesh? Does it print the local or global number of cells (see here)?

@ranocha
Copy link
Member

ranocha commented Mar 25, 2024

The TreeMesh replicates all cell info on all ranks. Thus, it prints the global info.

@ranocha ranocha requested a review from sloede March 26, 2024 11:24
@sloede
Copy link
Member

sloede commented May 10, 2024

@benegee Please note that you should also adapt the output of the AMR output, probably in these three functions:

function print_amr_information(callbacks, mesh, solver, cache)

function print_amr_information(callbacks, mesh::P4estMesh, solver, cache)

function print_amr_information(callbacks, mesh::T8codeMesh, solver, cache)

Otherwise we get a global element count but only rank-0 information on AMR, which is bound to cause confusion IMHO

@benegee
Copy link
Contributor Author

benegee commented May 10, 2024

True! I realized this in the meantime as well, but have not finished the MPI syncing of element counts.

@sloede
Copy link
Member

sloede commented May 10, 2024

True! I realized this in the meantime as well, but have not finished the MPI syncing of element counts.

Optimally, you'll use an implementation that only requires a single additional MPI_Reduce call.

src/meshes/p4est_mesh.jl Show resolved Hide resolved
src/meshes/t8code_mesh.jl Show resolved Hide resolved
src/callbacks_step/analysis.jl Show resolved Hide resolved
src/semidiscretization/semidiscretization.jl Outdated Show resolved Hide resolved
Comment on lines +126 to +128
@inline function ndofsglobal(semi::SemidiscretizationCoupled)
sum(ndofsglobal, semi.semis)
end
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
@inline function ndofsglobal(semi::SemidiscretizationCoupled)
sum(ndofsglobal, semi.semis)
end
"""
ndofsglobal(semi::SemidiscretizationCoupled)
Return the global number of degrees of freedom associated with each scalar variable across all MPI ranks, and summed up over all coupled systems.
This is the same as [`ndofs`](@ref) for simulations running in serial or
parallelized via threads. It will in general be different for simulations
running in parallel with MPI.
"""
@inline function ndofsglobal(semi::SemidiscretizationCoupled)
sum(ndofsglobal, semi.semis)
end

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would actually argue that this docstring doesn't really help in practice since it's the same as the one for the AbstractSemidiscretization - and SemidiscretizationCoupled <: AbstractSemidiscretization. But I don't have a strong opinion on this. Shall we keep it, @sloede?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Well, it explicitly mentions that it is the number of DOFs over all coupled systems. I don't have a strong opinion either, so I'll leave it up to @benegee to decide 🙂

src/semidiscretization/semidiscretization.jl Outdated Show resolved Hide resolved
src/semidiscretization/semidiscretization.jl Outdated Show resolved Hide resolved
@benegee
Copy link
Contributor Author

benegee commented May 29, 2024

Summary

Global number of elements and dofs

nodofsglobal and nelementsglobal are now used in the Base.show output of semidiscretizations and meshes, and of the AnalysisCallback.

For DG, nodofsglobal already relied on nelementsglobal:

Trixi.jl/src/solvers/dg.jl

Lines 461 to 463 in 76719a8

@inline function ndofsglobal(mesh, dg::DG, cache)
nelementsglobal(dg, cache) * nnodes(dg)^ndims(mesh)
end

and nelementsglobal was already MPI aware:

Trixi.jl/src/solvers/dg.jl

Lines 520 to 522 in 76719a8

@inline function nelementsglobal(dg::DG, cache)
mpi_isparallel() ? cache.mpi_cache.n_elements_global : nelements(dg, cache)
end

For DGMulti, ndofsglobal was already MPI aware as well:

function ndofsglobal(mesh::DGMultiMesh, solver::DGMulti, cache)
if mpi_isparallel()
error("`ndofsglobal` is not implemented for `DGMultiMesh` when used in parallel with MPI")
else
return ndofs(mesh, solver, cache)
end
end

I now added nelementsglobal in analogy.

New solver types would now have to implement ndofsglobal and nelementsglobal.

Global number of elements per level

The local element numbers per level are now summed up across all ranks before being printed on rank 0.
In order to not having to synchronize the minimum and maximum element levels in advance, I took this information from the AMRController. This currently works but would require new controllers to provide the same information.
If you see a better solution, please give me a hint.

@benegee benegee requested review from ranocha and sloede May 29, 2024 15:42
Copy link
Member

@ranocha ranocha left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks a lot! Looks quite good to me 👍

src/callbacks_step/analysis.jl Outdated Show resolved Hide resolved
Comment on lines +126 to +128
@inline function ndofsglobal(semi::SemidiscretizationCoupled)
sum(ndofsglobal, semi.semis)
end
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would actually argue that this docstring doesn't really help in practice since it's the same as the one for the AbstractSemidiscretization - and SemidiscretizationCoupled <: AbstractSemidiscretization. But I don't have a strong opinion on this. Shall we keep it, @sloede?

@ranocha ranocha merged commit 2043cfe into main Jun 7, 2024
36 of 38 checks passed
@ranocha ranocha deleted the bg/print-global-number-of-cells-dofs branch June 7, 2024 13:37
@sloede
Copy link
Member

sloede commented Jun 7, 2024

Thanks a lot for tackling this @benegee! This makes Trixi.jl much more usable in parallel 💪

benegee added a commit to trixi-framework/libtrixi that referenced this pull request Jun 25, 2024
nelementsglobal was changed in v.0.7.16
trixi-framework/Trixi.jl#1865
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
parallelization Related to MPI, threading, tasks etc.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Trixi displays local, and not global, number of elements / DOFs
5 participants