Nektar++
Loading...
Searching...
No Matches
Macros | Functions
ProfilerRiemannOps.hpp File Reference
#include <cmath>
#include <cstdio>
#include <iomanip>
#include <iostream>
#include <LibUtilities/BasicUtils/Field/Field.hpp>
#include <LibUtilities/BasicUtils/Math/Math.hpp>
#include <LibUtilities/BasicUtils/Utils/UtilsKernels.hpp>
#include <LibUtilities/LoopExecution/LoopExecution.hpp>
#include <LibUtilities/BasicUtils/ErrorUtil.hpp>
#include <LibUtilities/BasicUtils/Timer.h>
#include <MultiRegions/DisContField.h>
#include <MultiRegions/ExpList.h>
#include <SpatialDomains/MeshGraphIO.h>
#include <CompressibleFlowSolverRedesign/AdvTraceFluxCFE/AdvTraceFluxCFEOp.hpp>
#include <LibUtilities/BasicUtils/StringUtils.hpp>

Go to the source code of this file.

Macros

#define LIKWID_MARKER_INIT
 
#define LIKWID_MARKER_THREADINIT
 
#define LIKWID_MARKER_SWITCH
 
#define LIKWID_MARKER_REGISTER(regionTag)
 
#define LIKWID_MARKER_START(regionTag)
 
#define LIKWID_MARKER_STOP(regionTag)
 
#define LIKWID_MARKER_CLOSE
 
#define LIKWID_MARKER_GET(regionTag, nevents, events, time, count)
 

Functions

template<typename TData >
static Array< OneD, TData > FlattenCompMajor (const Array< OneD, Array< OneD, TData > > &a, unsigned int ncomp, size_t npts)
 
template<typename TData >
static void UnflattenCompMajor (const Array< OneD, TData > &flat, Array< OneD, Array< OneD, TData > > &a, unsigned int ncomp, size_t npts)
 
void GetExpectedResults (unsigned int spaceDim, size_t npts, const Array< OneD, Array< OneD, double > > &normals, Array< OneD, Array< OneD, double > > &fwd, Array< OneD, Array< OneD, double > > &bwd, Array< OneD, Array< OneD, double > > &flxRef, double gamma=1.4)
 Compute the expected results of certain operator from the expList.
 
template<FieldState TState>
void PrintBlockInfo (const MultiRegions::ExpListSharedPtr &expList, const std::vector< LibUtilities::BlockAttributes< TState > > &blockAttr, std::vector< double > &rankL1Err)
 Print the block information. If verbose=true, then print the block information for each rank. If verbose=false, then only print the total information for each rank. Caution: for many ranks and many blocks, setting verbose may cause the display content too big to read.
 
template<typename TData , FieldState TState>
void PrintProfileResult (const CommSharedPtr comm, std::vector< double > &rankElapsed, const std::vector< LibUtilities::BlockAttributes< TState > > &traceblockAttr)
 Print the profiler results, computed from the elapsed time and the total number of dofs.
 
template<typename TData >
void LaunchProfiler (MultiRegions::ExpListSharedPtr const &expList, const unsigned int Ntest, const std::string &method="", const unsigned int nHomo=1)
 

Macro Definition Documentation

◆ LIKWID_MARKER_CLOSE

#define LIKWID_MARKER_CLOSE

Definition at line 67 of file ProfilerRiemannOps.hpp.

◆ LIKWID_MARKER_GET

#define LIKWID_MARKER_GET (   regionTag,
  nevents,
  events,
  time,
  count 
)

Definition at line 68 of file ProfilerRiemannOps.hpp.

◆ LIKWID_MARKER_INIT

#define LIKWID_MARKER_INIT

Definition at line 61 of file ProfilerRiemannOps.hpp.

◆ LIKWID_MARKER_REGISTER

#define LIKWID_MARKER_REGISTER (   regionTag)

Definition at line 64 of file ProfilerRiemannOps.hpp.

◆ LIKWID_MARKER_START

#define LIKWID_MARKER_START (   regionTag)

Definition at line 65 of file ProfilerRiemannOps.hpp.

◆ LIKWID_MARKER_STOP

