-
Notifications
You must be signed in to change notification settings - Fork 105
Equation Indices and BC Types - Issue (#828) #860
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
base: master
Are you sure you want to change the base?
Conversation
@@ -16,8 +16,8 @@ | ||
"python.defaultInterpreterPath": "${workspaceFolder}/build/venv/bin/python3", | ||
|
||
"files.associations": { | ||
"*.f90": "FortranFreeForm", | ||
"*.fpp": "FortranFreeForm", | ||
"*.f90": "fortran-modern", |
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.
does this help anything?
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.
missed it
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.
not really
src/common/m_boundary_common.fpp
Outdated
@@ -22,7 +22,7 @@ module m_boundary_common | ||
type(scalar_field), dimension(:, :), allocatable :: bc_buffers | ||
!$acc declare create(bc_buffers) | ||
|
||
real(wp) :: bcxb, bcxe, bcyb, bcye, bczb, bcze | ||
type(boundary_flags) :: bc_flag |
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.
These aren't flags but rather bounds. bc_x_b = boundarycondition_xdirection_beginning.
src/common/m_derived_types.fpp
Outdated
@@ -345,6 +345,11 @@ module m_derived_types | ||
type(vec3_dt), allocatable, dimension(:) :: var | ||
end type mpi_io_airfoil_ib_var | ||
|
||
!> Derived type for boundary flags | ||
type boundary_flags |
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.
see above comment about the word 'flags'
call s_convert_species_to_mixture_variables_acc(rho, gamma, pi_inf, qv_K, alpha_IP, & | ||
alpha_rho_IP, Re_K, j, k, l, G_K, Gs) | ||
call s_convert_species_to_mixture_variables_acc(rho, gamma, pi_inf, qv_K, & | ||
gp%ip%alpha, gp%ip%alpha_rho, Re_K, j, k, l, G_K, Gs) |
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.
one advantage of this strategy of using more derived types is that we can just pass in gp%ip
(for ibm) or state%L
(or something like this) for riemann solvers. basically gathering all the data that could exist at a given point and lumping it into a derived type, and then the argument list becomes very short. for example, you just pass in
call s_routine(state)
where
subroutine s_routine(mystate)
type(state) :: mystate
[...]
mystate%rho = [......]
end subroutine
@@ -743,22 +757,15 @@ contains | ||
|
||
!> Function that uses the interpolation coefficients and the current state | ||
!! at the cell centers in order to estimate the state at the image point | ||
pure subroutine s_interpolate_image_point(q_prim_vf, gp, alpha_rho_IP, alpha_IP, pres_IP, vel_IP, c_IP, r_IP, v_IP, pb_IP, mv_IP, nmom_IP, pb, mv, presb_IP, massv_IP) | ||
pure subroutine s_interpolate_image_point(q_prim_vf, gp, pb, mv) |
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.
this is an good example of what i was talking about above... for removing so many arguments.
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.
yup yup I see that
src/simulation/m_ibm.fpp
Outdated
|
||
if (allocated(ghost_points)) then | ||
do i = 1, size(ghost_points) | ||
if (allocated(ghost_points(i)%ip%alpha_rho)) deallocate (ghost_points(i)%ip%alpha_rho) |
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.
FYI from perplexity:
Perfect! Given that your point_data
type uses allocatable components (not pointers), your manual deallocation loop is completely unnecessary.
The Clean Solution
Since all the components you're manually deallocating (alpha_rho
, alpha
, r
, v
, pb
, mv
, nmom
, presb
, massv
) are declared as allocatable
, Fortran will automatically deallocate them when the parent object is deallocated.
You can replace your entire verbose loop with just:
if (allocated(ghost_points)) deallocate(ghost_points)
That's it! When ghost_points
is deallocated, Fortran automatically:
- Deallocates all allocatable components within each
ghost_points(i)%ip
- Deallocates the
ghost_points
array itself
Why This Works
The Fortran standard guarantees that when a derived type object with allocatable components is deallocated (or goes out of scope), all of its allocatable components are automatically deallocated first. This is called automatic deallocation and is one of the key advantages of using allocatable
over pointer
.
Additional Benefits
This approach is not only cleaner but also:
- Safer: No risk of forgetting to deallocate a component
- More maintainable: Adding new allocatable components to
point_data
requires no changes to deallocation code - Better performance: No unnecessary allocation status checks in loops
Your original manual approach was doing work that Fortran handles automatically for allocatable components. The verbose loop is only necessary when dealing with pointer
components, which require explicit deallocation.
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.
neat will remove the loop
@@ -95,6 +95,35 @@ contains | ||
@:ALLOCATE(ghost_points(1:num_gps)) |
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.
i'm not sure how this ever worked. i would ask on the MFC Slack and tag @abbotts . this is an array of derived types. it seems like you would need to use something like this macro for AMD GPUs:
MFC/src/common/include/macros.fpp
Lines 48 to 62 in 32c0347
#:def ACC_SETUP_SFs(*args) | |
#ifdef _CRAYFTN | |
block | |
@:LOG({'@:ACC_SETUP_SFs(${', '.join(args)}$)'}) | |
#:for arg in args | |
!$acc enter data copyin(${arg}$) | |
if (associated(${arg}$%sf)) then | |
!$acc enter data create(${arg}$%sf) | |
end if | |
#:endfor | |
end block | |
#endif | |
#:enddef |
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.
the reason is perhaps that sf
is another derived type. when you have a derived type that has another allocatable derived type within it, you need to use a macro like this (except instead of sf
it would be something else)
src/simulation/m_ibm.fpp
Outdated
end if | ||
|
||
if (qbmm) then | ||
allocate (ghost_points(i)%ip%nmom(nb*nmom)) |
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.
we use the @:ALLOCATE
macro in almost all cases i think, since it declares the variable on the device.
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.
this is a good PR but isn't quite right. the issues are subtle though, and are somewhat MFC specific. ask about the things i brought up on the slack channel (or ask @wilfonba @abbotts @anandrdbz etc.)
Codecov ReportAttention: Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## master #860 +/- ##
==========================================
- Coverage 43.42% 43.39% -0.04%
==========================================
Files 68 68
Lines 19630 19655 +25
Branches 2353 2355 +2
==========================================
+ Hits 8525 8529 +4
- Misses 9676 9697 +21
Partials 1429 1429 ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
This CCE failure suggests something is wrong with allocation, deallocation, or memory access. It happens on Cray CPU cases.
and chatgpt says Thanks — since your simulation is written in Fortran, the 🔍 Common Causes in Fortran
🛠️ Recommended Actions✅ Compile with bounds and memory checks:Add flags to enable runtime checking:
✅ Use
|
So I made the following derived type, but the build always corrupts mainly in the post-process because sys_size clashes with all processes while being in the form !> @name Annotations of the structure of the state and flux vectors in terms of the
!! size and the configuration of the system of equations to which they belong
!> @{
type system_of_equations
integer :: sys_size !< Number of unknowns in system of eqns.
type(int_bounds_info) :: cont !< Indexes of first & last continuity eqns.
type(int_bounds_info) :: mom !< Indexes of first & last momentum eqns.
integer :: E !< Index of energy equation
integer :: n !< Index of number density
type(int_bounds_info) :: adv !< Indexes of first & last advection eqns.
type(int_bounds_info) :: internalEnergies !< Indexes of first & last internal energy eqns.
type(bub_bounds_info) :: bub !< Indexes of first & last bubble variable eqns.
integer :: alf !< Index of void fraction
integer :: gamma !< Index of specific heat ratio func. eqn.
integer :: pi_inf !< Index of liquid stiffness func. eqn.
type(int_bounds_info) :: B !< Indexes of first and last magnetic field eqns.
type(int_bounds_info) :: stress !< Indexes of first and last shear stress eqns.
type(int_bounds_info) :: xi !< Indexes of first and last reference map eqns.
integer :: b_size !< Number of elements in the symmetric b tensor, plus one
integer :: tensor_size !< Number of elements in the full tensor plus one
type(int_bounds_info) :: species !< Indexes of first & last concentration eqns.
integer :: c !< Index of color function
integer :: damage !< Index of damage state variable (D) for continuum damage model
integer, dimension(3) :: dir
real(wp), dimension(3) :: dir_flg
integer, dimension(3) :: dir_tau !!used for hypoelasticity=true
integer, dimension(2) :: Re_size
integer, allocatable, dimension(:, :) :: Re
end type system_of_equations |
if (allocated(ghost_points(i)%ip%massv)) deallocate (ghost_points(i)%ip%massv) | ||
end do | ||
end if | ||
|
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.
Do you mind checking out this line?
I suspect it to be causing all IBM cases to fail.
real(wp), dimension(3) :: dir_flg | ||
integer, dimension(3) :: dir_tau !!used for hypoelasticity=true | ||
integer, dimension(2) :: Re_size | ||
integer, allocatable, dimension(:, :) :: Re |
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.
you may need to be careful with this on GPU cases (especially Frontier/Cray). i forget exactly how we deal with cases where we have an allocatable in a derived type but i would look for other examples of the code that do this. also, isn't Re a real and not an integer? and why is its size unknown at compile time?
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.
I kinda omitted _idx
from all variables listed. It was Re_idx
and I just copied the declaration into under system_of_equations
type.
MFC/src/simulation/m_global_parameters.fpp Line 1219 in db44da1
|
nitpick but probably can change the naming pattern of |
FYI i moved pressure relaxation from RHS to its own module, which is why the merge conflict there looks so crazy |
Description
making derived types and addressing issue #828
Fixes #(issue) [optional]
Type of change
Please delete options that are not relevant.
Scope
If you cannot check the above box, please split your PR into multiple PRs that each have a common goal.
How Has This Been Tested?
Please describe the tests that you ran to verify your changes.
Provide instructions so we can reproduce.
Please also list any relevant details for your test configuration
Test Configuration:
Checklist
docs/
)examples/
that demonstrate my new feature performing as expected.They run to completion and demonstrate "interesting physics"
./mfc.sh format
before committing my codeIf your code changes any code source files (anything in
src/simulation
)To make sure the code is performing as expected on GPU devices, I have:
nvtx
ranges so that they can be identified in profiles./mfc.sh run XXXX --gpu -t simulation --nsys
, and have attached the output file (.nsys-rep
) and plain text results to this PR./mfc.sh run XXXX --gpu -t simulation --rsys --hip-trace
, and have attached the output file and plain text results to this PR.