Replies: 3 comments 3 replies
|
We tend to use explicit-shape arrays because (1) a lot of functions were called from C++ side (2) many functions were initially written before assumed-shape array was introduced in Fortran (3) its performance advantage in certain cases. |
|
One approach using modern Fortran would be to use assumed-shape arrays with remapped lower bounds, so that the physical region (spanning from
subroutine update_phi_2d(ngx, ngy, dx, dt, pold, pnew)
use fvheat__const_mod, RWP => fvheat_RWP
!! Precision defined in public module and set to amrex_real at compile time
implicit none
integer, intent(in) :: ngx, ngy
real(RWP), intent(in) :: dx, dt
real(RWP), intent(in) :: pold(1-ngx:, 1-ngy:)
real(RWP), intent(inout) :: pnew(1-ngx:, 1-ngy:)
integer :: nx, ny
integer :: i, j
nx = size(pnew, 1) - 2*ngx
ny = size(pnew, 2) - 2*ngy
do j = 1, ny
do i = 1, nx
! update stencil here
end do
end do
...
end subroutine update_phi_2dThis can also be generalized to cases where the assumptions above do not hold. In such cases, additional information about the guard-cell layout would need to be passed explicitly:
For C interoperability, one option would be to first write a wrapper subroutine with the I'm curious whether others here prefer to keep the assumed-shape version as the "real" implementation and treat the |
|
Thanks for your comments! I am not a compiler expert, but I have read that modern compilers are very good at optimizing for assumed-shape arrays; It was on the Intel Forum, if I am not mistaken. For me personally, working primarily with Fortran 90 and newer, the assumed-shape version is more intuitive, maintainable, and less error-prone compared to the explicit-shape version. I will keep in mind the potential tradeoffs regarding deep copies and performance losses. |
Uh oh!
There was an error while loading. Please reload this page.
Dear AMReX community,
I am new to AMReX, having previously worked with PARAMESH for CFD applications, and I am currently evaluating AMReX as a potential alternative framework. I’ve been going through the AMReX Fortran interface documentation and tutorial examples, and I had a question about a design choice that I’m trying to understand better.
In many routines, instead of using assumed-shape arrays in modern Fortran, AMReX passes both the data pointer and explicit index bounds (including bounds with and without ghost cells). . For example, in the HeatEquation_EX1_F tutorial:
and the corresponding subroutine:
My question is: what is the rationale for preferring explicit-shape arrays with explicitly passed bounds over assumed-shape arrays (
(:,:)) in this context? Is this mainly due to interoperability constraints (bind(C)) with the C++ AMReX data structures (e.g.,Box,Array4,FArrayBox), or are there additional considerations such as performance, compiler behavior, or control over array descriptors and aliasing?I understand that some form of bounds information (e.g.,
n,nguard) would need to be passed regardless in a box-based AMR setting, so the question is specifically about why the explicit-shape/explicit-bound Fortran interface is preferred over assumed-shape arrays.Any insight into the design choice would be appreciated.
All reactions