#define LIKWID_MARKER_STOP (   regionTag)

Definition at line 66 of file ProfilerRiemannOps.hpp.

◆ LIKWID_MARKER_SWITCH

#define LIKWID_MARKER_SWITCH

Definition at line 63 of file ProfilerRiemannOps.hpp.

◆ LIKWID_MARKER_THREADINIT

#define LIKWID_MARKER_THREADINIT

Definition at line 62 of file ProfilerRiemannOps.hpp.

Function Documentation

◆ FlattenCompMajor()

template<typename TData >
static Array< OneD, TData > FlattenCompMajor ( const Array< OneD, Array< OneD, TData > > &  a,
unsigned int  ncomp,
size_t  npts 
)
static

Definition at line 77 of file ProfilerRiemannOps.hpp.

79{
80 Array<OneD, TData> flat(ncomp * npts, 0.0);
81 for (unsigned int c = 0; c < ncomp; ++c)
82 {
83 for (size_t i = 0; i < npts; ++i)
84 {
85 flat[c * npts + i] = a[c][i];
86 }
87 }
88 return flat;
89}

Referenced by LaunchProfiler().

◆ GetExpectedResults()

void GetExpectedResults ( unsigned int  spaceDim,
size_t  npts,
const Array< OneD, Array< OneD, double > > &  normals,
Array< OneD, Array< OneD, double > > &  fwd,
Array< OneD, Array< OneD, double > > &  bwd,
Array< OneD, Array< OneD, double > > &  flxRef,
double  gamma = 1.4 
)

Compute the expected results of certain operator from the expList.

Definition at line 106 of file ProfilerRiemannOps.hpp.

112{
113 const unsigned int nFields = spaceDim + 2;
114
115 const double rho = 0.9;
116 const double p = 1.0;
117 double u[3] = {1.0, 2.0, 3.0};
118
119 for (size_t i = 0; i < npts; ++i)
120 {
121 // density
122 fwd[0][i] = rho;
123 bwd[0][i] = rho;
124
125 // momentum
126 double mom[3] = {0, 0, 0};
127 for (unsigned int d = 0; d < spaceDim; ++d)
128 {
129 mom[d] = rho * u[d];
130 fwd[1 + d][i] = mom[d];
131 bwd[1 + d][i] = mom[d];
132 }
133
134 // energy
135 const double rhoe = p / (gamma - 1.0);
136 double kin = 0.0;
137 for (unsigned int d = 0; d < spaceDim; ++d)
138 {
139 kin += 0.5 * mom[d] * mom[d] / rho;
140 }
141 const double E = rhoe + kin;
142 fwd[nFields - 1][i] = E;
143 bwd[nFields - 1][i] = E;
144
145 // normal velocity u_n = u dot n
146 double un = 0.0;
147 for (unsigned int d = 0; d < spaceDim; ++d)
148 {
149 un += u[d] * normals[d][i];
150 }
151
152 // reference flux F·n
153 // mass flux is rho * u_n
154 flxRef[0][i] = rho * un; // mass
155
156 // momentum flux is rho * u * u_n + p * n
157 for (unsigned int k = 0; k < spaceDim; ++k)
158 {
159 flxRef[1 + k][i] = mom[k] * un + p * normals[k][i];
160 }
161
162 // energy flux is (E + p) * u_n
163 flxRef[nFields - 1][i] = (E + p) * un;
164 }
165}
std::vector< double > p(NPUPPER)
std::vector< double > d(NPUPPER *NPUPPER)

Referenced by LaunchProfiler().

◆ LaunchProfiler()

template<typename TData >
void LaunchProfiler ( MultiRegions::ExpListSharedPtr const &  expList,
const unsigned int  Ntest,
const std::string &  method = "",
const unsigned int  nHomo = 1 
)

Definition at line 384 of file ProfilerRiemannOps.hpp.

