/usr/include/trilinos/Kokkos_DefaultSparseOps.hpp is in libtrilinos-dev 10.4.0.dfsg-1ubuntu2.
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 | //@HEADER
// ************************************************************************
//
// Kokkos: Node API and Parallel Node Kernels
// Copyright (2009) 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.
//
// This library is free software; you can redistribute it and/or modify
// it under the terms of the GNU Lesser General Public License as
// published by the Free Software Foundation; either version 2.1 of the
// License, or (at your option) any later version.
//
// This library is distributed in the hope that it will be useful, but
// WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
// Lesser General Public License for more details.
//
// You should have received a copy of the GNU Lesser General Public
// License along with this library; if not, write to the Free Software
// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
// USA
// Questions? Contact Michael A. Heroux (maherou@sandia.gov)
//
// ************************************************************************
//@HEADER
#ifndef KOKKOS_DEFAULTSPARSEOPS_HPP
#define KOKKOS_DEFAULTSPARSEOPS_HPP
#include <Teuchos_ArrayRCP.hpp>
#include <Teuchos_DataAccess.hpp>
#include <Teuchos_TestForException.hpp>
#include <Teuchos_TypeNameTraits.hpp>
#include <Teuchos_BLAS_types.hpp>
#include <stdexcept>
#include "Kokkos_ConfigDefs.hpp"
#include "Kokkos_CrsMatrix.hpp"
#include "Kokkos_CrsGraph.hpp"
#include "Kokkos_MultiVector.hpp"
#include "Kokkos_NodeHelpers.hpp"
#include "Kokkos_DefaultArithmetic.hpp"
#include "Kokkos_DefaultSparseSolveKernelOps.hpp"
#include "Kokkos_DefaultSparseMultiplyKernelOps.hpp"
namespace Kokkos {
// default implementation
template <class Scalar, class Ordinal, class Node = DefaultNode::DefaultNodeType>
class DefaultSparseOps {
public:
typedef Scalar ScalarType;
typedef Ordinal OrdinalType;
typedef Node NodeType;
//! @name Constructors/Destructor
//@{
//! DefaultSparseOps constuctor with variable number of indices per row.
DefaultSparseOps(const Teuchos::RCP<Node> &node = DefaultNode::getDefaultNode());
//! DefaultSparseOps Destructor
~DefaultSparseOps();
//@}
//! @name Accessor routines.
//@{
//! Node accessor.
Teuchos::RCP<Node> getNode() const;
//@}
//! @name Initialization of structure
//@{
//! Initialize structure of matrix
template <class GRAPH>
Teuchos::DataAccess initializeStructure(const GRAPH &graph, Teuchos::DataAccess cv);
//! Initialize values of matrix
template <class MATRIX>
Teuchos::DataAccess initializeValues(const MATRIX &matrix, Teuchos::DataAccess cv);
//! Initialize structure of matrix, using Kokkos::CrsGraph
Teuchos::DataAccess initializeStructure(const CrsGraph<Ordinal,Node> &graph, Teuchos::DataAccess cv);
//! Initialize values of matrix, using Kokkos::CrsMatrix
Teuchos::DataAccess initializeValues(const CrsMatrix<Scalar,Node> &matrix, Teuchos::DataAccess cv);
//! Clear all matrix structure and values.
void clear();
//@}
//! @name Computational methods
//@{
//! Applies the matrix to a MultiVector, overwriting Y.
template <class DomainScalar, class RangeScalar>
void multiply(Teuchos::ETransp trans, RangeScalar alpha, const MultiVector<DomainScalar,Node> &X, MultiVector<RangeScalar,Node> &Y) const;
//! Applies the matrix to a MultiVector, accumulating into Y.
template <class DomainScalar, class RangeScalar>
void multiply(Teuchos::ETransp trans,
RangeScalar alpha, const MultiVector<DomainScalar,Node> &X, RangeScalar beta, MultiVector<RangeScalar,Node> &Y) const;
//! Solves the matrix for a given set of right-hand-sides.
template <class DomainScalar, class RangeScalar>
void solve(Teuchos::ETransp trans, Teuchos::EUplo uplo, Teuchos::EDiag diag,
const MultiVector<DomainScalar,Node> &Y, MultiVector<RangeScalar,Node> &X) const;
//@}
protected:
//! Copy constructor (protected and unimplemented)
DefaultSparseOps(const DefaultSparseOps& source);
Teuchos::RCP<Node> node_;
// we do this one of two ways:
// 1D/packed: array of offsets, pointer for ordinals, pointer for values. obviously the smallest footprint.
Teuchos::ArrayRCP<const Ordinal> pbuf_inds1D_;
Teuchos::ArrayRCP<const size_t> pbuf_offsets1D_;
Teuchos::ArrayRCP<const Scalar> pbuf_vals1D_;
// 2D: array of pointers
Teuchos::ArrayRCP<const Ordinal *> pbuf_inds2D_;
Teuchos::ArrayRCP<const Scalar *> pbuf_vals2D_;
Teuchos::ArrayRCP<size_t> pbuf_numEntries_;
size_t numRows_;
bool indsInit_, valsInit_, isPacked_, isEmpty_;
};
template<class Scalar, class Ordinal, class Node>
DefaultSparseOps<Scalar,Ordinal,Node>::DefaultSparseOps(const Teuchos::RCP<Node> &node)
: node_(node)
, indsInit_(false)
, valsInit_(false)
, isPacked_(false)
, isEmpty_(false) {
}
template<class Scalar, class Ordinal, class Node>
DefaultSparseOps<Scalar,Ordinal,Node>::~DefaultSparseOps() {
}
template<class Scalar, class Ordinal, class Node>
template <class GRAPH>
Teuchos::DataAccess DefaultSparseOps<Scalar,Ordinal,Node>::initializeStructure(const GRAPH &graph, Teuchos::DataAccess cv) {
// not implemented for general sparse graphs
TEST_FOR_EXCEPTION(true, std::exception,
Teuchos::typeName(*this) << "::initializeStructure(): method is not implemented for graph of type " << Teuchos::typeName(graph));
}
template<class Scalar, class Ordinal, class Node>
template <class MATRIX>
Teuchos::DataAccess DefaultSparseOps<Scalar,Ordinal,Node>::initializeValues(const MATRIX &matrix, Teuchos::DataAccess cv) {
// not implemented for general sparse matrices
TEST_FOR_EXCEPTION(true, std::exception,
Teuchos::typeName(*this) << "::initializeValues(): method is not implemented for matrix of type " << Teuchos::typeName(matrix));
}
template <class Scalar, class Ordinal, class Node>
Teuchos::DataAccess DefaultSparseOps<Scalar,Ordinal,Node>::initializeStructure(const CrsGraph<Ordinal,Node> &graph, Teuchos::DataAccess cv) {
using Teuchos::ArrayRCP;
TEST_FOR_EXCEPTION(cv != Teuchos::View, std::runtime_error,
Teuchos::typeName(*this) << "::initializeStructure(): requires View access.");
TEST_FOR_EXCEPTION(indsInit_ == true, std::runtime_error,
Teuchos::typeName(*this) << "::initializeStructure(): structure already initialized.");
numRows_ = graph.getNumRows();
if (graph.isEmpty() || numRows_ == 0) {
isEmpty_ = true;
}
else if (graph.isPacked()) {
isEmpty_ = false;
isPacked_ = true;
pbuf_inds1D_ = graph.getPackedIndices();
pbuf_offsets1D_ = graph.getPackedOffsets();
}
else {
isEmpty_ = false;
isPacked_ = false;
pbuf_inds2D_ = node_->template allocBuffer<const Ordinal *>(numRows_);
pbuf_numEntries_ = node_->template allocBuffer<size_t>(numRows_);
ArrayRCP<const Ordinal *> inds2Dview = node_->template viewBufferNonConst<const Ordinal *>(WriteOnly, numRows_, pbuf_inds2D_);
ArrayRCP< size_t> numEntview = node_->template viewBufferNonConst< size_t>(WriteOnly, numRows_, pbuf_numEntries_);
for (size_t r=0; r < numRows_; ++r) {
ArrayRCP<const Ordinal> rowinds = graph.get2DIndices(r);
if (rowinds != Teuchos::null) {
inds2Dview[r] = rowinds.getRawPtr();
numEntview[r] = rowinds.size();
}
else {
inds2Dview[r] = NULL;
numEntview[r] = 0;
}
}
}
indsInit_ = true;
return Teuchos::View;
}
template <class Scalar, class Ordinal, class Node>
Teuchos::DataAccess DefaultSparseOps<Scalar,Ordinal,Node>::initializeValues(const CrsMatrix<Scalar,Node> &matrix, Teuchos::DataAccess cv) {
using Teuchos::ArrayRCP;
TEST_FOR_EXCEPTION(cv != Teuchos::View, std::runtime_error,
Teuchos::typeName(*this) << "::initializeValues(): requires View access.");
TEST_FOR_EXCEPTION(valsInit_ == true, std::runtime_error,
Teuchos::typeName(*this) << "::initializeValues(): values already initialized.");
TEST_FOR_EXCEPTION(numRows_ != matrix.getNumRows() || isPacked_ != matrix.isPacked(), std::runtime_error,
Teuchos::typeName(*this) << "::initializeValues(): matrix not compatible with previously supplied graph.");
if (isEmpty_ || matrix.isEmpty() || numRows_ == 0) {
isEmpty_ = true;
}
else if (matrix.isPacked()) {
isEmpty_ = false;
pbuf_vals1D_ = matrix.getPackedValues();
}
else {
isEmpty_ = false;
pbuf_vals2D_ = node_->template allocBuffer<const Scalar *>(numRows_);
ArrayRCP<const Scalar *> vals2Dview = node_->template viewBufferNonConst<const Scalar *>(WriteOnly, numRows_, pbuf_vals2D_);
for (size_t r=0; r < numRows_; ++r) {
ArrayRCP<const Scalar> rowvals = matrix.get2DValues(r);
if (rowvals != Teuchos::null) {
vals2Dview[r] = rowvals.getRawPtr();
}
else {
vals2Dview[r] = NULL;
}
}
}
valsInit_ = true;
return Teuchos::View;
}
template <class Scalar, class Ordinal, class Node>
Teuchos::RCP<Node> DefaultSparseOps<Scalar,Ordinal,Node>::getNode() const {
return node_;
}
template <class Scalar, class Ordinal, class Node>
void DefaultSparseOps<Scalar,Ordinal,Node>::clear() {
pbuf_inds1D_ = Teuchos::null;
pbuf_offsets1D_ = Teuchos::null;
pbuf_vals1D_ = Teuchos::null;
pbuf_inds2D_ = Teuchos::null;
pbuf_vals2D_ = Teuchos::null;
pbuf_numEntries_ = Teuchos::null;
indsInit_ = false;
valsInit_ = false;
isPacked_ = false;
isEmpty_ = false;
}
template <class Scalar, class Ordinal, class Node>
template <class DomainScalar, class RangeScalar>
void DefaultSparseOps<Scalar,Ordinal,Node>::solve(
Teuchos::ETransp trans, Teuchos::EUplo uplo, Teuchos::EDiag diag,
const MultiVector<DomainScalar,Node> &Y,
MultiVector<RangeScalar,Node> &X) const {
typedef DefaultSparseSolveOp1<Scalar,Ordinal,DomainScalar,RangeScalar> Op1D;
typedef DefaultSparseSolveOp2<Scalar,Ordinal,DomainScalar,RangeScalar> Op2D;
typedef DefaultSparseTransposeSolveOp1<Scalar,Ordinal,DomainScalar,RangeScalar> TOp1D;
typedef DefaultSparseTransposeSolveOp2<Scalar,Ordinal,DomainScalar,RangeScalar> TOp2D;
TEST_FOR_EXCEPTION(indsInit_ == false || valsInit_ == false, std::runtime_error,
Teuchos::typeName(*this) << "::solve(): this solve was not fully initialized.");
TEST_FOR_EXCEPTION(X.getNumCols() != Y.getNumCols(), std::runtime_error,
Teuchos::typeName(*this) << "::solve(): Left hand side and right hand side multivectors have differing numbers of vectors.");
TEST_FOR_EXCEPTION(X.getNumRows() < numRows_, std::runtime_error,
Teuchos::typeName(*this) << "::solve(): Left-hand-side multivector does not have enough rows. Likely cause is that the column map was not provided to the Tpetra::CrsMatrix in the case of an implicit unit diagonal.");
ReadyBufferHelper<Node> rbh(node_);
if (numRows_ == 0) {
// null op
}
else if (isEmpty_) {
TEST_FOR_EXCEPTION(diag != Teuchos::UNIT_DIAG, std::runtime_error,
Teuchos::typeName(*this) << "::solve(): solve of empty matrix only valid for an implicit unit diagonal.");
// solve I * X = Y for X = Y
DefaultArithmetic<MultiVector<RangeScalar,Node> >::Assign(X,Y);
}
else if (isPacked_ == true) {
if (trans == Teuchos::NO_TRANS) {
Op1D wdp;
rbh.begin();
wdp.offsets = rbh.template addConstBuffer<size_t>(pbuf_offsets1D_);
wdp.inds = rbh.template addConstBuffer<Ordinal>(pbuf_inds1D_);
wdp.vals = rbh.template addConstBuffer<Scalar>(pbuf_vals1D_);
wdp.x = rbh.template addNonConstBuffer<DomainScalar>(X.getValuesNonConst());
wdp.y = rbh.template addConstBuffer<RangeScalar>(Y.getValues());
rbh.end();
wdp.numRows = numRows_;
wdp.unitDiag = (diag == Teuchos::UNIT_DIAG ? true : false);
wdp.upper = (uplo == Teuchos::UPPER_TRI ? true : false);
wdp.xstride = X.getStride();
wdp.ystride = Y.getStride();
const size_t numRHS = X.getNumCols();
node_->template parallel_for<Op1D>(0,numRHS,wdp);
}
else {
TOp1D wdp;
rbh.begin();
wdp.offsets = rbh.template addConstBuffer<size_t>(pbuf_offsets1D_);
wdp.inds = rbh.template addConstBuffer<Ordinal>(pbuf_inds1D_);
wdp.vals = rbh.template addConstBuffer<Scalar>(pbuf_vals1D_);
wdp.x = rbh.template addNonConstBuffer<DomainScalar>(X.getValuesNonConst());
wdp.y = rbh.template addConstBuffer<RangeScalar>(Y.getValues());
rbh.end();
wdp.numRows = numRows_;
wdp.unitDiag = (diag == Teuchos::UNIT_DIAG ? true : false);
wdp.upper = (uplo == Teuchos::UPPER_TRI ? true : false);
wdp.xstride = X.getStride();
wdp.ystride = Y.getStride();
const size_t numRHS = X.getNumCols();
node_->template parallel_for<TOp1D>(0,numRHS,wdp);
}
}
else {
if (trans == Teuchos::NO_TRANS) {
Op2D wdp;
rbh.begin();
wdp.numEntries = rbh.template addConstBuffer<size_t>(pbuf_numEntries_);
wdp.inds_beg = rbh.template addConstBuffer<const Ordinal *>(pbuf_inds2D_);
wdp.vals_beg = rbh.template addConstBuffer<const Scalar *>(pbuf_vals2D_);
wdp.x = rbh.template addNonConstBuffer<DomainScalar>(X.getValuesNonConst());
wdp.y = rbh.template addConstBuffer<RangeScalar>(Y.getValues());
rbh.end();
wdp.numRows = numRows_;
wdp.unitDiag = (diag == Teuchos::UNIT_DIAG ? true : false);
wdp.upper = (uplo == Teuchos::UPPER_TRI ? true : false);
wdp.xstride = X.getStride();
wdp.ystride = Y.getStride();
const size_t numRHS = X.getNumCols();
node_->template parallel_for<Op2D>(0,numRHS,wdp);
}
else {
TOp2D wdp;
rbh.begin();
wdp.numEntries = rbh.template addConstBuffer<size_t>(pbuf_numEntries_);
wdp.inds_beg = rbh.template addConstBuffer<const Ordinal *>(pbuf_inds2D_);
wdp.vals_beg = rbh.template addConstBuffer<const Scalar *>(pbuf_vals2D_);
wdp.x = rbh.template addNonConstBuffer<DomainScalar>(X.getValuesNonConst());
wdp.y = rbh.template addConstBuffer<RangeScalar>(Y.getValues());
rbh.end();
wdp.numRows = numRows_;
wdp.unitDiag = (diag == Teuchos::UNIT_DIAG ? true : false);
wdp.upper = (uplo == Teuchos::UPPER_TRI ? true : false);
wdp.xstride = X.getStride();
wdp.ystride = Y.getStride();
const size_t numRHS = X.getNumCols();
node_->template parallel_for<TOp2D>(0,numRHS,wdp);
}
}
return;
}
template <class Scalar, class Ordinal, class Node>
template <class DomainScalar, class RangeScalar>
void DefaultSparseOps<Scalar,Ordinal,Node>::multiply(
Teuchos::ETransp trans,
RangeScalar alpha,
const MultiVector<DomainScalar,Node> &X,
MultiVector<RangeScalar,Node> &Y) const {
// the 1 parameter to the template means that beta is ignored and the output multivector enjoys overwrite semantics
typedef DefaultSparseMultiplyOp1<Scalar,Ordinal,DomainScalar,RangeScalar, 1> Op1D;
typedef DefaultSparseMultiplyOp2<Scalar,Ordinal,DomainScalar,RangeScalar, 1> Op2D;
typedef DefaultSparseTransposeMultiplyOp1<Scalar,Ordinal,DomainScalar,RangeScalar, 1> TOp1D;
typedef DefaultSparseTransposeMultiplyOp2<Scalar,Ordinal,DomainScalar,RangeScalar, 1> TOp2D;
TEST_FOR_EXCEPTION(indsInit_ == false || valsInit_ == false, std::runtime_error,
Teuchos::typeName(*this) << "::multiply(): operation not fully initialized.");
TEST_FOR_EXCEPT(X.getNumCols() != Y.getNumCols());
ReadyBufferHelper<Node> rbh(node_);
if (isEmpty_ == true) {
// Y <= 0 * X
// <= 0
DefaultArithmetic<MultiVector<RangeScalar,Node> >::Init(Y,Teuchos::ScalarTraits<RangeScalar>::zero());
}
else if (isPacked_ == true) {
if (trans == Teuchos::NO_TRANS) {
Op1D wdp;
rbh.begin();
wdp.alpha = alpha;
wdp.beta = Teuchos::ScalarTraits<RangeScalar>::zero(); // not used
wdp.numRows = numRows_;
wdp.offsets = rbh.template addConstBuffer<size_t>(pbuf_offsets1D_);
wdp.inds = rbh.template addConstBuffer<Ordinal>(pbuf_inds1D_);
wdp.vals = rbh.template addConstBuffer<Scalar>(pbuf_vals1D_);
wdp.x = rbh.template addConstBuffer<DomainScalar>(X.getValues());
wdp.y = rbh.template addNonConstBuffer<RangeScalar>(Y.getValuesNonConst());
wdp.xstride = X.getStride();
wdp.ystride = Y.getStride();
rbh.end();
const size_t numRHS = X.getNumCols();
node_->template parallel_for<Op1D>(0,numRows_*numRHS,wdp);
}
else {
TOp1D wdp;
rbh.begin();
wdp.alpha = alpha;
wdp.beta = Teuchos::ScalarTraits<RangeScalar>::zero(); // not used
wdp.numRows = numRows_;
wdp.numCols = Y.getNumRows();
wdp.offsets = rbh.template addConstBuffer<size_t>(pbuf_offsets1D_);
wdp.inds = rbh.template addConstBuffer<Ordinal>(pbuf_inds1D_);
wdp.vals = rbh.template addConstBuffer<Scalar>(pbuf_vals1D_);
wdp.x = rbh.template addConstBuffer<DomainScalar>(X.getValues());
wdp.y = rbh.template addNonConstBuffer<RangeScalar>(Y.getValuesNonConst());
wdp.xstride = X.getStride();
wdp.ystride = Y.getStride();
rbh.end();
const size_t numRHS = X.getNumCols();
node_->template parallel_for<TOp1D>(0,numRHS,wdp);
}
}
else {
if (trans == Teuchos::NO_TRANS) {
Op2D wdp;
rbh.begin();
wdp.alpha = alpha;
wdp.beta = Teuchos::ScalarTraits<RangeScalar>::zero(); // not used
wdp.numRows = numRows_;
wdp.numEntries = rbh.template addConstBuffer<size_t>(pbuf_numEntries_);
wdp.inds_beg = rbh.template addConstBuffer<const Ordinal *>(pbuf_inds2D_);
wdp.vals_beg = rbh.template addConstBuffer<const Scalar *>(pbuf_vals2D_);
wdp.x = rbh.template addConstBuffer<DomainScalar>(X.getValues());
wdp.y = rbh.template addNonConstBuffer<RangeScalar>(Y.getValuesNonConst());
rbh.end();
wdp.xstride = X.getStride();
wdp.ystride = Y.getStride();
const size_t numRHS = X.getNumCols();
node_->template parallel_for<Op2D>(0,numRows_*numRHS,wdp);
}
else {
TOp2D wdp;
rbh.begin();
wdp.alpha = alpha;
wdp.beta = Teuchos::ScalarTraits<RangeScalar>::zero(); // not used
wdp.numRows = numRows_;
wdp.numCols = Y.getNumRows();
wdp.numEntries = rbh.template addConstBuffer<size_t>(pbuf_numEntries_);
wdp.inds_beg = rbh.template addConstBuffer<const Ordinal *>(pbuf_inds2D_);
wdp.vals_beg = rbh.template addConstBuffer<const Scalar *>(pbuf_vals2D_);
wdp.x = rbh.template addConstBuffer<DomainScalar>(X.getValues());
wdp.y = rbh.template addNonConstBuffer<RangeScalar>(Y.getValuesNonConst());
wdp.xstride = X.getStride();
wdp.ystride = Y.getStride();
rbh.end();
const size_t numRHS = X.getNumCols();
node_->template parallel_for<TOp2D>(0,numRHS,wdp);
}
}
return;
}
template <class Scalar, class Ordinal, class Node>
template <class DomainScalar, class RangeScalar>
void DefaultSparseOps<Scalar,Ordinal,Node>::multiply(
Teuchos::ETransp trans,
RangeScalar alpha, const MultiVector<DomainScalar,Node> &X,
RangeScalar beta, MultiVector<RangeScalar,Node> &Y) const {
// the 0 parameter means that beta is considered, and the output multivector enjoys accumulate semantics
typedef DefaultSparseMultiplyOp1<Scalar,Ordinal,DomainScalar,RangeScalar, 0> Op1D;
typedef DefaultSparseMultiplyOp2<Scalar,Ordinal,DomainScalar,RangeScalar, 0> Op2D;
typedef DefaultSparseTransposeMultiplyOp1<Scalar,Ordinal,DomainScalar,RangeScalar, 0> TOp1D;
typedef DefaultSparseTransposeMultiplyOp2<Scalar,Ordinal,DomainScalar,RangeScalar, 0> TOp2D;
TEST_FOR_EXCEPTION(indsInit_ == false || valsInit_ == false, std::runtime_error,
Teuchos::typeName(*this) << "::multiply(): operation not fully initialized.");
TEST_FOR_EXCEPT(X.getNumCols() != Y.getNumCols());
ReadyBufferHelper<Node> rbh(node_);
if (isEmpty_ == true) {
// Y <= alpha * 0 * X + beta * Y
// <= beta * Y
// NOTE: this neglects NaNs in X, which don't satisfy 0*NaN == 0
// however, X and Y may be of different size, and we need entries to determine how to mix those potential NaNs in X into Y
// therefore, the best we can do is scale Y to zero. Setting Y to zero would destroy NaNs in Y, which violates the semantics of the call.
DefaultArithmetic<MultiVector<RangeScalar,Node> >::Scale(Y,beta);
}
else if (isPacked_ == true) {
if (trans == Teuchos::NO_TRANS) {
Op1D wdp;
rbh.begin();
wdp.alpha = alpha;
wdp.beta = beta;
wdp.numRows = numRows_;
wdp.offsets = rbh.template addConstBuffer<size_t>(pbuf_offsets1D_);
wdp.inds = rbh.template addConstBuffer<Ordinal>(pbuf_inds1D_);
wdp.vals = rbh.template addConstBuffer<Scalar>(pbuf_vals1D_);
wdp.x = rbh.template addConstBuffer<DomainScalar>(X.getValues());
wdp.y = rbh.template addNonConstBuffer<RangeScalar>(Y.getValuesNonConst());
wdp.xstride = X.getStride();
wdp.ystride = Y.getStride();
rbh.end();
const size_t numRHS = X.getNumCols();
node_->template parallel_for<Op1D>(0,numRows_*numRHS,wdp);
}
else {
TOp1D wdp;
rbh.begin();
wdp.alpha = alpha;
wdp.beta = beta;
wdp.numRows = numRows_;
wdp.numCols = Y.getNumRows();
wdp.offsets = rbh.template addConstBuffer<size_t>(pbuf_offsets1D_);
wdp.inds = rbh.template addConstBuffer<Ordinal>(pbuf_inds1D_);
wdp.vals = rbh.template addConstBuffer<Scalar>(pbuf_vals1D_);
wdp.x = rbh.template addConstBuffer<DomainScalar>(X.getValues());
wdp.y = rbh.template addNonConstBuffer<RangeScalar>(Y.getValuesNonConst());
wdp.xstride = X.getStride();
wdp.ystride = Y.getStride();
rbh.end();
const size_t numRHS = X.getNumCols();
node_->template parallel_for<TOp1D>(0,numRHS,wdp);
}
}
else {
if (trans == Teuchos::NO_TRANS) {
Op2D wdp;
rbh.begin();
wdp.numRows = numRows_;
wdp.numEntries = rbh.template addConstBuffer<size_t>(pbuf_numEntries_);
wdp.inds_beg = rbh.template addConstBuffer<const Ordinal *>(pbuf_inds2D_);
wdp.vals_beg = rbh.template addConstBuffer<const Scalar *>(pbuf_vals2D_);
wdp.x = rbh.template addConstBuffer<DomainScalar>(X.getValues());
wdp.y = rbh.template addNonConstBuffer<RangeScalar>(Y.getValuesNonConst());
rbh.end();
wdp.alpha = alpha;
wdp.beta = beta;
wdp.xstride = X.getStride();
wdp.ystride = Y.getStride();
const size_t numRHS = X.getNumCols();
node_->template parallel_for<Op2D>(0,numRows_*numRHS,wdp);
}
else {
TOp2D wdp;
rbh.begin();
wdp.alpha = alpha;
wdp.beta = beta;
wdp.numRows = numRows_;
wdp.numCols = Y.getNumRows();
wdp.numEntries = rbh.template addConstBuffer<size_t>(pbuf_numEntries_);
wdp.inds_beg = rbh.template addConstBuffer<const Ordinal *>(pbuf_inds2D_);
wdp.vals_beg = rbh.template addConstBuffer<const Scalar *>(pbuf_vals2D_);
wdp.x = rbh.template addConstBuffer<DomainScalar>(X.getValues());
wdp.y = rbh.template addNonConstBuffer<RangeScalar>(Y.getValuesNonConst());
wdp.xstride = X.getStride();
wdp.ystride = Y.getStride();
rbh.end();
const size_t numRHS = X.getNumCols();
node_->template parallel_for<TOp2D>(0,numRHS,wdp);
}
}
return;
}
} // namespace Kokkos
#endif /* KOKKOS_DEFAULTSPARSEOPS_HPP */
|