53 #include "Sacado_Fad_DFad.hpp"
54 #include "Sacado_mpl_apply.hpp"
55 #include "Sacado_Random.hpp"
61 template <
typename PCEType,
typename FadType>
72 typedef typename Sacado::mpl::apply<FadType,PCEType>::type
FadPCEType;
83 for (
int i=0; i<d; i++)
93 Stokhos::create_product_tensor<execution_space>(*
basis, *
Cijk);
106 template <
typename PCEType>
109 const std::string& tag,
113 bool success = (x.
size() == x2.
size());
114 out << tag <<
" PCE array size test";
119 out <<
": \n\tExpected: " << x.
size() <<
", \n\tGot: " << x2.
size()
123 for (
int i=0; i<x.
size(); i++) {
124 bool success2 = Sacado::IsEqual<PCEType>::eval(x[i], x2[i]);
125 out << tag <<
" PCE array comparison test " << i;
130 out <<
": \n\tExpected: " << x[i] <<
", \n\tGot: " << x2[i] <<
"."
132 success = success && success2;
138 template<
typename Ordinal>
145 out <<
"\nChecking that the above test passed in all processes ...";
146 int thisResult = ( result ? 1 : 0 );
150 const bool passed = sumResult==Teuchos::size(comm);
154 out <<
" (sumResult="<<sumResult<<
"!=numProcs="<<Teuchos::size(comm)<<
") failed\n";
164 Sacado::Random<double>
rnd;
173 for (
int i=0; i<n; i++) {
175 for (
int j=0;
j<setup.
sz;
j++)
178 if (comm->getRank() == 0)
181 success =
checkPCEArrays(x, x2, std::string(
"UQ::PCE")+
" Broadcast", out);
191 int size = comm->getSize();
192 int rank = comm->getRank();
195 for (
int i=0; i<n; i++) {
197 for (
int j=0;
j<setup.
sz;
j++)
200 for (
int j=0;
j<size;
j++) {
201 for (
int i=0; i<n; i++) {
203 for (
int k=0; k<setup.
sz; k++)
208 n, &x[0], N, &x2[0]);
209 success =
checkPCEArrays(x3, x2, std::string(
"UQ::PCE")+
" Gather All", out);
219 int num_proc = comm->getSize();
222 for (
int i=0; i<n; i++) {
224 for (
int j=0;
j<setup.
sz;
j++)
227 for (
int i=0; i<n; i++) {
229 for (
int j=0;
j<setup.
sz;
j++)
235 std::string(
"UQ::PCE")+
" Sum All", out);
245 int rank = comm->getRank();
246 int num_proc = comm->getSize();
249 for (
int i=0; i<n; i++) {
251 for (
int j=0;
j<setup.
sz;
j++)
254 for (
int i=0; i<n; i++) {
256 for (
int j=0;
j<setup.
sz;
j++)
262 std::string(
"UQ::PCE")+
" Max All", out);
272 int rank = comm->getRank();
275 for (
int i=0; i<n; i++) {
277 for (
int j=0;
j<setup.
sz;
j++)
280 for (
int i=0; i<n; i++) {
282 for (
int j=0;
j<setup.
sz;
j++)
288 std::string(
"UQ::PCE")+
" Min All", out);
298 int rank = comm->getRank();
301 for (
int i=0; i<n; i++) {
303 for (
int j=0;
j<setup.
sz;
j++)
306 for (
int i=0; i<n; i++) {
308 for (
int j=0;
j<setup.
sz;
j++)
314 std::string(
"UQ::PCE")+
" Scan Sum", out);
324 int rank = comm->getRank();
327 for (
int i=0; i<n; i++) {
329 for (
int j=0;
j<setup.
sz;
j++)
332 for (
int i=0; i<n; i++) {
334 for (
int j=0;
j<setup.
sz;
j++)
340 std::string(
"UQ::PCE")+
" Scan Max", out);
350 int rank = comm->getRank();
353 for (
int i=0; i<n; i++) {
355 for (
int j=0;
j<setup.
sz;
j++)
358 for (
int i=0; i<n; i++) {
360 for (
int j=0;
j<setup.
sz;
j++)
366 std::string(
"UQ::PCE")+
" Scan Min", out);
375 int num_proc = comm->getSize();
377 int rank = comm->getRank();
380 for (
int i=0; i<n; i++) {
382 for (
int j=0;
j<setup.
sz;
j++)
392 std::string(
"UQ::PCE")+
" Send/Receive", out);
400 typedef Sacado::mpl::apply<FadType,PCEType>::type FadPCEType;
408 for (
int i=0; i<n; i++) {
410 for (
int k=0; k<setup.
sz; k++)
411 f.fastAccessCoeff(k) =
rnd.number();
412 x[i] = FadPCEType(p, f);
413 for (
int j=0;
j<p;
j++) {
415 for (
int k=0; k<setup.
sz; k++)
416 g.fastAccessCoeff(k) =
rnd.number();
417 x[i].fastAccessDx(
j) =
g;
420 if (comm->getRank() == 0)
424 std::string(
"DFad")+
"<"+
"UQ::PCE"+
"> Broadcast", out);
429 typedef Sacado::mpl::apply<FadType,PCEType>::type FadPCEType;
436 int size = comm->getSize();
437 int rank = comm->getRank();
440 for (
int i=0; i<n; i++) {
442 for (
int k=0; k<setup.
sz; k++)
443 f.fastAccessCoeff(k) = (rank+1)*(i+1)*(k+1);
444 x[i] = FadPCEType(p, f);
445 for (
int j=0;
j<p;
j++) {
446 x[i].fastAccessDx(
j) =
f;
449 for (
int j=0;
j<size;
j++) {
450 for (
int i=0; i<n; i++) {
452 for (
int k=0; k<setup.
sz; k++)
453 f.fastAccessCoeff(k) = (
j+1)*(i+1)*(k+1);
454 x3[n*
j+i] = FadPCEType(p, f);
455 for (
int k=0; k<p; k++)
460 n, &x[0], N, &x2[0]);
462 std::string(
"DFad")+
"<"+
"UQ::PCE"+
"> Gather All", out);
467 typedef Sacado::mpl::apply<FadType,PCEType>::type FadPCEType;
474 int num_proc = comm->getSize();
477 for (
int i=0; i<n; i++) {
479 for (
int k=0; k<setup.
sz; k++)
480 f.fastAccessCoeff(k) = 2.0*(i+1);
481 x[i] = FadPCEType(p, f);
482 for (
int j=0;
j<p;
j++) {
484 for (
int k=0; k<setup.
sz; k++)
485 g.fastAccessCoeff(k) = 2.0*(i+1);
486 x[i].fastAccessDx(
j) =
g;
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)*num_proc;
493 sums[i] = FadPCEType(p, f);
494 for (
int j=0;
j<p;
j++) {
496 for (
int k=0; k<setup.
sz; k++)
497 g.fastAccessCoeff(k) = 2.0*(i+1)*num_proc;
498 sums[i].fastAccessDx(
j) =
g;
504 std::string(
"DFad")+
"<"+
"UQ::PCE"+
"> Sum All", out);
509 typedef Sacado::mpl::apply<FadType,PCEType>::type FadPCEType;
516 int rank = comm->getRank();
517 int num_proc = comm->getSize();
520 for (
int i=0; i<n; i++) {
522 for (
int k=0; k<setup.
sz; k++)
523 f.fastAccessCoeff(k) = 2.0*(i+1)*(rank+1);
524 x[i] = FadPCEType(p, f);
525 for (
int j=0;
j<p;
j++) {
526 x[i].fastAccessDx(
j) =
f;
529 for (
int i=0; i<n; i++) {
531 for (
int k=0; k<setup.
sz; k++)
532 f.fastAccessCoeff(k) = 2.0*(i+1)*num_proc;
533 maxs[i] = FadPCEType(p, f);
534 for (
int j=0;
j<p;
j++)
540 std::string(
"DFad")+
"<"+
"UQ::PCE"+
"> Max All", out);
545 typedef Sacado::mpl::apply<FadType,PCEType>::type FadPCEType;
552 int rank = comm->getRank();
555 for (
int i=0; i<n; i++) {
557 for (
int k=0; k<setup.
sz; k++)
558 f.fastAccessCoeff(k) = 2.0*(i+1)*(rank+1);
559 x[i] = FadPCEType(p, f);
560 for (
int j=0;
j<p;
j++) {
561 x[i].fastAccessDx(
j) =
f;
564 for (
int i=0; i<n; i++) {
566 for (
int k=0; k<setup.
sz; k++)
567 f.fastAccessCoeff(k) = 2.0*(i+1);
568 mins[i] = FadPCEType(p, f);
569 for (
int j=0;
j<p;
j++)
575 std::string(
"DFad")+
"<"+
"UQ::PCE"+
"> Min All", out);
580 typedef Sacado::mpl::apply<FadType,PCEType>::type FadPCEType;
587 int rank = comm->getRank();
590 for (
int i=0; i<n; i++) {
592 for (
int k=0; k<setup.
sz; k++)
593 f.fastAccessCoeff(k) = 2.0*(i+1);
594 x[i] = FadPCEType(p, f);
595 for (
int j=0;
j<p;
j++) {
596 x[i].fastAccessDx(
j) =
f;
599 for (
int i=0; i<n; i++) {
601 for (
int k=0; k<setup.
sz; k++)
602 f.fastAccessCoeff(k) = 2.0*(i+1)*(rank+1);
603 sums[i] = FadPCEType(p, f);
604 for (
int j=0;
j<p;
j++)
610 std::string(
"DFad")+
"<"+
"UQ::PCE"+
"> Scan Sum", out);
615 typedef Sacado::mpl::apply<FadType,PCEType>::type FadPCEType;
622 int rank = comm->getRank();
625 for (
int i=0; i<n; i++) {
627 for (
int k=0; k<setup.
sz; k++)
628 f.fastAccessCoeff(k) = 2.0*(i+1)*(rank+1);
629 x[i] = FadPCEType(p, f);
630 for (
int j=0;
j<p;
j++) {
631 x[i].fastAccessDx(
j) =
f;
634 for (
int i=0; i<n; i++) {
636 for (
int k=0; k<setup.
sz; k++)
637 f.fastAccessCoeff(k) = 2.0*(i+1)*(rank+1);
638 maxs[i] = FadPCEType(p, f);
639 for (
int j=0;
j<p;
j++)
645 std::string(
"DFad")+
"<"+
"UQ::PCE"+
"> Scan Max", out);
650 typedef Sacado::mpl::apply<FadType,PCEType>::type FadPCEType;
657 int rank = comm->getRank();
660 for (
int i=0; i<n; i++) {
662 for (
int k=0; k<setup.
sz; k++)
663 f.fastAccessCoeff(k) = 2.0*(i+1)*(rank+1);
664 x[i] = FadPCEType(p, f);
665 for (
int j=0;
j<p;
j++) {
666 x[i].fastAccessDx(
j) =
f;
669 for (
int i=0; i<n; i++) {
671 for (
int k=0; k<setup.
sz; k++)
672 f.fastAccessCoeff(k) = 2.0*(i+1);
673 mins[i] = FadPCEType(p, f);
674 for (
int j=0;
j<p;
j++)
680 std::string(
"DFad")+
"<"+
"UQ::PCE"+
"> Scan Min", out);
685 typedef Sacado::mpl::apply<FadType,PCEType>::type FadPCEType;
690 int num_proc = comm->getSize();
692 int rank = comm->getRank();
696 for (
int i=0; i<n; i++) {
698 for (
int k=0; k<setup.
sz; k++)
699 f.fastAccessCoeff(k) = 2.0*(i+1)*(k+1);
700 x[i] = FadPCEType(p, f);
701 for (
int j=0;
j<p;
j++)
711 std::string(
"DFad")+
"<"+
"UQ::PCE"+
"> Send/Receive", out);
721 Kokkos::initialize();
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
static int runUnitTestsFromMain(int argc, char *argv[])
TEUCHOS_DEPRECATED RCP< T > rcp(T *p, Dealloc_T dealloc, bool owns_mem)
TEUCHOS_DEPRECATED void scan(const Comm< Ordinal > &comm, const EReductionType reductType, const Packet &send, Packet *scanReduct)
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.
TEUCHOS_DEPRECATED void reduceAll(const Comm< Ordinal > &comm, const EReductionType reductType, const Packet &send, Packet *globalReduct)
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.
int main(int argc, char **argv)
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