387{
388 // Timer.
389 Timer timer;
390
391 auto session = expList->GetSession();
392
393 // Get communicator.
394 auto comm = expList->GetComm();
395
396 const unsigned int spaceDim = expList->GetExp(0)->GetShapeDimension();
397 const size_t npts = expList->GetTrace()->GetTotPoints();
398 const unsigned int nFields = (spaceDim + 2) * nHomo;
399
400 // The operator builds the boundary values of the session's variables,
401 // so they must be the conserved ones, with their boundary conditions.
402 const auto &variables = session->GetVariables();
403 ASSERTL0(variables.size() == nFields,
404 "The session must define the " + std::to_string(nFields) +
405 " conserved variables, and their boundary conditions.");
406
407 // Create operator: the Riemann solver for the session's equation of
408 // state, as the solver itself picks it, or the ideal gas's if the session
409 // names none.
410 std::string eos =
411 StringUtils::ToUpperCopy(session->GetEquationOfState().type);
412 if (eos.empty())
413 {
414 eos = "IDEALGAS";
415 }
416 auto oper =
417 AdvTraceFluxCFEOp<TData>::Create(expList, variables, method + eos);
418
419 // Set operator name tag.
420 std::string execName =
422 std::string opName = method;
423 std::string dataType = (std::is_same_v<TData, double>) ? "Double" : "Float";
424 auto tag = opName + execName + dataType;
425
426 // normals: unit along normalDir
427 Array<OneD, Array<OneD, double>> normals(spaceDim);
428 for (unsigned int d = 0; d < spaceDim; ++d)
429 {
430 normals[d] = Array<OneD, double>(npts, 0.0);
431 }
432 for (size_t i = 0; i < npts; ++i)
433 {
434 normals[0][i] = 1.0;
435 }
436
437 // arrays
438 Array<OneD, Array<OneD, double>> fwd(nFields), bwd(nFields), flx(nFields),
439 flxRef(nFields);
440 for (unsigned int c = 0; c < nFields; ++c)
441 {
442 fwd[c] = Array<OneD, double>(npts, 0.0);
443 bwd[c] = Array<OneD, double>(npts, 0.0);
444 flx[c] = Array<OneD, double>(npts, 0.0);
445 flxRef[c] = Array<OneD, double>(npts, 0.0);
446 }
447
448 // Get expected results by constant Euler state and reference physical flux
449 GetExpectedResults(spaceDim, npts, normals, fwd, bwd, flxRef);
450
451 // Create block attributes.
452 auto traceblockAttr =
453 GetBlockAttributes<TData, FieldState::Phys>(expList->GetTrace());
454
455 // Create fields.
457 "f_fwd", traceblockAttr, nFields, nHomo);
458
460 "f_bwd", traceblockAttr, nFields, nHomo);
461
463 "f_flux", traceblockAttr, nFields, nHomo);
464
466 "traceNormals", traceblockAttr, spaceDim, nHomo);
467
468 fwdField.template CopyArray<NektarSpaces::HostSpace>(
469 FlattenCompMajor(fwd, nFields, npts));
470 bwdField.template CopyArray<NektarSpaces::HostSpace>(
471 FlattenCompMajor(bwd, nFields, npts));
472 normalsField.template CopyArray<NektarSpaces::HostSpace>(
473 FlattenCompMajor(normals, spaceDim, npts));
474
475 // Warm-up : fill the cache and memory, and let core temperature/freq
476 // stabilized.
477 for (unsigned int i = 0; i < Ntest / 2; ++i)
478 {
479 oper->ApplyUnitTest(normalsField, fwdField, bwdField, fluxField);
480 }
481 comm->Block();
482
483 // Benchmark
484 // For CUDA, we synchronize the device before starting/stopping the timer
485 // For MPI, since elmental operators are local we don't need to synchronize
486 // after each operator call. Just add a block after the timer stops.
487
489 timer.Start();
490 LIKWID_MARKER_START(tag.c_str());
491
492 for (unsigned int i = 0; i < Ntest; ++i)
493 {
494 oper->ApplyUnitTest(normalsField, fwdField, bwdField, fluxField);
495 }
496
498 LIKWID_MARKER_STOP(tag.c_str());
499 timer.Stop();
500
501 comm->Block();
502
503 auto rankL1Error = std::vector<double>(1, 0.0);
504
505 // Print block information and get the total number of dofs.
506 if (comm->GetRank() == 0)
507 {
508 std::cout << "Input field: " << nFields << " components" << std::endl;
509 }
510 PrintBlockInfo(expList, traceblockAttr, rankL1Error);
511
512 // First check if the output is all zeros.
513 TData L2 = 0.0;
514 Math::l2norm<NektarSpaces::Serial>(fluxField, &L2);
515 if (L2 < 1e-9)
516 {
517 std::cout << "Warning: output does not change!"
518 << "Device may not be invoked!" << std::endl;
519 }
520
521 // Then check if results match with expected
522 // If we compare float results with double results, then it is
523 // reasonable to have some mismatched values (e.g., > 1e-4)
524 Array<OneD, double> tmpArr = fluxField.template ToArray<double>();
525 Array<OneD, double> fluxArr = FlattenCompMajor(flxRef, nFields, npts);
526 for (size_t i = 0, cnt = 0; i < tmpArr.size(); ++i)
527 {
528 // Print out first 100 mismatched values.
529 if (std::abs(tmpArr[i] - fluxArr[i]) >
530 1e-4 * std::sqrt(L2 / tmpArr.size()) &&
531 cnt < 100)
532 {
533 std::cout << "i=" << i << " computed result = " << tmpArr[i]
534 << " expected result = " << fluxArr[i] << std::endl;
535 ++cnt;
536 }
537 rankL1Error[0] += std::abs(tmpArr[i] - fluxArr[i]);
538 }
539
540 // Print block information and get the total number of dofs.
541 if (comm->GetRank() == 0)
542 {
543 std::cout << "Output field: " << nFields << " components" << std::endl;
544 }
545 PrintBlockInfo(expList->GetTrace(), traceblockAttr, rankL1Error);
546
547 if (comm->GetRank() == 0)
548 {
549 std::cout << "---------------------------------" << std::endl;
550 std::cout << "ElmtOps Profiler : " << tag << std::endl;
551 std::cout << "---------------------------------" << std::endl;
552 }
553 comm->Block();
554
555 // Collect elapsed time and compute the max, min, and average.
556 auto rankElapsed = std::vector<double>(1, timer.TimePerTest(Ntest));
557 PrintProfileResult<TData>(comm, rankElapsed, traceblockAttr);
558}
#define ASSERTL0(condition, msg)
#define LIKWID_MARKER_START(regionTag)
void PrintBlockInfo(const MultiRegions::ExpListSharedPtr &expList, const std::vector< LibUtilities::BlockAttributes< TState > > &blockAttr, std::vector< double > &rankL1Err)
Print the block information. If verbose=true, then print the block information for each rank....
void GetExpectedResults(unsigned int spaceDim, size_t npts, const Array< OneD, Array< OneD, double > > &normals, Array< OneD, Array< OneD, double > > &fwd, Array< OneD, Array< OneD, double > > &bwd, Array< OneD, Array< OneD, double > > &flxRef, double gamma=1.4)
Compute the expected results of certain operator from the expList.
#define LIKWID_MARKER_STOP(regionTag)
static Array< OneD, TData > FlattenCompMajor(const Array< OneD, Array< OneD, TData > > &a, unsigned int ncomp, size_t npts)
LibUtilities::SessionReaderSharedPtr session
static std::shared_ptr< AdvTraceFluxCFEOp< TData > > Create(const MultiRegions::ExpListSharedPtr &expansionList, const std::vector< std::string > &components, const std::string &solverType="", const std::string &execStr="")
Create the implementation registered for solverType.
A Field represents expansion data to be operated on.
NekDouble TimePerTest(unsigned int n)
Returns amount of seconds per iteration in a test with n iterations.
Definition Timer.cpp:65
static std::string GetOpExecSpace(std::shared_ptr< LibUtilities::SessionReader > session, const bool warn=true)
Return the execution space name ("opExecSpace") for an operator.
Definition Operator.hpp:190
std::string ToUpperCopy(std::string str)
static void nekDeviceSynchronize(void)
Definition Backends.hpp:413

