42 template <
typename TayType>
45 const std::string& tag,
49 bool success = (x.
size() == x2.
size());
50 out << tag <<
" Taylor array size test";
55 out <<
": \n\tExpected: " << x.
size() <<
", \n\tGot: " << x2.
size()
59 for (
int i=0; i<x.
size(); i++) {
61 out << tag <<
" Taylor array comparison test " << i;
66 out <<
": \n\tExpected: " << x[i] <<
", \n\tGot: " << x2[i] <<
"."
68 success = success && success2;
74 template<
typename Ordinal>
81 out <<
"\nChecking that the above test passed in all processes ...";
82 int thisResult = ( result ? 1 : 0 );
86 const bool passed = sumResult==Teuchos::size(comm);
90 out <<
" (sumResult="<<sumResult<<
"!=numProcs="<<Teuchos::size(comm)<<
") failed\n";
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(); \
101 ValueTypeSerializer<int,TayType> tts( \
102 rcp(new ValueTypeSerializer<int,double>), p+1); \
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(); \
110 for (int i=0; i<n; i++) { \
111 x2[i] = TayType(p, 0.0); \
113 if (comm->getRank() == 0) { \
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); \
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); \
128 success = success1 && success2; \
131 TEUCHOS_UNIT_TEST( TAY##_Comm, GatherAll ) { \
132 Teuchos::RCP<const Teuchos::Comm<Ordinal> > \
133 comm = Teuchos::DefaultComm<Ordinal>::getComm(); \
137 int size = comm->getSize(); \
138 int rank = comm->getRank(); \
140 ValueTypeSerializer<int,TayType> tts( \
141 rcp(new ValueTypeSerializer<int,double>), p+1); \
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); \
149 for (int i=0; i<N; i++) { \
150 x2[i] = TayType(p, 0.0); \
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); \
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); \
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); \
170 success = success1 && success2; \
173 TEUCHOS_UNIT_TEST( TAY##_Comm, SumAll ) { \
174 Teuchos::RCP<const Teuchos::Comm<Ordinal> > \
175 comm = Teuchos::DefaultComm<Ordinal>::getComm(); \
179 int num_proc = comm->getSize(); \
180 ValueTypeSerializer<int,TayType> tts( \
181 rcp(new ValueTypeSerializer<int,double>), p+1); \
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); \
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; \
194 for (int i=0; i<n; i++) { \
195 sums2[i] = TayType(p, 0.0); \
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); \
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); \
208 success = success1 && success2; \
211 TEUCHOS_UNIT_TEST( TAY##_Comm, MaxAll ) { \
212 Teuchos::RCP<const Teuchos::Comm<Ordinal> > \
213 comm = Teuchos::DefaultComm<Ordinal>::getComm(); \
217 int rank = comm->getRank(); \
218 int num_proc = comm->getSize(); \
219 ValueTypeSerializer<int,TayType> tts( \
220 rcp(new ValueTypeSerializer<int,double>), p+1); \
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); \
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; \
233 for (int i=0; i<n; i++) { \
234 maxs2[i] = TayType(p, 0.0); \
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); \
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); \
247 success = success1 && success2; \
250 TEUCHOS_UNIT_TEST( TAY##_Comm, MinAll ) { \
251 Teuchos::RCP<const Teuchos::Comm<Ordinal> > \
252 comm = Teuchos::DefaultComm<Ordinal>::getComm(); \
256 int rank = comm->getRank(); \
257 ValueTypeSerializer<int,TayType> tts( \
258 rcp(new ValueTypeSerializer<int,double>), p+1); \
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); \
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); \
271 for (int i=0; i<n; i++) { \
272 mins2[i] = TayType(p, 0.0); \
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); \
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); \
285 success = success1 && success2; \
288 TEUCHOS_UNIT_TEST( TAY##_Comm, ScanSum ) { \
289 Teuchos::RCP<const Teuchos::Comm<Ordinal> > \
290 comm = Teuchos::DefaultComm<Ordinal>::getComm(); \
294 int rank = comm->getRank(); \
295 ValueTypeSerializer<int,TayType> tts( \
296 rcp(new ValueTypeSerializer<int,double>), p+1); \
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); \
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); \
309 for (int i=0; i<n; i++) { \
310 sums2[i] = TayType(p, 0.0); \
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); \
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); \
323 success = success1 && success2; \
326 TEUCHOS_UNIT_TEST( TAY##_Comm, ScanMax ) { \
327 Teuchos::RCP<const Teuchos::Comm<Ordinal> > \
328 comm = Teuchos::DefaultComm<Ordinal>::getComm(); \
332 int rank = comm->getRank(); \
333 ValueTypeSerializer<int,TayType> tts( \
334 rcp(new ValueTypeSerializer<int,double>), p+1); \
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); \
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); \
347 for (int i=0; i<n; i++) { \
348 maxs2[i] = TayType(p, 0.0); \
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); \
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); \
361 success = success1 && success2; \
364 TEUCHOS_UNIT_TEST( TAY##_Comm, ScanMin ) { \
365 Teuchos::RCP<const Teuchos::Comm<Ordinal> > \
366 comm = Teuchos::DefaultComm<Ordinal>::getComm(); \
370 int rank = comm->getRank(); \
371 ValueTypeSerializer<int,TayType> tts( \
372 rcp(new ValueTypeSerializer<int,double>), p+1); \
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); \
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); \
385 for (int i=0; i<n; i++) { \
386 mins2[i] = TayType(p, 0.0); \
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); \
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); \
399 success = success1 && success2; \
402 TEUCHOS_UNIT_TEST( TAY##_Comm, SendReceive ) { \
403 Teuchos::RCP<const Teuchos::Comm<Ordinal> > \
404 comm = Teuchos::DefaultComm<Ordinal>::getComm(); \
406 int num_proc = comm->getSize(); \
407 if (num_proc > 1) { \
408 int rank = comm->getRank(); \
411 ValueTypeSerializer<int,TayType> tts( \
412 rcp(new ValueTypeSerializer<int,double>), p+1); \
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); \
420 for (int i=0; i<n; i++) { \
421 x2[i] = TayType(p, 0.0); \
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); \
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); \
440 success = success1 && success2; \
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(); \
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); \
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; \
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); \
477 if (comm->getRank() == 0) { \
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); \
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); \
492 success = success1 && success2; \
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(); \
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); \
508 int size = comm->getSize(); \
509 int rank = comm->getRank(); \
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; \
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); \
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; \
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); \
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); \
547 success = success1 && success2; \
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(); \
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); \
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; \
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; \
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); \
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); \
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); \
598 success = success1 && success2; \
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(); \
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); \
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; \
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; \
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); \
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); \
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); \
650 success = success1 && success2; \
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(); \
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); \
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; \
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; \
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); \
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); \
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); \
701 success = success1 && success2; \
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(); \
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); \
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; \
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; \
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); \
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); \
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); \
752 success = success1 && success2; \
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(); \
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); \
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; \
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; \
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); \
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); \
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); \
803 success = success1 && success2; \
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(); \
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); \
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; \
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; \
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); \
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); \
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); \
854 success = success1 && success2; \
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(); \
862 int num_proc = comm->getSize(); \
863 if (num_proc > 1) { \
864 int rank = comm->getRank(); \
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); \
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; \
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); \
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); \
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); \
904 success = success1 && success2; \
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)