Tpetra Matrix/Vector Services  Version of the Day
Tpetra_VbrMatrix_def.hpp
1 // @HEADER
2 // ***********************************************************************
3 //
4 // Tpetra: Templated Linear Algebra Services Package
5 // Copyright (2008) Sandia Corporation
6 //
7 // Under the terms of Contract DE-AC04-94AL85000 with Sandia Corporation,
8 // the U.S. Government retains certain rights in this software.
9 //
10 // Redistribution and use in source and binary forms, with or without
11 // modification, are permitted provided that the following conditions are
12 // met:
13 //
14 // 1. Redistributions of source code must retain the above copyright
15 // notice, this list of conditions and the following disclaimer.
16 //
17 // 2. Redistributions in binary form must reproduce the above copyright
18 // notice, this list of conditions and the following disclaimer in the
19 // documentation and/or other materials provided with the distribution.
20 //
21 // 3. Neither the name of the Corporation nor the names of the
22 // contributors may be used to endorse or promote products derived from
23 // this software without specific prior written permission.
24 //
25 // THIS SOFTWARE IS PROVIDED BY SANDIA CORPORATION "AS IS" AND ANY
26 // EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
27 // IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
28 // PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL SANDIA CORPORATION OR THE
29 // CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
30 // EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
31 // PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
32 // PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
33 // LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
34 // NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
35 // SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
36 //
37 // Questions? Contact Michael A. Heroux (maherou@sandia.gov)
38 //
39 // ************************************************************************
40 // @HEADER
41 
42 #ifndef TPETRA_VBRMATRIX_DEF_HPP
43 #define TPETRA_VBRMATRIX_DEF_HPP
44 
45 #include <Tpetra_BlockMap.hpp>
46 #include <Tpetra_BlockCrsGraph.hpp>
47 #include <Tpetra_Vector.hpp>
48 #include <Kokkos_NodeHelpers.hpp>
49 #include <Kokkos_VbrMatrix.hpp>
51 #include <algorithm>
52 #include <sstream>
53 
54 #ifdef DOXYGEN_USE_ONLY
56 #endif
57 
58 namespace Tpetra {
59 
60 template<class Scalar,class Node>
61 void fill_device_ArrayRCP(Teuchos::RCP<Node>& node, Teuchos::ArrayRCP<Scalar>& ptr, Scalar value)
62 {
63  Kokkos::ReadyBufferHelper<Node> rbh(node);
64  Kokkos::InitOp<Scalar> wdp;
65  wdp.alpha = value;
66  rbh.begin();
67  wdp.x = rbh.addNonConstBuffer(ptr);
68  rbh.end();
69  node->template parallel_for<Kokkos::InitOp<Scalar> >(0, ptr.size(), wdp);
70 }
71 
72 //-------------------------------------------------------------------
73 template<class Scalar, class LocalOrdinal, class GlobalOrdinal, class Node, class LocalMatOps>
75  : DistObject<char, LocalOrdinal, GlobalOrdinal, Node>(convertBlockMapToPointMap(*blkRowMap)),
76  blkGraph_(Teuchos::rcp(new BlockCrsGraph<LocalOrdinal,GlobalOrdinal,Node>(blkRowMap, maxNumEntriesPerRow, pftype))),
77  constBlkGraph_(blkGraph_),
78  lclMatrix_ (Teuchos::rcp (new Kokkos::VbrMatrix<Scalar, LocalOrdinal, Node> (blkRowMap->getNodeNumBlocks (), blkRowMap->getPointMap()->getNode ()))),
79  pbuf_values1D_(),
80  pbuf_indx_(),
81  lclMatOps_(blkRowMap->getPointMap()->getNode()),
82  importer_(),
83  exporter_(),
84  importedVec_(),
85  exportedVec_(),
86  data_2D_(Teuchos::rcp(new Teuchos::Array<RowGlobalCols>)),
87  nonlocal_data_(),
88  is_fill_completed_(false),
89  is_storage_optimized_(false)
90 {
91  //The graph of this VBR matrix is a BlockCrsGraph, which is a CrsGraph where
92  //each entry in the graph corresponds to a block-entry in the matrix.
93  //That is, you can think of a VBR matrix as a Crs matrix of dense
94  //submatrices...
95 }
96 
97 //-------------------------------------------------------------------
98 template<class Scalar, class LocalOrdinal, class GlobalOrdinal, class Node, class LocalMatOps>
100  : DistObject<char, LocalOrdinal, GlobalOrdinal, Node>(convertBlockMapToPointMap(*blkGraph->getBlockRowMap())),
101  blkGraph_(),
102  constBlkGraph_(blkGraph),
103  lclMatrix_ (Teuchos::rcp (new Kokkos::VbrMatrix<Scalar, LocalOrdinal, Node> (blkGraph->getBlockRowMap()->getNodeNumBlocks(),
104  blkGraph->getBlockRowMap()->getPointMap()->getNode()))),
105  pbuf_values1D_(),
106  pbuf_indx_(),
107  lclMatOps_(blkGraph->getBlockRowMap()->getPointMap()->getNode()),
108  importer_(),
109  exporter_(),
110  importedVec_(),
111  exportedVec_(),
112  data_2D_(Teuchos::rcp(new Teuchos::Array<RowGlobalCols>)),
113  nonlocal_data_(),
114  is_fill_completed_(false),
115  is_storage_optimized_(false)
116 {
117  //The graph of this VBR matrix is a BlockCrsGraph, which is a CrsGraph where
118  //each entry in the graph corresponds to a block-entry in the matrix.
119  //That is, you can think of a VBR matrix as a Crs matrix of dense
120  //submatrices...
121 
122  TEUCHOS_TEST_FOR_EXCEPTION(blkGraph->isFillComplete() == false, std::runtime_error,
123  "Tpetra::VbrMatrix::VbrMatrix(BlockCrsGraph) ERROR, this constructor requires graph.isFillComplete()==true.");
124 
125  createImporterExporter();
126 
127  is_fill_completed_ = true;
128 
129  optimizeStorage();
130 
131  fillLocalMatrix();
132  fillLocalMatVec();
133 }
134 
135 //-------------------------------------------------------------------
136 template<class Scalar, class LocalOrdinal, class GlobalOrdinal, class Node, class LocalMatOps>
138 {
139 }
140 
141 //-------------------------------------------------------------------
142 template<class Scalar, class LocalOrdinal, class GlobalOrdinal, class Node, class LocalMatOps>
145 {
146  return getBlockDomainMap()->getPointMap();
147 }
148 
149 //-------------------------------------------------------------------
150 template<class Scalar, class LocalOrdinal, class GlobalOrdinal, class Node, class LocalMatOps>
153 {
154  return getBlockRangeMap()->getPointMap();
155 }
156 
157 //-------------------------------------------------------------------
158 template<class Scalar, class LocalOrdinal, class GlobalOrdinal, class Node, class LocalMatOps>
159 bool
161 {
162  return is_fill_completed_;
163 }
164 
165 //-------------------------------------------------------------------
166 template<class Scalar, class LocalOrdinal, class GlobalOrdinal, class Node, class LocalMatOps>
167 template <class DomainScalar, class RangeScalar>
168 void
170 {
171  TEUCHOS_TEST_FOR_EXCEPTION(!isFillComplete(), std::runtime_error,
172  "Tpetra::VbrMatrix::multiply ERROR, multiply may only be called after fillComplete has been called.");
173 
174  const Kokkos::MultiVector<Scalar,Node> *lclX = &X.getLocalMV();
175  Kokkos::MultiVector<Scalar,Node> *lclY = &Y.getLocalMVNonConst();
176 
177  lclMatOps_.template multiply<Scalar,Scalar>(trans,alpha,*lclX,beta,*lclY);
178 }
179 
180 //-------------------------------------------------------------------
181 template<class Scalar, class LocalOrdinal, class GlobalOrdinal, class Node, class LocalMatOps>
182 template<class DomainScalar, class RangeScalar>
183 void
185 {
186  TEUCHOS_TEST_FOR_EXCEPTION(X.isConstantStride() == false || Y.isConstantStride() == false, std::runtime_error,
187  "Tpetra::VbrMatrix::solve(X,Y): X and Y must be constant stride.");
188 
189  TEUCHOS_TEST_FOR_EXCEPTION(!isFillComplete(), std::runtime_error,
190  "Tpetra::VbrMatrix::solve ERROR, solve may only be called after fillComplete has been called.");
191 
192  TEUCHOS_TEST_FOR_EXCEPTION(constBlkGraph_->isUpperTriangular()==false && constBlkGraph_->isLowerTriangular()==false, std::runtime_error,
193  "Tpetra::VbrMatrix::solve ERROR, matrix must be either upper or lower triangular.");
194 
195  const Kokkos::MultiVector<RangeScalar,Node> *lclY = &Y.getLocalMV();
196  Kokkos::MultiVector<DomainScalar,Node> *lclX = &X.getLocalMVNonConst();
197 
198  Teuchos::EUplo triang = constBlkGraph_->isUpperTriangular() ? Teuchos::UPPER_TRI : Teuchos::LOWER_TRI;
199  Teuchos::EDiag diag = (constBlkGraph_->getNodeNumBlockDiags() < constBlkGraph_->getNodeNumBlockRows()) ? Teuchos::UNIT_DIAG : Teuchos::NON_UNIT_DIAG;
200 
201  lclMatOps_.template solve<DomainScalar,RangeScalar>(trans,triang,diag, *lclY,*lclX);
202 }
203 
204 //-------------------------------------------------------------------
205 template<class Scalar, class LocalOrdinal, class GlobalOrdinal, class Node, class LocalMatOps>
206 void
208 {
209  if (importer_ != Teuchos::null) {
210  if (importedVec_ == Teuchos::null || importedVec_->getNumVectors() != X.getNumVectors()) {
212  }
213 
214  importedVec_->doImport(X, *importer_, REPLACE);
215  }
216 }
217 
218 //-------------------------------------------------------------------
219 template<class Scalar, class LocalOrdinal, class GlobalOrdinal, class Node, class LocalMatOps>
220 void
222 {
223  if (exporter_ != Teuchos::null) {
224  if (exportedVec_ == Teuchos::null || exportedVec_->getNumVectors() != Y.getNumVectors()) {
226  }
227 
228  exportedVec_->doExport(Y, *exporter_, REPLACE);
229  }
230 }
231 
232 //-------------------------------------------------------------------
233 template<class Scalar, class LocalOrdinal, class GlobalOrdinal, class Node, class LocalMatOps>
234 void
238  Teuchos::ETransp trans,
239  Scalar alpha,
240  Scalar beta) const
241 {
242  if (trans == Teuchos::NO_TRANS) {
243  updateImport(X);
244  const MultiVector<Scalar,LocalOrdinal,GlobalOrdinal,Node>& Xref = importedVec_ == Teuchos::null ? X : *importedVec_;
245  this->template multiply<Scalar,Scalar>(Xref, Y, trans, alpha, beta);
246  }
247  else if (trans == Teuchos::TRANS || trans == Teuchos::CONJ_TRANS) {
248  updateImport(Y);
249  MultiVector<Scalar,LocalOrdinal,GlobalOrdinal,Node>& Yref = importedVec_ == Teuchos::null ? Y : *importedVec_;
250  this->template multiply<Scalar,Scalar>(X, Yref, trans, alpha, beta);
251  if (importedVec_ != Teuchos::null) {
252  Y.doExport(*importedVec_, *importer_, ADD);
253  }
254  }
255 }
256 
257 //-------------------------------------------------------------------
258 template<class Scalar, class LocalOrdinal, class GlobalOrdinal, class Node, class LocalMatOps>
259 void
263  Teuchos::ETransp trans) const
264 {
265  if (trans == Teuchos::NO_TRANS) {
266  updateImport(Y);
267  MultiVector<Scalar,LocalOrdinal,GlobalOrdinal,Node>& Xref = importedVec_ == Teuchos::null ? X : *importedVec_;
268  this->template solve<Scalar,Scalar>(Y, Xref, trans);
269  }
270  else if (trans == Teuchos::TRANS || trans == Teuchos::CONJ_TRANS) {
271  updateImport(Y);
272  const MultiVector<Scalar,LocalOrdinal,GlobalOrdinal,Node>& Yref = importedVec_ == Teuchos::null ? Y : *importedVec_;
273  this->template solve<Scalar,Scalar>(Yref, X, trans);
274  if (importedVec_ != Teuchos::null) {
275  X.doExport(*importedVec_, *importer_, ADD);
276  }
277  }
278 }
279 
280 //-------------------------------------------------------------------
281 template<class Scalar, class LocalOrdinal, class GlobalOrdinal, class Node, class LocalMatOps>
282 bool
284 {
285  return true;
286 }
287 
288 //-------------------------------------------------------------------
289 template<class Scalar, class LocalOrdinal, class GlobalOrdinal, class Node, class LocalMatOps>
292 {
293  return constBlkGraph_->getBlockRowMap();
294 }
295 
296 //-------------------------------------------------------------------
297 template<class Scalar, class LocalOrdinal, class GlobalOrdinal, class Node, class LocalMatOps>
300 {
301  return constBlkGraph_->getBlockRowMap()->getPointMap();
302 }
303 
304 //-------------------------------------------------------------------
305 template<class Scalar, class LocalOrdinal, class GlobalOrdinal, class Node, class LocalMatOps>
308 {
309  return constBlkGraph_->getBlockColMap();
310 }
311 
312 //-------------------------------------------------------------------
313 template<class Scalar, class LocalOrdinal, class GlobalOrdinal, class Node, class LocalMatOps>
316 {
317  return constBlkGraph_->getBlockDomainMap();
318 }
319 
320 //-------------------------------------------------------------------
321 template<class Scalar, class LocalOrdinal, class GlobalOrdinal, class Node, class LocalMatOps>
324 {
325  return constBlkGraph_->getBlockRangeMap();
326 }
327 
328 //-------------------------------------------------------------------
329 template<class Scalar, class LocalOrdinal, class GlobalOrdinal, class Node, class LocalMatOps>
332 {
333  return constBlkGraph_->getBlockColMap()->getPointMap();
334 }
335 
336 //-------------------------------------------------------------------
337 template<class Scalar, class LocalOrdinal, class GlobalOrdinal, class Node, class LocalMatOps>
338 void
340  GlobalOrdinal globalBlockRow,
341  LocalOrdinal& numPtRows,
343  Teuchos::Array<LocalOrdinal>& ptColsPerBlockCol,
344  Teuchos::Array<Teuchos::ArrayRCP<const Scalar> >& blockEntries) const
345 {
346  TEUCHOS_TEST_FOR_EXCEPTION(isFillComplete(), std::runtime_error,
347  "Tpetra::VbrMatrix::getGlobalBlockRowView internal ERROR, isFillComplete() is required to be false.");
348 
350 
351  LocalOrdinal localRow = getBlockRowMap()->getLocalBlockID(globalBlockRow);
352  numPtRows = getBlockRowMap()->getLocalBlockSize(localRow);
353  constBlkGraph_->getGlobalBlockRowView(globalBlockRow, blockCols);
354  ptColsPerBlockCol.resize(blockCols.size());
355  blockEntries.resize(blockCols.size());
356  for(Tsize_t i=0; i<blockCols.size(); ++i) {
357  getGlobalBlockEntryView(globalBlockRow, blockCols[i],
358  numPtRows, ptColsPerBlockCol[i], blockEntries[i]);
359  }
360 }
361 
362 //-------------------------------------------------------------------
363 template<class Scalar, class LocalOrdinal, class GlobalOrdinal, class Node, class LocalMatOps>
364 void
366  LocalOrdinal localBlockRow,
367  LocalOrdinal& numPtRows,
369  Teuchos::Array<LocalOrdinal>& ptColsPerBlockCol,
370  Teuchos::ArrayRCP<const Scalar>& blockEntries) const
371 {
372  TEUCHOS_TEST_FOR_EXCEPTION(!isFillComplete(), std::runtime_error,
373  "Tpetra::VbrMatrix::getGlobalBlockRowView internal ERROR, isFillComplete() is required to be true.");
374 
376  typedef Teuchos::ArrayRCP<const size_t> Host_View;
377  typedef Teuchos::ArrayRCP<const LocalOrdinal> Host_View_LO;
378 
379  numPtRows = getBlockRowMap()->getLocalBlockSize(localBlockRow);
380  constBlkGraph_->getLocalBlockRowView(localBlockRow, blockCols);
381  ptColsPerBlockCol.resize(blockCols.size());
382  LocalOrdinal num_scalars_in_block_row = 0;
383  for(Tsize_t i=0; i<blockCols.size(); ++i) {
384  ptColsPerBlockCol[i] = getBlockColMap()->getLocalBlockSize(blockCols[i]);
385  num_scalars_in_block_row += numPtRows*ptColsPerBlockCol[i];
386  }
387 
388  Teuchos::RCP<Node> node = getNode();
389  Host_View bpr = constBlkGraph_->getNodeRowOffsets();
390  const size_t bindx_offset = bpr[localBlockRow];
391  Host_View_LO indx = node->template viewBuffer<LocalOrdinal>(1, pbuf_indx_+bindx_offset);
392  const LocalOrdinal offset = indx[0];
393  blockEntries = node->template viewBuffer<Scalar>(num_scalars_in_block_row, pbuf_values1D_+offset);
394 }
395 
396 //-------------------------------------------------------------------
397 template<class Scalar, class LocalOrdinal, class GlobalOrdinal, class Node, class LocalMatOps>
398 void
400  GlobalOrdinal globalBlockRow,
401  GlobalOrdinal globalBlockCol,
402  LocalOrdinal& numPtRows,
403  LocalOrdinal& numPtCols,
404  Teuchos::ArrayRCP<Scalar>& blockEntry)
405 {
406  //Return a non-const, read-write view of a block-entry (as an ArrayRCP),
407  //creating/allocating the block-entry if it doesn't already exist, (but only
408  //if fillComplete hasn't been called yet, and if the arguments numPtRows
409  //and numPtCols have been set on input).
410 
411  LocalOrdinal localBlockRow = getBlockRowMap()->getLocalBlockID(globalBlockRow);
412 
413  if (localBlockRow == Teuchos::OrdinalTraits<LocalOrdinal>::invalid()) {
414  VbrUtils::getGlobalBlockEntryViewNonConst(nonlocal_data_,
415  globalBlockRow, globalBlockCol,
416  numPtRows, numPtCols, blockEntry);
417  return;
418  }
419 
420  if (is_storage_optimized_) {
421  TEUCHOS_TEST_FOR_EXCEPTION(!isFillComplete(), std::runtime_error,
422  "Tpetra::VbrMatrix::getGlobalBlockEntryViewNonConst internal ERROR, storage is optimized but isFillComplete() is false.");
423 
424  LocalOrdinal localBlockCol = getBlockColMap()->getLocalBlockID(globalBlockCol);
425 
426  getLocalBlockEntryViewNonConst(localBlockRow, localBlockCol,
427  numPtRows, numPtCols, blockEntry);
428  return;
429  }
430 
431  //If we get to here, fillComplete hasn't been called yet, and the matrix data
432  //is stored in un-packed '2D' form.
433 
434  if (data_2D_->size() == 0) {
435  LocalOrdinal numBlockRows = constBlkGraph_->getNodeNumBlockRows();
436  data_2D_->resize(numBlockRows);
437  }
438 
439  RowGlobalCols& blkrow = (*data_2D_)[localBlockRow];
440 
441  typename RowGlobalCols::iterator col_iter = blkrow.find(globalBlockCol);
442 
443  if (col_iter != blkrow.end()) {
444  blockEntry = col_iter->second;
445  }
446  else {
447  //blockEntry doesn't already exist, so we will create it.
448 
449  //make sure block-size is specified:
450  TEUCHOS_TEST_FOR_EXCEPTION(numPtRows==0 || numPtCols==0, std::runtime_error,
451  "Tpetra::VbrMatrix::getGlobalBlockEntryViewNonConst ERROR: creating block-entry, but numPtRows and/or numPtCols is 0.");
452 
453  Teuchos::RCP<Node> node = getNode();
454  size_t blockSize = numPtRows*numPtCols;
455  blockEntry = Teuchos::arcp(new Scalar[blockSize], 0, blockSize);
456  std::fill(blockEntry.begin(), blockEntry.end(), 0);
457  blkrow.insert(std::make_pair(globalBlockCol, blockEntry));
458  blkGraph_->insertGlobalIndices(globalBlockRow, Teuchos::ArrayView<GlobalOrdinal>(&globalBlockCol, 1));
459  }
460 }
461 
462 //-------------------------------------------------------------------
463 template<class Scalar, class LocalOrdinal, class GlobalOrdinal, class Node, class LocalMatOps>
464 void
466  GlobalOrdinal globalBlockRow,
467  GlobalOrdinal globalBlockCol,
468  LocalOrdinal& numPtRows,
469  LocalOrdinal& numPtCols,
470  Teuchos::ArrayRCP<const Scalar>& blockEntry) const
471 {
472  //This method returns a const-view of a block-entry (as an ArrayRCP).
473  //Throws an exception if the block-entry doesn't already exist.
474 
475  if (is_storage_optimized_) {
476  TEUCHOS_TEST_FOR_EXCEPTION(!isFillComplete(), std::runtime_error,
477  "Tpetra::VbrMatrix::getGlobalBlockEntryView internal ERROR, storage is optimized but isFillComplete() is false.");
478 
479  LocalOrdinal localBlockRow = getBlockRowMap()->getLocalBlockID(globalBlockRow);
480  LocalOrdinal localBlockCol = getBlockColMap()->getLocalBlockID(globalBlockCol);
481  getLocalBlockEntryView(localBlockRow, localBlockCol, numPtRows, numPtCols, blockEntry);
482  return;
483  }
484 
485  TEUCHOS_TEST_FOR_EXCEPTION(data_2D_->size() == 0, std::runtime_error,
486  "Tpetra::VbrMatrix::getGlobalBlockEntryView ERROR, matrix storage not yet allocated, can't return a const view.");
487 
488  //this acts as a range-check for globalBlockRow:
489  LocalOrdinal localBlockRow = getBlockRowMap()->getLocalBlockID(globalBlockRow);
491  std::runtime_error,
492  "Tpetra::VbrMatrix::getGlobalBlockEntryView, globalBlockRow not on the local processor.");
493 
494  RowGlobalCols& blkrow = (*data_2D_)[localBlockRow];
495  typename RowGlobalCols::iterator col_iter = blkrow.find(globalBlockCol);
496 
497  if (col_iter == blkrow.end()) {
498  throw std::runtime_error("Tpetra::VbrMatrix::getGlobalBlockEntryView ERROR, specified block-entry doesn't exist.");
499  }
500 
501  numPtRows = getBlockRowMap()->getLocalBlockSize(localBlockRow);
502 
503  TEUCHOS_TEST_FOR_EXCEPTION(numPtRows == 0, std::runtime_error,
504  "Tpetra::VbrMatrix::getGlobalBlockEntryView ERROR, numPtRows == 0.");
505 
506  blockEntry = col_iter->second;
507  numPtCols = blockEntry.size() / numPtRows;
508 }
509 
510 //-------------------------------------------------------------------
511 template<class Scalar, class LocalOrdinal, class GlobalOrdinal, class Node, class LocalMatOps>
512 void
514  LocalOrdinal localBlockRow,
515  LocalOrdinal localBlockCol,
516  LocalOrdinal& numPtRows,
517  LocalOrdinal& numPtCols,
518  Teuchos::ArrayRCP<Scalar>& blockEntry)
519 {
520  typedef Teuchos::ArrayRCP<const LocalOrdinal> Host_View_LO;
521  typedef Teuchos::ArrayRCP<const size_t> Host_View;
522  typedef typename Host_View_LO::iterator ITER;
523  //This method returns a non-constant view of a block-entry (as an ArrayRCP).
524 
525  TEUCHOS_TEST_FOR_EXCEPTION(isFillComplete() == false, std::runtime_error,
526  "Tpetra::VbrMatrix::getLocalBlockEntryViewNonConst ERROR, this method can only be called after fillComplete() has been called.");
527 
528  TEUCHOS_TEST_FOR_EXCEPTION(is_storage_optimized_ == false, std::runtime_error,
529  "Tpetra::VbrMatrix::getLocalBlockEntryViewNonConst ERROR, this method can only be called if storage is optimized.");
530 
531  Teuchos::RCP<Node> node = getNode();
532 
533  Host_View bptr = constBlkGraph_->getNodeRowOffsets();
534  LocalOrdinal bindx_offset = bptr[localBlockRow];
535  LocalOrdinal length = bptr[localBlockRow+1] - bindx_offset;
536 
537  TEUCHOS_TEST_FOR_EXCEPTION( length < 1, std::runtime_error,
538  "Tpetra::VbrMatrix::getLocalBlockEntryViewNonConst ERROR, specified localBlockCol not found in localBlockRow.");
539 
540  Host_View_LO bindx = constBlkGraph_->getNodePackedIndices();
541  ITER bindx_beg = bindx.begin() + bindx_offset,
542  bindx_end = bindx_beg + length;
543  ITER it = std::lower_bound(bindx_beg, bindx_end, localBlockCol);
544 
545  TEUCHOS_TEST_FOR_EXCEPTION(it == bindx_end || *it != localBlockCol, std::runtime_error,
546  "Tpetra::VbrMatrix::getLocalBlockEntryViewNonConst ERROR, specified localBlockCol not found.");
547 
548  numPtRows = getBlockRowMap()->getLocalBlockSize(localBlockRow);
549  numPtCols = getBlockColMap()->getLocalBlockSize(localBlockCol);
550 
551  const LocalOrdinal blkSize = numPtRows*numPtCols;
552  Host_View_LO indx = node->template viewBuffer<LocalOrdinal>(1,pbuf_indx_+bptr[localBlockRow]+(it-bindx_beg));
553  const LocalOrdinal offset = indx[0];
554  blockEntry = node->template viewBufferNonConst<Scalar>(Kokkos::ReadWrite, blkSize, pbuf_values1D_ + offset);
555 }
556 
557 //-------------------------------------------------------------------
558 template<class Scalar, class LocalOrdinal, class GlobalOrdinal, class Node, class LocalMatOps>
559 void
562 {
564  TEUCHOS_TEST_FOR_EXCEPTION(diag.getMap()->isSameAs(*(rowmap->getPointMap())) != true,
565  std::runtime_error, "Tpetra::VbrMatrix::getLocalDiagCopy ERROR, vector must be distributed the same as this matrix' row-map.");
566 
567  Teuchos::ArrayRCP<Scalar> diag_view = diag.get1dViewNonConst();
568  Teuchos::ArrayView<const GlobalOrdinal> blockIDs = rowmap->getNodeBlockIDs();
569  size_t offset = 0;
571  for(Tsize_t i=0; i<blockIDs.size(); ++i) {
572  LocalOrdinal localBlockID = rowmap->getLocalBlockID(blockIDs[i]);
573  LocalOrdinal blockSize = rowmap->getLocalBlockSize(localBlockID);
575  getGlobalBlockEntryView(blockIDs[i], blockIDs[i], blockSize, blockSize, blockEntry);
576 
577  for(LocalOrdinal j=0; j<blockSize; ++j) {
578  diag_view[offset++] = blockEntry[j*blockSize+j];
579  }
580  }
581 }
582 
583 //-------------------------------------------------------------------
584 template<class Scalar, class LocalOrdinal, class GlobalOrdinal, class Node, class LocalMatOps>
585 bool
587 checkSizes (const SrcDistObject& source)
588 {
590  const this_type* srcVbrMat = dynamic_cast<const this_type*> (&source);
591 
592  if (srcVbrMat == NULL) {
593  typedef VbrUtils::VbrDataDist<LocalOrdinal,GlobalOrdinal,Scalar,Node> VDD;
594  VDD* vdd = const_cast<VDD*> (dynamic_cast<const VDD*> (&source));
595  // FIXME (mfh 01 Jul 2013) Should check dimensions of the VDD
596  // object here. Problem is that in Tpetra, SrcDistObject doesn't
597  // currently have a Map, unlike in Epetra.
598  return (vdd != NULL);
599  }
600  else {
601  bool ok = this->getMap ()->getMinAllGlobalIndex() <=
602  srcVbrMat->getMap ()->getMinAllGlobalIndex ();
603  ok = ok && this->getMap ()->getMaxAllGlobalIndex () >=
604  srcVbrMat->getMap ()->getMaxAllGlobalIndex ();
605  return ok;
606  }
607 }
608 
609 //-------------------------------------------------------------------
610 template<class Scalar,
611  class LocalOrdinal,
612  class GlobalOrdinal,
613  class Node,
614  class LocalMatOps>
615 void
618  size_t numSameIDs,
619  const Teuchos::ArrayView<const LocalOrdinal>& permuteToLIDs,
620  const Teuchos::ArrayView<const LocalOrdinal>& permuteFromLIDs)
621 {
622  typedef typename Teuchos::ArrayView<const LocalOrdinal>::size_type Tsize_t;
624  const this_type* src_mat_ptr = dynamic_cast<const this_type*> (&source);
625 
626  if (src_mat_ptr == NULL) {
627  throw std::runtime_error ("VbrMatrix::copyAndPermute ERROR, dynamic_cast failed.");
628  }
629  const this_type& src_mat = *src_mat_ptr;
630 
631  Teuchos::Array<LocalOrdinal> src_ptColsPerBlkCol;
632  LocalOrdinal numPtRows;
633 
634  LocalOrdinal numSame = numSameIDs;
635  for(LocalOrdinal i=0; i<numSame; ++i) {
636  if (isFillComplete()) {
637  Teuchos::ArrayRCP<const Scalar> src_blkEntries;
639 
640  src_mat.getLocalBlockRowView (i, numPtRows, src_blkCols,
641  src_ptColsPerBlkCol, src_blkEntries);
642  unsigned offset = 0;
643  for (Tsize_t j=0; j<src_blkCols.size(); ++j) {
644  LocalOrdinal numPtCols = src_ptColsPerBlkCol[j];
645  setLocalBlockEntry (i, src_blkCols[j], numPtRows, numPtCols, numPtCols,
646  src_blkEntries.view (offset, numPtRows*numPtCols));
647  offset += numPtRows*numPtCols;
648  }
649  }
650  else {
651  GlobalOrdinal gRow = getBlockRowMap ()->getGlobalBlockID (i);
654 
655  src_mat.getGlobalBlockRowView (gRow, numPtRows, src_blkCols,
656  src_ptColsPerBlkCol, src_blkEntries);
657  for (Tsize_t j = 0; j < src_blkCols.size (); ++j) {
658  LocalOrdinal numPtCols = src_ptColsPerBlkCol[j];
659  setGlobalBlockEntry (gRow, src_blkCols[j],
660  numPtRows, numPtCols, numPtRows,
661  src_blkEntries[j].view (0, numPtRows * numPtCols));
662  }
663  }
664  }
665 
666  for (Tsize_t i = 0; i < permuteToLIDs.size (); ++i) {
667  if (isFillComplete ()) {
668  Teuchos::ArrayRCP<const Scalar> src_blkEntries;
670 
671  src_mat.getLocalBlockRowView (permuteFromLIDs[i], numPtRows,
672  src_blkCols, src_ptColsPerBlkCol,
673  src_blkEntries);
674  unsigned offset = 0;
675  for (Tsize_t j=0; j<src_blkCols.size(); ++j) {
676  LocalOrdinal numPtCols = src_ptColsPerBlkCol[j];
677  setLocalBlockEntry (permuteToLIDs[i], src_blkCols[j], numPtRows, numPtCols, numPtCols,
678  src_blkEntries.view(offset, numPtRows*numPtCols));
679  offset += numPtRows*numPtCols;
680  }
681  }
682  else {
683  GlobalOrdinal gRow = getBlockRowMap ()->getGlobalBlockID (permuteToLIDs[i]);
686 
687  src_mat.getGlobalBlockRowView (gRow, numPtRows, src_blkCols,
688  src_ptColsPerBlkCol, src_blkEntries);
689  for (Tsize_t j = 0; j < src_blkCols.size (); ++j) {
690  LocalOrdinal numPtCols = src_ptColsPerBlkCol[j];
691  setGlobalBlockEntry (gRow, src_blkCols[j],
692  numPtRows, numPtCols, numPtRows,
693  src_blkEntries[j].view (0, numPtRows * numPtCols));
694  }
695  }
696  }
697 }
698 
699 //-------------------------------------------------------------------
700 template<class Scalar, class LocalOrdinal, class GlobalOrdinal, class Node, class LocalMatOps>
701 void
704  const Teuchos::ArrayView<const LocalOrdinal>& exportLIDs,
705  Teuchos::Array<char>& exports,
706  const Teuchos::ArrayView<size_t>& numPacketsPerLID,
707  size_t& constantNumPackets,
708  Distributor& distor)
709 {
710  typedef typename Teuchos::ArrayView<const LocalOrdinal>::size_type Tsize_t;
712  const this_type* src_mat_ptr = dynamic_cast<const this_type*> (&source);
713 
714  if (src_mat_ptr == NULL) {
715  typedef VbrUtils::VbrDataDist<LocalOrdinal,GlobalOrdinal,Scalar,Node> VDD;
716  VDD* vdd = const_cast<VDD*> (dynamic_cast<const VDD*> (&source));
717  if (vdd != NULL) {
718  vdd->packAndPrepare (source, exportLIDs, exports, numPacketsPerLID,
719  constantNumPackets, distor);
720  } else {
721  throw std::runtime_error("VbrMatrix::packAndPrepare ERROR, dynamic_cast failed.");
722  }
723  return;
724  }
725  const this_type& src_mat = *src_mat_ptr;
726 
727  //We will pack each row's data into the exports buffer as follows:
728  //[num-block-cols,numPtRows,{list-of-blk-cols},{list-of-ptColsPerBlkCol},{all vals}]
729  //so the length of the char exports buffer for a row is:
730  //sizeof(LocalOrdinal)*(2+2*(num-block-cols)) + sizeof(Scalar)*numPtRows*sum(numPtCols_i)
731 
732  //For each row corresponding to exportLIDs, accumulate the size that it will
733  //occupy in the exports buffer:
734  size_t total_exports_size = 0;
735  for (Tsize_t i = 0; i < exportLIDs.size (); ++i) {
736  Teuchos::Array<LocalOrdinal> src_ptColsPerBlkCol;
737  LocalOrdinal numPtRows;
738  LocalOrdinal numBlkCols = 0;
739  LocalOrdinal numScalars = 0;
740 
741  if (src_mat.isFillComplete ()) {
742  Teuchos::ArrayRCP<const Scalar> src_blkEntries;
744  src_mat.getLocalBlockRowView (exportLIDs[i], numPtRows,
745  src_blkCols, src_ptColsPerBlkCol,
746  src_blkEntries);
747  numBlkCols = src_blkCols.size ();
748  numScalars = src_blkEntries.size ();
749  }
750  else {
752  GlobalOrdinal gRow =
753  src_mat.getBlockRowMap ()->getGlobalBlockID (exportLIDs[i]);
755  src_mat.getGlobalBlockRowView (gRow, numPtRows, src_blkCols,
756  src_ptColsPerBlkCol, src_blkEntries);
757  numBlkCols = src_blkCols.size ();
758  for (Tsize_t j = 0; j < src_blkEntries.size (); ++j) {
759  numScalars += src_blkEntries[j].size ();
760  }
761  }
762 
763  const size_t size_for_this_row =
764  sizeof (GlobalOrdinal) * (2 + 2*numBlkCols) +
765  sizeof (Scalar) * numScalars;
766  numPacketsPerLID[i] = size_for_this_row;
767  total_exports_size += size_for_this_row;
768  }
769 
770  exports.resize (total_exports_size);
771 
772  ArrayView<char> avIndsC, avValsC;
773  ArrayView<Scalar> avVals;
774 
775  size_t offset = 0;
776 
777  for (Tsize_t i = 0; i < exportLIDs.size (); ++i) {
778  Teuchos::Array<LocalOrdinal> src_ptColsPerBlkCol;
779  LocalOrdinal numPtRows;
780  LocalOrdinal numBlkCols = 0;
781  LocalOrdinal numScalars = 0;
782 
783  if (src_mat.isFillComplete ()) {
784  Teuchos::ArrayRCP<const Scalar> src_blkEntries;
786  src_mat.getLocalBlockRowView (exportLIDs[i], numPtRows, src_blkCols,
787  src_ptColsPerBlkCol, src_blkEntries);
788  numBlkCols = src_blkCols.size ();
789  numScalars = src_blkEntries.size ();
790 
791  LocalOrdinal num_chars_for_ordinals =
792  (2*numBlkCols + 2) * sizeof (LocalOrdinal);
793  //get export views
794  avIndsC = exports (offset, num_chars_for_ordinals);
795  avValsC = exports (offset + num_chars_for_ordinals, numScalars * sizeof (Scalar));
796  ArrayView<GlobalOrdinal> avInds = av_reinterpret_cast<GlobalOrdinal>(avIndsC);
797  typename ArrayView<GlobalOrdinal>::iterator ind_it = avInds.begin();
798 
800  src_mat.getBlockColMap ();
801 
802  //put row info into the buffer views:
803  *ind_it++ = numBlkCols;
804  *ind_it++ = numPtRows;
805  for (Tsize_t j = 0; j < src_blkCols.size (); ++j) {
806  *ind_it++ = col_map->getGlobalBlockID (src_blkCols[j]);
807  }
808  std::copy (src_ptColsPerBlkCol.begin(), src_ptColsPerBlkCol.end(), ind_it);
809  avVals = av_reinterpret_cast<Scalar> (avValsC);
810  std::copy (src_blkEntries.begin(), src_blkEntries.end(), avVals.begin());
811  }
812  else {
814  GlobalOrdinal gRow = src_mat.getBlockRowMap()->getGlobalBlockID(exportLIDs[i]);
816  src_mat.getGlobalBlockRowView (gRow, numPtRows, src_blkCols,
817  src_ptColsPerBlkCol, src_blkEntries);
818  numBlkCols = src_blkCols.size();
819  numScalars = 0;
820  for(Tsize_t j=0; j<src_blkEntries.size(); ++j) {
821  numScalars += numPtRows*src_ptColsPerBlkCol[j];
822  }
823 
824  LocalOrdinal num_chars_for_ordinals = (2*numBlkCols+2)*sizeof(GlobalOrdinal);
825  //get export views
826  avIndsC = exports(offset, num_chars_for_ordinals);
827  avValsC = exports(offset+ num_chars_for_ordinals, numScalars*sizeof(Scalar));
828  ArrayView<GlobalOrdinal> avInds = av_reinterpret_cast<GlobalOrdinal>(avIndsC);
829  typename ArrayView<GlobalOrdinal>::iterator ind_it = avInds.begin();
830 
831  //put row info into the buffer views:
832  *ind_it++ = numBlkCols;
833  *ind_it++ = numPtRows;
834  std::copy(src_blkCols.begin(), src_blkCols.end(), ind_it);
835  ind_it += src_blkCols.size();
836  std::copy(src_ptColsPerBlkCol.begin(), src_ptColsPerBlkCol.end(), ind_it);
837  avVals = av_reinterpret_cast<Scalar>(avValsC);
838  typename ArrayView<Scalar>::iterator val_it = avVals.begin();
839  for(Tsize_t j=0; j<src_blkEntries.size(); ++j) {
840  std::copy(src_blkEntries[j].begin(), src_blkEntries[j].end(), val_it);
841  val_it += src_blkEntries[j].size();
842  }
843  }
844 
845  const size_t size_for_this_row =
846  sizeof (GlobalOrdinal) * (2 + 2*numBlkCols)
847  + sizeof (Scalar) * numScalars;
848  offset += size_for_this_row;
849  }
850 
851  constantNumPackets = 0;
852 }
853 
854 //-------------------------------------------------------------------
855 template<class Scalar, class LocalOrdinal, class GlobalOrdinal, class Node, class LocalMatOps>
856 void
859  const Teuchos::ArrayView<const char>& imports,
860  const Teuchos::ArrayView<size_t>& numPacketsPerLID,
861  size_t constantNumPackets,
862  Distributor& distor,
863  CombineMode CM)
864 {
865  typedef typename Teuchos::ArrayView<const LocalOrdinal>::size_type Tsize_t;
866 
867  if (CM == Tpetra::ABSMAX) {
868  std::cout << "Warning, VbrMatrix Import/Export doesn't support combine-mode==ABSMAX; use ADD, INSERT or REPLACE. (REPLACE is being used now.)"<<std::endl;
869  }
870 
871  size_t offset = 0;
872  for(Tsize_t i=0; i<importLIDs.size(); ++i) {
873  ArrayView<const char> avC = imports.view(offset, numPacketsPerLID[i]);
874  ArrayView<const GlobalOrdinal> avOrds = av_reinterpret_cast<const GlobalOrdinal>(avC);
875  GlobalOrdinal gRow = this->getBlockRowMap()->getGlobalBlockID(importLIDs[i]);
876  size_t avOrdsOffset = 0;
877  LocalOrdinal numBlkCols = avOrds[avOrdsOffset++];
878  LocalOrdinal numPtRows = avOrds[avOrdsOffset++];
879  LocalOrdinal num_chars_for_ordinals = (2*numBlkCols+2)*sizeof(GlobalOrdinal);
880  ArrayView<const char> avValsC = imports.view(offset+num_chars_for_ordinals, numPacketsPerLID[i]-num_chars_for_ordinals);
881  ArrayView<const Scalar> avVals = av_reinterpret_cast<const Scalar>(avValsC);
882 
883  size_t avValsOffset = 0;
884  for(Tsize_t j=0; j<numBlkCols; ++j) {
885  GlobalOrdinal blkCol = avOrds[avOrdsOffset+j];
886  LocalOrdinal numPtCols = avOrds[avOrdsOffset+numBlkCols+j];
887  LocalOrdinal LDA = numPtRows;
888  if (CM == Tpetra::ADD) {
889  sumIntoGlobalBlockEntry(gRow, blkCol, numPtRows, numPtCols, LDA,
890  avVals.view(avValsOffset, numPtRows*numPtCols));
891  }
892  else if (CM == Tpetra::INSERT || CM == Tpetra::REPLACE) {
893  setGlobalBlockEntry(gRow, blkCol, numPtRows, numPtCols, LDA,
894  avVals.view(avValsOffset, numPtRows*numPtCols));
895  }
896  else {
897 // std::cout << "Warning, VbrMatrix Import/Export doesn't support combine-mode==ABSMAX; use ADD, INSERT or REPLACE. (REPLACE is being used now.)"<<std::endl;
898  setGlobalBlockEntry(gRow, blkCol, numPtRows, numPtCols, LDA,
899  avVals.view(avValsOffset, numPtRows*numPtCols));
900  }
901  avValsOffset += numPtRows*numPtCols;
902  }
903  }
904 }
905 
906 //-------------------------------------------------------------------
907 template<class Scalar, class LocalOrdinal, class GlobalOrdinal, class Node, class LocalMatOps>
908 void
910  LocalOrdinal localBlockRow,
911  LocalOrdinal localBlockCol,
912  LocalOrdinal& numPtRows,
913  LocalOrdinal& numPtCols,
914  Teuchos::ArrayRCP<const Scalar>& blockEntry) const
915 {
916  typedef Teuchos::ArrayRCP<const size_t> Host_View;
917  typedef Teuchos::ArrayRCP<const LocalOrdinal> Host_View_LO;
918  typedef typename Host_View_LO::iterator ITER;
919  //This method returns a constant view of a block-entry (as an ArrayRCP).
920 
921  TEUCHOS_TEST_FOR_EXCEPTION(isFillComplete() == false, std::runtime_error,
922  "Tpetra::VbrMatrix::getLocalBlockEntryView ERROR, this method can only be called after fillComplete() has been called.");
923 
924  TEUCHOS_TEST_FOR_EXCEPTION(is_storage_optimized_ == false, std::runtime_error,
925  "Tpetra::VbrMatrix::getLocalBlockEntryView ERROR, this method can only be called if storage is optimized.");
926 
927  Teuchos::RCP<Node> node = getNode();
928 
929  Host_View bpr = constBlkGraph_->getNodeRowOffsets();
930  const size_t bindx_offset = bpr[localBlockRow];
931  const size_t length = bpr[localBlockRow+1] - bindx_offset;
932 
933  Host_View_LO bindx = constBlkGraph_->getNodePackedIndices();
934  ITER bindx_beg = bindx.begin()+bindx_offset,
935  bindx_end = bindx_beg + length;
936  ITER it = std::lower_bound(bindx_beg, bindx_end, localBlockCol);
937 
938  TEUCHOS_TEST_FOR_EXCEPTION(it == bindx_end || *it != localBlockCol, std::runtime_error,
939  "Tpetra::VbrMatrix::getLocalBlockEntryView ERROR, specified localBlockCol not found.");
940 
941  numPtRows = getBlockRowMap()->getLocalBlockSize(localBlockRow);
942  numPtCols = getBlockColMap()->getLocalBlockSize(localBlockCol);
943 
944  const LocalOrdinal blkSize = numPtRows*numPtCols;
945  Host_View_LO indx = node->template viewBuffer<LocalOrdinal>(1, pbuf_indx_+bpr[localBlockRow]+(it-bindx_beg));
946  const LocalOrdinal offset = indx[0];
947  blockEntry = node->template viewBuffer<Scalar>(blkSize, pbuf_values1D_ + offset);
948 }
949 
950 //-------------------------------------------------------------------
951 template<class Scalar, class LocalOrdinal, class GlobalOrdinal, class Node, class LocalMatOps>
954 {
955  return getBlockRowMap()->getPointMap()->getNode();
956 }
957 
958 //-------------------------------------------------------------------
959 template<class Scalar, class LocalOrdinal, class GlobalOrdinal, class Node, class LocalMatOps>
960 void
962 {
963  Teuchos::RCP<Node> node = getNode();
964 
965  if (isFillComplete()) {
966  fill_device_ArrayRCP(node, pbuf_values1D_, s);
967  }
968  else {
969  typedef typename Teuchos::Array<RowGlobalCols>::size_type Tsize_t;
970  Teuchos::Array<RowGlobalCols>& rows = *data_2D_;
971  Tsize_t numBlockRows = rows.size();
972  for(Tsize_t r=0; r<numBlockRows; ++r) {
973  typename RowGlobalCols::iterator
974  col_iter = rows[r].begin(),
975  col_end = rows[r].end();
976  for(; col_iter != col_end; ++col_iter) {
977  Teuchos::ArrayRCP<Scalar>& vals = col_iter->second;
978  std::fill(vals.begin(), vals.end(), s);
979  }
980  }
981  }
982 }
983 
984 //-------------------------------------------------------------------
985 template<class ArrayType1,class ArrayType2,class Ordinal>
986 void set_array_values(ArrayType1& dest, ArrayType2& src, Ordinal rows, Ordinal cols, Ordinal stride, Tpetra::CombineMode mode)
987 {
988  size_t offset = 0;
989  size_t src_offset = 0;
990 
991  if (mode == ADD) {
992  for(Ordinal col=0; col<cols; ++col) {
993  for(Ordinal row=0; row<rows; ++row) {
994  dest[offset++] += src[src_offset + row];
995  }
996  src_offset += stride;
997  }
998  }
999  else {
1000  for(Ordinal col=0; col<cols; ++col) {
1001  for(Ordinal row=0; row<rows; ++row) {
1002  dest[offset++] = src[src_offset + row];
1003  }
1004  src_offset += stride;
1005  }
1006  }
1007 }
1008 
1009 //-------------------------------------------------------------------
1010 template<class Scalar, class LocalOrdinal, class GlobalOrdinal, class Node, class LocalMatOps>
1011 void
1013 {
1014  //first get an ArrayRCP for the internal storage for this block-entry:
1015  Teuchos::ArrayRCP<Scalar> internalBlockEntry;
1016  LocalOrdinal blkRowSize = blockEntry.numRows();
1017  LocalOrdinal blkColSize = blockEntry.numCols();
1018  getGlobalBlockEntryViewNonConst(globalBlockRow,globalBlockCol, blkRowSize, blkColSize, internalBlockEntry);
1019 
1020  //now copy the incoming block-entry into internal storage:
1021  const Scalar* inputvalues = blockEntry.values();
1022  set_array_values<Teuchos::ArrayRCP<Scalar>, const Scalar*, LocalOrdinal >(
1023  internalBlockEntry, inputvalues, blkRowSize, blkColSize, blockEntry.stride(), REPLACE);
1024 }
1025 
1026 //-------------------------------------------------------------------
1027 template<class Scalar, class LocalOrdinal, class GlobalOrdinal, class Node, class LocalMatOps>
1028 void
1030 {
1031  //first get an ArrayRCP for the internal storage for this block-entry:
1032  Teuchos::ArrayRCP<Scalar> internalBlockEntry;
1033  LocalOrdinal blkRowSize = blockEntry.numRows();
1034  LocalOrdinal blkColSize = blockEntry.numCols();
1035  getLocalBlockEntryViewNonConst(localBlockRow,localBlockCol, blkRowSize, blkColSize, internalBlockEntry);
1036 
1037  //now copy the incoming block-entry into internal storage:
1038  const Scalar* inputvalues = blockEntry.values();
1039  set_array_values<Teuchos::ArrayRCP<Scalar>, const Scalar*, LocalOrdinal>(
1040 internalBlockEntry, inputvalues, blkRowSize, blkColSize, blockEntry.stride(), REPLACE);
1041 }
1042 
1043 //-------------------------------------------------------------------
1044 template<class Scalar, class LocalOrdinal, class GlobalOrdinal, class Node, class LocalMatOps>
1045 void
1047 {
1048  //first get an ArrayRCP for the internal storage for this block-entry:
1049  Teuchos::ArrayRCP<Scalar> internalBlockEntry;
1050  LocalOrdinal blkRowSize = blockEntry.numRows();
1051  LocalOrdinal blkColSize = blockEntry.numCols();
1052  getGlobalBlockEntryViewNonConst(globalBlockRow,globalBlockCol, blkRowSize, blkColSize, internalBlockEntry);
1053 
1054  //now sum (add) the incoming block-entry into internal storage:
1055  const Scalar* inputvalues = blockEntry.values();
1056  set_array_values<Teuchos::ArrayRCP<Scalar>, const Scalar*, LocalOrdinal>(
1057  internalBlockEntry, inputvalues, blkRowSize, blkColSize, blockEntry.stride(), ADD);
1058 }
1059 
1060 //-------------------------------------------------------------------
1061 template<class Scalar, class LocalOrdinal, class GlobalOrdinal, class Node, class LocalMatOps>
1062 void
1064 {
1065  //first get an ArrayRCP for the internal storage for this block-entry:
1066  Teuchos::ArrayRCP<Scalar> internalBlockEntry;
1067  LocalOrdinal blkRowSize = blockEntry.numRows();
1068  LocalOrdinal blkColSize = blockEntry.numCols();
1069  getLocalBlockEntryViewNonConst(localBlockRow,localBlockCol, blkRowSize, blkColSize, internalBlockEntry);
1070 
1071  //now sum (add) the incoming block-entry into internal storage:
1072  const Scalar* inputvalues = blockEntry.values();
1073  set_array_values<Teuchos::ArrayRCP<Scalar>, const Scalar*, LocalOrdinal>(
1074  internalBlockEntry, inputvalues, blkRowSize, blkColSize, blockEntry.stride(), ADD);
1075 }
1076 
1077 //-------------------------------------------------------------------
1078 template<class Scalar, class LocalOrdinal, class GlobalOrdinal, class Node, class LocalMatOps>
1079 void
1080 VbrMatrix<Scalar,LocalOrdinal,GlobalOrdinal,Node,LocalMatOps>::setGlobalBlockEntry(GlobalOrdinal globalBlockRow, GlobalOrdinal globalBlockCol, LocalOrdinal blkRowSize, LocalOrdinal blkColSize, LocalOrdinal LDA, const Teuchos::ArrayView<const Scalar>& blockEntry)
1081 {
1082  //first get an ArrayRCP for the internal storage for this block-entry:
1083  Teuchos::ArrayRCP<Scalar> internalBlockEntry;
1084  getGlobalBlockEntryViewNonConst(globalBlockRow,globalBlockCol, blkRowSize, blkColSize, internalBlockEntry);
1085 
1086  LocalOrdinal blk_size = blockEntry.size();
1087  TEUCHOS_TEST_FOR_EXCEPTION(blkColSize*LDA > blk_size, std::runtime_error,
1088  "Tpetra::VbrMatrix::setGlobalBlockEntry ERROR, inconsistent block-entry sizes.");
1089 
1090  //copy the incoming block-entry into internal storage:
1091  set_array_values(internalBlockEntry, blockEntry, blkRowSize, blkColSize, LDA, REPLACE);
1092 }
1093 
1094 //-------------------------------------------------------------------
1095 template<class Scalar, class LocalOrdinal, class GlobalOrdinal, class Node, class LocalMatOps>
1096 void
1097 VbrMatrix<Scalar,LocalOrdinal,GlobalOrdinal,Node,LocalMatOps>::setLocalBlockEntry(LocalOrdinal localBlockRow, LocalOrdinal localBlockCol, LocalOrdinal blkRowSize, LocalOrdinal blkColSize, LocalOrdinal LDA, const Teuchos::ArrayView<const Scalar>& blockEntry)
1098 {
1099  //first get an ArrayRCP for the internal storage for this block-entry:
1100  Teuchos::ArrayRCP<Scalar> internalBlockEntry;
1101  getLocalBlockEntryViewNonConst(localBlockRow,localBlockCol, blkRowSize, blkColSize, internalBlockEntry);
1102 
1103  LocalOrdinal blk_size = blockEntry.size();
1104  TEUCHOS_TEST_FOR_EXCEPTION(blkColSize*LDA > blk_size, std::runtime_error,
1105  "Tpetra::VbrMatrix::setLocalBlockEntry ERROR, inconsistent block-entry sizes.");
1106 
1107  //copy the incoming block-entry into internal storage:
1108  set_array_values(internalBlockEntry, blockEntry, blkRowSize, blkColSize, LDA, REPLACE);
1109 }
1110 
1111 //-------------------------------------------------------------------
1112 template<class Scalar, class LocalOrdinal, class GlobalOrdinal, class Node, class LocalMatOps>
1113 void
1114 VbrMatrix<Scalar,LocalOrdinal,GlobalOrdinal,Node,LocalMatOps>::sumIntoGlobalBlockEntry(GlobalOrdinal globalBlockRow, GlobalOrdinal globalBlockCol, LocalOrdinal blkRowSize, LocalOrdinal blkColSize, LocalOrdinal LDA, const Teuchos::ArrayView<const Scalar>& blockEntry)
1115 {
1116  //first get an ArrayRCP for the internal storage for this block-entry:
1117  Teuchos::ArrayRCP<Scalar> internalBlockEntry;
1118  getGlobalBlockEntryViewNonConst(globalBlockRow,globalBlockCol, blkRowSize, blkColSize, internalBlockEntry);
1119 
1120  LocalOrdinal blk_size = blockEntry.size();
1121  TEUCHOS_TEST_FOR_EXCEPTION(blkColSize*LDA > blk_size, std::runtime_error,
1122  "Tpetra::VbrMatrix::setGlobalBlockEntry ERROR, inconsistent block-entry sizes.");
1123 
1124  //copy the incoming block-entry into internal storage:
1125  set_array_values(internalBlockEntry, blockEntry, blkRowSize, blkColSize, LDA, ADD);
1126 }
1127 
1128 //-------------------------------------------------------------------
1129 template<class Scalar, class LocalOrdinal, class GlobalOrdinal, class Node, class LocalMatOps>
1130 void
1131 VbrMatrix<Scalar,LocalOrdinal,GlobalOrdinal,Node,LocalMatOps>::sumIntoLocalBlockEntry(LocalOrdinal localBlockRow, LocalOrdinal localBlockCol, LocalOrdinal blkRowSize, LocalOrdinal blkColSize, LocalOrdinal LDA, const Teuchos::ArrayView<const Scalar>& blockEntry)
1132 {
1133  //first get an ArrayRCP for the internal storage for this block-entry:
1134  Teuchos::ArrayRCP<Scalar> internalBlockEntry;
1135  getLocalBlockEntryViewNonConst(localBlockRow,localBlockCol, blkRowSize, blkColSize, internalBlockEntry);
1136 
1137  LocalOrdinal blk_size = blockEntry.size();
1138  TEUCHOS_TEST_FOR_EXCEPTION(blkColSize*LDA > blk_size, std::runtime_error,
1139  "Tpetra::VbrMatrix::setLocalBlockEntry ERROR, inconsistent block-entry sizes.");
1140 
1141  //copy the incoming block-entry into internal storage:
1142  set_array_values(internalBlockEntry, blockEntry, blkRowSize, blkColSize, LDA, ADD);
1143 }
1144 
1145 //-------------------------------------------------------------------
1146 template<class Scalar, class LocalOrdinal, class GlobalOrdinal, class Node, class LocalMatOps>
1147 void
1149 {
1150  typedef Teuchos::ArrayRCP<const size_t> Host_View;
1151  typedef Teuchos::ArrayRCP<const LocalOrdinal> Host_View_LO;
1152  typedef typename Teuchos::ArrayRCP<size_t>::size_type Tsize_t;
1153 
1154  if (is_storage_optimized_ == true) return;
1155 
1156  TEUCHOS_TEST_FOR_EXCEPTION(constBlkGraph_->isFillComplete() != true, std::runtime_error,
1157  "Tpetra::VbrMatrix::optimizeStorage ERROR, isFillComplete() is false, required to be true before optimizeStorage is called.");
1158 
1159  size_t num_block_nonzeros = constBlkGraph_->getNodeNumBlockEntries();
1160 
1161  const Teuchos::RCP<const BlockMap<LocalOrdinal,GlobalOrdinal,Node> >& rowmap = constBlkGraph_->getBlockRowMap();
1162  const Teuchos::RCP<const BlockMap<LocalOrdinal,GlobalOrdinal,Node> >& colmap = constBlkGraph_->getBlockColMap();
1163 
1164  const Teuchos::RCP<Node>& node = getBlockRowMap()->getPointMap()->getNode();
1165 
1166  //need to count the number of point-entries:
1167  size_t num_point_entries = 0;
1168  Host_View bptr = constBlkGraph_->getNodeRowOffsets();
1169 
1170  if (bptr.size() == 0) {
1171  is_storage_optimized_ = true;
1172  return;
1173  }
1174 
1175  Host_View_LO bindx = constBlkGraph_->getNodePackedIndices();
1176 
1177  for(Tsize_t r=0; r<bptr.size()-1; ++r) {
1178  size_t rbeg = bptr[r];
1179  size_t rend = bptr[r+1];
1180 
1181  LocalOrdinal rsize = rowmap->getLocalBlockSize(r);
1182 
1183  for(size_t j=rbeg; j<rend; ++j) {
1184  LocalOrdinal csize = colmap->getLocalBlockSize(bindx[j]);
1185  num_point_entries += rsize*csize;
1186  }
1187  }
1188 
1189  pbuf_indx_ = node->template allocBuffer<LocalOrdinal>(num_block_nonzeros+1);
1190  pbuf_values1D_ = node->template allocBuffer<Scalar>(num_point_entries);
1191 
1192  Teuchos::ArrayRCP<LocalOrdinal> view_indx = node->template viewBufferNonConst<LocalOrdinal>(Kokkos::WriteOnly, num_block_nonzeros+1, pbuf_indx_);
1193  Teuchos::ArrayRCP<Scalar> view_values1D = node->template viewBufferNonConst<Scalar>(Kokkos::WriteOnly, num_point_entries, pbuf_values1D_);
1194 
1195  bool have_2D_data = data_2D_->size() > 0;
1196  Scalar zero = Teuchos::ScalarTraits<Scalar>::zero();
1197 
1198  size_t ioffset = 0;
1199  size_t offset = 0;
1200  for(Tsize_t r=0; r<bptr.size()-1; ++r) {
1201  LocalOrdinal rsize = rowmap->getLocalBlockSize(r);
1202 
1203  RowGlobalCols* blk_row = have_2D_data ? &((*data_2D_)[r]) : NULL;
1204 
1205  for(size_t c=bptr[r]; c<bptr[r+1]; ++c) {
1206  view_indx[ioffset++] = offset;
1207 
1208  LocalOrdinal csize = colmap->getLocalBlockSize(bindx[c]);
1209  Tsize_t blkSize = rsize*csize;
1210 
1211  if (blk_row != NULL) {
1212  GlobalOrdinal global_col = colmap->getGlobalBlockID(bindx[c]);
1213  typename RowGlobalCols::iterator iter = blk_row->find(global_col);
1214  TEUCHOS_TEST_FOR_EXCEPTION(iter == blk_row->end(), std::runtime_error,
1215  "Tpetra::VbrMatrix::optimizeStorage ERROR, global_col not found in row.");
1216 
1217  Teuchos::ArrayRCP<Scalar> vals = iter->second;
1218  for(Tsize_t n=0; n<blkSize; ++n) {
1219  view_values1D[offset+n] = vals[n];
1220  }
1221  }
1222  else {
1223  for(Tsize_t n=0; n<blkSize; ++n) view_values1D[offset+n] = zero;
1224  }
1225  offset += blkSize;
1226  }
1227  }
1228  view_indx[ioffset] = offset;
1229 
1230  //Final step: release memory for the "2D" storage:
1231  data_2D_ = Teuchos::null;
1232 
1233  is_storage_optimized_ = true;
1234 }
1235 
1236 //-------------------------------------------------------------------
1237 template<class Scalar, class LocalOrdinal, class GlobalOrdinal, class Node, class LocalMatOps>
1239 {
1240  //We insist that optimzeStorage has already been called.
1241  //We don't care whether this function (fillLocalMatrix()) is being
1242  //called for the first time or not.
1243  TEUCHOS_TEST_FOR_EXCEPTION(is_storage_optimized_ != true, std::runtime_error,
1244  "Tpetra::VbrMatrix::fillLocalMatrix ERROR, optimizeStorage is required to have already been called.");
1245 
1246  Teuchos::ArrayRCP<const size_t > nodeRowOffsets = constBlkGraph_->getNodeRowOffsets();
1247  Teuchos::ArrayRCP<const LocalOrdinal> nodePackedInds = constBlkGraph_->getNodePackedIndices();
1248  if (Node::isHostNode == false) {
1249  RCP<Node> node = getRangeMap()->getNode();
1250  //
1251  Teuchos::ArrayRCP<size_t> dev_nodeRowOffsets = node->template allocBuffer<size_t>(nodeRowOffsets.size());
1252  node->copyToBuffer(nodeRowOffsets.size(), nodeRowOffsets(), dev_nodeRowOffsets);
1253  nodeRowOffsets = dev_nodeRowOffsets;
1254  //
1255  Teuchos::ArrayRCP<LocalOrdinal> dev_nodePackedInds = node->template allocBuffer<LocalOrdinal>(nodePackedInds.size());
1256  node->copyToBuffer(nodePackedInds.size(), nodePackedInds(), dev_nodePackedInds);
1257  nodePackedInds = dev_nodePackedInds;
1258  }
1259  lclMatrix_->setPackedValues (pbuf_values1D_,
1260  getBlockRowMap()->getNodeFirstPointInBlocks_Device(),
1261  getBlockColMap()->getNodeFirstPointInBlocks_Device(),
1262  nodeRowOffsets,
1263  nodePackedInds,
1264  pbuf_indx_);
1265 }
1266 
1267 //-------------------------------------------------------------------
1268 template<class Scalar, class LocalOrdinal, class GlobalOrdinal, class Node, class LocalMatOps>
1270 {
1271  //We insist that optimzeStorage has already been called.
1272  //We don't care whether this function (fillLocalMatVec()) is being
1273  //called for the first time or not.
1274  TEUCHOS_TEST_FOR_EXCEPTION(is_storage_optimized_ != true, std::runtime_error,
1275  "Tpetra::VbrMatrix::fillLocalMatrix ERROR, optimizeStorage is required to have already been called.");
1276 
1277  lclMatOps_.initializeValues (*lclMatrix_);
1278 }
1279 
1280 //-------------------------------------------------------------------
1281 template<class Scalar, class LocalOrdinal, class GlobalOrdinal, class Node, class LocalMatOps>
1282 void
1284 {
1286 
1287  const PtMap& ptDomMap = (constBlkGraph_->getBlockDomainMap())->getPointMap();
1288  const PtMap& ptRngMap = (constBlkGraph_->getBlockRangeMap())->getPointMap();
1289  const PtMap& ptRowMap = (constBlkGraph_->getBlockRowMap())->getPointMap();
1290  const PtMap& ptColMap = (constBlkGraph_->getBlockColMap())->getPointMap();
1291 
1292  if (!ptDomMap->isSameAs(*ptColMap)) {
1293  importer_ = Teuchos::rcp(new Tpetra::Import<LocalOrdinal,GlobalOrdinal,Node>(ptDomMap, ptColMap));
1294  }
1295  if (!ptRngMap->isSameAs(*ptRowMap)) {
1296  exporter_ = Teuchos::rcp(new Tpetra::Export<LocalOrdinal,GlobalOrdinal,Node>(ptRowMap, ptRngMap));
1297  }
1298 }
1299 
1300 //-------------------------------------------------------------------
1301 template<class Scalar, class LocalOrdinal, class GlobalOrdinal, class Node, class LocalMatOps>
1302 void
1304 {
1305  if (isFillComplete()) return;
1306 
1307  globalAssemble();
1308 
1309  blkGraph_->fillComplete(blockDomainMap, blockRangeMap);
1310 
1311  createImporterExporter();
1312 
1313  is_fill_completed_ = true;
1314 
1315  optimizeStorage();
1316 
1317  fillLocalMatrix();
1318  fillLocalMatVec();
1319 }
1320 
1321 //-------------------------------------------------------------------
1322 template<class Scalar, class LocalOrdinal, class GlobalOrdinal, class Node, class LocalMatOps>
1324 {
1325  //In this case, our block-row-map will also be our domain-map and
1326  //range-map.
1327 
1329 }
1330 
1331 //-------------------------------------------------------------------
1332 template<class Scalar, class LocalOrdinal, class GlobalOrdinal, class Node, class LocalMatOps>
1334 {
1335  if (getPointRowMap()->getComm()->getSize() == 1) {
1336  return;
1337  }
1338 
1339  //nonlocal_data_ contains data that belongs on other processors.
1340  //We'll refer to this as overlapping data, and create an 'overlapMap'
1341  //that describes the layout of this overlapping data.
1343  overlapMap = VbrUtils::createOverlapMap(nonlocal_data_, *getBlockRowMap());
1344 
1345  if (overlapMap->getGlobalNumBlocks() == 0) {
1346  return;
1347  }
1348 
1349  //VbrDataDist is a wrapper that makes our overlapping data behave
1350  //like a DistObject so that the overlapping data can be exported
1351  //to the owning processors in a standard way.
1352  VbrUtils::VbrDataDist<LocalOrdinal,GlobalOrdinal,Scalar,Node>
1353  vdd(nonlocal_data_, *overlapMap, *this->getBlockRowMap());
1354 
1355  //Create an exporter where the source map is our overlapMap and the
1356  //target map is the rowmap of our VbrMatrix.
1358  importer( vdd.getMap(), convertBlockMapToPointMap(*getBlockRowMap()));
1359 
1360  //Communicate the overlapping data to the owning processors and add it
1361  //into this VbrMatrix.
1362  this->doImport(vdd, importer, Tpetra::ADD);
1363 
1364  //Zero out the overlapping data so it can be re-populated and re-assembled
1365  //in future calls to globalAssemble.
1366  VbrUtils::zeroEntries(nonlocal_data_);
1367 }
1368 
1369 //-------------------------------------------------------------------
1370 template<class Scalar, class LocalOrdinal, class GlobalOrdinal, class Node, class LocalMatOps>
1371 std::string
1373 {
1374  std::ostringstream oss;
1376  if (isFillComplete()) {
1377  oss << "{status = fill complete, global num block rows = " << getBlockRowMap()->getGlobalNumBlocks() << "}";
1378  }
1379  else {
1380  oss << "{status = fill not complete, global num block rows = " << getBlockRowMap()->getGlobalNumBlocks() << "}";
1381  }
1382  return oss.str();
1383 }
1384 
1385 //-------------------------------------------------------------------
1386 template<class Scalar, class LocalOrdinal, class GlobalOrdinal, class Node, class LocalMatOps>
1387 void
1389 {
1390  Teuchos::EVerbosityLevel vl = verbLevel;
1391  if (vl == Teuchos::VERB_DEFAULT) vl = Teuchos::VERB_LOW;
1392 
1393  if (vl == Teuchos::VERB_NONE) return;
1394 
1395  Teuchos::RCP<const Teuchos::Comm<int> > comm = getBlockRowMap()->getPointMap()->getComm();
1396  const int myProc = comm->getRank();
1397 
1398  if (myProc == 0) out << "VbrMatrix::describe is under construction..." << std::endl;
1399 }
1400 
1401 }//namespace Tpetra
1402 
1403 //
1404 // Explicit instantiation macro
1405 //
1406 // Must be expanded from within the Tpetra namespace!
1407 //
1408 
1409 #define TPETRA_VBRMATRIX_INSTANT(SCALAR,LO,GO,NODE) \
1410  \
1411  template class VbrMatrix< SCALAR , LO , GO , NODE >;
1412 
1413 #endif //TPETRA_VBRMATRIX_DEF_HPP
1414 
ScalarType * values() const
void getLocalBlockEntryView(LocalOrdinal localBlockRow, LocalOrdinal localBlockCol, LocalOrdinal &numPtRows, LocalOrdinal &numPtCols, Teuchos::ArrayRCP< const Scalar > &blockEntry) const
Returns a const read-only view of a block-entry.
Block-entry counterpart to Tpetra::Map.
Communication plan for data redistribution from a uniquely-owned to a (possibly) multiply-owned distr...
Namespace Tpetra contains the class and methods constituting the Tpetra library.
const Teuchos::RCP< const Map< LocalOrdinal, GlobalOrdinal, Node > > & getRangeMap() const
Returns the (point-entry) Map associated with the range of this operator.
VbrMatrix(const Teuchos::RCP< const BlockMap< LocalOrdinal, GlobalOrdinal, Node > > &blkRowMap, size_t maxNumEntriesPerRow, ProfileType pftype=DynamicProfile)
Constructor specifying the row-map and the max number of (block) non-zeros for all rows...
void setLocalBlockEntry(LocalOrdinal localBlockRow, LocalOrdinal localBlockCol, const Teuchos::SerialDenseMatrix< int, Scalar > &blockEntry)
Copy the contents of the input block-entry into the matrix.
Teuchos::ArrayRCP< Scalar > get1dViewNonConst()
Nonconst persisting (1-D) view of this multivector&#39;s local values.
Block-entry counterpart to Tpetra::CrsGraph.
iterator begin() const
size_t getNumVectors() const
Number of columns in the multivector.
std::string description() const
One-line descriptiion of this object.
bool isConstantStride() const
Whether this multivector has constant stride between columns.
const Teuchos::RCP< const BlockMap< LocalOrdinal, GlobalOrdinal, Node > > & getBlockRangeMap() const
Returns the block-range map.
One or more distributed dense vectors.
bool isFillComplete() const
Return true if fillComplete has been called, false otherwise.
#define TEUCHOS_TEST_FOR_EXCEPTION(throw_exception_test, Exception, msg)
size_type size() const
void putScalar(Scalar s)
Set the specified scalar throughout the matrix.
void fillComplete()
Transition the matrix to the packed, optimized-storage state.
const Teuchos::RCP< const BlockMap< LocalOrdinal, GlobalOrdinal, Node > > & getBlockRowMap() const
Returns the block-row map.
void sumIntoLocalBlockEntry(LocalOrdinal localBlockRow, LocalOrdinal localBlockCol, const Teuchos::SerialDenseMatrix< int, Scalar > &blockEntry)
Add the contents of the input block-entry into the matrix.
virtual void unpackAndCombine(const Teuchos::ArrayView< const LocalOrdinal > &importLIDs, const Teuchos::ArrayView< const char > &imports, const Teuchos::ArrayView< size_t > &numPacketsPerLID, size_t constantNumPackets, Distributor &distor, CombineMode CM)
Perform any unpacking and combining after communication.
size_type size() const
VbrMatrix: Variable block row matrix.
virtual void copyAndPermute(const SrcDistObject &source, size_t numSameIDs, const Teuchos::ArrayView< const LocalOrdinal > &permuteToLIDs, const Teuchos::ArrayView< const LocalOrdinal > &permuteFromLIDs)
Perform copies and permutations that are local to this process.
void getLocalBlockEntryViewNonConst(LocalOrdinal localBlockRow, LocalOrdinal localBlockCol, LocalOrdinal &numPtRows, LocalOrdinal &numPtCols, Teuchos::ArrayRCP< Scalar > &blockEntry)
Returns a non-const read-write view of a block-entry.
void setGlobalBlockEntry(GlobalOrdinal globalBlockRow, GlobalOrdinal globalBlockCol, const Teuchos::SerialDenseMatrix< int, Scalar > &blockEntry)
Copy the contents of the input block-entry into the matrix.
void applyInverse(const MultiVector< Scalar, LocalOrdinal, GlobalOrdinal, Node > &Y, MultiVector< Scalar, LocalOrdinal, GlobalOrdinal, Node > &X, Teuchos::ETransp trans) const
Triangular Solve – Matrix must be triangular.
void getGlobalBlockEntryViewNonConst(GlobalOrdinal globalBlockRow, GlobalOrdinal globalBlockCol, LocalOrdinal &numPtRows, LocalOrdinal &numPtCols, Teuchos::ArrayRCP< Scalar > &blockEntry)
Returns a non-const read-write view of a block-entry.
void getGlobalBlockEntryView(GlobalOrdinal globalBlockRow, GlobalOrdinal globalBlockCol, LocalOrdinal &numPtRows, LocalOrdinal &numPtCols, Teuchos::ArrayRCP< const Scalar > &blockEntry) const
Returns a const read-only view of a block-entry.
Ordinal size_type
TEUCHOS_DEPRECATED RCP< T > rcp(T *p, Dealloc_T dealloc, bool owns_mem)
void multiply(const MultiVector< DomainScalar, LocalOrdinal, GlobalOrdinal, Node > &X, MultiVector< RangeScalar, LocalOrdinal, GlobalOrdinal, Node > &Y, Teuchos::ETransp trans, RangeScalar alpha, RangeScalar beta) const
Multiply this matrix by a MultiVector.
const Teuchos::RCP< const Map< LocalOrdinal, GlobalOrdinal, Node > > & getDomainMap() const
Returns the (point-entry) Map associated with the domain of this operator.
Communication plan for data redistribution from a (possibly) multiply-owned to a uniquely-owned distr...
Sets up and executes a communication plan for a Tpetra DistObject.
CombineMode
Tpetra::Combine Mode enumerable type.
virtual std::string description() const
const Teuchos::RCP< const Map< LocalOrdinal, GlobalOrdinal, Node > > & getMap() const
The Map describing the parallel distribution of this object.
virtual void packAndPrepare(const SrcDistObject &source, const Teuchos::ArrayView< const LocalOrdinal > &exportLIDs, Teuchos::Array< char > &exports, const Teuchos::ArrayView< size_t > &numPacketsPerLID, size_t &constantNumPackets, Distributor &distor)
Perform any packing or preparation required for communication.
Abstract base class for objects that can be the source of an Import or Export operation.
void resize(size_type new_size, const value_type &x=value_type())
iterator end()
void globalAssemble()
Communicate non-local contributions to the processors that own those contributions.
void getLocalDiagCopy(Tpetra::Vector< Scalar, LocalOrdinal, GlobalOrdinal, Node > &diag) const
Return a copy of the (point-entry) diagonal values.
OrdinalType numCols() const
const Teuchos::RCP< const Map< LocalOrdinal, GlobalOrdinal, Node > > & getPointColMap() const
Returns the point-column map.
const Kokkos::MultiVector< Scalar, Node > & getLocalMV() const
Return a const reference to the underlying Kokkos::MultiVector object (advanced use only) ...
const Teuchos::RCP< const BlockMap< LocalOrdinal, GlobalOrdinal, Node > > & getBlockColMap() const
Returns the block-column map.
virtual ~VbrMatrix()
Destructor.
void apply(const MultiVector< Scalar, LocalOrdinal, GlobalOrdinal, Node > &X, MultiVector< Scalar, LocalOrdinal, GlobalOrdinal, Node > &Y, Teuchos::ETransp trans=Teuchos::NO_TRANS, Scalar alpha=Teuchos::ScalarTraits< Scalar >::one(), Scalar beta=Teuchos::ScalarTraits< Scalar >::zero()) const
Computes the operator-multivector application.
iterator end() const
size_type size() const
A distributed dense vector.
const Teuchos::RCP< const Map< LocalOrdinal, GlobalOrdinal, Node > > & getPointRowMap() const
Returns the point-row map.
void getGlobalBlockRowView(GlobalOrdinal globalBlockRow, LocalOrdinal &numPtRows, Teuchos::ArrayView< const GlobalOrdinal > &blockCols, Teuchos::Array< LocalOrdinal > &ptColsPerBlockCol, Teuchos::Array< Teuchos::ArrayRCP< const Scalar > > &blockEntries) const
Returns a const read-only view of the block-entries in the specified row.
iterator end() const
ArrayView< T > view(size_type offset, size_type size) const
void doImport(const SrcDistObject &source, const Import< LocalOrdinal, GlobalOrdinal, Node > &importer, CombineMode CM)
Import data into this object using an Import object ("forward mode").
void solve(const MultiVector< RangeScalar, LocalOrdinal, GlobalOrdinal, Node > &Y, MultiVector< DomainScalar, LocalOrdinal, GlobalOrdinal, Node > &X, Teuchos::ETransp trans) const
Triangular Solve – Matrix must be triangular.
void sumIntoGlobalBlockEntry(GlobalOrdinal globalBlockRow, GlobalOrdinal globalBlockCol, const Teuchos::SerialDenseMatrix< int, Scalar > &blockEntry)
Add the contents of the input block-entry into the matrix.
Declarations for the class Tpetra::VbrMatrix.
const Teuchos::RCP< const BlockMap< LocalOrdinal, GlobalOrdinal, Node > > & getBlockDomainMap() const
Returns the block-domain map.
Base class for distributed Tpetra objects that support data redistribution.
void getLocalBlockRowView(LocalOrdinal localBlockRow, LocalOrdinal &numPtRows, Teuchos::ArrayView< const LocalOrdinal > &blockCols, Teuchos::Array< LocalOrdinal > &ptColsPerBlockCol, Teuchos::ArrayRCP< const Scalar > &blockEntries) const
Returns a const read-only view of the block-entries in the specified row.
iterator begin()
void doExport(const SrcDistObject &source, const Export< LocalOrdinal, GlobalOrdinal, Node > &exporter, CombineMode CM)
Export data into this object using an Export object ("forward mode").
virtual bool checkSizes(const SrcDistObject &source)
Compare the source and target (this) objects for compatibility.
iterator begin() const
OrdinalType stride() const
bool hasTransposeApply() const
Indicates whether this operator supports applying the adjoint operator.
OrdinalType numRows() const
Kokkos::MultiVector< Scalar, Node > & getLocalMVNonConst()
Return a non-const reference to the underlying Kokkos::MultiVector object (advanced use only) ...
void describe(Teuchos::FancyOStream &out, const Teuchos::EVerbosityLevel verbLevel=Teuchos::Describable::verbLevel_default) const
Print the object with some verbosity level to a FancyOStream object.
ArrayView< T > view(size_type lowerOffset, size_type size) const