References ASSERTL0, Nektar::AdvTraceFluxCFEOp< TData >::Create(), FlattenCompMajor(), GetExpectedResults(), Nektar::MultiRegions::Operator< TData >::GetOpExecSpace(), LIKWID_MARKER_START, LIKWID_MARKER_STOP, Nektar::nekDeviceSynchronize(), PrintBlockInfo(), session, Nektar::LibUtilities::Timer::Start(), Nektar::LibUtilities::Timer::Stop(), Nektar::LibUtilities::Timer::TimePerTest(), and Nektar::StringUtils::ToUpperCopy().

◆ PrintBlockInfo()

template<FieldState TState>
void PrintBlockInfo ( const MultiRegions::ExpListSharedPtr &  expList,
const std::vector< LibUtilities::BlockAttributes< TState > > &  blockAttr,
std::vector< double > &  rankL1Err 
)

Print the block information. If verbose=true, then print the block information for each rank. If verbose=false, then only print the total information for each rank. Caution: for many ranks and many blocks, setting verbose may cause the display content too big to read.

Definition at line 172 of file ProfilerRiemannOps.hpp.

176{
177 auto comm = expList->GetComm();
178 unsigned int nrank = comm->GetSize();
179 auto rankBlockNum = std::vector<unsigned int>(1, blockAttr.size());
180 auto rankBlockNumDofs = std::vector<size_t>(blockAttr.size(), 0);
181 auto rankBlockNumData = std::vector<unsigned int>(blockAttr.size(), 0);
182 auto rankBlockNumElmts = std::vector<size_t>(blockAttr.size(), 0);
183 auto rankBlockNumPaddings = std::vector<size_t>(blockAttr.size(), 0);
184 auto rankNumDofs = std::vector<size_t>(1, 0);
185 auto rankNumElmts = std::vector<size_t>(1, 0);
186 auto rankNumPaddings = std::vector<size_t>(1, 0);
187 auto rankGeomTypes = std::vector<unsigned int>(1, 0);
188
189 // Collect total information for each rank.
190 for (size_t i = 0, expId = 0; i < blockAttr.size(); ++i)
191 {
192 rankBlockNumDofs[i] = blockAttr[i].CompSize();
193 rankBlockNumData[i] = blockAttr[i].GetNumData();
194 rankBlockNumElmts[i] = blockAttr[i].GetNumElements();
195 rankBlockNumPaddings[i] = blockAttr[i].GetNumElementsWithPadding() -
196 blockAttr[i].GetNumElements();
197 rankNumDofs[0] += blockAttr[i].CompSize();
198 rankNumElmts[0] += blockAttr[i].GetNumElements();
199 rankNumPaddings[0] += blockAttr[i].GetNumElementsWithPadding() -
200 blockAttr[i].GetNumElements();
201
202 // Check the geometry type of the block: deformed or regular
203 // if both types exist in the same rank, then it is labeled as mixed.
204 auto gtype = expList->GetExp(expId)->GetGeomFactors()->GetGtype();
205 if (gtype == SpatialDomains::eDeformed && rankGeomTypes[0] != 1)
206 {
207 rankGeomTypes[0] = 2; // Deformed
208 }
209 else if (gtype == SpatialDomains::eRegular && rankGeomTypes[0] != 2)
210 {
211 rankGeomTypes[0] = 1; // Regular
212 }
213 else
214 {
215 rankGeomTypes[0] = 3; // Mixed
216 }
217 }
218 auto allRankBlockNum = comm->Gather(0, rankBlockNum);
219 auto allRankBlockNumDofs = comm->Gather(0, rankBlockNumDofs);
220 auto allRankBlockNumData = comm->Gather(0, rankBlockNumData);
221 auto allRankBlockNumElmts = comm->Gather(0, rankBlockNumElmts);
222 auto allRankBlockNumPaddings = comm->Gather(0, rankBlockNumPaddings);
223 auto allRankNumDofs = comm->Gather(0, rankNumDofs);
224 auto allRankNumElmts = comm->Gather(0, rankNumElmts);
225 auto allRankNumPaddings = comm->Gather(0, rankNumPaddings);
226 auto allRankGeomTypes = comm->Gather(0, rankGeomTypes);
227 auto allRankL1Err = comm->Gather(0, rankL1Err);
228
229 // Print summary information.
230 if (comm->GetRank() == 0)
231 {
232 // Get the geometry type of the whole domain :
233 // Calculate the average value, if average is 1, then it is regular
234 // if average is 2, then it is deformed, otherwise it is mixed/
235 auto GeomType = Vmath::Vsum(nrank, allRankGeomTypes.data(), 1) / nrank;
236
237 std::string Gtype = "Null";
238 if (std::abs(GeomType - 1.0) < 1e-8)
239 {
240 Gtype = "Regular";
241 }
242 else if (std::abs(GeomType - 2.0) < 1e-8)
243 {
244 Gtype = "Deformed";
245 }
246 else
247 {
248 Gtype = "Mixed";
249 }
250
251 // Check if verbose is set.
252 auto verbose = expList->GetSession()->DefinesCmdLineArgument("verbose");
253
254 if (verbose)
255 {
256 for (unsigned int rank = 0, cnt = 0; rank < nrank; rank++)
257 {
258 // Print block information in a table like format.
259 // | BlockId | #Elements | #Paddings | #Points | BlockSize |
260 std::cout << std::setw(5) << "Rank#" << std::setw(5) << rank
261 << std::endl;
262 std::cout << std::endl;
263 std::cout << std::setw(10) << "BlockId" << std::setw(12)
264 << "#Elements" << std::setw(12) << "#Paddings"
265 << std::setw(10) << "#Points" << std::setw(12)
266 << "BlockSize" << std::endl;
267 // Print a dash line.
268 std::cout << std::setw(10) << std::setfill('-') << ""
269 << std::setw(12) << "" << std::setw(12) << ""
270 << std::setw(10) << "" << std::setw(12) << ""
271 << std::setfill(' ') << std::endl;
272
273 for (unsigned int i = 0; i < allRankBlockNum[rank]; ++i, ++cnt)
274 {
275 std::cout << std::setw(10) << i << std::setw(12)
276 << allRankBlockNumElmts[cnt] << std::setw(12)
277 << allRankBlockNumPaddings[cnt] << std::setw(12)
278 << std::setw(10) << allRankBlockNumData[cnt]
279 << std::setw(12) << allRankBlockNumDofs[cnt]
280 << std::endl;
281 }
282
283 // Print a dash line.
284 std::cout << std::setw(10) << std::setfill('-') << ""
285 << std::setw(12) << "" << std::setw(12) << ""
286 << std::setw(10) << "" << std::setw(12) << ""
287 << std::setfill(' ') << std::endl;
288 // Final line is sum of all blocks.
289 std::cout << std::setw(5) << "Total" << std::setw(5)
290 << allRankBlockNum[rank] << std::setw(12)
291 << allRankNumElmts[rank] << std::setw(12)
292 << allRankNumPaddings[rank] << std::setw(10) << "N/A"
293 << std::setw(12) << allRankNumDofs[rank]
294 << std::setw(16) << std::endl;
295 std::cout << std::endl;
296 }
297 }
298
299 std::cout << std::setw(10) << "Rank# " << std::setw(12) << "#Elements"
300 << std::setw(12) << "#Paddings" << std::setw(12) << "#DoFs"
301 << std::setw(12) << "Gtype" << std::setw(16) << "L1 error"
302 << std::endl;
303 for (unsigned int rank = 0; rank < nrank; rank++)
304 {
305 std::cout << std::setw(10) << rank << std::setw(12)
306 << allRankNumElmts[rank] << std::setw(12)
307 << allRankNumPaddings[rank] << std::setw(12)
308 << allRankNumDofs[rank] << std::setw(12) << Gtype
309 << std::setw(16)
310 << allRankL1Err[rank] / allRankNumDofs[rank] << std::endl;
311 }
312 }
313 comm->Block();
314}
GeomType
Indicates the type of element geometry.
@ eRegular
Geometry is straight-sided with constant geometric factors.
@ eDeformed
Geometry is curved or has non-constant factors.
T Vsum(int n, const T *x, const int incx)
Subtract return sum(x)
Definition Vmath.hpp:611

