Skip to content

Commit 537a556

Browse files
authored
SENSEI: Allocator (AMReX-Codes#4949)
## Summary Add the `Allocator` template, so we can use this with polymorphic PCs (and generally any PC that does not use the default allocator). ## Additional background Same as AMReX-Codes#4776 AMReX-Codes#4948 but for SENSEI. ## Checklist The proposed changes: - [ ] fix a bug or incorrect behavior in AMReX - [x] add new capabilities to AMReX - [ ] changes answers in the test suite to more than roundoff level - [ ] are likely to significantly affect the results of downstream AMReX users - [ ] include documentation in the code and/or rst files, if appropriate
1 parent 6229666 commit 537a556

10 files changed

Lines changed: 149 additions & 148 deletions

Src/Extern/Conduit/AMReX_Conduit_Blueprint_ParticlesI.H

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,11 +20,12 @@ namespace amrex
2020
// Note:
2121
// This is a helper function, it's not part of the AMReX Blueprint Interface.
2222
//---------------------------------------------------------------------------//
23-
template <typename ParticleType, int NArrayReal, int NArrayInt>
23+
template <typename ParticleType, int NArrayReal, int NArrayInt, template<class> class Allocator=DefaultAllocator>
2424
void
2525
ParticleTileToBlueprint(const ParticleTile<ParticleType,
2626
NArrayReal,
27-
NArrayInt> &ptile,
27+
NArrayInt,
28+
Allocator> &ptile,
2829
const Vector<std::string> &real_comp_names,
2930
const Vector<std::string> &int_comp_names,
3031
conduit::Node &res,

Src/Extern/SENSEI/AMReX_AmrMeshParticleDataAdaptor.H

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616

1717
namespace amrex
1818
{
19-
template<typename ParticleType, int NArrayReal, int NArrayInt>
19+
template<typename ParticleType, int NArrayReal, int NArrayInt, template<class> class Allocator=DefaultAllocator>
2020
class AmrMeshParticleDataAdaptor : public sensei::DataAdaptor
2121
{
2222
public:
@@ -27,7 +27,7 @@ public:
2727
AmrMesh *mesh,
2828
const std::vector<amrex::Vector<amrex::MultiFab>*> &mesh_states,
2929
const std::vector<std::vector<std::string>> &mesh_names,
30-
amrex::ParticleContainer_impl<ParticleType, NArrayReal, NArrayInt> * particles,
30+
amrex::ParticleContainer_impl<ParticleType, NArrayReal, NArrayInt, Allocator> * particles,
3131
const std::map<std::string, std::vector<int>> & rStructs = {},
3232
const std::map<std::string, int> & iStructs = {},
3333
const std::map<std::string, std::vector<int>> & rArrays = {},
@@ -55,7 +55,7 @@ protected:
5555
AmrMeshParticleDataAdaptor()
5656
{
5757
m_meshAdaptor = AmrMeshDataAdaptor::New();
58-
m_particleAdaptor = ParticleDataAdaptor<ParticleType, NArrayReal, NArrayInt>::New();
58+
m_particleAdaptor = ParticleDataAdaptor<ParticleType, NArrayReal, NArrayInt, Allocator>::New();
5959
}
6060

6161
~AmrMeshParticleDataAdaptor()
@@ -65,7 +65,7 @@ protected:
6565
}
6666

6767
private:
68-
ParticleDataAdaptor<ParticleType, NArrayReal, NArrayInt>* m_particleAdaptor;
68+
ParticleDataAdaptor<ParticleType, NArrayReal, NArrayInt, Allocator>* m_particleAdaptor;
6969
AmrMeshDataAdaptor* m_meshAdaptor;
7070

7171
const std::string m_meshName = "mesh";

Src/Extern/SENSEI/AMReX_AmrMeshParticleDataAdaptorI.H

Lines changed: 31 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -3,22 +3,22 @@
33
namespace amrex
44
{
55
//-----------------------------------------------------------------------------
6-
template <typename ParticleType, int NArrayReal, int NArrayInt>
7-
AmrMeshParticleDataAdaptor<ParticleType, NArrayReal, NArrayInt>*
8-
AmrMeshParticleDataAdaptor<ParticleType, NArrayReal, NArrayInt>::New()
6+
template <typename ParticleType, int NArrayReal, int NArrayInt, template<class> class Allocator>
7+
AmrMeshParticleDataAdaptor<ParticleType, NArrayReal, NArrayInt, Allocator>*
8+
AmrMeshParticleDataAdaptor<ParticleType, NArrayReal, NArrayInt, Allocator>::New()
99
{
10-
auto result = new AmrMeshParticleDataAdaptor<ParticleType, NArrayReal, NArrayInt>;
10+
auto result = new AmrMeshParticleDataAdaptor<ParticleType, NArrayReal, NArrayInt, Allocator>;
1111
result->InitializeObjectBase();
1212
return result;
1313
}
1414

1515
//-----------------------------------------------------------------------------
16-
template<typename ParticleType, int NArrayReal, int NArrayInt>
17-
int AmrMeshParticleDataAdaptor<ParticleType, NArrayReal, NArrayInt>::SetDataSource(
16+
template<typename ParticleType, int NArrayReal, int NArrayInt, template<class> class Allocator>
17+
int AmrMeshParticleDataAdaptor<ParticleType, NArrayReal, NArrayInt, Allocator>::SetDataSource(
1818
AmrMesh *mesh,
1919
const std::vector<amrex::Vector<amrex::MultiFab>*> &mesh_states,
2020
const std::vector<std::vector<std::string>> &mesh_names,
21-
amrex::ParticleContainer_impl<ParticleType, NArrayReal, NArrayInt> * particles,
21+
amrex::ParticleContainer_impl<ParticleType, NArrayReal, NArrayInt, Allocator> * particles,
2222
const std::map<std::string, std::vector<int>> & rStructs,
2323
const std::map<std::string, int> & iStructs,
2424
const std::map<std::string, std::vector<int>> & rArrays,
@@ -31,8 +31,8 @@ int AmrMeshParticleDataAdaptor<ParticleType, NArrayReal, NArrayInt>::SetDataSour
3131

3232
// SENSEI API
3333
#if SENSEI_VERSION_MAJOR >= 3
34-
template<typename ParticleType, int NArrayReal, int NArrayInt>
35-
int AmrMeshParticleDataAdaptor<ParticleType, NArrayReal, NArrayInt>::GetMeshMetadata(
34+
template<typename ParticleType, int NArrayReal, int NArrayInt, template<class> class Allocator>
35+
int AmrMeshParticleDataAdaptor<ParticleType, NArrayReal, NArrayInt, Allocator>::GetMeshMetadata(
3636
unsigned int id,
3737
sensei::MeshMetadataPtr &metadata)
3838
{
@@ -49,8 +49,8 @@ int AmrMeshParticleDataAdaptor<ParticleType, NArrayReal, NArrayInt>::GetMeshMeta
4949
}
5050

5151
#else
52-
template<typename ParticleType, int NArrayReal, int NArrayInt>
53-
int AmrMeshParticleDataAdaptor<ParticleType, NArrayReal, NArrayInt>::GetMeshName(
52+
template<typename ParticleType, int NArrayReal, int NArrayInt, template<class> class Allocator>
53+
int AmrMeshParticleDataAdaptor<ParticleType, NArrayReal, NArrayInt, Allocator>::GetMeshName(
5454
unsigned int id,
5555
std::string &meshName)
5656
{
@@ -66,8 +66,8 @@ int AmrMeshParticleDataAdaptor<ParticleType, NArrayReal, NArrayInt>::GetMeshName
6666
return -1;
6767
}
6868

69-
template<typename ParticleType, int NArrayReal, int NArrayInt>
70-
int AmrMeshParticleDataAdaptor<ParticleType, NArrayReal, NArrayInt>::GetMeshHasGhostNodes(
69+
template<typename ParticleType, int NArrayReal, int NArrayInt, template<class> class Allocator>
70+
int AmrMeshParticleDataAdaptor<ParticleType, NArrayReal, NArrayInt, Allocator>::GetMeshHasGhostNodes(
7171
const std::string &meshName, int &nLayers)
7272
{
7373
if(id == 0)
@@ -82,8 +82,8 @@ int AmrMeshParticleDataAdaptor<ParticleType, NArrayReal, NArrayInt>::GetMeshHasG
8282
return -1;
8383
}
8484

85-
template<typename ParticleType, int NArrayReal, int NArrayInt>
86-
int AmrMeshParticleDataAdaptor<ParticleType, NArrayReal, NArrayInt>::GetMeshHasGhostCells(
85+
template<typename ParticleType, int NArrayReal, int NArrayInt, template<class> class Allocator>
86+
int AmrMeshParticleDataAdaptor<ParticleType, NArrayReal, NArrayInt, Allocator>::GetMeshHasGhostCells(
8787
const std::string &meshName, int &nLayers)
8888
{
8989
if(id == 0)
@@ -98,8 +98,8 @@ int AmrMeshParticleDataAdaptor<ParticleType, NArrayReal, NArrayInt>::GetMeshHasG
9898
return -1;
9999
}
100100

101-
template<typename ParticleType, int NArrayReal, int NArrayInt>
102-
int AmrMeshParticleDataAdaptor<ParticleType, NArrayReal, NArrayInt>::GetNumberOfArrays(
101+
template<typename ParticleType, int NArrayReal, int NArrayInt, template<class> class Allocator>
102+
int AmrMeshParticleDataAdaptor<ParticleType, NArrayReal, NArrayInt, Allocator>::GetNumberOfArrays(
103103
const std::string &meshName,
104104
int association,
105105
unsigned int &numberOfArrays)
@@ -116,8 +116,8 @@ int AmrMeshParticleDataAdaptor<ParticleType, NArrayReal, NArrayInt>::GetNumberOf
116116
return -1;
117117
}
118118

119-
template<typename ParticleType, int NArrayReal, int NArrayInt>
120-
int AmrMeshParticleDataAdaptor<ParticleType, NArrayReal, NArrayInt>::GetArrayName(
119+
template<typename ParticleType, int NArrayReal, int NArrayInt, template<class> class Allocator>
120+
int AmrMeshParticleDataAdaptor<ParticleType, NArrayReal, NArrayInt, Allocator>::GetArrayName(
121121
const std::string &meshName,
122122
int association,
123123
unsigned int index,
@@ -136,16 +136,16 @@ int AmrMeshParticleDataAdaptor<ParticleType, NArrayReal, NArrayInt>::GetArrayNam
136136
}
137137
#endif
138138

139-
template<typename ParticleType, int NArrayReal, int NArrayInt>
140-
int AmrMeshParticleDataAdaptor<ParticleType, NArrayReal, NArrayInt>::GetNumberOfMeshes(
139+
template<typename ParticleType, int NArrayReal, int NArrayInt, template<class> class Allocator>
140+
int AmrMeshParticleDataAdaptor<ParticleType, NArrayReal, NArrayInt, Allocator>::GetNumberOfMeshes(
141141
unsigned int &numMeshes)
142142
{
143143
numMeshes = 2;
144144
return 0;
145145
}
146146

147-
template<typename ParticleType, int NArrayReal, int NArrayInt>
148-
int AmrMeshParticleDataAdaptor<ParticleType, NArrayReal, NArrayInt>::GetMesh(
147+
template<typename ParticleType, int NArrayReal, int NArrayInt, template<class> class Allocator>
148+
int AmrMeshParticleDataAdaptor<ParticleType, NArrayReal, NArrayInt, Allocator>::GetMesh(
149149
const std::string &meshName,
150150
bool structureOnly,
151151
svtkDataObject *&mesh)
@@ -162,8 +162,8 @@ int AmrMeshParticleDataAdaptor<ParticleType, NArrayReal, NArrayInt>::GetMesh(
162162
return -1;
163163
}
164164

165-
template<typename ParticleType, int NArrayReal, int NArrayInt>
166-
int AmrMeshParticleDataAdaptor<ParticleType, NArrayReal, NArrayInt>::AddGhostNodesArray(
165+
template<typename ParticleType, int NArrayReal, int NArrayInt, template<class> class Allocator>
166+
int AmrMeshParticleDataAdaptor<ParticleType, NArrayReal, NArrayInt, Allocator>::AddGhostNodesArray(
167167
svtkDataObject* mesh,
168168
const std::string &meshName)
169169
{
@@ -179,8 +179,8 @@ int AmrMeshParticleDataAdaptor<ParticleType, NArrayReal, NArrayInt>::AddGhostNod
179179
return -1;
180180
}
181181

182-
template<typename ParticleType, int NArrayReal, int NArrayInt>
183-
int AmrMeshParticleDataAdaptor<ParticleType, NArrayReal, NArrayInt>::AddGhostCellsArray(
182+
template<typename ParticleType, int NArrayReal, int NArrayInt, template<class> class Allocator>
183+
int AmrMeshParticleDataAdaptor<ParticleType, NArrayReal, NArrayInt, Allocator>::AddGhostCellsArray(
184184
svtkDataObject* mesh,
185185
const std::string &meshName)
186186
{
@@ -196,8 +196,8 @@ int AmrMeshParticleDataAdaptor<ParticleType, NArrayReal, NArrayInt>::AddGhostCel
196196
return -1;
197197
}
198198

199-
template<typename ParticleType, int NArrayReal, int NArrayInt>
200-
int AmrMeshParticleDataAdaptor<ParticleType, NArrayReal, NArrayInt>::AddArray(
199+
template<typename ParticleType, int NArrayReal, int NArrayInt, template<class> class Allocator>
200+
int AmrMeshParticleDataAdaptor<ParticleType, NArrayReal, NArrayInt, Allocator>::AddArray(
201201
svtkDataObject* mesh,
202202
const std::string &meshName,
203203
int association,
@@ -215,8 +215,8 @@ int AmrMeshParticleDataAdaptor<ParticleType, NArrayReal, NArrayInt>::AddArray(
215215
return -1;
216216
}
217217

218-
template<typename ParticleType, int NArrayReal, int NArrayInt>
219-
int AmrMeshParticleDataAdaptor<ParticleType, NArrayReal, NArrayInt>::ReleaseData()
218+
template<typename ParticleType, int NArrayReal, int NArrayInt, template<class> class Allocator>
219+
int AmrMeshParticleDataAdaptor<ParticleType, NArrayReal, NArrayInt, Allocator>::ReleaseData()
220220
{
221221
this->m_particleAdaptor->ReleaseData();
222222
this->m_meshAdaptor->ReleaseData();

Src/Extern/SENSEI/AMReX_AmrMeshParticleInSituBridge.H

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -33,26 +33,26 @@ public:
3333

3434
// invoke the in situ analysis with data from an AmrMesh and ParticleContainer
3535
// instance.
36-
template<typename ParticleType, int NArrayReal, int NArrayInt>
36+
template<typename ParticleType, int NArrayReal, int NArrayInt, template<class> class Allocator=DefaultAllocator>
3737
int update(
3838
long step, double time,
3939
amrex::AmrMesh *mesh,
4040
const std::vector<amrex::Vector<amrex::MultiFab>*> &mesh_states,
4141
const std::vector<std::vector<std::string>> &mesh_names,
42-
amrex::ParticleContainer_impl<ParticleType, NArrayReal, NArrayInt> * particles,
42+
amrex::ParticleContainer_impl<ParticleType, NArrayReal, NArrayInt, Allocator> * particles,
4343
const std::map<std::string, std::vector<int>> & particles_rStructs = {},
4444
const std::map<std::string, int> & particles_iStructs = {},
4545
const std::map<std::string, std::vector<int>> & particles_rArrays = {},
4646
const std::map<std::string, int> & particles_iArrays = {});
4747
};
4848

49-
template<typename ParticleType, int NArrayReal, int NArrayInt>
49+
template<typename ParticleType, int NArrayReal, int NArrayInt, template<class> class Allocator>
5050
int AmrMeshParticleInSituBridge::update(
5151
long step, double time,
5252
amrex::AmrMesh *mesh,
5353
const std::vector<amrex::Vector<amrex::MultiFab>*> &mesh_states,
5454
const std::vector<std::vector<std::string>> &mesh_names,
55-
amrex::ParticleContainer_impl<ParticleType, NArrayReal, NArrayInt> * particles,
55+
amrex::ParticleContainer_impl<ParticleType, NArrayReal, NArrayInt, Allocator> * particles,
5656
const std::map<std::string, std::vector<int>> & particles_rStructs,
5757
const std::map<std::string, int> & particles_iStructs,
5858
const std::map<std::string, std::vector<int>> & particles_rArrays,
@@ -73,8 +73,8 @@ int AmrMeshParticleInSituBridge::update(
7373
return -1;
7474
}
7575

76-
amrex::AmrMeshParticleDataAdaptor<ParticleType, NArrayReal, NArrayInt> *data_adaptor
77-
= amrex::AmrMeshParticleDataAdaptor<ParticleType, NArrayReal, NArrayInt>::New();
76+
amrex::AmrMeshParticleDataAdaptor<ParticleType, NArrayReal, NArrayInt, Allocator> *data_adaptor
77+
= amrex::AmrMeshParticleDataAdaptor<ParticleType, NArrayReal, NArrayInt, Allocator>::New();
7878

7979
if (comm != MPI_COMM_NULL)
8080
data_adaptor->SetCommunicator(comm);

Src/Extern/SENSEI/AMReX_AmrParticleDataAdaptor.H

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616

1717
namespace amrex
1818
{
19-
template<typename ParticleType, int NArrayReal, int NArrayInt>
19+
template<typename ParticleType, int NArrayReal, int NArrayInt, template<class> class Allocator=DefaultAllocator>
2020
class AmrParticleDataAdaptor : public sensei::DataAdaptor
2121
{
2222
public:
@@ -25,7 +25,7 @@ public:
2525

2626
int SetDataSource(
2727
Amr *amr,
28-
amrex::ParticleContainer_impl<ParticleType, NArrayReal, NArrayInt> * particles,
28+
amrex::ParticleContainer_impl<ParticleType, NArrayReal, NArrayInt, Allocator> * particles,
2929
const std::map<std::string, std::vector<int>> & rStructs = {},
3030
const std::map<std::string, int> & iStructs = {},
3131
const std::map<std::string, std::vector<int>> & rArrays = {},
@@ -53,7 +53,7 @@ protected:
5353
AmrParticleDataAdaptor()
5454
{
5555
m_meshAdaptor = AmrDataAdaptor::New();
56-
m_particleAdaptor = ParticleDataAdaptor<ParticleType, NArrayReal, NArrayInt>::New();
56+
m_particleAdaptor = ParticleDataAdaptor<ParticleType, NArrayReal, NArrayInt, Allocator>::New();
5757
}
5858

5959
~AmrParticleDataAdaptor()
@@ -63,7 +63,7 @@ protected:
6363
}
6464

6565
private:
66-
ParticleDataAdaptor<ParticleType, NArrayReal, NArrayInt>* m_particleAdaptor;
66+
ParticleDataAdaptor<ParticleType, NArrayReal, NArrayInt, Allocator>* m_particleAdaptor;
6767
AmrDataAdaptor* m_meshAdaptor;
6868

6969
const std::string m_meshName = "mesh";

0 commit comments

Comments
 (0)