Nektar++
Loading...
Searching...
No Matches
Public Member Functions | Protected Attributes | List of all members
TestParallelReduce< TData > Class Template Reference

#include <TestParallelReduce.hpp>

Public Member Functions

 TestParallelReduce ()
 
 ~TestParallelReduce ()
 
void Configure ()
 
void SetTestCase ()
 
TData sum ()
 
TData max ()
 
TData min ()
 

Protected Attributes

std::string m_meshName = ""
 
Field< TData, FieldState::Phys > * m_in = nullptr
 
ExpListSharedPtr m_expList
 
SessionReaderSharedPtr m_session
 

Detailed Description

template<typename TData>
class TestParallelReduce< TData >

Definition at line 65 of file TestParallelReduce.hpp.

Constructor & Destructor Documentation

◆ TestParallelReduce()

template<typename TData >
TestParallelReduce< TData >::TestParallelReduce ( )
inline

Definition at line 68 of file TestParallelReduce.hpp.

69 {
70 m_meshName = "run/segment.xml";
71 }

References TestParallelReduce< TData >::m_meshName.

◆ ~TestParallelReduce()

template<typename TData >
TestParallelReduce< TData >::~TestParallelReduce ( )
inline

Definition at line 73 of file TestParallelReduce.hpp.

74 {
75 BOOST_TEST_MESSAGE("teardown this->fixture");
76
77 if (this->m_in)
78 {
79 delete this->m_in;
80 }
81 }
Field< TData, FieldState::Phys > * m_in

References TestParallelReduce< TData >::m_in.

Member Function Documentation

◆ Configure()

template<typename TData >
void TestParallelReduce< TData >::Configure ( )
inline

Definition at line 83 of file TestParallelReduce.hpp.

84 {
85 BOOST_TEST_MESSAGE("Creating input and output fields");
86
87 // Construct a fake command-line argument array to be fed to
88 // Session::Reader::CreateInstance. The first element stands for
89 // the name of the executable which, in our case, doesn't matter.
90 int argc = 2;
91 char **argv = new char *[argc];
92 argv[0] = strdup("exe_name");
93 argv[1] = strdup(m_meshName.data());
94
95 this->m_session = SessionReader::CreateInstance(argc, argv);
97
98 for (int i = 0; i < argc; ++i)
99 {
100 free(argv[i]);
101 }
102 delete[] argv;
103
105 this->m_session, graph, true, "u", Collections::eNoCollection);
106
107 // One component per session variable, so the reducers are exercised
108 // over a field wider than a single component.
109 const auto &components = this->m_session->GetVariables();
110 auto blocksAttr = GetBlockAttributes<TData, FieldState::Phys>(
111 m_expList, MultiRegions::UnitInterleaveWidths(m_expList));
112 auto f_in =
113 Field<TData, FieldState::Phys>("f_in", blocksAttr, components, 1);
114 m_in = new Field<TData, FieldState::Phys>(std::move(f_in));
115 }
SpatialDomains::MeshGraphSharedPtr graph
A Field represents expansion data to be operated on.
static SessionReaderSharedPtr CreateInstance(int argc, char *argv[])
Creates an instance of the SessionReader class.
static std::shared_ptr< DataType > AllocateSharedPtr(const Args &...args)
Allocate a shared pointer from the memory pool.
static MeshGraphSharedPtr Read(const LibUtilities::SessionReaderSharedPtr pSession, LibUtilities::DomainRangeShPtr rng=LibUtilities::NullDomainRangeShPtr, bool fillGraph=true, SpatialDomains::MeshGraphSharedPtr partitionedGraph=nullptr)
ExpListSharedPtr m_expList
SessionReaderSharedPtr m_session

References Nektar::MemoryManager< DataType >::AllocateSharedPtr(), Nektar::LibUtilities::SessionReader::CreateInstance(), Nektar::Collections::eNoCollection, graph, TestParallelReduce< TData >::m_expList, TestParallelReduce< TData >::m_in, TestParallelReduce< TData >::m_meshName, TestParallelReduce< TData >::m_session, and Nektar::SpatialDomains::MeshGraphIO::Read().

◆ max()

template<typename TData >
TData TestParallelReduce< TData >::max ( )
inline

Definition at line 166 of file TestParallelReduce.hpp.

167 {
168 TData out = std::numeric_limits<TData>::lowest();
169 for (unsigned int blk = 0; blk < this->m_in->GetBlocks().size(); ++blk)
170 {
171 auto x = this->m_in->GetBlocks()[blk]
172 .template GetPtr<NektarSpaces::HostSpace, ReadOnly>();
173 auto size = this->m_in->GetBlocks()[blk].GetNumElements() *
174 this->m_in->GetBlocks()[blk].GetNumData();
175 auto stride = this->m_in->GetBlocks()[blk].CompSize();
176
177 for (unsigned int nc = 0; nc < this->m_in->GetNumComponents();
178 ++nc, x += stride)
179 {
180 out = std::max(out, *(std::max_element(x, x + size)));
181 }
182 }
183 return out;
184 }
std::vector< BlockAccessor< TData, TState > > & GetBlocks()
Get BlockAccessors for the field.
unsigned int GetNumComponents() const
Gets the number of components for a vector field.
NEK_DEVICE_KERNEL void const TData *NEK_RESTRICT const TData *NEK_RESTRICT const size_t const unsigned int const unsigned int const unsigned int const unsigned int const size_t const TData *NEK_RESTRICT const TData *NEK_RESTRICT const TUseSharedWsp TData *NEK_RESTRICT const TData *NEK_RESTRICT TData *NEK_RESTRICT out

