Stokhos Package Browser (Single Doxygen Collection)  Version of the Day
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
Stokhos_SacadoUQPCECommTests.cpp
Go to the documentation of this file.
1 // @HEADER
2 // *****************************************************************************
3 // Stokhos Package
4 //
5 // Copyright 2009 NTESS and the Stokhos contributors.
6 // SPDX-License-Identifier: BSD-3-Clause
7 // *****************************************************************************
8 // @HEADER
9 
14 #include "Teuchos_CommHelpers.hpp"
15 #include "Teuchos_DefaultComm.hpp"
16 #include "Teuchos_Array.hpp"
17 #include "Teuchos_Comm.hpp"
18 
19 #include "Sacado.hpp"
20 #include "Stokhos.hpp"
22 #include "Sacado_Fad_DFad.hpp"
23 #include "Sacado_mpl_apply.hpp"
24 #include "Sacado_Random.hpp"
25 
26 using Teuchos::RCP;
27 using Teuchos::rcp;
28 
29 // Common setup for unit tests
30 template <typename PCEType, typename FadType>
31 struct UnitTestSetup {
34 
35  typedef typename PCEType::cijk_type kokkos_cijk_type;
37 
40 
41  typedef typename Sacado::mpl::apply<FadType,PCEType>::type FadPCEType;
44  int sz;
45 
47  const int d = 2;
48  const int p = 7;
49 
50  // Create product basis
52  for (int i=0; i<d; i++)
53  bases[i] =
55  basis =
57 
58  // Triple product tensor
61  kokkos_cijk =
62  Stokhos::create_product_tensor<execution_space>(*basis, *Cijk);
63 
64  // Serializers
66  rcp(new PCESerializerT(
69  fad_pce_serializer = rcp(new FadPCESerializerT(pce_serializer, 5));
70 
71  sz = basis->size();
72  }
73 };
74 
75 template <typename PCEType>
77  const Teuchos::Array<PCEType>& x2,
78  const std::string& tag,
79  Teuchos::FancyOStream& out) {
80 
81  // Check sizes match
82  bool success = (x.size() == x2.size());
83  out << tag << " PCE array size test";
84  if (success)
85  out << " passed";
86  else
87  out << " failed";
88  out << ": \n\tExpected: " << x.size() << ", \n\tGot: " << x2.size()
89  << "." << std::endl;
90 
91  // Check Fads match
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;
95  if (success2)
96  out << " passed";
97  else
98  out << " failed";
99  out << ": \n\tExpected: " << x[i] << ", \n\tGot: " << x2[i] << "."
100  << std::endl;
101  success = success && success2;
102  }
103 
104  return success;
105 }
106 
107 template<typename Ordinal>
109  const Teuchos::Comm<Ordinal> &comm,
111  const bool result
112  )
113 {
114  out << "\nChecking that the above test passed in all processes ...";
115  int thisResult = ( result ? 1 : 0 );
116  int sumResult = -1;
117  Teuchos::reduceAll(comm,Teuchos::REDUCE_SUM,Ordinal(1),&thisResult,
118  &sumResult);
119  const bool passed = sumResult==Teuchos::size(comm);
120  if(passed)
121  out << " passed\n";
122  else
123  out << " (sumResult="<<sumResult<<"!=numProcs="<<Teuchos::size(comm)<<") failed\n";
124  return passed;
125 }
126 
127 typedef int Ordinal;
128 typedef Sacado::Fad::DFad<double> FadType;
129 typedef Kokkos::DefaultExecutionSpace execution_space;
132 
133 Sacado::Random<double> rnd;
134 
135 TEUCHOS_UNIT_TEST( UQ_PCE_Comm, PCE_Broadcast ) {
139 
140  int n = 7;
141  Teuchos::Array<PCEType> x(n), x2(n);
142  for (int i=0; i<n; i++) {
143  x[i].reset(setup.kokkos_cijk);
144  for (int j=0; j<setup.sz; j++)
145  x[i].fastAccessCoeff(j) = rnd.number();
146  }
147  if (comm->getRank() == 0)
148  x2 = x;
149  Teuchos::broadcast(*comm, *setup.pce_serializer, 0, n, &x2[0]);
150  success = checkPCEArrays(x, x2, std::string("UQ::PCE")+" Broadcast", out);
151  success = checkResultOnAllProcs(*comm, out, success);
152 }
153 
154 TEUCHOS_UNIT_TEST( UQ_PCE_Comm, PCE_GatherAll ) {
158 
159  int n = 7;
160  int size = comm->getSize();
161  int rank = comm->getRank();
162  int N = n*size;
163  Teuchos::Array<PCEType> x(n), x2(N), x3(N);
164  for (int i=0; i<n; i++) {
165  x[i].reset(setup.kokkos_cijk);
166  for (int j=0; j<setup.sz; j++)
167  x[i].fastAccessCoeff(j) = (rank+1)*(i+1)*(j+1);
168  }
169  for (int j=0; j<size; j++) {
170  for (int i=0; i<n; i++) {
171  x3[n*j+i].reset(setup.kokkos_cijk);
172  for (int k=0; k<setup.sz; k++)
173  x3[n*j+i].fastAccessCoeff(k) = (j+1)*(i+1)*(k+1);
174  }
175  }
176  Teuchos::gatherAll(*comm, *setup.pce_serializer,
177  n, &x[0], N, &x2[0]);
178  success = checkPCEArrays(x3, x2, std::string("UQ::PCE")+" Gather All", out);
179  success = checkResultOnAllProcs(*comm, out, success);
180 }
181 
182 TEUCHOS_UNIT_TEST( UQ_PCE_Comm, PCE_SumAll ) {
186 
187  int n = 7;
188  int num_proc = comm->getSize();
189 
190  Teuchos::Array<PCEType> x(n), sums(n), sums2(n);
191  for (int i=0; i<n; i++) {
192  x[i].reset(setup.kokkos_cijk);
193  for (int j=0; j<setup.sz; j++)
194  x[i].fastAccessCoeff(j) = 2.0*(i+1);
195  }
196  for (int i=0; i<n; i++) {
197  sums[i].reset(setup.kokkos_cijk);
198  for (int j=0; j<setup.sz; j++)
199  sums[i].fastAccessCoeff(j) = 2.0*(i+1)*num_proc;
200  }
201  Teuchos::reduceAll(*comm, *setup.pce_serializer,
202  Teuchos::REDUCE_SUM, n, &x[0], &sums2[0]);
203  success = checkPCEArrays(sums, sums2,
204  std::string("UQ::PCE")+" Sum All", out);
205  success = checkResultOnAllProcs(*comm, out, success);
206 }
207 
208 TEUCHOS_UNIT_TEST( UQ_PCE_Comm, PCE_MaxAll ) {
212 
213  int n = 7;
214  int rank = comm->getRank();
215  int num_proc = comm->getSize();
216 
217  Teuchos::Array<PCEType> x(n), maxs(n), maxs2(n);
218  for (int i=0; i<n; i++) {
219  x[i].reset(setup.kokkos_cijk);
220  for (int j=0; j<setup.sz; j++)
221  x[i].fastAccessCoeff(j) = 2.0*(i+1)*(rank+1);
222  }
223  for (int i=0; i<n; i++) {
224  maxs[i].reset(setup.kokkos_cijk);
225  for (int j=0; j<setup.sz; j++)
226  maxs[i].fastAccessCoeff(j) = 2.0*(i+1)*num_proc;
227  }
228  Teuchos::reduceAll(*comm, *setup.pce_serializer,
229  Teuchos::REDUCE_MAX, n, &x[0], &maxs2[0]);
230  success = checkPCEArrays(maxs, maxs2,
231  std::string("UQ::PCE")+" Max All", out);
232  success = checkResultOnAllProcs(*comm, out, success);
233 }
234 
235 TEUCHOS_UNIT_TEST( UQ_PCE_Comm, PCE_MinAll ) {
239 
240  int n = 7;
241  int rank = comm->getRank();
242 
243  Teuchos::Array<PCEType> x(n), mins(n), mins2(n);
244  for (int i=0; i<n; i++) {
245  x[i].reset(setup.kokkos_cijk);
246  for (int j=0; j<setup.sz; j++)
247  x[i].fastAccessCoeff(j) = 2.0*(i+1)*(rank+1);
248  }
249  for (int i=0; i<n; i++) {
250  mins[i].reset(setup.kokkos_cijk);
251  for (int j=0; j<setup.sz; j++)
252  mins[i].fastAccessCoeff(j) = 2.0*(i+1);
253  }
254  Teuchos::reduceAll(*comm, *setup.pce_serializer,
255  Teuchos::REDUCE_MIN, n, &x[0], &mins2[0]);
256  success = checkPCEArrays(mins, mins2,
257  std::string("UQ::PCE")+" Min All", out);
258  success = checkResultOnAllProcs(*comm, out, success);
259 }
260 
261 TEUCHOS_UNIT_TEST( UQ_PCE_Comm, PCE_ScanSum ) {
265 
266  int n = 7;
267  int rank = comm->getRank();
268 
269  Teuchos::Array<PCEType> x(n), sums(n), sums2(n);
270  for (int i=0; i<n; i++) {
271  x[i].reset(setup.kokkos_cijk);
272  for (int j=0; j<setup.sz; j++)
273  x[i].fastAccessCoeff(j) = 2.0*(i+1);
274  }
275  for (int i=0; i<n; i++) {
276  sums[i].reset(setup.kokkos_cijk);
277  for (int j=0; j<setup.sz; j++)
278  sums[i].fastAccessCoeff(j) = 2.0*(i+1)*(rank+1);
279  }
280  Teuchos::scan(*comm, *setup.pce_serializer,
281  Teuchos::REDUCE_SUM, n, &x[0], &sums2[0]);
282  success = checkPCEArrays(sums, sums2,
283  std::string("UQ::PCE")+" Scan Sum", out);
284  success = checkResultOnAllProcs(*comm, out, success);
285 }
286 
287 TEUCHOS_UNIT_TEST( UQ_PCE_Comm, PCE_ScanMax ) {
291 
292  int n = 7;
293  int rank = comm->getRank();
294 
295  Teuchos::Array<PCEType> x(n), maxs(n), maxs2(n);
296  for (int i=0; i<n; i++) {
297  x[i].reset(setup.kokkos_cijk);
298  for (int j=0; j<setup.sz; j++)
299  x[i].fastAccessCoeff(j) = 2.0*(i+1)*(rank+1);
300  }
301  for (int i=0; i<n; i++) {
302  maxs[i].reset(setup.kokkos_cijk);
303  for (int j=0; j<setup.sz; j++)
304  maxs[i].fastAccessCoeff(j) = 2.0*(i+1)*(rank+1);
305  }
306  Teuchos::scan(*comm, *setup.pce_serializer,
307  Teuchos::REDUCE_MAX, n, &x[0], &maxs2[0]);
308  success = checkPCEArrays(maxs, maxs2,
309  std::string("UQ::PCE")+" Scan Max", out);
310  success = checkResultOnAllProcs(*comm, out, success);
311 }
312 
313 TEUCHOS_UNIT_TEST( UQ_PCE_Comm, PCE_ScanMin ) {
317 
318  int n = 7;
319  int rank = comm->getRank();
320 
321  Teuchos::Array<PCEType> x(n), mins(n), mins2(n);
322  for (int i=0; i<n; i++) {
323  x[i].reset(setup.kokkos_cijk);
324  for (int j=0; j<setup.sz; j++)
325  x[i].fastAccessCoeff(j) = 2.0*(i+1)*(rank+1);
326  }
327  for (int i=0; i<n; i++) {
328  mins[i].reset(setup.kokkos_cijk);
329  for (int j=0; j<setup.sz; j++)
330  mins[i].fastAccessCoeff(j) = 2.0*(i+1);
331  }
332  Teuchos::scan(*comm, *setup.pce_serializer,
333  Teuchos::REDUCE_MIN, n, &x[0], &mins2[0]);
334  success = checkPCEArrays(mins, mins2,
335  std::string("UQ::PCE")+" Scan Min", out);
336  success = checkResultOnAllProcs(*comm, out, success);
337 }
338 
339 TEUCHOS_UNIT_TEST( UQ_PCE_Comm, PCE_SendReceive ) {
343 
344  int num_proc = comm->getSize();
345  if (num_proc > 1) {
346  int rank = comm->getRank();
347  int n = 7;
348  Teuchos::Array<PCEType> x(n), x2(n);
349  for (int i=0; i<n; i++) {
350  x[i].reset(setup.kokkos_cijk);
351  for (int j=0; j<setup.sz; j++)
352  x[i].fastAccessCoeff(j) = 2.0*(i+1)*(j+1);
353  }
354  if (rank != 1)
355  x2 = x;
356  if (rank == 0) Teuchos::send(*comm, *setup.pce_serializer,
357  n, &x[0], 1);
358  if (rank == 1) Teuchos::receive(*comm, *setup.pce_serializer,
359  0, n, &x2[0]);
360  success = checkPCEArrays(x, x2,
361  std::string("UQ::PCE")+" Send/Receive", out);
362  success = checkResultOnAllProcs(*comm, out, success);
363  }
364  else
365  success = true;
366 }
367 
368 TEUCHOS_UNIT_TEST( UQ_PCE_Comm, FadPCE_Broadcast ) {
369  typedef Sacado::mpl::apply<FadType,PCEType>::type FadPCEType;
373 
374  int n = 7;
375  int p = 5;
376  Teuchos::Array<FadPCEType> x(n), x2(n);
377  for (int i=0; i<n; i++) {
378  PCEType f(setup.kokkos_cijk);
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++) {
383  PCEType g(setup.kokkos_cijk);
384  for (int k=0; k<setup.sz; k++)
385  g.fastAccessCoeff(k) = rnd.number();
386  x[i].fastAccessDx(j) = g;
387  }
388  }
389  if (comm->getRank() == 0)
390  x2 = x;
391  Teuchos::broadcast(*comm, *setup.fad_pce_serializer, 0, n, &x2[0]);
392  success = checkPCEArrays(x, x2,
393  std::string("DFad")+"<"+"UQ::PCE"+"> Broadcast", out);
394  success = checkResultOnAllProcs(*comm, out, success);
395 }
396 
397 TEUCHOS_UNIT_TEST( UQ_PCE_Comm, FadPCE_GatherAll ) {
398  typedef Sacado::mpl::apply<FadType,PCEType>::type FadPCEType;
402 
403  int n = 7;
404  int p = 5;
405  int size = comm->getSize();
406  int rank = comm->getRank();
407  int N = n*size;
408  Teuchos::Array<FadPCEType> x(n), x2(N), x3(N);
409  for (int i=0; i<n; i++) {
410  PCEType f(setup.kokkos_cijk);
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;
416  }
417  }
418  for (int j=0; j<size; j++) {
419  for (int i=0; i<n; i++) {
420  PCEType f(setup.kokkos_cijk);
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++)
425  x3[n*j+i].fastAccessDx(k) = f;
426  }
427  }
428  Teuchos::gatherAll(*comm, *setup.fad_pce_serializer,
429  n, &x[0], N, &x2[0]);
430  success = checkPCEArrays(x3, x2,
431  std::string("DFad")+"<"+"UQ::PCE"+"> Gather All", out);
432  success = checkResultOnAllProcs(*comm, out, success);
433 }
434 
435 TEUCHOS_UNIT_TEST( UQ_PCE_Comm, FadPCE_SumAll ) {
436  typedef Sacado::mpl::apply<FadType,PCEType>::type FadPCEType;
440 
441  int n = 7;
442  int p = 5;
443  int num_proc = comm->getSize();
444 
445  Teuchos::Array<FadPCEType> x(n), sums(n), sums2(n);
446  for (int i=0; i<n; i++) {
447  PCEType f(setup.kokkos_cijk);
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++) {
452  PCEType g(setup.kokkos_cijk);
453  for (int k=0; k<setup.sz; k++)
454  g.fastAccessCoeff(k) = 2.0*(i+1);
455  x[i].fastAccessDx(j) = g;
456  }
457  }
458  for (int i=0; i<n; i++) {
459  PCEType f(setup.kokkos_cijk);
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++) {
464  PCEType g(setup.kokkos_cijk);
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;
468  }
469  }
470  Teuchos::reduceAll(*comm, *setup.fad_pce_serializer,
471  Teuchos::REDUCE_SUM, n, &x[0], &sums2[0]);
472  success = checkPCEArrays(sums, sums2,
473  std::string("DFad")+"<"+"UQ::PCE"+"> Sum All", out);
474  success = checkResultOnAllProcs(*comm, out, success);
475 }
476 
477 TEUCHOS_UNIT_TEST( UQ_PCE_Comm, FadPCE_MaxAll ) {
478  typedef Sacado::mpl::apply<FadType,PCEType>::type FadPCEType;
482 
483  int n = 8;
484  int p = 5;
485  int rank = comm->getRank();
486  int num_proc = comm->getSize();
487 
488  Teuchos::Array<FadPCEType> x(n), maxs(n), maxs2(n);
489  for (int i=0; i<n; i++) {
490  PCEType f(setup.kokkos_cijk);
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;
496  }
497  }
498  for (int i=0; i<n; i++) {
499  PCEType f(setup.kokkos_cijk);
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++)
504  maxs[i].fastAccessDx(j) = f;
505  }
506  Teuchos::reduceAll(*comm, *setup.fad_pce_serializer,
507  Teuchos::REDUCE_MAX, n, &x[0], &maxs2[0]);
508  success = checkPCEArrays(maxs, maxs2,
509  std::string("DFad")+"<"+"UQ::PCE"+"> Max All", out);
510  success = checkResultOnAllProcs(*comm, out, success);
511 }
512 
513 TEUCHOS_UNIT_TEST( UQ_PCE_Comm, FadPCE_MinAll ) {
514  typedef Sacado::mpl::apply<FadType,PCEType>::type FadPCEType;
518 
519  int n = 8;
520  int p = 5;
521  int rank = comm->getRank();
522 
523  Teuchos::Array<FadPCEType> x(n), mins(n), mins2(n);
524  for (int i=0; i<n; i++) {
525  PCEType f(setup.kokkos_cijk);
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;
531  }
532  }
533  for (int i=0; i<n; i++) {
534  PCEType f(setup.kokkos_cijk);
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++)
539  mins[i].fastAccessDx(j) = f;
540  }
541  Teuchos::reduceAll(*comm, *setup.fad_pce_serializer,
542  Teuchos::REDUCE_MIN, n, &x[0], &mins2[0]);
543  success = checkPCEArrays(mins, mins2,
544  std::string("DFad")+"<"+"UQ::PCE"+"> Min All", out);
545  success = checkResultOnAllProcs(*comm, out, success);
546 }
547 
548 TEUCHOS_UNIT_TEST( UQ_PCE_Comm, FadPCE_ScanSum ) {
549  typedef Sacado::mpl::apply<FadType,PCEType>::type FadPCEType;
553 
554  int n = 7;
555  int p = 5;
556  int rank = comm->getRank();
557 
558  Teuchos::Array<FadPCEType> x(n), sums(n), sums2(n);
559  for (int i=0; i<n; i++) {
560  PCEType f(setup.kokkos_cijk);
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;
566  }
567  }
568  for (int i=0; i<n; i++) {
569  PCEType f(setup.kokkos_cijk);
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++)
574  sums[i].fastAccessDx(j) = f;
575  }
576  Teuchos::scan(*comm, *setup.fad_pce_serializer,
577  Teuchos::REDUCE_SUM, n, &x[0], &sums2[0]);
578  success = checkPCEArrays(sums, sums2,
579  std::string("DFad")+"<"+"UQ::PCE"+"> Scan Sum", out);
580  success = checkResultOnAllProcs(*comm, out, success);
581 }
582 
583 TEUCHOS_UNIT_TEST( UQ_PCE_Comm, FadPCE_ScanMax ) {
584  typedef Sacado::mpl::apply<FadType,PCEType>::type FadPCEType;
588 
589  int n = 7;
590  int p = 5;
591  int rank = comm->getRank();
592 
593  Teuchos::Array<FadPCEType> x(n), maxs(n), maxs2(n);
594  for (int i=0; i<n; i++) {
595  PCEType f(setup.kokkos_cijk);
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;
601  }
602  }
603  for (int i=0; i<n; i++) {
604  PCEType f(setup.kokkos_cijk);
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++)
609  maxs[i].fastAccessDx(j) = f;
610  }
611  Teuchos::scan(*comm, *setup.fad_pce_serializer,
612  Teuchos::REDUCE_MAX, n, &x[0], &maxs2[0]);
613  success = checkPCEArrays(maxs, maxs2,
614  std::string("DFad")+"<"+"UQ::PCE"+"> Scan Max", out);
615  success = checkResultOnAllProcs(*comm, out, success);
616 }
617 
618 TEUCHOS_UNIT_TEST( UQ_PCE_Comm, FadPCE_ScanMin ) {
619  typedef Sacado::mpl::apply<FadType,PCEType>::type FadPCEType;
623 
624  int n = 7;
625  int p = 5;
626  int rank = comm->getRank();
627 
628  Teuchos::Array<FadPCEType> x(n), mins(n), mins2(n);
629  for (int i=0; i<n; i++) {
630  PCEType f(setup.kokkos_cijk);
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;
636  }
637  }
638  for (int i=0; i<n; i++) {
639  PCEType f(setup.kokkos_cijk);
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++)
644  mins[i].fastAccessDx(j) = f;
645  }
646  Teuchos::scan(*comm, *setup.fad_pce_serializer,
647  Teuchos::REDUCE_MIN, n, &x[0], &mins2[0]);
648  success = checkPCEArrays(mins, mins2,
649  std::string("DFad")+"<"+"UQ::PCE"+"> Scan Min", out);
650  success = checkResultOnAllProcs(*comm, out, success);
651 }
652 
653 TEUCHOS_UNIT_TEST( UQ_PCE_Comm, FadPCE_SendReceive ) {
654  typedef Sacado::mpl::apply<FadType,PCEType>::type FadPCEType;
658 
659  int num_proc = comm->getSize();
660  if (num_proc > 1) {
661  int rank = comm->getRank();
662  int n = 7;
663  int p = 5;
664  Teuchos::Array<FadPCEType> x(n), x2(n);
665  for (int i=0; i<n; i++) {
666  PCEType f(setup.kokkos_cijk);
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++)
671  x[i].fastAccessDx(j) = f;
672  }
673  if (rank != 1)
674  x2 = x;
675  if (rank == 0) Teuchos::send(*comm, *setup.fad_pce_serializer,
676  n, &x[0], 1);
677  if (rank == 1) Teuchos::receive(*comm, *setup.fad_pce_serializer,
678  0, n, &x2[0]);
679  success = checkPCEArrays(x, x2,
680  std::string("DFad")+"<"+"UQ::PCE"+"> Send/Receive", out);
681  success = checkResultOnAllProcs(*comm, out, success);
682  }
683  else
684  success = true;
685 }
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)
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)
size_type size() const
bool checkResultOnAllProcs(const Teuchos::Comm< Ordinal > &comm, Teuchos::FancyOStream &out, const bool result)
TEUCHOS_UNIT_TEST(tAdaptivityManager, test_interface)
PCEType::cijk_type kokkos_cijk_type
int n
ScalarType g(const Teuchos::Array< ScalarType > &x, const ScalarType &y)
RCP< Stokhos::Sparse3Tensor< int, double > > Cijk
Teuchos::ValueTypeSerializer< int, PCEType > PCESerializerT