Sacado Package Browser (Single Doxygen Collection)  Version of the Day
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
Tay_CommTests.hpp
Go to the documentation of this file.
1 // @HEADER
2 // ***********************************************************************
3 //
4 // Sacado Package
5 // Copyright (2006) Sandia Corporation
6 //
7 // Under the terms of Contract DE-AC04-94AL85000 with Sandia Corporation,
8 // the U.S. Government retains certain rights in this software.
9 //
10 // This library is free software; you can redistribute it and/or modify
11 // it under the terms of the GNU Lesser General Public License as
12 // published by the Free Software Foundation; either version 2.1 of the
13 // License, or (at your option) any later version.
14 //
15 // This library is distributed in the hope that it will be useful, but
16 // WITHOUT ANY WARRANTY; without even the implied warranty of
17 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
18 // Lesser General Public License for more details.
19 //
20 // You should have received a copy of the GNU Lesser General Public
21 // License along with this library; if not, write to the Free Software
22 // Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301
23 // USA
24 // Questions? Contact David M. Gay (dmgay@sandia.gov) or Eric T. Phipps
25 // (etphipp@sandia.gov).
26 //
27 // ***********************************************************************
28 // @HEADER
30 #include "Teuchos_CommHelpers.hpp"
31 #include "Teuchos_DefaultComm.hpp"
32 #include "Teuchos_Array.hpp"
33 #include "Teuchos_Comm.hpp"
34 
35 #include "Sacado_mpl_apply.hpp"
36 #include "Sacado_Random.hpp"
37 
38 using Teuchos::RCP;
39 using Teuchos::rcp;
41 
42 template <typename TayType>
44  const Teuchos::Array<TayType>& x2,
45  const std::string& tag,
46  Teuchos::FancyOStream& out) {
47 
48  // Check sizes match
49  bool success = (x.size() == x2.size());
50  out << tag << " Taylor array size test";
51  if (success)
52  out << " passed";
53  else
54  out << " failed";
55  out << ": \n\tExpected: " << x.size() << ", \n\tGot: " << x2.size()
56  << "." << std::endl;
57 
58  // Check coefficients match
59  for (int i=0; i<x.size(); i++) {
60  bool success2 = Sacado::IsEqual<TayType>::eval(x[i], x2[i]);
61  out << tag << " Taylor array comparison test " << i;
62  if (success2)
63  out << " passed";
64  else
65  out << " failed";
66  out << ": \n\tExpected: " << x[i] << ", \n\tGot: " << x2[i] << "."
67  << std::endl;
68  success = success && success2;
69  }
70 
71  return success;
72 }
73 
74 template<typename Ordinal>
76  const Teuchos::Comm<Ordinal> &comm,
78  const bool result
79  )
80 {
81  out << "\nChecking that the above test passed in all processes ...";
82  int thisResult = ( result ? 1 : 0 );
83  int sumResult = -1;
85  &sumResult);
86  const bool passed = sumResult==Teuchos::size(comm);
87  if(passed)
88  out << " passed\n";
89  else
90  out << " (sumResult="<<sumResult<<"!=numProcs="<<Teuchos::size(comm)<<") failed\n";
91  return passed;
92 }
93 
94 #define TAY_COMM_TESTS(TayType, TAY) \
95 TEUCHOS_UNIT_TEST( TAY##_Comm, Broadcast ) { \
96  Teuchos::RCP<const Teuchos::Comm<Ordinal> > \
97  comm = Teuchos::DefaultComm<Ordinal>::getComm(); \
98  \
99  int n = 7; \
100  int p = 5; \
101  ValueTypeSerializer<int,TayType> tts( \
102  rcp(new ValueTypeSerializer<int,double>), p+1); \
103  \
104  Teuchos::Array<TayType> x(n), x2(n), x3(n); \
105  for (int i=0; i<n; i++) { \
106  x[i] = TayType(p, rnd.number()); \
107  for (int j=0; j<=p; j++) \
108  x[i].fastAccessCoeff(j) = rnd.number(); \
109  } \
110  for (int i=0; i<n; i++) { \
111  x2[i] = TayType(p, 0.0); \
112  } \
113  if (comm->getRank() == 0) { \
114  x2 = x; \
115  x3 = x; \
116  } \
117  \
118  Teuchos::broadcast(*comm, 0, n, &x2[0]); \
119  bool success1 = checkFadArrays( \
120  x, x2, std::string(#TAY)+" Broadcast", out); \
121  success1 = checkResultOnAllProcs(*comm, out, success1); \
122  \
123  Teuchos::broadcast(*comm, tts, 0, n, &x3[0]); \
124  bool success2 = checkFadArrays( \
125  x, x3, std::string(#TAY)+" Broadcast TTS", out); \
126  success2 = checkResultOnAllProcs(*comm, out, success2); \
127  \
128  success = success1 && success2; \
129 } \
130  \
131 TEUCHOS_UNIT_TEST( TAY##_Comm, GatherAll ) { \
132  Teuchos::RCP<const Teuchos::Comm<Ordinal> > \
133  comm = Teuchos::DefaultComm<Ordinal>::getComm(); \
134  \
135  int n = 7; \
136  int p = 5; \
137  int size = comm->getSize(); \
138  int rank = comm->getRank(); \
139  int N = n*size; \
140  ValueTypeSerializer<int,TayType> tts( \
141  rcp(new ValueTypeSerializer<int,double>), p+1); \
142  \
143  Teuchos::Array<TayType> x(n), x2(N), x3(N), x4(N); \
144  for (int i=0; i<n; i++) { \
145  x[i] = TayType(p, (rank+1)*(i+1)); \
146  for (int j=0; j<=p; j++) \
147  x[i].fastAccessCoeff(j) = (rank+1)*(i+1)*(j+1); \
148  } \
149  for (int i=0; i<N; i++) { \
150  x2[i] = TayType(p, 0.0); \
151  } \
152  for (int j=0; j<size; j++) { \
153  for (int i=0; i<n; i++) { \
154  x3[n*j+i] = TayType(p, (j+1)*(i+1)); \
155  for (int k=0; k<=p; k++) \
156  x3[n*j+i].fastAccessCoeff(k) = (j+1)*(i+1)*(k+1); \
157  } \
158  } \
159  \
160  Teuchos::gatherAll(*comm, n, &x[0], N, &x2[0]); \
161  bool success1 = checkFadArrays( \
162  x3, x2, std::string(#TAY)+" Gather All", out); \
163  success1 = checkResultOnAllProcs(*comm, out, success1); \
164  \
165  Teuchos::gatherAll(*comm, tts, n, &x[0], N, &x4[0]); \
166  bool success2 = checkFadArrays( \
167  x3, x4, std::string(#TAY)+" Gather All TTS", out); \
168  success2 = checkResultOnAllProcs(*comm, out, success2); \
169  \
170  success = success1 && success2; \
171 } \
172  \
173 TEUCHOS_UNIT_TEST( TAY##_Comm, SumAll ) { \
174  Teuchos::RCP<const Teuchos::Comm<Ordinal> > \
175  comm = Teuchos::DefaultComm<Ordinal>::getComm(); \
176  \
177  int n = 7; \
178  int p = 5; \
179  int num_proc = comm->getSize(); \
180  ValueTypeSerializer<int,TayType> tts( \
181  rcp(new ValueTypeSerializer<int,double>), p+1); \
182  \
183  Teuchos::Array<TayType> x(n), sums(n), sums2(n), sums3(n); \
184  for (int i=0; i<n; i++) { \
185  x[i] = TayType(p, 1.0*(i+1)); \
186  for (int j=0; j<=p; j++) \
187  x[i].fastAccessCoeff(j) = 2.0*(i+1); \
188  } \
189  for (int i=0; i<n; i++) { \
190  sums[i] = TayType(p, 1.0*(i+1)*num_proc); \
191  for (int j=0; j<=p; j++) \
192  sums[i].fastAccessCoeff(j) = 2.0*(i+1)*num_proc; \
193  } \
194  for (int i=0; i<n; i++) { \
195  sums2[i] = TayType(p, 0.0); \
196  } \
197  \
198  Teuchos::reduceAll(*comm, Teuchos::REDUCE_SUM, n, &x[0], &sums2[0]); \
199  bool success1 = checkFadArrays( \
200  sums, sums2, std::string(#TAY)+" Sum All", out); \
201  success1 = checkResultOnAllProcs(*comm, out, success1); \
202  \
203  Teuchos::reduceAll(*comm, tts, Teuchos::REDUCE_SUM, n, &x[0], &sums3[0]); \
204  bool success2 = checkFadArrays( \
205  sums, sums3, std::string(#TAY)+" Sum All TTS", out); \
206  success2 = checkResultOnAllProcs(*comm, out, success2); \
207  \
208  success = success1 && success2; \
209 } \
210  \
211 TEUCHOS_UNIT_TEST( TAY##_Comm, MaxAll ) { \
212  Teuchos::RCP<const Teuchos::Comm<Ordinal> > \
213  comm = Teuchos::DefaultComm<Ordinal>::getComm(); \
214  \
215  int n = 7; \
216  int p = 5; \
217  int rank = comm->getRank(); \
218  int num_proc = comm->getSize(); \
219  ValueTypeSerializer<int,TayType> tts( \
220  rcp(new ValueTypeSerializer<int,double>), p+1); \
221  \
222  Teuchos::Array<TayType> x(n), maxs(n), maxs2(n), maxs3(n); \
223  for (int i=0; i<n; i++) { \
224  x[i] = TayType(p, 1.0*(i+1)*(rank+1)); \
225  for (int j=0; j<=p; j++) \
226  x[i].fastAccessCoeff(j) = 2.0*(i+1)*(rank+1); \
227  } \
228  for (int i=0; i<n; i++) { \
229  maxs[i] = TayType(p, 1.0*(i+1)*num_proc); \
230  for (int j=0; j<=p; j++) \
231  maxs[i].fastAccessCoeff(j) = 2.0*(i+1)*num_proc; \
232  } \
233  for (int i=0; i<n; i++) { \
234  maxs2[i] = TayType(p, 0.0); \
235  } \
236  \
237  Teuchos::reduceAll(*comm, Teuchos::REDUCE_MAX, n, &x[0], &maxs2[0]); \
238  bool success1 = checkFadArrays( \
239  maxs, maxs2, std::string(#TAY)+" Max All", out); \
240  success1 = checkResultOnAllProcs(*comm, out, success1); \
241  \
242  Teuchos::reduceAll(*comm, tts, Teuchos::REDUCE_MAX, n, &x[0], &maxs3[0]); \
243  bool success2 = checkFadArrays( \
244  maxs, maxs3, std::string(#TAY)+" Max All TTS", out); \
245  success2 = checkResultOnAllProcs(*comm, out, success2); \
246  \
247  success = success1 && success2; \
248 } \
249  \
250 TEUCHOS_UNIT_TEST( TAY##_Comm, MinAll ) { \
251  Teuchos::RCP<const Teuchos::Comm<Ordinal> > \
252  comm = Teuchos::DefaultComm<Ordinal>::getComm(); \
253  \
254  int n = 7; \
255  int p = 5; \
256  int rank = comm->getRank(); \
257  ValueTypeSerializer<int,TayType> tts( \
258  rcp(new ValueTypeSerializer<int,double>), p+1); \
259  \
260  Teuchos::Array<TayType> x(n), mins(n), mins2(n), mins3(n); \
261  for (int i=0; i<n; i++) { \
262  x[i] = TayType(p, 1.0*(i+1)*(rank+1)); \
263  for (int j=0; j<=p; j++) \
264  x[i].fastAccessCoeff(j) = 2.0*(i+1)*(rank+1); \
265  } \
266  for (int i=0; i<n; i++) { \
267  mins[i] = TayType(p, 1.0*(i+1)); \
268  for (int j=0; j<=p; j++) \
269  mins[i].fastAccessCoeff(j) = 2.0*(i+1); \
270  } \
271  for (int i=0; i<n; i++) { \
272  mins2[i] = TayType(p, 0.0); \
273  } \
274  \
275  Teuchos::reduceAll(*comm, Teuchos::REDUCE_MIN, n, &x[0], &mins2[0]); \
276  bool success1 = checkFadArrays( \
277  mins, mins2, std::string(#TAY)+" Min All", out); \
278  success1 = checkResultOnAllProcs(*comm, out, success1); \
279  \
280  Teuchos::reduceAll(*comm, tts, Teuchos::REDUCE_MIN, n, &x[0], &mins3[0]); \
281  bool success2 = checkFadArrays( \
282  mins, mins3, std::string(#TAY)+" Min All TTS", out); \
283  success2 = checkResultOnAllProcs(*comm, out, success2); \
284  \
285  success = success1 && success2; \
286 } \
287  \
288 TEUCHOS_UNIT_TEST( TAY##_Comm, ScanSum ) { \
289  Teuchos::RCP<const Teuchos::Comm<Ordinal> > \
290  comm = Teuchos::DefaultComm<Ordinal>::getComm(); \
291  \
292  int n = 7; \
293  int p = 5; \
294  int rank = comm->getRank(); \
295  ValueTypeSerializer<int,TayType> tts( \
296  rcp(new ValueTypeSerializer<int,double>), p+1); \
297  \
298  Teuchos::Array<TayType> x(n), sums(n), sums2(n), sums3(n); \
299  for (int i=0; i<n; i++) { \
300  x[i] = TayType(p, 1.0*(i+1)); \
301  for (int j=0; j<=p; j++) \
302  x[i].fastAccessCoeff(j) = 2.0*(i+1); \
303  } \
304  for (int i=0; i<n; i++) { \
305  sums[i] = TayType(p, 1.0*(i+1)*(rank+1)); \
306  for (int j=0; j<=p; j++) \
307  sums[i].fastAccessCoeff(j) = 2.0*(i+1)*(rank+1); \
308  } \
309  for (int i=0; i<n; i++) { \
310  sums2[i] = TayType(p, 0.0); \
311  } \
312  \
313  Teuchos::scan(*comm, Teuchos::REDUCE_SUM, n, &x[0], &sums2[0]); \
314  bool success1 = checkFadArrays( \
315  sums, sums2, std::string(#TAY)+" Scan Sum", out); \
316  success1 = checkResultOnAllProcs(*comm, out, success1); \
317  \
318  Teuchos::scan(*comm, tts, Teuchos::REDUCE_SUM, n, &x[0], &sums3[0]); \
319  bool success2 = checkFadArrays( \
320  sums, sums3, std::string(#TAY)+" Scan Sum TTS", out); \
321  success2 = checkResultOnAllProcs(*comm, out, success2); \
322  \
323  success = success1 && success2; \
324 } \
325  \
326 TEUCHOS_UNIT_TEST( TAY##_Comm, ScanMax ) { \
327  Teuchos::RCP<const Teuchos::Comm<Ordinal> > \
328  comm = Teuchos::DefaultComm<Ordinal>::getComm(); \
329  \
330  int n = 7; \
331  int p = 5; \
332  int rank = comm->getRank(); \
333  ValueTypeSerializer<int,TayType> tts( \
334  rcp(new ValueTypeSerializer<int,double>), p+1); \
335  \
336  Teuchos::Array<TayType> x(n), maxs(n), maxs2(n), maxs3(n); \
337  for (int i=0; i<n; i++) { \
338  x[i] = TayType(p, 1.0*(i+1)*(rank+1)); \
339  for (int j=0; j<=p; j++) \
340  x[i].fastAccessCoeff(j) = 2.0*(i+1)*(rank+1); \
341  } \
342  for (int i=0; i<n; i++) { \
343  maxs[i] = TayType(p, 1.0*(i+1)*(rank+1)); \
344  for (int j=0; j<=p; j++) \
345  maxs[i].fastAccessCoeff(j) = 2.0*(i+1)*(rank+1); \
346  } \
347  for (int i=0; i<n; i++) { \
348  maxs2[i] = TayType(p, 0.0); \
349  } \
350  \
351  Teuchos::scan(*comm, Teuchos::REDUCE_MAX, n, &x[0], &maxs2[0]); \
352  bool success1 = checkFadArrays( \
353  maxs, maxs2, std::string(#TAY)+" Scan Max", out); \
354  success1 = checkResultOnAllProcs(*comm, out, success1); \
355  \
356  Teuchos::scan(*comm, tts, Teuchos::REDUCE_MAX, n, &x[0], &maxs3[0]); \
357  bool success2 = checkFadArrays( \
358  maxs, maxs3, std::string(#TAY)+" Scan Max TTS", out); \
359  success2 = checkResultOnAllProcs(*comm, out, success2); \
360  \
361  success = success1 && success2; \
362 } \
363  \
364 TEUCHOS_UNIT_TEST( TAY##_Comm, ScanMin ) { \
365  Teuchos::RCP<const Teuchos::Comm<Ordinal> > \
366  comm = Teuchos::DefaultComm<Ordinal>::getComm(); \
367  \
368  int n = 7; \
369  int p = 5; \
370  int rank = comm->getRank(); \
371  ValueTypeSerializer<int,TayType> tts( \
372  rcp(new ValueTypeSerializer<int,double>), p+1); \
373  \
374  Teuchos::Array<TayType> x(n), mins(n), mins2(n), mins3(n); \
375  for (int i=0; i<n; i++) { \
376  x[i] = TayType(p, 1.0*(i+1)*(rank+1)); \
377  for (int j=0; j<=p; j++) \
378  x[i].fastAccessCoeff(j) = 2.0*(i+1)*(rank+1); \
379  } \
380  for (int i=0; i<n; i++) { \
381  mins[i] = TayType(p, 1.0*(i+1)); \
382  for (int j=0; j<=p; j++) \
383  mins[i].fastAccessCoeff(j) = 2.0*(i+1); \
384  } \
385  for (int i=0; i<n; i++) { \
386  mins2[i] = TayType(p, 0.0); \
387  } \
388  \
389  Teuchos::scan(*comm, Teuchos::REDUCE_MIN, n, &x[0], &mins2[0]); \
390  bool success1 = checkFadArrays( \
391  mins, mins2, std::string(#TAY)+" Scan Min", out); \
392  success1 = checkResultOnAllProcs(*comm, out, success1); \
393  \
394  Teuchos::scan(*comm, tts, Teuchos::REDUCE_MIN, n, &x[0], &mins3[0]); \
395  bool success2 = checkFadArrays( \
396  mins, mins3, std::string(#TAY)+" Scan Min TTS", out); \
397  success2 = checkResultOnAllProcs(*comm, out, success2); \
398  \
399  success = success1 && success2; \
400 } \
401  \
402 TEUCHOS_UNIT_TEST( TAY##_Comm, SendReceive ) { \
403  Teuchos::RCP<const Teuchos::Comm<Ordinal> > \
404  comm = Teuchos::DefaultComm<Ordinal>::getComm(); \
405  \
406  int num_proc = comm->getSize(); \
407  if (num_proc > 1) { \
408  int rank = comm->getRank(); \
409  int n = 7; \
410  int p = 5; \
411  ValueTypeSerializer<int,TayType> tts( \
412  rcp(new ValueTypeSerializer<int,double>), p+1); \
413  \
414  Teuchos::Array<TayType> x(n), x2(n), x3(n); \
415  for (int i=0; i<n; i++) { \
416  x[i] = TayType(p, 1.0*(i+1)); \
417  for (int j=0; j<=p; j++) \
418  x[i].fastAccessCoeff(j) = 2.0*(i+1)*(j+1); \
419  } \
420  for (int i=0; i<n; i++) { \
421  x2[i] = TayType(p, 0.0); \
422  } \
423  if (rank != 1) { \
424  x2 = x; \
425  x3 = x2; \
426  } \
427  \
428  if (rank == 0) Teuchos::send(*comm, n, &x[0], 1); \
429  if (rank == 1) Teuchos::receive(*comm, 0, n, &x2[0]); \
430  bool success1 = checkFadArrays( \
431  x, x2, std::string(#TAY)+" Send/Receive", out); \
432  success1 = checkResultOnAllProcs(*comm, out, success1); \
433  \
434  if (rank == 0) Teuchos::send(*comm, tts, n, &x[0], 1); \
435  if (rank == 1) Teuchos::receive(*comm, tts, 0, n, &x3[0]); \
436  bool success2 = checkFadArrays( \
437  x, x3, std::string(#TAY)+" Send/Receive TTS", out); \
438  success2 = checkResultOnAllProcs(*comm, out, success2); \
439  \
440  success = success1 && success2; \
441  } \
442  else \
443  success = true; \
444 } \
445  \
446 TEUCHOS_UNIT_TEST( TAY##_Comm, NestedBroadcast ) { \
447  typedef Sacado::mpl::apply<TayType,TayType>::type TayTayType; \
448  Teuchos::RCP<const Teuchos::Comm<Ordinal> > \
449  comm = Teuchos::DefaultComm<Ordinal>::getComm(); \
450  \
451  int n = 7; \
452  int p1 = 5; \
453  int p2 = 5; \
454  RCP< ValueTypeSerializer<int,TayType> > tts = \
455  rcp(new ValueTypeSerializer<int,TayType>( \
456  rcp(new ValueTypeSerializer<int,double>), p1+1)); \
457  ValueTypeSerializer<int,TayTayType> ttts(tts, p2+1); \
458  \
459  Teuchos::Array<TayTayType> x(n), x2(n), x3(n); \
460  for (int i=0; i<n; i++) { \
461  TayType f(p1, rnd.number()); \
462  for (int k=0; k<=p1; k++) \
463  f.fastAccessCoeff(k) = rnd.number(); \
464  x[i] = TayTayType(p2, f); \
465  for (int j=0; j<=p2; j++) { \
466  TayType g(p1, rnd.number()); \
467  for (int k=0; k<=p1; k++) \
468  g.fastAccessCoeff(k) = rnd.number(); \
469  x[i].fastAccessCoeff(j) = g; \
470  } \
471  } \
472  for (int i=0; i<n; i++) { \
473  x2[i] = TayTayType(p2, TayType(p1, 0.0)); \
474  for (int j=0; j<=p2; j++) \
475  x2[i].fastAccessCoeff(j) = TayType(p1, 0.0); \
476  } \
477  if (comm->getRank() == 0) { \
478  x2 = x; \
479  x3 = x; \
480  } \
481  \
482  Teuchos::broadcast(*comm, 0, n, &x2[0]); \
483  bool success1 = checkFadArrays( \
484  x, x2, std::string(#TAY)+"<"+#TAY+"> Broadcast", out); \
485  success1 = checkResultOnAllProcs(*comm, out, success1); \
486  \
487  Teuchos::broadcast(*comm, ttts, 0, n, &x3[0]); \
488  bool success2 = checkFadArrays( \
489  x, x3, std::string(#TAY)+"<"+#TAY+"> Broadcast TTS", out); \
490  success2 = checkResultOnAllProcs(*comm, out, success2); \
491  \
492  success = success1 && success2; \
493 } \
494  \
495 TEUCHOS_UNIT_TEST( TAY##_Comm, NestedGatherAll ) { \
496  typedef Sacado::mpl::apply<TayType,TayType>::type TayTayType; \
497  Teuchos::RCP<const Teuchos::Comm<Ordinal> > \
498  comm = Teuchos::DefaultComm<Ordinal>::getComm(); \
499  \
500  int n = 7; \
501  int p1 = 5; \
502  int p2 = 5; \
503  RCP< ValueTypeSerializer<int,TayType> > tts = \
504  rcp(new ValueTypeSerializer<int,TayType>( \
505  rcp(new ValueTypeSerializer<int,double>), p1+1)); \
506  ValueTypeSerializer<int,TayTayType> ttts(tts, p2+1); \
507  \
508  int size = comm->getSize(); \
509  int rank = comm->getRank(); \
510  int N = n*size; \
511  Teuchos::Array<TayTayType> x(n), x2(N), x3(N), x4(N); \
512  for (int i=0; i<n; i++) { \
513  TayType f(p1, (rank+1)*(i+1)); \
514  for (int k=0; k<=p1; k++) \
515  f.fastAccessCoeff(k) = (rank+1)*(i+1)*(k+1); \
516  x[i] = TayTayType(p2, f); \
517  for (int j=0; j<=p2; j++) { \
518  x[i].fastAccessCoeff(j) = f; \
519  } \
520  } \
521  for (int i=0; i<N; i++) { \
522  x2[i] = TayTayType(p2, TayType(p1, 0.0)); \
523  for (int j=0; j<=p2; j++) \
524  x2[i].fastAccessCoeff(j) = TayType(p1, 0.0); \
525  } \
526  for (int j=0; j<size; j++) { \
527  for (int i=0; i<n; i++) { \
528  TayType f(p1, (j+1)*(i+1)); \
529  for (int k=0; k<=p1; k++) \
530  f.fastAccessCoeff(k) = (j+1)*(i+1)*(k+1); \
531  x3[n*j+i] = TayTayType(p2, f); \
532  for (int k=0; k<=p2; k++) \
533  x3[n*j+i].fastAccessCoeff(k) = f; \
534  } \
535  } \
536  \
537  Teuchos::gatherAll(*comm, n, &x[0], N, &x2[0]); \
538  bool success1 = checkFadArrays( \
539  x3, x2, std::string(#TAY)+"<"+#TAY+"> Gather All", out); \
540  success1 = checkResultOnAllProcs(*comm, out, success1); \
541  \
542  Teuchos::gatherAll(*comm, ttts, n, &x[0], N, &x4[0]); \
543  bool success2 = checkFadArrays( \
544  x3, x4, std::string(#TAY)+"<"+#TAY+"> Gather All FTS", out); \
545  success2 = checkResultOnAllProcs(*comm, out, success2); \
546  \
547  success = success1 && success2; \
548 } \
549  \
550 TEUCHOS_UNIT_TEST( TAY##_Comm, NestedSumAll ) { \
551  typedef Sacado::mpl::apply<TayType,TayType>::type TayTayType; \
552  Teuchos::RCP<const Teuchos::Comm<Ordinal> > \
553  comm = Teuchos::DefaultComm<Ordinal>::getComm(); \
554  \
555  int n = 7; \
556  int p1 = 5; \
557  int p2 = 5; \
558  int num_proc = comm->getSize(); \
559  RCP< ValueTypeSerializer<int,TayType> > tts = \
560  rcp(new ValueTypeSerializer<int,TayType>( \
561  rcp(new ValueTypeSerializer<int,double>), p1+1)); \
562  ValueTypeSerializer<int,TayTayType> ttts(tts, p2+1); \
563  \
564  Teuchos::Array<TayTayType> x(n), sums(n), sums2(n), sums3(n); \
565  for (int i=0; i<n; i++) { \
566  TayType f(p1, 1.0*(i+1)); \
567  for (int k=0; k<=p1; k++) \
568  f.fastAccessCoeff(k) = 2.0*(i+1); \
569  x[i] = TayTayType(p2, f); \
570  for (int j=0; j<=p2; j++) { \
571  x[i].fastAccessCoeff(j) = f; \
572  } \
573  } \
574  for (int i=0; i<n; i++) { \
575  TayType f(p1, 1.0*(i+1)*num_proc); \
576  for (int k=0; k<=p1; k++) \
577  f.fastAccessCoeff(k) = 2.0*(i+1)*num_proc; \
578  sums[i] = TayTayType(p2, f); \
579  for (int j=0; j<=p2; j++) \
580  sums[i].fastAccessCoeff(j) = f; \
581  } \
582  for (int i=0; i<n; i++) { \
583  sums2[i] = TayTayType(p2, TayType(p1, 0.0)); \
584  for (int j=0; j<=p2; j++) \
585  sums2[i].fastAccessCoeff(j) = TayType(p1, 0.0); \
586  } \
587  \
588  Teuchos::reduceAll(*comm, Teuchos::REDUCE_SUM, n, &x[0], &sums2[0]); \
589  bool success1 = checkFadArrays( \
590  sums, sums2, std::string(#TAY)+"<"+#TAY+"> Sum All", out); \
591  success1 = checkResultOnAllProcs(*comm, out, success1); \
592  \
593  Teuchos::reduceAll(*comm, ttts, Teuchos::REDUCE_SUM, n, &x[0], &sums3[0]); \
594  bool success2 = checkFadArrays( \
595  sums, sums3, std::string(#TAY)+"<"+#TAY+"> Sum All", out); \
596  success2 = checkResultOnAllProcs(*comm, out, success2); \
597  \
598  success = success1 && success2; \
599 } \
600  \
601 TEUCHOS_UNIT_TEST( TAY##_Comm, NestedMaxAll ) { \
602  typedef Sacado::mpl::apply<TayType,TayType>::type TayTayType; \
603  Teuchos::RCP<const Teuchos::Comm<Ordinal> > \
604  comm = Teuchos::DefaultComm<Ordinal>::getComm(); \
605  \
606  int n = 7; \
607  int p1 = 5; \
608  int p2 = 5; \
609  int rank = comm->getRank(); \
610  int num_proc = comm->getSize(); \
611  RCP< ValueTypeSerializer<int,TayType> > tts = \
612  rcp(new ValueTypeSerializer<int,TayType>( \
613  rcp(new ValueTypeSerializer<int,double>), p1+1)); \
614  ValueTypeSerializer<int,TayTayType> ttts(tts, p2+1); \
615  \
616  Teuchos::Array<TayTayType> x(n), maxs(n), maxs2(n), maxs3(n); \
617  for (int i=0; i<n; i++) { \
618  TayType f(p1, 1.0*(i+1)*(rank+1)); \
619  for (int k=0; k<=p1; k++) \
620  f.fastAccessCoeff(k) = 2.0*(i+1)*(rank+1); \
621  x[i] = TayTayType(p2, f); \
622  for (int j=0; j<=p2; j++) { \
623  x[i].fastAccessCoeff(j) = f; \
624  } \
625  } \
626  for (int i=0; i<n; i++) { \
627  TayType f(p1, 1.0*(i+1)*num_proc); \
628  for (int k=0; k<=p1; k++) \
629  f.fastAccessCoeff(k) = 2.0*(i+1)*num_proc; \
630  maxs[i] = TayTayType(p2, f); \
631  for (int j=0; j<=p2; j++) \
632  maxs[i].fastAccessCoeff(j) = f; \
633  } \
634  for (int i=0; i<n; i++) { \
635  maxs2[i] = TayTayType(p2, TayType(p1, 0.0)); \
636  for (int j=0; j<=p2; j++) \
637  maxs2[i].fastAccessCoeff(j) = TayType(p1, 0.0); \
638  } \
639  \
640  Teuchos::reduceAll(*comm, Teuchos::REDUCE_MAX, n, &x[0], &maxs2[0]); \
641  bool success1 = checkFadArrays( \
642  maxs, maxs2, std::string(#TAY)+"<"+#TAY+"> Max All", out); \
643  success1 = checkResultOnAllProcs(*comm, out, success1); \
644  \
645  Teuchos::reduceAll(*comm, ttts, Teuchos::REDUCE_MAX, n, &x[0], &maxs3[0]); \
646  bool success2 = checkFadArrays( \
647  maxs, maxs3, std::string(#TAY)+"<"+#TAY+"> Max All FTS", out); \
648  success2 = checkResultOnAllProcs(*comm, out, success2); \
649  \
650  success = success1 && success2; \
651 } \
652  \
653 TEUCHOS_UNIT_TEST( TAY##_Comm, NestedMinAll ) { \
654  typedef Sacado::mpl::apply<TayType,TayType>::type TayTayType; \
655  Teuchos::RCP<const Teuchos::Comm<Ordinal> > \
656  comm = Teuchos::DefaultComm<Ordinal>::getComm(); \
657  \
658  int n = 7; \
659  int p1 = 5; \
660  int p2 = 5; \
661  int rank = comm->getRank(); \
662  RCP< ValueTypeSerializer<int,TayType> > tts = \
663  rcp(new ValueTypeSerializer<int,TayType>( \
664  rcp(new ValueTypeSerializer<int,double>), p1+1)); \
665  ValueTypeSerializer<int,TayTayType> ttts(tts, p2+1); \
666  \
667  Teuchos::Array<TayTayType> x(n), mins(n), mins2(n), mins3(n); \
668  for (int i=0; i<n; i++) { \
669  TayType f(p1, 1.0*(i+1)*(rank+1)); \
670  for (int k=0; k<=p1; k++) \
671  f.fastAccessCoeff(k) = 2.0*(i+1)*(rank+1); \
672  x[i] = TayTayType(p2, f); \
673  for (int j=0; j<=p2; j++) { \
674  x[i].fastAccessCoeff(j) = f; \
675  } \
676  } \
677  for (int i=0; i<n; i++) { \
678  TayType f(p1, 1.0*(i+1)); \
679  for (int k=0; k<=p1; k++) \
680  f.fastAccessCoeff(k) = 2.0*(i+1); \
681  mins[i] = TayTayType(p2, f); \
682  for (int j=0; j<=p2; j++) \
683  mins[i].fastAccessCoeff(j) = f; \
684  } \
685  for (int i=0; i<n; i++) { \
686  mins2[i] = TayTayType(p2, TayType(p1, 0.0)); \
687  for (int j=0; j<=p2; j++) \
688  mins2[i].fastAccessCoeff(j) = TayType(p1, 0.0); \
689  } \
690  \
691  Teuchos::reduceAll(*comm, Teuchos::REDUCE_MIN, n, &x[0], &mins2[0]); \
692  bool success1 = checkFadArrays( \
693  mins, mins2, std::string(#TAY)+"<"+#TAY+"> Min All", out); \
694  success1 = checkResultOnAllProcs(*comm, out, success1); \
695  \
696  Teuchos::reduceAll(*comm, ttts, Teuchos::REDUCE_MIN, n, &x[0], &mins3[0]); \
697  bool success2 = checkFadArrays( \
698  mins, mins3, std::string(#TAY)+"<"+#TAY+"> Min All FTS", out); \
699  success2 = checkResultOnAllProcs(*comm, out, success2); \
700  \
701  success = success1 && success2; \
702 } \
703  \
704 TEUCHOS_UNIT_TEST( TAY##_Comm, NestedScanSum ) { \
705  typedef Sacado::mpl::apply<TayType,TayType>::type TayTayType; \
706  Teuchos::RCP<const Teuchos::Comm<Ordinal> > \
707  comm = Teuchos::DefaultComm<Ordinal>::getComm(); \
708  \
709  int n = 7; \
710  int p1 = 5; \
711  int p2 = 5; \
712  int rank = comm->getRank(); \
713  RCP< ValueTypeSerializer<int,TayType> > tts = \
714  rcp(new ValueTypeSerializer<int,TayType>( \
715  rcp(new ValueTypeSerializer<int,double>), p1+1)); \
716  ValueTypeSerializer<int,TayTayType> ttts(tts, p2+1); \
717  \
718  Teuchos::Array<TayTayType> x(n), sums(n), sums2(n), sums3(n); \
719  for (int i=0; i<n; i++) { \
720  TayType f(p1, 1.0*(i+1)); \
721  for (int k=0; k<=p1; k++) \
722  f.fastAccessCoeff(k) = 2.0*(i+1); \
723  x[i] = TayTayType(p2, f); \
724  for (int j=0; j<=p2; j++) { \
725  x[i].fastAccessCoeff(j) = f; \
726  } \
727  } \
728  for (int i=0; i<n; i++) { \
729  TayType f(p1, 1.0*(i+1)*(rank+1)); \
730  for (int k=0; k<=p1; k++) \
731  f.fastAccessCoeff(k) = 2.0*(i+1)*(rank+1); \
732  sums[i] = TayTayType(p2, f); \
733  for (int j=0; j<=p2; j++) \
734  sums[i].fastAccessCoeff(j) = f; \
735  } \
736  for (int i=0; i<n; i++) { \
737  sums2[i] = TayTayType(p2, TayType(p1, 0.0)); \
738  for (int j=0; j<=p2; j++) \
739  sums2[i].fastAccessCoeff(j) = TayType(p1, 0.0); \
740  } \
741  \
742  Teuchos::scan(*comm, Teuchos::REDUCE_SUM, n, &x[0], &sums2[0]); \
743  bool success1 = checkFadArrays( \
744  sums, sums2, std::string(#TAY)+"<"+#TAY+"> Scan Sum", out); \
745  success1 = checkResultOnAllProcs(*comm, out, success1); \
746  \
747  Teuchos::scan(*comm, ttts, Teuchos::REDUCE_SUM, n, &x[0], &sums3[0]); \
748  bool success2 = checkFadArrays( \
749  sums, sums3, std::string(#TAY)+"<"+#TAY+"> Scan Sum FTS", out); \
750  success2 = checkResultOnAllProcs(*comm, out, success2); \
751  \
752  success = success1 && success2; \
753 } \
754  \
755 TEUCHOS_UNIT_TEST( TAY##_Comm, NestedScanMax ) { \
756  typedef Sacado::mpl::apply<TayType,TayType>::type TayTayType; \
757  Teuchos::RCP<const Teuchos::Comm<Ordinal> > \
758  comm = Teuchos::DefaultComm<Ordinal>::getComm(); \
759  \
760  int n = 7; \
761  int p1 = 5; \
762  int p2 = 5; \
763  int rank = comm->getRank(); \
764  RCP< ValueTypeSerializer<int,TayType> > tts = \
765  rcp(new ValueTypeSerializer<int,TayType>( \
766  rcp(new ValueTypeSerializer<int,double>), p1+1)); \
767  ValueTypeSerializer<int,TayTayType> ttts(tts, p2+1); \
768  \
769  Teuchos::Array<TayTayType> x(n), maxs(n), maxs2(n), maxs3(n); \
770  for (int i=0; i<n; i++) { \
771  TayType f(p1, 1.0*(i+1)*(rank+1)); \
772  for (int k=0; k<=p1; k++) \
773  f.fastAccessCoeff(k) = 2.0*(i+1)*(rank+1); \
774  x[i] = TayTayType(p2, f); \
775  for (int j=0; j<=p2; j++) { \
776  x[i].fastAccessCoeff(j) = f; \
777  } \
778  } \
779  for (int i=0; i<n; i++) { \
780  TayType f(p1, 1.0*(i+1)*(rank+1)); \
781  for (int k=0; k<=p1; k++) \
782  f.fastAccessCoeff(k) = 2.0*(i+1)*(rank+1); \
783  maxs[i] = TayTayType(p2, f); \
784  for (int j=0; j<=p2; j++) \
785  maxs[i].fastAccessCoeff(j) = f; \
786  } \
787  for (int i=0; i<n; i++) { \
788  maxs2[i] = TayTayType(p2, TayType(p1, 0.0)); \
789  for (int j=0; j<=p2; j++) \
790  maxs2[i].fastAccessCoeff(j) = TayType(p1, 0.0); \
791  } \
792  \
793  Teuchos::scan(*comm, Teuchos::REDUCE_MAX, n, &x[0], &maxs2[0]); \
794  bool success1 = checkFadArrays( \
795  maxs, maxs2, std::string(#TAY)+"<"+#TAY+"> Scan Max", out); \
796  success1 = checkResultOnAllProcs(*comm, out, success1); \
797  \
798  Teuchos::scan(*comm, ttts, Teuchos::REDUCE_MAX, n, &x[0], &maxs3[0]); \
799  bool success2 = checkFadArrays( \
800  maxs, maxs3, std::string(#TAY)+"<"+#TAY+"> Scan Max FTS", out); \
801  success2 = checkResultOnAllProcs(*comm, out, success2); \
802  \
803  success = success1 && success2; \
804 } \
805  \
806 TEUCHOS_UNIT_TEST( TAY##_Comm, NestedScanMin ) { \
807  typedef Sacado::mpl::apply<TayType,TayType>::type TayTayType; \
808  Teuchos::RCP<const Teuchos::Comm<Ordinal> > \
809  comm = Teuchos::DefaultComm<Ordinal>::getComm(); \
810  \
811  int n = 7; \
812  int p1 = 5; \
813  int p2 = 5; \
814  int rank = comm->getRank(); \
815  RCP< ValueTypeSerializer<int,TayType> > tts = \
816  rcp(new ValueTypeSerializer<int,TayType>( \
817  rcp(new ValueTypeSerializer<int,double>), p1+1)); \
818  ValueTypeSerializer<int,TayTayType> ttts(tts, p2+1); \
819  \
820  Teuchos::Array<TayTayType> x(n), mins(n), mins2(n), mins3(n); \
821  for (int i=0; i<n; i++) { \
822  TayType f(p1, 1.0*(i+1)*(rank+1)); \
823  for (int k=0; k<=p1; k++) \
824  f.fastAccessCoeff(k) = 2.0*(i+1)*(rank+1); \
825  x[i] = TayTayType(p2, f); \
826  for (int j=0; j<=p2; j++) { \
827  x[i].fastAccessCoeff(j) = f; \
828  } \
829  } \
830  for (int i=0; i<n; i++) { \
831  TayType f(p1, 1.0*(i+1)); \
832  for (int k=0; k<=p1; k++) \
833  f.fastAccessCoeff(k) = 2.0*(i+1); \
834  mins[i] = TayTayType(p2, f); \
835  for (int j=0; j<=p2; j++) \
836  mins[i].fastAccessCoeff(j) = f; \
837  } \
838  for (int i=0; i<n; i++) { \
839  mins2[i] = TayTayType(p2, TayType(p1, 0.0)); \
840  for (int j=0; j<=p2; j++) \
841  mins2[i].fastAccessCoeff(j) = TayType(p1, 0.0); \
842  } \
843  \
844  Teuchos::scan(*comm, Teuchos::REDUCE_MIN, n, &x[0], &mins2[0]); \
845  bool success1 = checkFadArrays( \
846  mins, mins2, std::string(#TAY)+"<"+#TAY+"> Scan Min", out); \
847  success1 = checkResultOnAllProcs(*comm, out, success1); \
848  \
849  Teuchos::scan(*comm, ttts, Teuchos::REDUCE_MIN, n, &x[0], &mins3[0]); \
850  bool success2 = checkFadArrays( \
851  mins, mins3, std::string(#TAY)+"<"+#TAY+"> Scan Min FTS", out); \
852  success2 = checkResultOnAllProcs(*comm, out, success2); \
853  \
854  success = success1 && success2; \
855 } \
856  \
857 TEUCHOS_UNIT_TEST( TAY##_Comm, NestedSendReceive ) { \
858  typedef Sacado::mpl::apply<TayType,TayType>::type TayTayType; \
859  Teuchos::RCP<const Teuchos::Comm<Ordinal> > \
860  comm = Teuchos::DefaultComm<Ordinal>::getComm(); \
861  \
862  int num_proc = comm->getSize(); \
863  if (num_proc > 1) { \
864  int rank = comm->getRank(); \
865  int n = 7; \
866  int p1 = 5; \
867  int p2 = 5; \
868  RCP< ValueTypeSerializer<int,TayType> > tts = \
869  rcp(new ValueTypeSerializer<int,TayType>( \
870  rcp(new ValueTypeSerializer<int,double>), p1+1)); \
871  ValueTypeSerializer<int,TayTayType> ttts(tts, p2+1); \
872  \
873  Teuchos::Array<TayTayType> x(n), x2(n), x3(n); \
874  for (int i=0; i<n; i++) { \
875  TayType f(p1, 1.0*(i+1)); \
876  for (int k=0; k<=p1; k++) \
877  f.fastAccessCoeff(k) = 2.0*(i+1)*(k+1); \
878  x[i] = TayTayType(p2, f); \
879  for (int j=0; j<=p2; j++) \
880  x[i].fastAccessCoeff(j) = f; \
881  } \
882  for (int i=0; i<n; i++) { \
883  x2[i] = TayTayType(p2, TayType(p1, 0.0)); \
884  for (int j=0; j<=p2; j++) \
885  x2[i].fastAccessCoeff(j) = TayType(p1, 0.0); \
886  } \
887  if (rank != 1) { \
888  x2 = x; \
889  x3 = x2; \
890  } \
891  \
892  if (rank == 0) Teuchos::send(*comm, n, &x[0], 1); \
893  if (rank == 1) Teuchos::receive(*comm, 0, n, &x2[0]); \
894  bool success1 = checkFadArrays( \
895  x, x2, std::string(#TAY)+"<"+#TAY+"> Send/Receive", out); \
896  success1 = checkResultOnAllProcs(*comm, out, success1); \
897  \
898  if (rank == 0) Teuchos::send(*comm, ttts, n, &x[0], 1); \
899  if (rank == 1) Teuchos::receive(*comm, ttts, 0, n, &x3[0]); \
900  bool success2 = checkFadArrays( \
901  x, x3, std::string(#TAY)+"<"+#TAY+"> Send/Receive FTS", out); \
902  success2 = checkResultOnAllProcs(*comm, out, success2); \
903  \
904  success = success1 && success2; \
905  } \
906  else \
907  success = true; \
908 }
static KOKKOS_INLINE_FUNCTION bool eval(const T &x, const T &y)
TEUCHOS_DEPRECATED RCP< T > rcp(T *p, Dealloc_T dealloc, bool owns_mem)
bool checkFadArrays(const ArrayType &x, const ArrayType &x2, const std::string &tag, Teuchos::FancyOStream &out)
bool checkResultOnAllProcs(const Teuchos::Comm< Ordinal > &comm, Teuchos::FancyOStream &out, const bool result)
TEUCHOS_DEPRECATED void reduceAll(const Comm< Ordinal > &comm, const EReductionType reductType, const Packet &send, Packet *globalReduct)
int Ordinal
size_type size() const