/usr/include/trilinos/RTOpPack_RTOpTHelpers_decl.hpp is in libtrilinos-rtop-dev 12.12.1-5.
This file is owned by root:root, with mode 0o644.
The actual contents of the file can be viewed below.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 830 831 832 833 834 835 836 837 838 839 840 841 842 843 844 845 846 847 848 849 850 851 852 853 854 855 856 857 858 859 860 861 862 863 864 865 866 867 868 869 870 871 872 873 874 875 876 877 878 879 880 881 882 883 884 885 886 887 888 889 890 891 892 893 894 895 896 897 898 899 900 901 902 903 904 905 906 907 908 909 910 911 912 913 914 915 916 917 918 919 920 921 922 923 924 925 926 927 928 929 930 931 932 933 934 935 936 937 938 939 940 941 942 943 944 945 946 947 948 949 950 951 952 953 954 955 956 957 958 959 960 961 962 963 964 965 966 967 968 969 970 971 972 973 974 975 976 977 978 979 980 981 982 983 984 985 986 987 988 989 990 991 992 993 994 995 996 997 998 999 1000 1001 1002 1003 1004 1005 1006 1007 1008 1009 1010 1011 1012 1013 1014 1015 1016 1017 1018 1019 1020 1021 1022 1023 1024 1025 1026 1027 1028 1029 1030 1031 1032 1033 1034 1035 1036 1037 1038 1039 1040 1041 1042 1043 1044 1045 1046 1047 1048 1049 1050 1051 1052 1053 1054 1055 1056 1057 1058 1059 1060 1061 1062 1063 1064 1065 1066 1067 1068 1069 1070 1071 1072 1073 1074 1075 1076 1077 1078 1079 1080 1081 1082 1083 1084 1085 1086 1087 1088 1089 1090 1091 1092 1093 1094 1095 1096 1097 1098 1099 1100 1101 1102 1103 1104 1105 1106 1107 1108 1109 1110 1111 1112 1113 1114 1115 1116 1117 1118 1119 1120 1121 1122 1123 1124 1125 1126 1127 1128 1129 1130 1131 1132 1133 1134 1135 1136 1137 1138 1139 1140 1141 1142 1143 1144 1145 1146 1147 1148 1149 1150 1151 | // @HEADER
// ***********************************************************************
//
// RTOp: Interfaces and Support Software for Vector Reduction Transformation
// Operations
// Copyright (2006) Sandia Corporation
//
// Under terms of Contract DE-AC04-94AL85000, there is a non-exclusive
// license for use of this work by or on behalf of the U.S. Government.
//
// Redistribution and use in source and binary forms, with or without
// modification, are permitted provided that the following conditions are
// met:
//
// 1. Redistributions of source code must retain the above copyright
// notice, this list of conditions and the following disclaimer.
//
// 2. Redistributions in binary form must reproduce the above copyright
// notice, this list of conditions and the following disclaimer in the
// documentation and/or other materials provided with the distribution.
//
// 3. Neither the name of the Corporation nor the names of the
// contributors may be used to endorse or promote products derived from
// this software without specific prior written permission.
//
// THIS SOFTWARE IS PROVIDED BY SANDIA CORPORATION "AS IS" AND ANY
// EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
// IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
// PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL SANDIA CORPORATION OR THE
// CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
// EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
// PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
// PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
// LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
// NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
// SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
//
// Questions? Contact Roscoe A. Bartlett (rabartl@sandia.gov)
//
// ***********************************************************************
// @HEADER
#ifndef RTOPPACK_RTOP_T_HELPERS_DECL_HPP
#define RTOPPACK_RTOP_T_HELPERS_DECL_HPP
//#define RTOPPACK_RTOPT_HELPER_DUMP_OUTPUT
#include <typeinfo>
#include "RTOpPack_RTOpT.hpp"
#include "Teuchos_StandardMemberCompositionMacros.hpp"
#include "Teuchos_ScalarTraits.hpp"
#include "Teuchos_dyn_cast.hpp"
#include "Teuchos_TypeNameTraits.hpp"
#ifdef RTOPPACK_RTOPT_HELPER_DUMP_OUTPUT
# include "Teuchos_VerboseObject.hpp"
namespace RTOpPack { extern bool rtop_helpers_dump_all; }
#endif // RTOPPACK_RTOPT_HELPER_DUMP_OUTPUT
namespace RTOpPack {
/** \brief Simple struct for a Scalar and an Ordinal object.
*
* \ingroup RTOpPack_RTOpTHelpers_grp
*/
template<class Scalar>
struct ScalarIndex {
/** \brief. */
Scalar scalar;
/** \brief. */
Ordinal index;
/** \brief. */
ScalarIndex( const Scalar &_scalar, const Ordinal &_index )
: scalar(_scalar), index(_index)
{}
/** \brief. */
ScalarIndex()
: scalar(ScalarTraits<Scalar>::zero()), index(-1)
{}
};
/** \brief .
*
* \relates ScalarIndex
*/
template<class Scalar>
std::ostream& operator<<(std::ostream &out, const ScalarIndex<Scalar> &scalarIndex)
{
out << "{"<<scalarIndex.scalar<<","<<scalarIndex.index<<"}";
return out;
}
/** \brief Partial specialization of <tt>PrimitiveTypeTraits</tt> for
* <tt>ScalarIndex</tt>.
*/
template <class Scalar>
class PrimitiveTypeTraits<Scalar, ScalarIndex<Scalar> > {
public:
/** \brief . */
typedef PrimitiveTypeTraits<Scalar,Scalar> ScalarPrimitiveTypeTraits;
/** \brief . */
typedef typename ScalarPrimitiveTypeTraits::primitiveType primitiveType;
/** \brief . */
static int numPrimitiveObjs() { return ScalarPrimitiveTypeTraits::numPrimitiveObjs(); }
/** \brief . */
static int numIndexObjs() { return 1; }
/** \brief . */
static int numCharObjs() { return 0; }
/** \brief . */
static void extractPrimitiveObjs(
const ScalarIndex<Scalar> &obj,
const ArrayView<primitiveType> &primitiveObjs,
const ArrayView<index_type> &indexObjs,
const ArrayView<char> &charObjs
)
{
assertInput(primitiveObjs, indexObjs, charObjs);
ScalarPrimitiveTypeTraits::extractPrimitiveObjs(
obj.scalar, primitiveObjs, Teuchos::null, Teuchos::null );
indexObjs[0] = obj.index;
}
/** \brief . */
static void loadPrimitiveObjs(
const ArrayView<const primitiveType> &primitiveObjs,
const ArrayView<const index_type> &indexObjs,
const ArrayView<const char> &charObjs,
const Ptr<ScalarIndex<Scalar> > &obj
)
{
assertInput(primitiveObjs, indexObjs, charObjs);
ScalarPrimitiveTypeTraits::loadPrimitiveObjs(
primitiveObjs, Teuchos::null, Teuchos::null,
Teuchos::outArg(obj->scalar) );
obj->index = indexObjs[0];
}
private:
static void assertInput(
const ArrayView<const primitiveType> &primitiveObjs,
const ArrayView<const index_type> &indexObjs,
const ArrayView<const char> &charObjs
)
{
#ifdef TEUCHOS_DEBUG
TEUCHOS_TEST_FOR_EXCEPT(
primitiveObjs.size()!=ScalarPrimitiveTypeTraits::numPrimitiveObjs()
|| indexObjs.size()!=1
|| charObjs.size()!=0 );
#endif
}
};
/** \brief Simple <tt>ReductTarget</tt> subclass for simple scalar objects.
*
* \ingroup RTOpPack_RTOpTHelpers_grp
*/
template<class ConcreteReductObj>
class DefaultReductTarget : public ReductTarget {
public:
/** \brief. */
DefaultReductTarget( const ConcreteReductObj &concreteReductObj )
: concreteReductObj_(concreteReductObj)
{}
/** \brief. */
void set( const ConcreteReductObj &concreteReductObj )
{ concreteReductObj_ = concreteReductObj; }
/** \brief. */
const ConcreteReductObj& get() const
{ return concreteReductObj_; }
/** \brief. */
std::string description() const;
private:
ConcreteReductObj concreteReductObj_;
};
/** \brief Nonmember constructor.
*
* \relates DefaultReductTarget
*/
template<class ConcreteReductObj>
const RCP<DefaultReductTarget<ConcreteReductObj> >
defaultReductTarget( const ConcreteReductObj &concreteReductObj )
{
return Teuchos::rcp(
new DefaultReductTarget<ConcreteReductObj>(concreteReductObj));
}
/** \brief Validate the input to an apply_op(...) function.
*
* \param op [in] The RTOpT object we are validating apply_op(...) input for.
*
* \param allowed_num_sub_vecs [in] The allowed number of subvectors for
* sub_vecs.size(). If <tt>allowed_num_sub_vecs < 0</tt> then this number is
* not valided.
*
* \param allowed_num_targ_sub_vecs [in] The allowed number of subvectors for
* targ_sub_vecs.size(). If <tt>allowed_num_targ_sub_vecs < 0</tt> then this
* number is not valided.
*
* \param expect_reduct_obj [in] Determines if reduct_obj must be present or
* not and the type will be validated as well.
*
* \param sub_vecs [in] Input to apply_op(...) being validated
*
* \param targ_sub_vecs [in] Input to apply_op(...) being validated, not
* modified here
*
* \param reduct_obj_in [in] Input to apply_op(...) being validated
*/
template<class Scalar>
void validate_apply_op(
const RTOpT<Scalar> &op,
const int allowed_num_sub_vecs,
const int allowed_num_targ_sub_vecs,
const bool expect_reduct_obj,
const ArrayView<const ConstSubVectorView<Scalar> > &sub_vecs,
const ArrayView<const SubVectorView<Scalar> > &targ_sub_vecs,
const Ptr<const ReductTarget> &reduct_obj
);
//
// Reduction object operator support
//
/** \brief. */
enum EBasicReductTypes { REDUCT_TYPE_SUM, REDUCT_TYPE_MAX, REDUCT_TYPE_MIN };
/** \brief. */
template<class ConcreteReductObj, int ReductionType>
class BasicReductObjReductionOp {
public:
/** \brief . */
inline void operator()(const ConcreteReductObj& in_reduct, ConcreteReductObj& inout_reduct) const
{
return in_reduct.this_reduction_type_needs_a_specialization();
}
};
/** \brief. */
template<class ConcreteReductObj>
class BasicReductObjReductionOp<ConcreteReductObj, REDUCT_TYPE_SUM> {
public:
/** \brief . */
inline void operator()(const ConcreteReductObj& in_reduct, ConcreteReductObj& inout_reduct) const
{
inout_reduct += in_reduct;
}
};
/** \brief. */
template<class ConcreteReductObj>
class BasicReductObjReductionOp<ConcreteReductObj, REDUCT_TYPE_MAX> {
public:
/** \brief . */
inline void operator()(const ConcreteReductObj& in_reduct, ConcreteReductObj& inout_reduct) const
{
inout_reduct = std::max(inout_reduct, in_reduct);
}
};
/** \brief. */
template<class ConcreteReductObj>
class BasicReductObjReductionOp<ConcreteReductObj, REDUCT_TYPE_MIN> {
public:
/** \brief . */
inline void operator()(const ConcreteReductObj& in_reduct, ConcreteReductObj& inout_reduct) const
{
inout_reduct = std::min(inout_reduct, in_reduct);
}
};
/** \brief Null reduction object reduction operator. */
template<class Scalar>
class SumScalarReductObjReduction {
public:
/** \brief . */
inline void operator()(const Scalar& in_reduct, Scalar& inout_reduct) const
{
inout_reduct += in_reduct;
}
};
// 2008/07/03: rabart: Above: I have broken from the Thyra guideline of
// passing in-out arguments as const Ptr<Type>& and used raw non-const
// reference Type& instead to allow the user function to be more readable.
/** \brief . */
template<class Scalar, class ConcreteReductObj, class ReductObjReduction>
class ROpScalarReductionWithOpBase : public RTOpT<Scalar>
{
public:
/** \brief . */
using RTOpT<Scalar>::apply_op;
/** \brief . */
typedef typename RTOpT<Scalar>::primitive_value_type primitive_value_type;
/** \brief . */
ROpScalarReductionWithOpBase(
const ConcreteReductObj &initReductObjValue_in = ScalarTraits<Scalar>::zero(),
ReductObjReduction reductObjReduction_in = ReductObjReduction()
)
: initReductObjValue_(initReductObjValue_in),
reductObjReduction_(reductObjReduction_in)
{}
/** \brief . */
const ConcreteReductObj& getRawVal( const ReductTarget &reduct_obj ) const
{
using Teuchos::dyn_cast;
return dyn_cast<const DefaultReductTarget<ConcreteReductObj> >(reduct_obj).get();
}
/** \brief . */
void setRawVal( const ConcreteReductObj &rawVal,
const Ptr<ReductTarget> &reduct_obj
) const
{
using Teuchos::dyn_cast;
dyn_cast<DefaultReductTarget<ConcreteReductObj> >(*reduct_obj).set(rawVal);
}
/** \brief . */
ConcreteReductObj operator()(const ReductTarget& reduct_obj ) const
{
return this->getRawVal(reduct_obj);
}
/** @name Overridden from RTOpT */
//@{
/** \brief . */
void get_reduct_type_num_entries_impl(
const Ptr<int> &num_values,
const Ptr<int> &num_indexes,
const Ptr<int> &num_chars
) const
{
typedef PrimitiveTypeTraits<Scalar, ConcreteReductObj> PTT;
*num_values = PTT::numPrimitiveObjs();
*num_indexes = PTT::numIndexObjs();
*num_chars = PTT::numCharObjs();
}
/** \brief . */
Teuchos::RCP<ReductTarget> reduct_obj_create_impl() const
{
return Teuchos::rcp(
new DefaultReductTarget<ConcreteReductObj>(initReductObjValue()));
}
/** \brief . */
virtual void reduce_reduct_objs_impl(
const ReductTarget& in_reduct_obj, const Ptr<ReductTarget>& inout_reduct_obj
) const
{
const ConcreteReductObj scalar_in_reduct_obj = this->getRawVal(in_reduct_obj);
ConcreteReductObj scalar_inout_reduct_obj = this->getRawVal(*inout_reduct_obj);
reductObjReduction_(scalar_in_reduct_obj, scalar_inout_reduct_obj);
this->setRawVal( scalar_inout_reduct_obj, inout_reduct_obj );
}
/** \brief . */
void reduct_obj_reinit_impl( const Ptr<ReductTarget> &reduct_obj ) const
{
setRawVal( initReductObjValue(), reduct_obj );
}
/** \brief . */
void extract_reduct_obj_state_impl(
const ReductTarget &reduct_obj,
const ArrayView<primitive_value_type> &value_data,
const ArrayView<index_type> &index_data,
const ArrayView<char_type> &char_data
) const
{
typedef PrimitiveTypeTraits<Scalar, ConcreteReductObj> PTT;
PTT::extractPrimitiveObjs( getRawVal(reduct_obj),
value_data, index_data, char_data );
}
/** \brief . */
void load_reduct_obj_state_impl(
const ArrayView<const primitive_value_type> &value_data,
const ArrayView<const index_type> &index_data,
const ArrayView<const char_type> &char_data,
const Ptr<ReductTarget> &reduct_obj
) const
{
typedef PrimitiveTypeTraits<Scalar, ConcreteReductObj> PTT;
ConcreteReductObj concrete_reduct_obj;
PTT::loadPrimitiveObjs( value_data, index_data, char_data,
Teuchos::outArg(concrete_reduct_obj) );
this->setRawVal( concrete_reduct_obj, reduct_obj );
}
//@}
protected:
/** \brief . */
STANDARD_MEMBER_COMPOSITION_MEMBERS( ConcreteReductObj, initReductObjValue );
private:
ReductObjReduction reductObjReduction_;
};
//
// ROp 1 vector scalar reduction
//
/** \brief Base class for scalar reduction RTOps with one input vector. */
template<class Scalar, class ConcreteReductObj, class EleWiseReduction,
class ReductObjReduction = SumScalarReductObjReduction<ConcreteReductObj> >
class ROp_1_ScalarReduction
: public ROpScalarReductionWithOpBase<Scalar, ConcreteReductObj, ReductObjReduction>
{
public:
/** \brief . */
typedef ROpScalarReductionWithOpBase<Scalar, ConcreteReductObj, ReductObjReduction> base_t;
/** \brief . */
ROp_1_ScalarReduction(
const ConcreteReductObj &initReductObjValue_in = ConcreteReductObj(),
EleWiseReduction eleWiseReduction_in = EleWiseReduction(),
ReductObjReduction reductObjReduction_in = ReductObjReduction()
)
: base_t(initReductObjValue_in, reductObjReduction_in),
eleWiseReduction_(eleWiseReduction_in)
{}
/** @name Overridden from RTOpT */
//@{
/** \brief . */
void apply_op_impl(
const ArrayView<const ConstSubVectorView<Scalar> > &sub_vecs,
const ArrayView<const SubVectorView<Scalar> > &targ_sub_vecs,
const Ptr<ReductTarget> &reduct_obj_inout
) const
{
typedef typename Teuchos::ArrayRCP<const Scalar>::iterator const_iter_t;
using Teuchos::dyn_cast;
#ifdef TEUCHOS_DEBUG
validate_apply_op<Scalar>(*this, 1, 0, true,
sub_vecs, targ_sub_vecs, reduct_obj_inout.getConst());
#endif
DefaultReductTarget<ConcreteReductObj> &reduct_obj =
dyn_cast<DefaultReductTarget<ConcreteReductObj> >(*reduct_obj_inout);
ConcreteReductObj reduct = reduct_obj.get();
const RTOpPack::index_type subDim = sub_vecs[0].subDim();
const_iter_t v0_val = sub_vecs[0].values().begin();
const ptrdiff_t v0_s = sub_vecs[0].stride();
if ( v0_s == 1 ) {
for( Teuchos_Ordinal i = 0; i < subDim; ++i )
eleWiseReduction_( *v0_val++, reduct);
}
else {
for( Teuchos_Ordinal i = 0; i < subDim; ++i, v0_val += v0_s )
eleWiseReduction_( *v0_val, reduct);
}
reduct_obj.set(reduct);
}
//@}
private:
EleWiseReduction eleWiseReduction_;
};
/** \brief. */
#define RTOP_ROP_1_REDUCT_SCALAR_CUSTOM_DEFAULT( ROP_CLASS_NAME, REDUCT_SCALAR, \
BASIC_REDUCT_TYPE_ENUM, CUSTOM_DEFAULT \
) \
\
template<class Scalar, class ReductScalar> \
class ROP_CLASS_NAME ## EleWiseReduction \
{ \
public: \
inline void operator()( \
const Scalar &v0, \
ReductScalar &reduct \
) const; \
}; \
\
\
template<class Scalar> \
class ROP_CLASS_NAME \
: public RTOpPack::ROp_1_ScalarReduction< \
Scalar, \
REDUCT_SCALAR, \
ROP_CLASS_NAME ## EleWiseReduction<Scalar, REDUCT_SCALAR >, \
RTOpPack::BasicReductObjReductionOp<REDUCT_SCALAR, BASIC_REDUCT_TYPE_ENUM> > \
{ \
typedef RTOpPack::ROp_1_ScalarReduction< \
Scalar, \
REDUCT_SCALAR, \
ROP_CLASS_NAME ## EleWiseReduction<Scalar, REDUCT_SCALAR >, \
RTOpPack::BasicReductObjReductionOp<REDUCT_SCALAR, BASIC_REDUCT_TYPE_ENUM> > \
base_t; \
public: \
ROP_CLASS_NAME() \
: base_t(CUSTOM_DEFAULT) \
{ \
this->setOpNameBase( #ROP_CLASS_NAME ); \
} \
}; \
\
\
template<class Scalar, class ReductScalar> \
void ROP_CLASS_NAME ## EleWiseReduction<Scalar, ReductScalar>::operator()( \
const Scalar &v0, ReductScalar &reduct \
) const
/** \brief. */
#define RTOP_ROP_1_REDUCT_SCALAR( ROP_CLASS_NAME, REDUCT_SCALAR, \
BASIC_REDUCT_TYPE_ENUM \
) \
RTOP_ROP_1_REDUCT_SCALAR_CUSTOM_DEFAULT(ROP_CLASS_NAME, REDUCT_SCALAR, \
BASIC_REDUCT_TYPE_ENUM, Teuchos::ScalarTraits<REDUCT_SCALAR >::zero() )
//
// ROp 1 coordinate-variant vector scalar reduction
//
/** \brief Base class for coordinate-variant scalar reduction RTOps with one
* input vector. */
template<
class Scalar,
class ReductScalar,
class EleWiseReduction,
class ReductObjReduction = SumScalarReductObjReduction<ReductScalar>
>
class ROp_1_CoordVariantScalarReduction
: public ROpScalarReductionWithOpBase<Scalar, ReductScalar, ReductObjReduction>
{
public:
/** \name Public members */
//@{
/** \brief . */
typedef ROpScalarReductionWithOpBase<Scalar, ReductScalar, ReductObjReduction> base_t;
/** \brief . */
ROp_1_CoordVariantScalarReduction(
const ReductScalar &initReductObjValue_in = ReductScalar(),
EleWiseReduction eleWiseReduction_in = EleWiseReduction(),
ReductObjReduction reductObjReduction_in = ReductObjReduction()
)
: base_t(initReductObjValue_in, reductObjReduction_in),
eleWiseReduction_(eleWiseReduction_in)
{}
/** \brief . */
void setEleWiseReduction(EleWiseReduction eleWiseReduction_in)
{ eleWiseReduction_ = eleWiseReduction_in; }
/** \brief . */
const EleWiseReduction& getEleWiseReduction() const
{ return eleWiseReduction_; }
//@}
/** @name Overridden from RTOpT */
//@{
/** \brief This RTOp is NOT coordinate invariant! . */
bool coord_invariant_impl() const { return false; }
/** \brief . */
void apply_op_impl(
const ArrayView<const ConstSubVectorView<Scalar> > &sub_vecs,
const ArrayView<const SubVectorView<Scalar> > &targ_sub_vecs,
const Ptr<ReductTarget> &reduct_obj_inout
) const
{
typedef typename Teuchos::ArrayRCP<const Scalar>::iterator const_iter_t;
using Teuchos::dyn_cast;
#ifdef TEUCHOS_DEBUG
validate_apply_op<Scalar>(*this, 1, 0, true,
sub_vecs, targ_sub_vecs, reduct_obj_inout);
#endif
DefaultReductTarget<ReductScalar> &reduct_obj =
dyn_cast<DefaultReductTarget<ReductScalar> >(*reduct_obj_inout);
ReductScalar reduct = reduct_obj.get();
const RTOpPack::index_type subDim = sub_vecs[0].subDim();
const_iter_t v0_val = sub_vecs[0].values().begin();
const ptrdiff_t v0_s = sub_vecs[0].stride();
RTOpPack::index_type global_i = sub_vecs[0].globalOffset();
if ( v0_s == 1 ) {
for( Teuchos_Ordinal i = 0; i < subDim; ++i, ++global_i )
eleWiseReduction_( global_i, *v0_val++, reduct);
}
else {
for( Teuchos_Ordinal i = 0; i < subDim; ++i, v0_val += v0_s, ++global_i )
eleWiseReduction_( global_i, *v0_val, reduct);
}
reduct_obj.set(reduct);
}
//@}
private:
EleWiseReduction eleWiseReduction_;
};
//
// ROp 2 vector scalar reduction
//
/** \brief Base class for scalar reduction RTOps with two input vectors. */
template<
class Scalar,
class ReductScalar,
class EleWiseReduction,
class ReductObjReduction = SumScalarReductObjReduction<ReductScalar>
>
class ROp_2_ScalarReduction
: public ROpScalarReductionWithOpBase<Scalar, ReductScalar, ReductObjReduction>
{
public:
/** \brief . */
typedef ROpScalarReductionWithOpBase<Scalar, ReductScalar, ReductObjReduction>
base_t;
/** \brief . */
ROp_2_ScalarReduction(
const ReductScalar &initReductObjValue_in = ReductScalar(),
EleWiseReduction eleWiseReduction_in = EleWiseReduction(),
ReductObjReduction reductObjReduction_in = ReductObjReduction()
)
: base_t(initReductObjValue_in, reductObjReduction_in),
eleWiseReduction_(eleWiseReduction_in)
{}
/** @name Overridden from RTOpT */
//@{
/** \brief . */
void apply_op_impl(
const ArrayView<const ConstSubVectorView<Scalar> > &sub_vecs,
const ArrayView<const SubVectorView<Scalar> > &targ_sub_vecs,
const Ptr<ReductTarget> &reduct_obj_inout
) const
{
typedef typename Teuchos::ArrayRCP<const Scalar>::iterator const_iter_t;
using Teuchos::dyn_cast;
#ifdef TEUCHOS_DEBUG
validate_apply_op<Scalar>(*this, 2, 0, true,
sub_vecs, targ_sub_vecs, reduct_obj_inout.getConst());
#endif
DefaultReductTarget<Scalar> &reduct_obj =
dyn_cast<DefaultReductTarget<Scalar> >(*reduct_obj_inout);
Scalar reduct = reduct_obj.get();
const RTOpPack::index_type subDim = sub_vecs[0].subDim();
const_iter_t v0_val = sub_vecs[0].values().begin();
const ptrdiff_t v0_s = sub_vecs[0].stride();
const_iter_t v1_val = sub_vecs[1].values().begin();
const ptrdiff_t v1_s = sub_vecs[1].stride();
if( v0_s == 1 && v1_s == 1 ) {
for( Teuchos_Ordinal i = 0; i < subDim; ++i )
eleWiseReduction_( *v0_val++, *v1_val++, reduct);
}
else {
for( Teuchos_Ordinal i = 0; i < subDim; ++i, v0_val += v0_s, v1_val += v1_s )
eleWiseReduction_( *v0_val, *v1_val, reduct);
}
reduct_obj.set(reduct);
}
//@}
private:
EleWiseReduction eleWiseReduction_;
};
/** \brief Declare and define a concreate reduction RTOp that accepts to
* vector arguments.
*/
#define RTOP_ROP_2_REDUCT_SCALAR( ROP_CLASS_NAME, REDUCT_SCALAR, \
BASIC_REDUCT_TYPE_ENUM \
) \
\
template<class Scalar, class ReductScalar> \
class ROP_CLASS_NAME ## EleWiseReduction \
{ \
public: \
inline void operator()(const Scalar &v0, \
const Scalar &v1, \
ReductScalar &reduct \
) const; \
}; \
\
\
template<class Scalar> \
class ROP_CLASS_NAME \
: public RTOpPack::ROp_2_ScalarReduction< \
Scalar, \
REDUCT_SCALAR, \
ROP_CLASS_NAME ## EleWiseReduction<Scalar, REDUCT_SCALAR >, \
RTOpPack::BasicReductObjReductionOp<REDUCT_SCALAR, BASIC_REDUCT_TYPE_ENUM> > \
{ \
public: \
ROP_CLASS_NAME() \
{ \
this->setOpNameBase( #ROP_CLASS_NAME ); \
this->initReductObjValue(ScalarTraits<REDUCT_SCALAR >::zero()); \
} \
}; \
\
template<class Scalar, class ReductScalar> \
void ROP_CLASS_NAME ## EleWiseReduction<Scalar, ReductScalar>::operator()( \
const Scalar &v0, const Scalar &v1, ReductScalar &reduct) const
//
// TOp 0 to 1 vector transformation
//
/** \brief Base class for transformations for 0 input and 1 output vector. */
template<class Scalar, class EleWiseTransformation>
class TOp_0_1_Base : public RTOpT<Scalar>
{
public:
/** \brief . */
TOp_0_1_Base(
EleWiseTransformation eleWiseTransformation = EleWiseTransformation()
)
: eleWiseTransformation_(eleWiseTransformation)
{}
/** @name Overridden from RTOpT */
//@{
/** \brief . */
void apply_op_impl(
const ArrayView<const ConstSubVectorView<Scalar> > &sub_vecs,
const ArrayView<const SubVectorView<Scalar> > &targ_sub_vecs,
const Ptr<ReductTarget> &reduct_obj_inout
) const
{
typedef typename Teuchos::ArrayRCP<Scalar>::iterator iter_t;
#ifdef TEUCHOS_DEBUG
validate_apply_op<Scalar>(*this, 0, 1, false,
sub_vecs, targ_sub_vecs, reduct_obj_inout.getConst());
#endif
const RTOpPack::index_type subDim = targ_sub_vecs[0].subDim();
iter_t z0_val = targ_sub_vecs[0].values().begin();
const ptrdiff_t z0_s = targ_sub_vecs[0].stride();
if ( z0_s == 1 ) {
for( Teuchos_Ordinal i = 0; i < subDim; ++i )
eleWiseTransformation_( *z0_val++);
}
else {
for( Teuchos_Ordinal i = 0; i < subDim; ++i, z0_val += z0_s )
eleWiseTransformation_( *z0_val);
}
}
//@}
private:
EleWiseTransformation eleWiseTransformation_;
};
/** \brief Base class for coordinate variant transformations for 0 input and 1
* output vector. */
template<class Scalar, class EleWiseTransformation>
class TOp_0_1_CoordVariantBase : public RTOpT<Scalar>
{
public:
/** \brief . */
TOp_0_1_CoordVariantBase(
EleWiseTransformation eleWiseTransformation = EleWiseTransformation()
)
: eleWiseTransformation_(eleWiseTransformation)
{}
/** \brief . */
void setEleWiseTransformation(EleWiseTransformation eleWiseTransformation)
{
eleWiseTransformation_ = eleWiseTransformation;
}
/** \brief . */
const EleWiseTransformation& getEleWiseTransformation() const
{
return eleWiseTransformation_;
}
/** @name Overridden from RTOpT */
//@{
/** \brief This RTOp is NOT coordinate invariant! . */
bool coord_invariant_impl() const { return false; }
/** \brief . */
void apply_op_impl(
const ArrayView<const ConstSubVectorView<Scalar> > &sub_vecs,
const ArrayView<const SubVectorView<Scalar> > &targ_sub_vecs,
const Ptr<ReductTarget> &reduct_obj_inout
) const
{
typedef typename Teuchos::ArrayRCP<Scalar>::iterator iter_t;
#ifdef TEUCHOS_DEBUG
validate_apply_op<Scalar>(*this, 0, 1, false,
sub_vecs, targ_sub_vecs, reduct_obj_inout.getConst());
#endif
const RTOpPack::index_type subDim = targ_sub_vecs[0].subDim();
iter_t z0_val = targ_sub_vecs[0].values().begin();
const ptrdiff_t z0_s = targ_sub_vecs[0].stride();
RTOpPack::index_type global_i = targ_sub_vecs[0].globalOffset();
if ( z0_s == 1 ) {
for( Teuchos_Ordinal i = 0; i < subDim; ++i, ++global_i )
eleWiseTransformation_(global_i, *z0_val++);
}
else {
for( Teuchos_Ordinal i = 0; i < subDim; ++i, z0_val += z0_s, ++global_i )
eleWiseTransformation_(global_i, *z0_val);
}
}
//@}
private:
EleWiseTransformation eleWiseTransformation_;
};
//
// TOp 1 to 1 vector transformation
//
/** \brief Base class for transformations for 1 input and 1 output vector. */
template<class Scalar, class EleWiseTransformation>
class TOp_1_1_Base : public RTOpT<Scalar>
{
public:
/** \brief . */
TOp_1_1_Base(
EleWiseTransformation eleWiseTransformation = EleWiseTransformation()
)
: eleWiseTransformation_(eleWiseTransformation)
{}
/** @name Overridden from RTOpT */
//@{
/** \brief . */
void apply_op_impl(
const ArrayView<const ConstSubVectorView<Scalar> > &sub_vecs,
const ArrayView<const SubVectorView<Scalar> > &targ_sub_vecs,
const Ptr<ReductTarget> &reduct_obj_inout
) const
{
typedef typename Teuchos::ArrayRCP<const Scalar>::iterator const_iter_t;
typedef typename Teuchos::ArrayRCP<Scalar>::iterator iter_t;
#ifdef TEUCHOS_DEBUG
validate_apply_op<Scalar>(*this, 1, 1, false,
sub_vecs, targ_sub_vecs, reduct_obj_inout.getConst());
#endif
const RTOpPack::index_type subDim = sub_vecs[0].subDim();
const_iter_t v0_val = sub_vecs[0].values().begin();
const ptrdiff_t v0_s = sub_vecs[0].stride();
iter_t z0_val = targ_sub_vecs[0].values().begin();
const ptrdiff_t z0_s = targ_sub_vecs[0].stride();
if ( v0_s == 1 && z0_s == 1 ) {
for( Teuchos_Ordinal i = 0; i < subDim; ++i )
eleWiseTransformation_( *v0_val++, *z0_val++);
}
else {
for( Teuchos_Ordinal i = 0; i < subDim; ++i, v0_val += v0_s, z0_val += z0_s )
eleWiseTransformation_( *v0_val, *z0_val);
}
}
//@}
private:
EleWiseTransformation eleWiseTransformation_;
};
/** \brief. */
#define RTOP_TOP_1_1( TOP_CLASS_NAME ) \
\
template<class Scalar> \
class TOP_CLASS_NAME ## EleWiseTransformation \
{ \
public: \
inline void operator()( const Scalar &v0, Scalar &z0 ) const; \
}; \
\
\
template<class Scalar> \
class TOP_CLASS_NAME \
: public RTOpPack::TOp_1_1_Base< Scalar, \
TOP_CLASS_NAME ## EleWiseTransformation<Scalar> > \
{ \
public: \
TOP_CLASS_NAME() \
{ \
this->setOpNameBase( #TOP_CLASS_NAME ); \
} \
}; \
\
\
template<class Scalar> \
void TOP_CLASS_NAME ## EleWiseTransformation<Scalar>::operator()( \
const Scalar &v0, Scalar &z0 \
) const
//
// TOp 2 to 1 vector transformation
//
/** \brief Base class for transformations for 2 input and 1 output vector. */
template<class Scalar, class EleWiseTransformation>
class TOp_2_1_Base : public RTOpT<Scalar>
{
public:
/** \brief . */
TOp_2_1_Base(
EleWiseTransformation eleWiseTransformation = EleWiseTransformation()
)
: eleWiseTransformation_(eleWiseTransformation)
{}
/** @name Overridden from RTOpT */
//@{
/** \brief . */
void apply_op_impl(
const ArrayView<const ConstSubVectorView<Scalar> > &sub_vecs,
const ArrayView<const SubVectorView<Scalar> > &targ_sub_vecs,
const Ptr<ReductTarget> &reduct_obj_inout
) const
{
typedef typename Teuchos::ArrayRCP<const Scalar>::iterator const_iter_t;
typedef typename Teuchos::ArrayRCP<Scalar>::iterator iter_t;
#ifdef TEUCHOS_DEBUG
validate_apply_op<Scalar>(*this, 2, 1, false,
sub_vecs, targ_sub_vecs, reduct_obj_inout);
#endif
const RTOpPack::index_type subDim = sub_vecs[0].subDim();
const_iter_t v0_val = sub_vecs[0].values().begin();
const ptrdiff_t v0_s = sub_vecs[0].stride();
const_iter_t v1_val = sub_vecs[1].values().begin();
const ptrdiff_t v1_s = sub_vecs[1].stride();
iter_t z0_val = targ_sub_vecs[0].values().begin();
const ptrdiff_t z0_s = targ_sub_vecs[0].stride();
if ( v0_s == 1 && v1_s == 1 && z0_s == 1 ) {
for( Teuchos_Ordinal i = 0; i < subDim; ++i )
eleWiseTransformation_( *v0_val++, *v1_val++, *z0_val++ );
}
else {
for(
Teuchos_Ordinal i = 0;
i < subDim;
++i, v0_val += v0_s, v1_val += v1_s, z0_val += z0_s
)
{
eleWiseTransformation_( *v0_val, *v1_val, *z0_val );
}
}
}
//@}
private:
EleWiseTransformation eleWiseTransformation_;
};
/** \brief Base class for transformations for 3 input and 1 output vector. */
template<class Scalar, class EleWiseTransformation>
class TOp_3_1_Base : public RTOpT<Scalar>
{
public:
/** \brief . */
TOp_3_1_Base(
EleWiseTransformation eleWiseTransformation = EleWiseTransformation()
)
: eleWiseTransformation_(eleWiseTransformation)
{}
/** @name Overridden from RTOpT */
//@{
/** \brief . */
void apply_op_impl(
const ArrayView<const ConstSubVectorView<Scalar> > &sub_vecs,
const ArrayView<const SubVectorView<Scalar> > &targ_sub_vecs,
const Ptr<ReductTarget> &reduct_obj_inout
) const
{
typedef typename Teuchos::ArrayRCP<const Scalar>::iterator const_iter_t;
typedef typename Teuchos::ArrayRCP<Scalar>::iterator iter_t;
#ifdef TEUCHOS_DEBUG
validate_apply_op<Scalar>(*this, 3, 1, false,
sub_vecs, targ_sub_vecs, reduct_obj_inout);
#endif
const RTOpPack::index_type subDim = sub_vecs[0].subDim();
const_iter_t v0_val = sub_vecs[0].values().begin();
const ptrdiff_t v0_s = sub_vecs[0].stride();
const_iter_t v1_val = sub_vecs[1].values().begin();
const ptrdiff_t v1_s = sub_vecs[1].stride();
const_iter_t v2_val = sub_vecs[2].values().begin();
const ptrdiff_t v2_s = sub_vecs[2].stride();
iter_t z0_val = targ_sub_vecs[0].values().begin();
const ptrdiff_t z0_s = targ_sub_vecs[0].stride();
if ( v0_s == 1 && v1_s == 1 && v2_s == 1 && z0_s == 1 ) {
for( Teuchos_Ordinal i = 0; i < subDim; ++i )
eleWiseTransformation_( *v0_val++, *v1_val++, *v2_val++, *z0_val++ );
}
else {
for(
Teuchos_Ordinal i = 0;
i < subDim;
++i, v0_val += v0_s, v1_val += v1_s, v2_val += v2_s, z0_val += z0_s
)
{
eleWiseTransformation_( *v0_val, *v1_val, *v2_val, *z0_val );
}
}
}
//@}
private:
EleWiseTransformation eleWiseTransformation_;
};
} // namespace RTOpPack
#endif // RTOPPACK_RTOP_T_HELPERS_DECL_HPP
|