-
Notifications
You must be signed in to change notification settings - Fork 362
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
Named SoA Support #4163
Named SoA Support #4163
Changes from 3 commits
9986eef
91785b8
8a7fd21
d6d40cd
588e0c6
8abc2a4
78d7db0
7676c4d
e7a88e1
dbd9262
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -6,7 +6,11 @@ | |
#include <AMReX_Vector.H> | ||
#include <AMReX_GpuContainers.H> | ||
|
||
#include <algorithm> | ||
#include <array> | ||
#include <string> | ||
#include <vector> | ||
|
||
|
||
namespace amrex { | ||
|
||
|
@@ -19,11 +23,18 @@ | |
using RealVector = amrex::PODVector<ParticleReal, Allocator<ParticleReal> >; | ||
using IntVector = amrex::PODVector<int, Allocator<int> >; | ||
|
||
void define (int a_num_runtime_real, int a_num_runtime_int) | ||
void define ( | ||
int a_num_runtime_real, | ||
int a_num_runtime_int, | ||
std::vector<std::string>* soa_rdata_names=nullptr, | ||
std::vector<std::string>* soa_idata_names=nullptr | ||
Comment on lines
+29
to
+30
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. Yes, this is indeed not super save... Should we store a reference to a PC instead? Or store the names in |
||
) | ||
{ | ||
m_defined = true; | ||
m_runtime_rdata.resize(a_num_runtime_real); | ||
m_runtime_idata.resize(a_num_runtime_int ); | ||
m_rdata_names = soa_rdata_names; | ||
Check warning Code scanning / CodeQL Local variable address stored in non-local memory Warning
A stack address which arrived via a
parameter Error loading related location Loading |
||
m_idata_names = soa_idata_names; | ||
Check warning Code scanning / CodeQL Local variable address stored in non-local memory Warning
A stack address which arrived via a
parameter Error loading related location Loading |
||
} | ||
|
||
[[nodiscard]] int NumRealComps () const noexcept { return NReal + m_runtime_rdata.size(); } | ||
|
@@ -79,6 +90,32 @@ | |
} | ||
} | ||
|
||
/** Get access to a particle Real component Array (compile-time and runtime component) | ||
* | ||
* @param name named component component with 0...NReal-1 compile-time and NReal... runtime arguments | ||
*/ | ||
[[nodiscard]] RealVector& GetRealData (std::string const & name) { | ||
AMREX_ALWAYS_ASSERT_WITH_MESSAGE(m_rdata_names != nullptr, "SoA Real names were not defined."); | ||
auto const pos = std::find(m_rdata_names->begin(), m_rdata_names->end(), name); | ||
AMREX_ALWAYS_ASSERT_WITH_MESSAGE(pos != m_rdata_names->end(), "Soa Real name='" + name + "' was not found components"); | ||
|
||
int const index = std::distance(m_rdata_names->begin(), pos); | ||
return GetRealData(index); | ||
} | ||
|
||
/** Get access to a particle Real component Array (compile-time and runtime component) | ||
* | ||
* @param name named component component with 0...NReal-1 compile-time and NReal... runtime arguments | ||
*/ | ||
[[nodiscard]] const RealVector& GetRealData (std::string const & name) const { | ||
AMREX_ALWAYS_ASSERT_WITH_MESSAGE(m_rdata_names != nullptr, "SoA Real names were not defined."); | ||
auto const pos = std::find(m_rdata_names->begin(), m_rdata_names->end(), name); | ||
AMREX_ALWAYS_ASSERT_WITH_MESSAGE(pos != m_rdata_names->end(), "Soa Real name='" + name + "' was not found components"); | ||
|
||
int const index = std::distance(m_rdata_names->begin(), pos); | ||
return GetRealData(index); | ||
} | ||
|
||
/** Get access to a particle Int component Array (compile-time and runtime component) | ||
* | ||
* @param index component with 0...NInt-1 compile-time and NInt... runtime arguments | ||
|
@@ -118,6 +155,34 @@ | |
} | ||
} | ||
|
||
/** Get access to a particle Int component Array (compile-time and runtime component) | ||
* | ||
* @param index component with 0...NInt-1 compile-time and NInt... runtime arguments | ||
* @return | ||
*/ | ||
[[nodiscard]] IntVector& GetIntData (std::string const & name) { | ||
AMREX_ALWAYS_ASSERT_WITH_MESSAGE(m_idata_names != nullptr, "SoA Int names were not defined."); | ||
auto const pos = std::find(m_idata_names->begin(), m_idata_names->end(), name); | ||
AMREX_ALWAYS_ASSERT_WITH_MESSAGE(pos != m_idata_names->end(), "Soa Int name='" + name + "' was not found components"); | ||
|
||
int const index = std::distance(m_idata_names->begin(), pos); | ||
return GetIntData(index); | ||
} | ||
|
||
/** Get access to a particle Int component Array (compile-time and runtime component) | ||
* | ||
* @param index component with 0...NInt-1 compile-time and NInt... runtime arguments | ||
* @return | ||
*/ | ||
[[nodiscard]] const IntVector& GetIntData (std::string const & name) const { | ||
AMREX_ALWAYS_ASSERT_WITH_MESSAGE(m_idata_names != nullptr, "SoA Int names were not defined."); | ||
auto const pos = std::find(m_idata_names->begin(), m_idata_names->end(), name); | ||
AMREX_ALWAYS_ASSERT_WITH_MESSAGE(pos != m_idata_names->end(), "Soa Int name='" + name + "' was not found components"); | ||
|
||
int const index = std::distance(m_idata_names->begin(), pos); | ||
return GetIntData(index); | ||
} | ||
|
||
/** | ||
* \brief Returns the total number of particles (real and neighbor) | ||
* | ||
|
@@ -226,13 +291,20 @@ | |
int m_num_neighbor_particles{0}; | ||
|
||
private: | ||
// compile-time data | ||
IdCPU m_idcpu; | ||
std::array<RealVector, NReal> m_rdata; | ||
std::array< IntVector, NInt> m_idata; | ||
|
||
// runtime data | ||
std::vector<RealVector> m_runtime_rdata; | ||
std::vector<IntVector > m_runtime_idata; | ||
|
||
// names of both compile-time and runtime Real and Int data | ||
std::vector<std::string>* m_rdata_names = nullptr; | ||
std::vector<std::string>* m_idata_names = nullptr; | ||
Comment on lines
+303
to
+305
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. We could own the names here and let PC and ParticleTile reference them... |
||
|
||
//! whether the runtime components are sized correctly | ||
bool m_defined{false}; | ||
}; | ||
|
||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
foreach(D IN LISTS AMReX_SPACEDIM) | ||
set(_sources main.cpp) | ||
#set(_input_files) | ||
#set(_input_files inputs) | ||
|
||
setup_test(${D} _sources _input_files NTHREADS 2) | ||
|
||
unset(_sources) | ||
unset(_input_files) | ||
endforeach() |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
AMREX_HOME = ../../../ | ||
|
||
DEBUG = FALSE | ||
|
||
DIM = 3 | ||
|
||
COMP = gcc | ||
|
||
USE_MPI = TRUE | ||
USE_OMP = FALSE | ||
USE_CUDA = FALSE | ||
|
||
#TINY_PROFILE = TRUE | ||
USE_PARTICLES = TRUE | ||
|
||
include $(AMREX_HOME)/Tools/GNUMake/Make.defs | ||
|
||
include ./Make.package | ||
include $(AMREX_HOME)/Src/Base/Make.package | ||
include $(AMREX_HOME)/Src/Particle/Make.package | ||
|
||
include $(AMREX_HOME)/Tools/GNUMake/Make.rules |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
CEXE_sources += main.cpp |
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 discussed that we want to make this two functions (one for real, one for int) that take the ParticleType and index to return a default name on the current index.
This way, we can reuse this in the:
AddRealComp
/AddIntComp
withoutname
argument