References Nektar::SpatialDomains::eDeformed, Nektar::SpatialDomains::eRegular, rank, and Vmath::Vsum().

Referenced by LaunchProfiler().

◆ PrintProfileResult()

template<typename TData , FieldState TState>
void PrintProfileResult ( const CommSharedPtr  comm,
std::vector< double > &  rankElapsed,
const std::vector< LibUtilities::BlockAttributes< TState > > &  traceblockAttr 
)

Print the profiler results, computed from the elapsed time and the total number of dofs.

Definition at line 319 of file ProfilerRiemannOps.hpp.

322{
323 // Collect elapsed time and compute the max, min, and average.
324 unsigned int nrank = comm->GetSize();
325 auto rankNumInDofs = std::vector<size_t>(1, 0);
326 auto rankNumOutDofs = std::vector<size_t>(1, 0);
327
328 // Collect total information for each rank.
329 for (unsigned int i = 0; i < traceblockAttr.size(); ++i)
330 {
331 rankNumInDofs[0] += traceblockAttr[i].CompSize();
332 rankNumOutDofs[0] += traceblockAttr[i].CompSize();
333 }
334
335 auto allRankElapsed = comm->Gather(0, rankElapsed);
336 auto allRankNumInDofs = comm->Gather(0, rankNumInDofs);
337 auto allRankNumOutDofs = comm->Gather(0, rankNumOutDofs);
338
339 if (comm->GetRank() == 0)
340 {
341 double maxElapsed = Vmath::Vmax(nrank, allRankElapsed.data(), 1);
342 double minElapsed = Vmath::Vmin(nrank, allRankElapsed.data(), 1);
343 double aveElapsed =
344 Vmath::Vsum(nrank, allRankElapsed.data(), 1) / nrank;
345
346 // Collect throughput for each rank:
347 // The throughput for each rank is calucated by the total number of dofs
348 // and the elapsed time in that rank. The total throughput is the sum of
349 // all rank. So the total throughput by this way will not be identical
350 // to total dofs divided by the total (min/ave/max) elapsed time.
351 double inThroughput = 0.0;
352 double outThroughput = 0.0;
353 size_t totInDofs = 0;
354 size_t totOutDofs = 0;
355 for (unsigned int rank = 0; rank < nrank; rank++)
356 {
357 inThroughput += allRankNumInDofs[rank] / allRankElapsed[rank];
358 outThroughput += allRankNumOutDofs[rank] / allRankElapsed[rank];
359 totInDofs += allRankNumInDofs[rank];
360 totOutDofs += allRankNumOutDofs[rank];
361 }
362
363 // Print the summary :
364 // Max/Min/Aver time can be used to judge the load-balance in parallel
365 std::cout << "Max time per test (s): " << maxElapsed << std::endl;
366 std::cout << "Min time per test (s): " << minElapsed << std::endl;
367 std::cout << "Average time per test (s): " << aveElapsed << std::endl;
368 std::cout << "Total ndof (input/output): " << totInDofs << " "
369 << totOutDofs << std::endl;
370 std::cout << "Throughput (ndof/s): " << inThroughput << " "
371 << outThroughput << std::endl;
372 std::cout << "Throughput (GB/s): " << inThroughput * sizeof(TData) / 1e9
373 << " " << outThroughput * sizeof(TData) / 1e9 << std::endl;
374 std::cout << std::endl;
375 std::cout << std::endl;
376 }
377 comm->Block();
378}
T Vmin(int n, const T *x, const int incx)
Return the minimum element in x - called vmin to avoid conflict with min.
Definition Vmath.hpp:728
T Vmax(int n, const T *x, const int incx)
Return the maximum element in x – called vmax to avoid conflict with max.
Definition Vmath.hpp:647

References rank, Vmath::Vmax(), Vmath::Vmin(), and Vmath::Vsum().

◆ UnflattenCompMajor()

template<typename TData >
static void UnflattenCompMajor ( const Array< OneD, TData > &  flat,
Array< OneD, Array< OneD, TData > > &  a,
unsigned int  ncomp,
size_t  npts 
)
static

Definition at line 92 of file ProfilerRiemannOps.hpp.

95{
96 for (unsigned int c = 0; c < ncomp; ++c)
97 {
98 for (size_t i = 0; i < npts; ++i)
99 {
100 a[c][i] = flat[c * npts + i];
101 }
102 }
103}