References Nektar::LibUtilities::Field< TData, TState >::GetBlocks(), Nektar::LibUtilities::Field< TData, TState >::GetNumComponents(), and TestParallelReduce< TData >::m_in.

◆ min()

template<typename TData >
TData TestParallelReduce< TData >::min ( )
inline

Definition at line 186 of file TestParallelReduce.hpp.

187 {
188 TData out = std::numeric_limits<TData>::max();
189 for (unsigned int blk = 0; blk < this->m_in->GetBlocks().size(); ++blk)
190 {
191 auto x = this->m_in->GetBlocks()[blk]
192 .template GetPtr<NektarSpaces::HostSpace, ReadOnly>();
193 auto size = this->m_in->GetBlocks()[blk].GetNumElements() *
194 this->m_in->GetBlocks()[blk].GetNumData();
195 auto stride = this->m_in->GetBlocks()[blk].CompSize();
196
197 for (unsigned int nc = 0; nc < this->m_in->GetNumComponents();
198 ++nc, x += stride)
199 {
200 out = std::min(out, *(std::min_element(x, x + size)));
201 }
202 }
203 return out;
204 }

References Nektar::LibUtilities::Field< TData, TState >::GetBlocks(), Nektar::LibUtilities::Field< TData, TState >::GetNumComponents(), and TestParallelReduce< TData >::m_in.

◆ SetTestCase()

template<typename TData >
void TestParallelReduce< TData >::SetTestCase ( )
inline

Definition at line 117 of file TestParallelReduce.hpp.

118 {
119 // GetCoords() and Equation::Evaluate() take double arrays, whatever
120 // TData is; the values are narrowed when copied into the field.
121 Array<OneD, double> x(this->m_expList->GetTotPoints(), 0.0);
122 Array<OneD, double> y(this->m_expList->GetTotPoints(), 0.0);
123 Array<OneD, double> z(this->m_expList->GetTotPoints(), 0.0);
124 Array<OneD, double> fce(this->m_expList->GetTotPoints());
125 this->m_expList->GetCoords(x, y, z);
126
127 for (unsigned int nc = 0; nc < this->m_in->GetNumComponents(); ++nc)
128 {
129 auto func = this->m_session->GetFunction("Forcing", nc);
130 func->Evaluate(x, y, z, fce);
131
132 auto ptr = fce.data();
133 for (unsigned int blk = 0; blk < this->m_in->GetBlocks().size();
134 ++blk)
135 {
136 auto &block = this->m_in->GetBlocks()[blk];
137 auto inptr =
138 block.template GetPtr<NektarSpaces::HostSpace, WriteOnly>();
139 auto size = block.GetNumElements() * block.GetNumData();
140 std::copy(ptr, ptr + size, inptr + nc * block.CompSize());
141 ptr += size;
142 }
143 }
144 }

References Nektar::LibUtilities::Field< TData, TState >::GetBlocks(), Nektar::LibUtilities::Field< TData, TState >::GetNumComponents(), TestParallelReduce< TData >::m_expList, TestParallelReduce< TData >::m_in, and TestParallelReduce< TData >::m_session.

◆ sum()

template<typename TData >
TData TestParallelReduce< TData >::sum ( )
inline

Definition at line 146 of file TestParallelReduce.hpp.

147 {
148 TData out = 0;
149 for (unsigned int blk = 0; blk < this->m_in->GetBlocks().size(); ++blk)
150 {
151 auto x = this->m_in->GetBlocks()[blk]
152 .template GetPtr<NektarSpaces::HostSpace, ReadOnly>();
153 auto size = this->m_in->GetBlocks()[blk].GetNumElements() *
154 this->m_in->GetBlocks()[blk].GetNumData();
155 auto stride = this->m_in->GetBlocks()[blk].CompSize();
156
157 for (unsigned int nc = 0; nc < this->m_in->GetNumComponents();
158 ++nc, x += stride)
159 {
160 out = std::accumulate(x, x + size, out);
161 }
162 }
163 return out;
164 }

References Nektar::LibUtilities::Field< TData, TState >::GetBlocks(), Nektar::LibUtilities::Field< TData, TState >::GetNumComponents(), and TestParallelReduce< TData >::m_in.

Member Data Documentation

◆ m_expList

template<typename TData >
ExpListSharedPtr TestParallelReduce< TData >::m_expList
protected

◆ m_in

template<typename TData >
Field<TData, FieldState::Phys>* TestParallelReduce< TData >::m_in = nullptr
protected

◆ m_meshName

template<typename TData >
std::string TestParallelReduce< TData >::m_meshName = ""
protected

◆ m_session

template<typename TData >
SessionReaderSharedPtr TestParallelReduce< TData >::m_session
protected