Convert Array4 to ArrayND#4868
Conversation
|
/run-hpsf-gitlab-ci |
|
does |
We use it. I haven't seen any issues. |
|
GitLab CI 1365185 finished with status: failed. See details at https://gitlab.spack.io/amrex/amrex/-/pipelines/1365185. |
There was a problem hiding this comment.
Currently there are a lot of special cases for dim == 4 for both the accessors and constructors. I think in general it is useful to use an ArrayND with n-1 spatial dimensions and 1 component dimension, even if dim != 4. For example, I would use this for a 2+1D array. There should be these 5 accessor overloads, each for both operator() and ptr():
idx... i: This should cover bothsizeof...(idx) == dimanddim-1like currently, but also replace theint, int, int, intversion. For this, we might have to allow all types that are implicitly convertible to int foridx.IntVectND<Dim>: forDim == dim,dim-1andDIM < dim-1. In the last case, the remaining indexes are set to 0, except the last one, which is set tolo[dim-1]but not present in the offset calculation.IntVectND<Dim>, int: forDim == dim-1andDIM < dim-1. In the second case, the IntVect is zero-extended as above. This overload won't be usable ifdim == 1Dim3kept for backward compatibility, only works ifdim == 4.Dim3, intkept for backward compatibility, only works ifdim == 4.
In addition to that, I think there should be more constructors, for example, taking a BoxND as input or an ArrayND of different dimensions.
|
@AlexanderSinn Could you provide more information regarding the types of constructors that would be beneficial for your application? I am not convinced that |
|
Yes, currently lower dimensions also use Array4. I assume this is out of simplicity and to make it easy to write code that works in 1D, 2D and 3D by always passing i,j,k,n to the array. However, I think eventually it should also be possible to use the ArrayND of the dimension the code is compiled for (plus one), as this should be slightly more performant and cleaner. The constructors should allow for both ways of using the array and should essentially mirror the interface of
Additionally, the For the application I'm working on, I currently use implicit conversions from Array4 to a 2D array and a 3D array, where the 3D version removes the second to last dimension but keeps the last one. Dimensions that are removed are asserted to have size one if the constructor is called on the CPU. This might be best left to the application, not AMReX. |
|
I believe the final issue to address is the default indices used by |
|
The forward declaration template <typename T> struct Array4;in Also in the |
|
@yut23 Note that this PR will break the GDB script (https://github.com/AMReX-Codes/amrex/tree/development/Tools/GDB) contributed by you. It would be great if you can fix it when this is merged. |
|
one of our Castro problem setups fails to build with this PR: |
|
The Castro issue is that the indices passed to ArrayND are Real not integers. |
The error is from this line I believe |
|
Sorry, my earlier test case was incorrect, since the Real* nullptr_real = nullptr;
Dim3 begin = IntVect(0).dim3();
Dim3 end = IntVect(ncells).dim3();
Array4 t (nullptr_real, begin, end, 1); |
|
For discussion. Should we allow this construction now that ArrayND<Real, 5> a(nullptr, IntVectND<1>(0), IntVectND<1>(ncells));
ArrayND<Real, 5> b(nullptr, BoxND(IntVectND<1>(0), IntVectND<1>(ncells)));I find this rather confusing tbh. |
|
Agreed. It's very confusing. We should only allow |
|
/run-hpsf-gitlab-ci |
|
GitLab CI 1389041 finished with status: success. See details at https://gitlab.spack.io/amrex/amrex/-/pipelines/1389041. |
|
This now compiles. |
Co-authored-by: Weiqun Zhang <[email protected]>
|
Thank you for patiently reviewing the PR so many times. |
|
Thank you for the PR! You did the work! If there are still bugs/defects there, it's all my fault for not catching it. :) |
|
This change causes Castro when built with |
|
Yes we should be able to get the performance back.
…On Fri, Jan 16, 2026, 5:31 AM Michael Zingale ***@***.***> wrote:
*zingale* left a comment (AMReX-Codes/amrex#4868)
<#4868 (comment)>
This change causes Castro when built with DEBUG=TRUE to run 3x slower. Is
there a way to get the performance back in debug mode? Things only seem
slightly slower when optimized.
—
Reply to this email directly, view it on GitHub
<#4868 (comment)>,
or unsubscribe
<https://github.com/notifications/unsubscribe-auth/AB37TYJUBVO45YJHLDLHFVD4HDR3VAVCNFSM6AAAAACQBZ6IT6VHI2DSMVQWIX3LMV43OSLTON2WKQ3PNVWWK3TUHMZTONRQGAZTSMJQGU>
.
You are receiving this because you modified the open/close state.Message
ID: ***@***.***>
|
The innard of amrex::Array has changed in AMReX-Codes/amrex#4868.
|
I have a version that is only 10% slower than the original version in debug mode. |
|
See #4900 |
Summary
This PR introduces a preliminary implementation that generalizes Array4 to an N-dimensional case, extending AMReX support for arbitrary dimensionality as outlined in #3955.
The new
ArrayNDimplementation has the same size asArray4(64 bytes) and is intended to exhibit identical behaviour. However, this change modifies the types ofbeginandendand removesncomp, which may break downstream code. In particular,pyamrexwill likely need to be updated to accommodate these type changes. All internal AMReX source code that usesbegin,end, orncomphas been updated.One open question concerns the behaviour of
ArrayND<dim>::operator()(idx...)when the number of indices provided isdim-1. InArray4, this case sets the last dimensionncompto zero. Should this behaviour be extended to alldimcases inArrayND?Additional background
Checklist
The proposed changes: