23 template <
typename TayType>
26 const std::string& tag,
30 bool success = (x.
size() == x2.
size());
31 out << tag <<
" Taylor array size test";
36 out <<
": \n\tExpected: " << x.
size() <<
", \n\tGot: " << x2.
size()
40 for (
int i=0;
i<x.
size();
i++) {
42 out << tag <<
" Taylor array comparison test " <<
i;
47 out <<
": \n\tExpected: " << x[
i] <<
", \n\tGot: " << x2[
i] <<
"."
49 success = success && success2;
55 template<
typename Ordinal>
62 out <<
"\nChecking that the above test passed in all processes ...";
63 int thisResult = ( result ? 1 : 0 );
67 const bool passed = sumResult==Teuchos::size(comm);
71 out <<
" (sumResult="<<sumResult<<
"!=numProcs="<<Teuchos::size(comm)<<
") failed\n";
75 #define TAY_COMM_TESTS(TayType, TAY) \
76 TEUCHOS_UNIT_TEST( TAY##_Comm, Broadcast ) { \
77 Teuchos::RCP<const Teuchos::Comm<Ordinal> > \
78 comm = Teuchos::DefaultComm<Ordinal>::getComm(); \
82 ValueTypeSerializer<int,TayType> tts( \
83 rcp(new ValueTypeSerializer<int,double>), p+1); \
85 Teuchos::Array<TayType> x(n), x2(n), x3(n); \
86 for (int i=0; i<n; i++) { \
87 x[i] = TayType(p, rnd.number()); \
88 for (int j=0; j<=p; j++) \
89 x[i].fastAccessCoeff(j) = rnd.number(); \
91 for (int i=0; i<n; i++) { \
92 x2[i] = TayType(p, 0.0); \
94 if (comm->getRank() == 0) { \
99 Teuchos::broadcast(*comm, 0, n, &x2[0]); \
100 bool success1 = checkFadArrays( \
101 x, x2, std::string(#TAY)+" Broadcast", out); \
102 success1 = checkResultOnAllProcs(*comm, out, success1); \
104 Teuchos::broadcast(*comm, tts, 0, n, &x3[0]); \
105 bool success2 = checkFadArrays( \
106 x, x3, std::string(#TAY)+" Broadcast TTS", out); \
107 success2 = checkResultOnAllProcs(*comm, out, success2); \
109 success = success1 && success2; \
112 TEUCHOS_UNIT_TEST( TAY##_Comm, GatherAll ) { \
113 Teuchos::RCP<const Teuchos::Comm<Ordinal> > \
114 comm = Teuchos::DefaultComm<Ordinal>::getComm(); \
118 int size = comm->getSize(); \
119 int rank = comm->getRank(); \
121 ValueTypeSerializer<int,TayType> tts( \
122 rcp(new ValueTypeSerializer<int,double>), p+1); \
124 Teuchos::Array<TayType> x(n), x2(N), x3(N), x4(N); \
125 for (int i=0; i<n; i++) { \
126 x[i] = TayType(p, (rank+1)*(i+1)); \
127 for (int j=0; j<=p; j++) \
128 x[i].fastAccessCoeff(j) = (rank+1)*(i+1)*(j+1); \
130 for (int i=0; i<N; i++) { \
131 x2[i] = TayType(p, 0.0); \
133 for (int j=0; j<size; j++) { \
134 for (int i=0; i<n; i++) { \
135 x3[n*j+i] = TayType(p, (j+1)*(i+1)); \
136 for (int k=0; k<=p; k++) \
137 x3[n*j+i].fastAccessCoeff(k) = (j+1)*(i+1)*(k+1); \
141 Teuchos::gatherAll(*comm, n, &x[0], N, &x2[0]); \
142 bool success1 = checkFadArrays( \
143 x3, x2, std::string(#TAY)+" Gather All", out); \
144 success1 = checkResultOnAllProcs(*comm, out, success1); \
146 Teuchos::gatherAll(*comm, tts, n, &x[0], N, &x4[0]); \
147 bool success2 = checkFadArrays( \
148 x3, x4, std::string(#TAY)+" Gather All TTS", out); \
149 success2 = checkResultOnAllProcs(*comm, out, success2); \
151 success = success1 && success2; \
154 TEUCHOS_UNIT_TEST( TAY##_Comm, SumAll ) { \
155 Teuchos::RCP<const Teuchos::Comm<Ordinal> > \
156 comm = Teuchos::DefaultComm<Ordinal>::getComm(); \
160 int num_proc = comm->getSize(); \
161 ValueTypeSerializer<int,TayType> tts( \
162 rcp(new ValueTypeSerializer<int,double>), p+1); \
164 Teuchos::Array<TayType> x(n), sums(n), sums2(n), sums3(n); \
165 for (int i=0; i<n; i++) { \
166 x[i] = TayType(p, 1.0*(i+1)); \
167 for (int j=0; j<=p; j++) \
168 x[i].fastAccessCoeff(j) = 2.0*(i+1); \
170 for (int i=0; i<n; i++) { \
171 sums[i] = TayType(p, 1.0*(i+1)*num_proc); \
172 for (int j=0; j<=p; j++) \
173 sums[i].fastAccessCoeff(j) = 2.0*(i+1)*num_proc; \
175 for (int i=0; i<n; i++) { \
176 sums2[i] = TayType(p, 0.0); \
179 Teuchos::reduceAll(*comm, Teuchos::REDUCE_SUM, n, &x[0], &sums2[0]); \
180 bool success1 = checkFadArrays( \
181 sums, sums2, std::string(#TAY)+" Sum All", out); \
182 success1 = checkResultOnAllProcs(*comm, out, success1); \
184 Teuchos::reduceAll(*comm, tts, Teuchos::REDUCE_SUM, n, &x[0], &sums3[0]); \
185 bool success2 = checkFadArrays( \
186 sums, sums3, std::string(#TAY)+" Sum All TTS", out); \
187 success2 = checkResultOnAllProcs(*comm, out, success2); \
189 success = success1 && success2; \
192 TEUCHOS_UNIT_TEST( TAY##_Comm, MaxAll ) { \
193 Teuchos::RCP<const Teuchos::Comm<Ordinal> > \
194 comm = Teuchos::DefaultComm<Ordinal>::getComm(); \
198 int rank = comm->getRank(); \
199 int num_proc = comm->getSize(); \
200 ValueTypeSerializer<int,TayType> tts( \
201 rcp(new ValueTypeSerializer<int,double>), p+1); \
203 Teuchos::Array<TayType> x(n), maxs(n), maxs2(n), maxs3(n); \
204 for (int i=0; i<n; i++) { \
205 x[i] = TayType(p, 1.0*(i+1)*(rank+1)); \
206 for (int j=0; j<=p; j++) \
207 x[i].fastAccessCoeff(j) = 2.0*(i+1)*(rank+1); \
209 for (int i=0; i<n; i++) { \
210 maxs[i] = TayType(p, 1.0*(i+1)*num_proc); \
211 for (int j=0; j<=p; j++) \
212 maxs[i].fastAccessCoeff(j) = 2.0*(i+1)*num_proc; \
214 for (int i=0; i<n; i++) { \
215 maxs2[i] = TayType(p, 0.0); \
218 Teuchos::reduceAll(*comm, Teuchos::REDUCE_MAX, n, &x[0], &maxs2[0]); \
219 bool success1 = checkFadArrays( \
220 maxs, maxs2, std::string(#TAY)+" Max All", out); \
221 success1 = checkResultOnAllProcs(*comm, out, success1); \
223 Teuchos::reduceAll(*comm, tts, Teuchos::REDUCE_MAX, n, &x[0], &maxs3[0]); \
224 bool success2 = checkFadArrays( \
225 maxs, maxs3, std::string(#TAY)+" Max All TTS", out); \
226 success2 = checkResultOnAllProcs(*comm, out, success2); \
228 success = success1 && success2; \
231 TEUCHOS_UNIT_TEST( TAY##_Comm, MinAll ) { \
232 Teuchos::RCP<const Teuchos::Comm<Ordinal> > \
233 comm = Teuchos::DefaultComm<Ordinal>::getComm(); \
237 int rank = comm->getRank(); \
238 ValueTypeSerializer<int,TayType> tts( \
239 rcp(new ValueTypeSerializer<int,double>), p+1); \
241 Teuchos::Array<TayType> x(n), mins(n), mins2(n), mins3(n); \
242 for (int i=0; i<n; i++) { \
243 x[i] = TayType(p, 1.0*(i+1)*(rank+1)); \
244 for (int j=0; j<=p; j++) \
245 x[i].fastAccessCoeff(j) = 2.0*(i+1)*(rank+1); \
247 for (int i=0; i<n; i++) { \
248 mins[i] = TayType(p, 1.0*(i+1)); \
249 for (int j=0; j<=p; j++) \
250 mins[i].fastAccessCoeff(j) = 2.0*(i+1); \
252 for (int i=0; i<n; i++) { \
253 mins2[i] = TayType(p, 0.0); \
256 Teuchos::reduceAll(*comm, Teuchos::REDUCE_MIN, n, &x[0], &mins2[0]); \
257 bool success1 = checkFadArrays( \
258 mins, mins2, std::string(#TAY)+" Min All", out); \
259 success1 = checkResultOnAllProcs(*comm, out, success1); \
261 Teuchos::reduceAll(*comm, tts, Teuchos::REDUCE_MIN, n, &x[0], &mins3[0]); \
262 bool success2 = checkFadArrays( \
263 mins, mins3, std::string(#TAY)+" Min All TTS", out); \
264 success2 = checkResultOnAllProcs(*comm, out, success2); \
266 success = success1 && success2; \
269 TEUCHOS_UNIT_TEST( TAY##_Comm, ScanSum ) { \
270 Teuchos::RCP<const Teuchos::Comm<Ordinal> > \
271 comm = Teuchos::DefaultComm<Ordinal>::getComm(); \
275 int rank = comm->getRank(); \
276 ValueTypeSerializer<int,TayType> tts( \
277 rcp(new ValueTypeSerializer<int,double>), p+1); \
279 Teuchos::Array<TayType> x(n), sums(n), sums2(n), sums3(n); \
280 for (int i=0; i<n; i++) { \
281 x[i] = TayType(p, 1.0*(i+1)); \
282 for (int j=0; j<=p; j++) \
283 x[i].fastAccessCoeff(j) = 2.0*(i+1); \
285 for (int i=0; i<n; i++) { \
286 sums[i] = TayType(p, 1.0*(i+1)*(rank+1)); \
287 for (int j=0; j<=p; j++) \
288 sums[i].fastAccessCoeff(j) = 2.0*(i+1)*(rank+1); \
290 for (int i=0; i<n; i++) { \
291 sums2[i] = TayType(p, 0.0); \
294 Teuchos::scan(*comm, Teuchos::REDUCE_SUM, n, &x[0], &sums2[0]); \
295 bool success1 = checkFadArrays( \
296 sums, sums2, std::string(#TAY)+" Scan Sum", out); \
297 success1 = checkResultOnAllProcs(*comm, out, success1); \
299 Teuchos::scan(*comm, tts, Teuchos::REDUCE_SUM, n, &x[0], &sums3[0]); \
300 bool success2 = checkFadArrays( \
301 sums, sums3, std::string(#TAY)+" Scan Sum TTS", out); \
302 success2 = checkResultOnAllProcs(*comm, out, success2); \
304 success = success1 && success2; \
307 TEUCHOS_UNIT_TEST( TAY##_Comm, ScanMax ) { \
308 Teuchos::RCP<const Teuchos::Comm<Ordinal> > \
309 comm = Teuchos::DefaultComm<Ordinal>::getComm(); \
313 int rank = comm->getRank(); \
314 ValueTypeSerializer<int,TayType> tts( \
315 rcp(new ValueTypeSerializer<int,double>), p+1); \
317 Teuchos::Array<TayType> x(n), maxs(n), maxs2(n), maxs3(n); \
318 for (int i=0; i<n; i++) { \
319 x[i] = TayType(p, 1.0*(i+1)*(rank+1)); \
320 for (int j=0; j<=p; j++) \
321 x[i].fastAccessCoeff(j) = 2.0*(i+1)*(rank+1); \
323 for (int i=0; i<n; i++) { \
324 maxs[i] = TayType(p, 1.0*(i+1)*(rank+1)); \
325 for (int j=0; j<=p; j++) \
326 maxs[i].fastAccessCoeff(j) = 2.0*(i+1)*(rank+1); \
328 for (int i=0; i<n; i++) { \
329 maxs2[i] = TayType(p, 0.0); \
332 Teuchos::scan(*comm, Teuchos::REDUCE_MAX, n, &x[0], &maxs2[0]); \
333 bool success1 = checkFadArrays( \
334 maxs, maxs2, std::string(#TAY)+" Scan Max", out); \
335 success1 = checkResultOnAllProcs(*comm, out, success1); \
337 Teuchos::scan(*comm, tts, Teuchos::REDUCE_MAX, n, &x[0], &maxs3[0]); \
338 bool success2 = checkFadArrays( \
339 maxs, maxs3, std::string(#TAY)+" Scan Max TTS", out); \
340 success2 = checkResultOnAllProcs(*comm, out, success2); \
342 success = success1 && success2; \
345 TEUCHOS_UNIT_TEST( TAY##_Comm, ScanMin ) { \
346 Teuchos::RCP<const Teuchos::Comm<Ordinal> > \
347 comm = Teuchos::DefaultComm<Ordinal>::getComm(); \
351 int rank = comm->getRank(); \
352 ValueTypeSerializer<int,TayType> tts( \
353 rcp(new ValueTypeSerializer<int,double>), p+1); \
355 Teuchos::Array<TayType> x(n), mins(n), mins2(n), mins3(n); \
356 for (int i=0; i<n; i++) { \
357 x[i] = TayType(p, 1.0*(i+1)*(rank+1)); \
358 for (int j=0; j<=p; j++) \
359 x[i].fastAccessCoeff(j) = 2.0*(i+1)*(rank+1); \
361 for (int i=0; i<n; i++) { \
362 mins[i] = TayType(p, 1.0*(i+1)); \
363 for (int j=0; j<=p; j++) \
364 mins[i].fastAccessCoeff(j) = 2.0*(i+1); \
366 for (int i=0; i<n; i++) { \
367 mins2[i] = TayType(p, 0.0); \
370 Teuchos::scan(*comm, Teuchos::REDUCE_MIN, n, &x[0], &mins2[0]); \
371 bool success1 = checkFadArrays( \
372 mins, mins2, std::string(#TAY)+" Scan Min", out); \
373 success1 = checkResultOnAllProcs(*comm, out, success1); \
375 Teuchos::scan(*comm, tts, Teuchos::REDUCE_MIN, n, &x[0], &mins3[0]); \
376 bool success2 = checkFadArrays( \
377 mins, mins3, std::string(#TAY)+" Scan Min TTS", out); \
378 success2 = checkResultOnAllProcs(*comm, out, success2); \
380 success = success1 && success2; \
383 TEUCHOS_UNIT_TEST( TAY##_Comm, SendReceive ) { \
384 Teuchos::RCP<const Teuchos::Comm<Ordinal> > \
385 comm = Teuchos::DefaultComm<Ordinal>::getComm(); \
387 int num_proc = comm->getSize(); \
388 if (num_proc > 1) { \
389 int rank = comm->getRank(); \
392 ValueTypeSerializer<int,TayType> tts( \
393 rcp(new ValueTypeSerializer<int,double>), p+1); \
395 Teuchos::Array<TayType> x(n), x2(n), x3(n); \
396 for (int i=0; i<n; i++) { \
397 x[i] = TayType(p, 1.0*(i+1)); \
398 for (int j=0; j<=p; j++) \
399 x[i].fastAccessCoeff(j) = 2.0*(i+1)*(j+1); \
401 for (int i=0; i<n; i++) { \
402 x2[i] = TayType(p, 0.0); \
409 if (rank == 0) Teuchos::send(*comm, n, &x[0], 1); \
410 if (rank == 1) Teuchos::receive(*comm, 0, n, &x2[0]); \
411 bool success1 = checkFadArrays( \
412 x, x2, std::string(#TAY)+" Send/Receive", out); \
413 success1 = checkResultOnAllProcs(*comm, out, success1); \
415 if (rank == 0) Teuchos::send(*comm, tts, n, &x[0], 1); \
416 if (rank == 1) Teuchos::receive(*comm, tts, 0, n, &x3[0]); \
417 bool success2 = checkFadArrays( \
418 x, x3, std::string(#TAY)+" Send/Receive TTS", out); \
419 success2 = checkResultOnAllProcs(*comm, out, success2); \
421 success = success1 && success2; \
427 TEUCHOS_UNIT_TEST( TAY##_Comm, NestedBroadcast ) { \
428 typedef Sacado::mpl::apply<TayType,TayType>::type TayTayType; \
429 Teuchos::RCP<const Teuchos::Comm<Ordinal> > \
430 comm = Teuchos::DefaultComm<Ordinal>::getComm(); \
435 RCP< ValueTypeSerializer<int,TayType> > tts = \
436 rcp(new ValueTypeSerializer<int,TayType>( \
437 rcp(new ValueTypeSerializer<int,double>), p1+1)); \
438 ValueTypeSerializer<int,TayTayType> ttts(tts, p2+1); \
440 Teuchos::Array<TayTayType> x(n), x2(n), x3(n); \
441 for (int i=0; i<n; i++) { \
442 TayType f(p1, rnd.number()); \
443 for (int k=0; k<=p1; k++) \
444 f.fastAccessCoeff(k) = rnd.number(); \
445 x[i] = TayTayType(p2, f); \
446 for (int j=0; j<=p2; j++) { \
447 TayType g(p1, rnd.number()); \
448 for (int k=0; k<=p1; k++) \
449 g.fastAccessCoeff(k) = rnd.number(); \
450 x[i].fastAccessCoeff(j) = g; \
453 for (int i=0; i<n; i++) { \
454 x2[i] = TayTayType(p2, TayType(p1, 0.0)); \
455 for (int j=0; j<=p2; j++) \
456 x2[i].fastAccessCoeff(j) = TayType(p1, 0.0); \
458 if (comm->getRank() == 0) { \
463 Teuchos::broadcast(*comm, 0, n, &x2[0]); \
464 bool success1 = checkFadArrays( \
465 x, x2, std::string(#TAY)+"<"+#TAY+"> Broadcast", out); \
466 success1 = checkResultOnAllProcs(*comm, out, success1); \
468 Teuchos::broadcast(*comm, ttts, 0, n, &x3[0]); \
469 bool success2 = checkFadArrays( \
470 x, x3, std::string(#TAY)+"<"+#TAY+"> Broadcast TTS", out); \
471 success2 = checkResultOnAllProcs(*comm, out, success2); \
473 success = success1 && success2; \
476 TEUCHOS_UNIT_TEST( TAY##_Comm, NestedGatherAll ) { \
477 typedef Sacado::mpl::apply<TayType,TayType>::type TayTayType; \
478 Teuchos::RCP<const Teuchos::Comm<Ordinal> > \
479 comm = Teuchos::DefaultComm<Ordinal>::getComm(); \
484 RCP< ValueTypeSerializer<int,TayType> > tts = \
485 rcp(new ValueTypeSerializer<int,TayType>( \
486 rcp(new ValueTypeSerializer<int,double>), p1+1)); \
487 ValueTypeSerializer<int,TayTayType> ttts(tts, p2+1); \
489 int size = comm->getSize(); \
490 int rank = comm->getRank(); \
492 Teuchos::Array<TayTayType> x(n), x2(N), x3(N), x4(N); \
493 for (int i=0; i<n; i++) { \
494 TayType f(p1, (rank+1)*(i+1)); \
495 for (int k=0; k<=p1; k++) \
496 f.fastAccessCoeff(k) = (rank+1)*(i+1)*(k+1); \
497 x[i] = TayTayType(p2, f); \
498 for (int j=0; j<=p2; j++) { \
499 x[i].fastAccessCoeff(j) = f; \
502 for (int i=0; i<N; i++) { \
503 x2[i] = TayTayType(p2, TayType(p1, 0.0)); \
504 for (int j=0; j<=p2; j++) \
505 x2[i].fastAccessCoeff(j) = TayType(p1, 0.0); \
507 for (int j=0; j<size; j++) { \
508 for (int i=0; i<n; i++) { \
509 TayType f(p1, (j+1)*(i+1)); \
510 for (int k=0; k<=p1; k++) \
511 f.fastAccessCoeff(k) = (j+1)*(i+1)*(k+1); \
512 x3[n*j+i] = TayTayType(p2, f); \
513 for (int k=0; k<=p2; k++) \
514 x3[n*j+i].fastAccessCoeff(k) = f; \
518 Teuchos::gatherAll(*comm, n, &x[0], N, &x2[0]); \
519 bool success1 = checkFadArrays( \
520 x3, x2, std::string(#TAY)+"<"+#TAY+"> Gather All", out); \
521 success1 = checkResultOnAllProcs(*comm, out, success1); \
523 Teuchos::gatherAll(*comm, ttts, n, &x[0], N, &x4[0]); \
524 bool success2 = checkFadArrays( \
525 x3, x4, std::string(#TAY)+"<"+#TAY+"> Gather All FTS", out); \
526 success2 = checkResultOnAllProcs(*comm, out, success2); \
528 success = success1 && success2; \
531 TEUCHOS_UNIT_TEST( TAY##_Comm, NestedSumAll ) { \
532 typedef Sacado::mpl::apply<TayType,TayType>::type TayTayType; \
533 Teuchos::RCP<const Teuchos::Comm<Ordinal> > \
534 comm = Teuchos::DefaultComm<Ordinal>::getComm(); \
539 int num_proc = comm->getSize(); \
540 RCP< ValueTypeSerializer<int,TayType> > tts = \
541 rcp(new ValueTypeSerializer<int,TayType>( \
542 rcp(new ValueTypeSerializer<int,double>), p1+1)); \
543 ValueTypeSerializer<int,TayTayType> ttts(tts, p2+1); \
545 Teuchos::Array<TayTayType> x(n), sums(n), sums2(n), sums3(n); \
546 for (int i=0; i<n; i++) { \
547 TayType f(p1, 1.0*(i+1)); \
548 for (int k=0; k<=p1; k++) \
549 f.fastAccessCoeff(k) = 2.0*(i+1); \
550 x[i] = TayTayType(p2, f); \
551 for (int j=0; j<=p2; j++) { \
552 x[i].fastAccessCoeff(j) = f; \
555 for (int i=0; i<n; i++) { \
556 TayType f(p1, 1.0*(i+1)*num_proc); \
557 for (int k=0; k<=p1; k++) \
558 f.fastAccessCoeff(k) = 2.0*(i+1)*num_proc; \
559 sums[i] = TayTayType(p2, f); \
560 for (int j=0; j<=p2; j++) \
561 sums[i].fastAccessCoeff(j) = f; \
563 for (int i=0; i<n; i++) { \
564 sums2[i] = TayTayType(p2, TayType(p1, 0.0)); \
565 for (int j=0; j<=p2; j++) \
566 sums2[i].fastAccessCoeff(j) = TayType(p1, 0.0); \
569 Teuchos::reduceAll(*comm, Teuchos::REDUCE_SUM, n, &x[0], &sums2[0]); \
570 bool success1 = checkFadArrays( \
571 sums, sums2, std::string(#TAY)+"<"+#TAY+"> Sum All", out); \
572 success1 = checkResultOnAllProcs(*comm, out, success1); \
574 Teuchos::reduceAll(*comm, ttts, Teuchos::REDUCE_SUM, n, &x[0], &sums3[0]); \
575 bool success2 = checkFadArrays( \
576 sums, sums3, std::string(#TAY)+"<"+#TAY+"> Sum All", out); \
577 success2 = checkResultOnAllProcs(*comm, out, success2); \
579 success = success1 && success2; \
582 TEUCHOS_UNIT_TEST( TAY##_Comm, NestedMaxAll ) { \
583 typedef Sacado::mpl::apply<TayType,TayType>::type TayTayType; \
584 Teuchos::RCP<const Teuchos::Comm<Ordinal> > \
585 comm = Teuchos::DefaultComm<Ordinal>::getComm(); \
590 int rank = comm->getRank(); \
591 int num_proc = comm->getSize(); \
592 RCP< ValueTypeSerializer<int,TayType> > tts = \
593 rcp(new ValueTypeSerializer<int,TayType>( \
594 rcp(new ValueTypeSerializer<int,double>), p1+1)); \
595 ValueTypeSerializer<int,TayTayType> ttts(tts, p2+1); \
597 Teuchos::Array<TayTayType> x(n), maxs(n), maxs2(n), maxs3(n); \
598 for (int i=0; i<n; i++) { \
599 TayType f(p1, 1.0*(i+1)*(rank+1)); \
600 for (int k=0; k<=p1; k++) \
601 f.fastAccessCoeff(k) = 2.0*(i+1)*(rank+1); \
602 x[i] = TayTayType(p2, f); \
603 for (int j=0; j<=p2; j++) { \
604 x[i].fastAccessCoeff(j) = f; \
607 for (int i=0; i<n; i++) { \
608 TayType f(p1, 1.0*(i+1)*num_proc); \
609 for (int k=0; k<=p1; k++) \
610 f.fastAccessCoeff(k) = 2.0*(i+1)*num_proc; \
611 maxs[i] = TayTayType(p2, f); \
612 for (int j=0; j<=p2; j++) \
613 maxs[i].fastAccessCoeff(j) = f; \
615 for (int i=0; i<n; i++) { \
616 maxs2[i] = TayTayType(p2, TayType(p1, 0.0)); \
617 for (int j=0; j<=p2; j++) \
618 maxs2[i].fastAccessCoeff(j) = TayType(p1, 0.0); \
621 Teuchos::reduceAll(*comm, Teuchos::REDUCE_MAX, n, &x[0], &maxs2[0]); \
622 bool success1 = checkFadArrays( \
623 maxs, maxs2, std::string(#TAY)+"<"+#TAY+"> Max All", out); \
624 success1 = checkResultOnAllProcs(*comm, out, success1); \
626 Teuchos::reduceAll(*comm, ttts, Teuchos::REDUCE_MAX, n, &x[0], &maxs3[0]); \
627 bool success2 = checkFadArrays( \
628 maxs, maxs3, std::string(#TAY)+"<"+#TAY+"> Max All FTS", out); \
629 success2 = checkResultOnAllProcs(*comm, out, success2); \
631 success = success1 && success2; \
634 TEUCHOS_UNIT_TEST( TAY##_Comm, NestedMinAll ) { \
635 typedef Sacado::mpl::apply<TayType,TayType>::type TayTayType; \
636 Teuchos::RCP<const Teuchos::Comm<Ordinal> > \
637 comm = Teuchos::DefaultComm<Ordinal>::getComm(); \
642 int rank = comm->getRank(); \
643 RCP< ValueTypeSerializer<int,TayType> > tts = \
644 rcp(new ValueTypeSerializer<int,TayType>( \
645 rcp(new ValueTypeSerializer<int,double>), p1+1)); \
646 ValueTypeSerializer<int,TayTayType> ttts(tts, p2+1); \
648 Teuchos::Array<TayTayType> x(n), mins(n), mins2(n), mins3(n); \
649 for (int i=0; i<n; i++) { \
650 TayType f(p1, 1.0*(i+1)*(rank+1)); \
651 for (int k=0; k<=p1; k++) \
652 f.fastAccessCoeff(k) = 2.0*(i+1)*(rank+1); \
653 x[i] = TayTayType(p2, f); \
654 for (int j=0; j<=p2; j++) { \
655 x[i].fastAccessCoeff(j) = f; \
658 for (int i=0; i<n; i++) { \
659 TayType f(p1, 1.0*(i+1)); \
660 for (int k=0; k<=p1; k++) \
661 f.fastAccessCoeff(k) = 2.0*(i+1); \
662 mins[i] = TayTayType(p2, f); \
663 for (int j=0; j<=p2; j++) \
664 mins[i].fastAccessCoeff(j) = f; \
666 for (int i=0; i<n; i++) { \
667 mins2[i] = TayTayType(p2, TayType(p1, 0.0)); \
668 for (int j=0; j<=p2; j++) \
669 mins2[i].fastAccessCoeff(j) = TayType(p1, 0.0); \
672 Teuchos::reduceAll(*comm, Teuchos::REDUCE_MIN, n, &x[0], &mins2[0]); \
673 bool success1 = checkFadArrays( \
674 mins, mins2, std::string(#TAY)+"<"+#TAY+"> Min All", out); \
675 success1 = checkResultOnAllProcs(*comm, out, success1); \
677 Teuchos::reduceAll(*comm, ttts, Teuchos::REDUCE_MIN, n, &x[0], &mins3[0]); \
678 bool success2 = checkFadArrays( \
679 mins, mins3, std::string(#TAY)+"<"+#TAY+"> Min All FTS", out); \
680 success2 = checkResultOnAllProcs(*comm, out, success2); \
682 success = success1 && success2; \
685 TEUCHOS_UNIT_TEST( TAY##_Comm, NestedScanSum ) { \
686 typedef Sacado::mpl::apply<TayType,TayType>::type TayTayType; \
687 Teuchos::RCP<const Teuchos::Comm<Ordinal> > \
688 comm = Teuchos::DefaultComm<Ordinal>::getComm(); \
693 int rank = comm->getRank(); \
694 RCP< ValueTypeSerializer<int,TayType> > tts = \
695 rcp(new ValueTypeSerializer<int,TayType>( \
696 rcp(new ValueTypeSerializer<int,double>), p1+1)); \
697 ValueTypeSerializer<int,TayTayType> ttts(tts, p2+1); \
699 Teuchos::Array<TayTayType> x(n), sums(n), sums2(n), sums3(n); \
700 for (int i=0; i<n; i++) { \
701 TayType f(p1, 1.0*(i+1)); \
702 for (int k=0; k<=p1; k++) \
703 f.fastAccessCoeff(k) = 2.0*(i+1); \
704 x[i] = TayTayType(p2, f); \
705 for (int j=0; j<=p2; j++) { \
706 x[i].fastAccessCoeff(j) = f; \
709 for (int i=0; i<n; i++) { \
710 TayType f(p1, 1.0*(i+1)*(rank+1)); \
711 for (int k=0; k<=p1; k++) \
712 f.fastAccessCoeff(k) = 2.0*(i+1)*(rank+1); \
713 sums[i] = TayTayType(p2, f); \
714 for (int j=0; j<=p2; j++) \
715 sums[i].fastAccessCoeff(j) = f; \
717 for (int i=0; i<n; i++) { \
718 sums2[i] = TayTayType(p2, TayType(p1, 0.0)); \
719 for (int j=0; j<=p2; j++) \
720 sums2[i].fastAccessCoeff(j) = TayType(p1, 0.0); \
723 Teuchos::scan(*comm, Teuchos::REDUCE_SUM, n, &x[0], &sums2[0]); \
724 bool success1 = checkFadArrays( \
725 sums, sums2, std::string(#TAY)+"<"+#TAY+"> Scan Sum", out); \
726 success1 = checkResultOnAllProcs(*comm, out, success1); \
728 Teuchos::scan(*comm, ttts, Teuchos::REDUCE_SUM, n, &x[0], &sums3[0]); \
729 bool success2 = checkFadArrays( \
730 sums, sums3, std::string(#TAY)+"<"+#TAY+"> Scan Sum FTS", out); \
731 success2 = checkResultOnAllProcs(*comm, out, success2); \
733 success = success1 && success2; \
736 TEUCHOS_UNIT_TEST( TAY##_Comm, NestedScanMax ) { \
737 typedef Sacado::mpl::apply<TayType,TayType>::type TayTayType; \
738 Teuchos::RCP<const Teuchos::Comm<Ordinal> > \
739 comm = Teuchos::DefaultComm<Ordinal>::getComm(); \
744 int rank = comm->getRank(); \
745 RCP< ValueTypeSerializer<int,TayType> > tts = \
746 rcp(new ValueTypeSerializer<int,TayType>( \
747 rcp(new ValueTypeSerializer<int,double>), p1+1)); \
748 ValueTypeSerializer<int,TayTayType> ttts(tts, p2+1); \
750 Teuchos::Array<TayTayType> x(n), maxs(n), maxs2(n), maxs3(n); \
751 for (int i=0; i<n; i++) { \
752 TayType f(p1, 1.0*(i+1)*(rank+1)); \
753 for (int k=0; k<=p1; k++) \
754 f.fastAccessCoeff(k) = 2.0*(i+1)*(rank+1); \
755 x[i] = TayTayType(p2, f); \
756 for (int j=0; j<=p2; j++) { \
757 x[i].fastAccessCoeff(j) = f; \
760 for (int i=0; i<n; i++) { \
761 TayType f(p1, 1.0*(i+1)*(rank+1)); \
762 for (int k=0; k<=p1; k++) \
763 f.fastAccessCoeff(k) = 2.0*(i+1)*(rank+1); \
764 maxs[i] = TayTayType(p2, f); \
765 for (int j=0; j<=p2; j++) \
766 maxs[i].fastAccessCoeff(j) = f; \
768 for (int i=0; i<n; i++) { \
769 maxs2[i] = TayTayType(p2, TayType(p1, 0.0)); \
770 for (int j=0; j<=p2; j++) \
771 maxs2[i].fastAccessCoeff(j) = TayType(p1, 0.0); \
774 Teuchos::scan(*comm, Teuchos::REDUCE_MAX, n, &x[0], &maxs2[0]); \
775 bool success1 = checkFadArrays( \
776 maxs, maxs2, std::string(#TAY)+"<"+#TAY+"> Scan Max", out); \
777 success1 = checkResultOnAllProcs(*comm, out, success1); \
779 Teuchos::scan(*comm, ttts, Teuchos::REDUCE_MAX, n, &x[0], &maxs3[0]); \
780 bool success2 = checkFadArrays( \
781 maxs, maxs3, std::string(#TAY)+"<"+#TAY+"> Scan Max FTS", out); \
782 success2 = checkResultOnAllProcs(*comm, out, success2); \
784 success = success1 && success2; \
787 TEUCHOS_UNIT_TEST( TAY##_Comm, NestedScanMin ) { \
788 typedef Sacado::mpl::apply<TayType,TayType>::type TayTayType; \
789 Teuchos::RCP<const Teuchos::Comm<Ordinal> > \
790 comm = Teuchos::DefaultComm<Ordinal>::getComm(); \
795 int rank = comm->getRank(); \
796 RCP< ValueTypeSerializer<int,TayType> > tts = \
797 rcp(new ValueTypeSerializer<int,TayType>( \
798 rcp(new ValueTypeSerializer<int,double>), p1+1)); \
799 ValueTypeSerializer<int,TayTayType> ttts(tts, p2+1); \
801 Teuchos::Array<TayTayType> x(n), mins(n), mins2(n), mins3(n); \
802 for (int i=0; i<n; i++) { \
803 TayType f(p1, 1.0*(i+1)*(rank+1)); \
804 for (int k=0; k<=p1; k++) \
805 f.fastAccessCoeff(k) = 2.0*(i+1)*(rank+1); \
806 x[i] = TayTayType(p2, f); \
807 for (int j=0; j<=p2; j++) { \
808 x[i].fastAccessCoeff(j) = f; \
811 for (int i=0; i<n; i++) { \
812 TayType f(p1, 1.0*(i+1)); \
813 for (int k=0; k<=p1; k++) \
814 f.fastAccessCoeff(k) = 2.0*(i+1); \
815 mins[i] = TayTayType(p2, f); \
816 for (int j=0; j<=p2; j++) \
817 mins[i].fastAccessCoeff(j) = f; \
819 for (int i=0; i<n; i++) { \
820 mins2[i] = TayTayType(p2, TayType(p1, 0.0)); \
821 for (int j=0; j<=p2; j++) \
822 mins2[i].fastAccessCoeff(j) = TayType(p1, 0.0); \
825 Teuchos::scan(*comm, Teuchos::REDUCE_MIN, n, &x[0], &mins2[0]); \
826 bool success1 = checkFadArrays( \
827 mins, mins2, std::string(#TAY)+"<"+#TAY+"> Scan Min", out); \
828 success1 = checkResultOnAllProcs(*comm, out, success1); \
830 Teuchos::scan(*comm, ttts, Teuchos::REDUCE_MIN, n, &x[0], &mins3[0]); \
831 bool success2 = checkFadArrays( \
832 mins, mins3, std::string(#TAY)+"<"+#TAY+"> Scan Min FTS", out); \
833 success2 = checkResultOnAllProcs(*comm, out, success2); \
835 success = success1 && success2; \
838 TEUCHOS_UNIT_TEST( TAY##_Comm, NestedSendReceive ) { \
839 typedef Sacado::mpl::apply<TayType,TayType>::type TayTayType; \
840 Teuchos::RCP<const Teuchos::Comm<Ordinal> > \
841 comm = Teuchos::DefaultComm<Ordinal>::getComm(); \
843 int num_proc = comm->getSize(); \
844 if (num_proc > 1) { \
845 int rank = comm->getRank(); \
849 RCP< ValueTypeSerializer<int,TayType> > tts = \
850 rcp(new ValueTypeSerializer<int,TayType>( \
851 rcp(new ValueTypeSerializer<int,double>), p1+1)); \
852 ValueTypeSerializer<int,TayTayType> ttts(tts, p2+1); \
854 Teuchos::Array<TayTayType> x(n), x2(n), x3(n); \
855 for (int i=0; i<n; i++) { \
856 TayType f(p1, 1.0*(i+1)); \
857 for (int k=0; k<=p1; k++) \
858 f.fastAccessCoeff(k) = 2.0*(i+1)*(k+1); \
859 x[i] = TayTayType(p2, f); \
860 for (int j=0; j<=p2; j++) \
861 x[i].fastAccessCoeff(j) = f; \
863 for (int i=0; i<n; i++) { \
864 x2[i] = TayTayType(p2, TayType(p1, 0.0)); \
865 for (int j=0; j<=p2; j++) \
866 x2[i].fastAccessCoeff(j) = TayType(p1, 0.0); \
873 if (rank == 0) Teuchos::send(*comm, n, &x[0], 1); \
874 if (rank == 1) Teuchos::receive(*comm, 0, n, &x2[0]); \
875 bool success1 = checkFadArrays( \
876 x, x2, std::string(#TAY)+"<"+#TAY+"> Send/Receive", out); \
877 success1 = checkResultOnAllProcs(*comm, out, success1); \
879 if (rank == 0) Teuchos::send(*comm, ttts, n, &x[0], 1); \
880 if (rank == 1) Teuchos::receive(*comm, ttts, 0, n, &x3[0]); \
881 bool success2 = checkFadArrays( \
882 x, x3, std::string(#TAY)+"<"+#TAY+"> Send/Receive FTS", out); \
883 success2 = checkResultOnAllProcs(*comm, out, success2); \
885 success = success1 && success2; \
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)
static SACADO_INLINE_FUNCTION bool eval(const T &x, const T &y)