22 #include "Sacado_Fad_DFad.hpp"
23 #include "Sacado_mpl_apply.hpp"
24 #include "Sacado_Random.hpp"
30 template <
typename PCEType,
typename FadType>
41 typedef typename Sacado::mpl::apply<FadType,PCEType>::type
FadPCEType;
52 for (
int i=0; i<d; i++)
62 Stokhos::create_product_tensor<execution_space>(*
basis, *
Cijk);
75 template <
typename PCEType>
78 const std::string& tag,
82 bool success = (x.
size() == x2.
size());
83 out << tag <<
" PCE array size test";
88 out <<
": \n\tExpected: " << x.
size() <<
", \n\tGot: " << x2.
size()
92 for (
int i=0; i<x.
size(); i++) {
93 bool success2 = Sacado::IsEqual<PCEType>::eval(x[i], x2[i]);
94 out << tag <<
" PCE array comparison test " << i;
99 out <<
": \n\tExpected: " << x[i] <<
", \n\tGot: " << x2[i] <<
"."
101 success = success && success2;
107 template<
typename Ordinal>
114 out <<
"\nChecking that the above test passed in all processes ...";
115 int thisResult = ( result ? 1 : 0 );
119 const bool passed = sumResult==Teuchos::size(comm);
123 out <<
" (sumResult="<<sumResult<<
"!=numProcs="<<Teuchos::size(comm)<<
") failed\n";
133 Sacado::Random<double>
rnd;
142 for (
int i=0; i<n; i++) {
144 for (
int j=0;
j<setup.
sz;
j++)
147 if (comm->getRank() == 0)
150 success =
checkPCEArrays(x, x2, std::string(
"UQ::PCE")+
" Broadcast", out);
160 int size = comm->getSize();
161 int rank = comm->getRank();
164 for (
int i=0; i<n; i++) {
166 for (
int j=0;
j<setup.
sz;
j++)
169 for (
int j=0;
j<size;
j++) {
170 for (
int i=0; i<n; i++) {
172 for (
int k=0; k<setup.
sz; k++)
177 n, &x[0], N, &x2[0]);
178 success =
checkPCEArrays(x3, x2, std::string(
"UQ::PCE")+
" Gather All", out);
188 int num_proc = comm->getSize();
191 for (
int i=0; i<n; i++) {
193 for (
int j=0;
j<setup.
sz;
j++)
196 for (
int i=0; i<n; i++) {
198 for (
int j=0;
j<setup.
sz;
j++)
204 std::string(
"UQ::PCE")+
" Sum All", out);
214 int rank = comm->getRank();
215 int num_proc = comm->getSize();
218 for (
int i=0; i<n; i++) {
220 for (
int j=0;
j<setup.
sz;
j++)
223 for (
int i=0; i<n; i++) {
225 for (
int j=0;
j<setup.
sz;
j++)
231 std::string(
"UQ::PCE")+
" Max All", out);
241 int rank = comm->getRank();
244 for (
int i=0; i<n; i++) {
246 for (
int j=0;
j<setup.
sz;
j++)
249 for (
int i=0; i<n; i++) {
251 for (
int j=0;
j<setup.
sz;
j++)
257 std::string(
"UQ::PCE")+
" Min All", out);
267 int rank = comm->getRank();
270 for (
int i=0; i<n; i++) {
272 for (
int j=0;
j<setup.
sz;
j++)
275 for (
int i=0; i<n; i++) {
277 for (
int j=0;
j<setup.
sz;
j++)
283 std::string(
"UQ::PCE")+
" Scan Sum", out);
293 int rank = comm->getRank();
296 for (
int i=0; i<n; i++) {
298 for (
int j=0;
j<setup.
sz;
j++)
301 for (
int i=0; i<n; i++) {
303 for (
int j=0;
j<setup.
sz;
j++)
309 std::string(
"UQ::PCE")+
" Scan Max", out);
319 int rank = comm->getRank();
322 for (
int i=0; i<n; i++) {
324 for (
int j=0;
j<setup.
sz;
j++)
327 for (
int i=0; i<n; i++) {
329 for (
int j=0;
j<setup.
sz;
j++)
335 std::string(
"UQ::PCE")+
" Scan Min", out);
344 int num_proc = comm->getSize();
346 int rank = comm->getRank();
349 for (
int i=0; i<n; i++) {
351 for (
int j=0;
j<setup.
sz;
j++)
361 std::string(
"UQ::PCE")+
" Send/Receive", out);
369 typedef Sacado::mpl::apply<FadType,PCEType>::type FadPCEType;
377 for (
int i=0; i<n; i++) {
379 for (
int k=0; k<setup.
sz; k++)
380 f.fastAccessCoeff(k) =
rnd.number();
381 x[i] = FadPCEType(p, f);
382 for (
int j=0;
j<p;
j++) {
384 for (
int k=0; k<setup.
sz; k++)
385 g.fastAccessCoeff(k) =
rnd.number();
386 x[i].fastAccessDx(
j) =
g;
389 if (comm->getRank() == 0)
393 std::string(
"DFad")+
"<"+
"UQ::PCE"+
"> Broadcast", out);
398 typedef Sacado::mpl::apply<FadType,PCEType>::type FadPCEType;
405 int size = comm->getSize();
406 int rank = comm->getRank();
409 for (
int i=0; i<n; i++) {
411 for (
int k=0; k<setup.
sz; k++)
412 f.fastAccessCoeff(k) = (rank+1)*(i+1)*(k+1);
413 x[i] = FadPCEType(p, f);
414 for (
int j=0;
j<p;
j++) {
415 x[i].fastAccessDx(
j) =
f;
418 for (
int j=0;
j<size;
j++) {
419 for (
int i=0; i<n; i++) {
421 for (
int k=0; k<setup.
sz; k++)
422 f.fastAccessCoeff(k) = (
j+1)*(i+1)*(k+1);
423 x3[n*
j+i] = FadPCEType(p, f);
424 for (
int k=0; k<p; k++)
429 n, &x[0], N, &x2[0]);
431 std::string(
"DFad")+
"<"+
"UQ::PCE"+
"> Gather All", out);
436 typedef Sacado::mpl::apply<FadType,PCEType>::type FadPCEType;
443 int num_proc = comm->getSize();
446 for (
int i=0; i<n; i++) {
448 for (
int k=0; k<setup.
sz; k++)
449 f.fastAccessCoeff(k) = 2.0*(i+1);
450 x[i] = FadPCEType(p, f);
451 for (
int j=0;
j<p;
j++) {
453 for (
int k=0; k<setup.
sz; k++)
454 g.fastAccessCoeff(k) = 2.0*(i+1);
455 x[i].fastAccessDx(
j) =
g;
458 for (
int i=0; i<n; i++) {
460 for (
int k=0; k<setup.
sz; k++)
461 f.fastAccessCoeff(k) = 2.0*(i+1)*num_proc;
462 sums[i] = FadPCEType(p, f);
463 for (
int j=0;
j<p;
j++) {
465 for (
int k=0; k<setup.
sz; k++)
466 g.fastAccessCoeff(k) = 2.0*(i+1)*num_proc;
467 sums[i].fastAccessDx(
j) =
g;
473 std::string(
"DFad")+
"<"+
"UQ::PCE"+
"> Sum All", out);
478 typedef Sacado::mpl::apply<FadType,PCEType>::type FadPCEType;
485 int rank = comm->getRank();
486 int num_proc = comm->getSize();
489 for (
int i=0; i<n; i++) {
491 for (
int k=0; k<setup.
sz; k++)
492 f.fastAccessCoeff(k) = 2.0*(i+1)*(rank+1);
493 x[i] = FadPCEType(p, f);
494 for (
int j=0;
j<p;
j++) {
495 x[i].fastAccessDx(
j) =
f;
498 for (
int i=0; i<n; i++) {
500 for (
int k=0; k<setup.
sz; k++)
501 f.fastAccessCoeff(k) = 2.0*(i+1)*num_proc;
502 maxs[i] = FadPCEType(p, f);
503 for (
int j=0;
j<p;
j++)
509 std::string(
"DFad")+
"<"+
"UQ::PCE"+
"> Max All", out);
514 typedef Sacado::mpl::apply<FadType,PCEType>::type FadPCEType;
521 int rank = comm->getRank();
524 for (
int i=0; i<n; i++) {
526 for (
int k=0; k<setup.
sz; k++)
527 f.fastAccessCoeff(k) = 2.0*(i+1)*(rank+1);
528 x[i] = FadPCEType(p, f);
529 for (
int j=0;
j<p;
j++) {
530 x[i].fastAccessDx(
j) =
f;
533 for (
int i=0; i<n; i++) {
535 for (
int k=0; k<setup.
sz; k++)
536 f.fastAccessCoeff(k) = 2.0*(i+1);
537 mins[i] = FadPCEType(p, f);
538 for (
int j=0;
j<p;
j++)
544 std::string(
"DFad")+
"<"+
"UQ::PCE"+
"> Min All", out);
549 typedef Sacado::mpl::apply<FadType,PCEType>::type FadPCEType;
556 int rank = comm->getRank();
559 for (
int i=0; i<n; i++) {
561 for (
int k=0; k<setup.
sz; k++)
562 f.fastAccessCoeff(k) = 2.0*(i+1);
563 x[i] = FadPCEType(p, f);
564 for (
int j=0;
j<p;
j++) {
565 x[i].fastAccessDx(
j) =
f;
568 for (
int i=0; i<n; i++) {
570 for (
int k=0; k<setup.
sz; k++)
571 f.fastAccessCoeff(k) = 2.0*(i+1)*(rank+1);
572 sums[i] = FadPCEType(p, f);
573 for (
int j=0;
j<p;
j++)
579 std::string(
"DFad")+
"<"+
"UQ::PCE"+
"> Scan Sum", out);
584 typedef Sacado::mpl::apply<FadType,PCEType>::type FadPCEType;
591 int rank = comm->getRank();
594 for (
int i=0; i<n; i++) {
596 for (
int k=0; k<setup.
sz; k++)
597 f.fastAccessCoeff(k) = 2.0*(i+1)*(rank+1);
598 x[i] = FadPCEType(p, f);
599 for (
int j=0;
j<p;
j++) {
600 x[i].fastAccessDx(
j) =
f;
603 for (
int i=0; i<n; i++) {
605 for (
int k=0; k<setup.
sz; k++)
606 f.fastAccessCoeff(k) = 2.0*(i+1)*(rank+1);
607 maxs[i] = FadPCEType(p, f);
608 for (
int j=0;
j<p;
j++)
614 std::string(
"DFad")+
"<"+
"UQ::PCE"+
"> Scan Max", out);
619 typedef Sacado::mpl::apply<FadType,PCEType>::type FadPCEType;
626 int rank = comm->getRank();
629 for (
int i=0; i<n; i++) {
631 for (
int k=0; k<setup.
sz; k++)
632 f.fastAccessCoeff(k) = 2.0*(i+1)*(rank+1);
633 x[i] = FadPCEType(p, f);
634 for (
int j=0;
j<p;
j++) {
635 x[i].fastAccessDx(
j) =
f;
638 for (
int i=0; i<n; i++) {
640 for (
int k=0; k<setup.
sz; k++)
641 f.fastAccessCoeff(k) = 2.0*(i+1);
642 mins[i] = FadPCEType(p, f);
643 for (
int j=0;
j<p;
j++)
649 std::string(
"DFad")+
"<"+
"UQ::PCE"+
"> Scan Min", out);
654 typedef Sacado::mpl::apply<FadType,PCEType>::type FadPCEType;
659 int num_proc = comm->getSize();
661 int rank = comm->getRank();
665 for (
int i=0; i<n; i++) {
667 for (
int k=0; k<setup.
sz; k++)
668 f.fastAccessCoeff(k) = 2.0*(i+1)*(k+1);
669 x[i] = FadPCEType(p, f);
670 for (
int j=0;
j<p;
j++)
680 std::string(
"DFad")+
"<"+
"UQ::PCE"+
"> Send/Receive", out);
Stokhos::StandardStorage< int, double > storage_type
RCP< FadPCESerializerT > fad_pce_serializer
Kokkos::DefaultExecutionSpace execution_space
RCP< const Stokhos::CompletePolynomialBasis< int, double > > basis
RCP< PCESerializerT > pce_serializer
static Teuchos::RCP< const Comm< OrdinalType > > getComm()
bool checkPCEArrays(const Teuchos::Array< PCEType > &x, const Teuchos::Array< PCEType > &x2, const std::string &tag, Teuchos::FancyOStream &out)
Teuchos::ValueTypeSerializer< int, FadPCEType > FadPCESerializerT
TEUCHOS_DEPRECATED RCP< T > rcp(T *p, Dealloc_T dealloc, bool owns_mem)
UnitTestSetup< int, double > setup
Sacado::Fad::DFad< double > FadType
expr expr expr expr fastAccessDx(i, j)) FAD_UNARYOP_MACRO(exp
virtual Teuchos::RCP< Stokhos::Sparse3Tensor< ordinal_type, value_type > > computeTripleProductTensor() const
Compute triple product tensor.
void send(const Packet sendBuffer[], const Ordinal count, const int destRank, const int tag, const Comm< Ordinal > &comm)
expr1 expr1 expr1 expr2 expr1 expr1 c expr2 expr1 c fastAccessCoeff(j)-expr2.val(j)
Sacado::Random< double > rnd
Sacado::mpl::apply< FadType, PCEType >::type FadPCEType
Legendre polynomial basis.
Sacado::UQ::PCE< storage_type > PCEType
ScalarType f(const Teuchos::Array< ScalarType > &x, double a, double b)
bool checkResultOnAllProcs(const Teuchos::Comm< Ordinal > &comm, Teuchos::FancyOStream &out, const bool result)
PCEType::cijk_type kokkos_cijk_type
kokkos_cijk_type kokkos_cijk
ScalarType g(const Teuchos::Array< ScalarType > &x, const ScalarType &y)
RCP< Stokhos::Sparse3Tensor< int, double > > Cijk
Teuchos::ValueTypeSerializer< int, PCEType > PCESerializerT