Tpetra Matrix/Vector Services  Version of the Day
Tpetra_MultiVectorFiller.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 #ifndef __Tpetra_MultiVectorFiller_hpp
42 #define __Tpetra_MultiVectorFiller_hpp
43 
44 #include <Tpetra_MultiVector.hpp>
45 #include <Teuchos_CommHelpers.hpp>
46 #include <iterator>
47 
48 namespace Tpetra {
49 namespace Details {
50  // \fn sortAndMergeIn
51  // \brief Sort and merge newEntries into allEntries, and make unique.
52  //
53  // \param allEntries [in/out]: Array in which current entries have
54  // already been stored, and in which the new entries are to be
55  // stored. Passed by reference in case we need to resize it.
56  //
57  // \param currentEntries [in/out]: Current entries, which we assume
58  // have already been sorted and made unique. Aliases the
59  // beginning of allEntries.
60  //
61  // \param newEntries [in/out] New entries, which have not yet been
62  // sorted or made unique. This does <i>not</i> alias allEntries.
63  //
64  // Sort and make entries of newEntries unique. Resize allEntries if
65  // necessary to fit the unique entries of newEntries. Merge
66  // newEntries into allEntries and make the results unique. (This is
67  // cheaper than sorting the whole array.)
68  //
69  // \return A view of all the entries (current and new) in allEntries.
70  template<class T>
72  sortAndMergeIn (Teuchos::Array<T>& allEntries,
73  Teuchos::ArrayView<T> currentEntries,
74  Teuchos::ArrayView<T> newEntries)
75  {
76  using Teuchos::ArrayView;
77  using Teuchos::as;
78  typedef typename ArrayView<T>::iterator iter_type;
79  typedef typename ArrayView<T>::size_type size_type;
80 
81  std::unique (newEntries.begin(), newEntries.end());
82  iter_type it = std::unique (newEntries.begin(), newEntries.end());
83  const size_type numNew = as<size_type> (it - newEntries.begin());
84  // View of the sorted, made-unique new entries to merge in.
85  ArrayView<T> newEntriesView = newEntries.view (0, numNew);
86 
87  const size_type numCur = currentEntries.size();
88  if (allEntries.size() < numCur + numNew) {
89  allEntries.resize (numCur + numNew);
90  }
91  ArrayView<T> allView = allEntries.view (0, numCur + numNew);
92  ArrayView<T> newView = allEntries.view (numCur, numNew); // target of copy
93 
94  std::copy (newEntries.begin(), newEntries.end(), newView.begin());
95  std::inplace_merge (allView.begin(), newView.begin(), allView.end());
96  iter_type it2 = std::unique (allView.begin(), allView.end());
97  const size_type numTotal = as<size_type> (it2 - allView.begin());
98 
99  return allEntries.view (0, numTotal);
100  }
101 
107  template<class MV>
109  public:
110  typedef typename MV::scalar_type scalar_type;
111  typedef typename MV::local_ordinal_type local_ordinal_type;
112  typedef typename MV::global_ordinal_type global_ordinal_type;
113  typedef typename MV::node_type node_type;
114 
116 
129  map_ (map),
130  numCols_ (0)
131  {}
132 
150  const size_t numColumns) :
151  map_ (map),
152  numCols_ (numColumns),
153  sourceIndices_ (numColumns),
154  sourceValues_ (numColumns)
155  {}
156 
158  void
159  setNumColumns (const size_t newNumColumns)
160  {
161  const size_t oldNumColumns = getNumColumns();
162  if (newNumColumns >= oldNumColumns) {
163  for (size_t j = oldNumColumns; j < newNumColumns; ++j) {
164  sourceIndices_.push_back (Teuchos::Array<global_ordinal_type> ());
165  sourceValues_.push_back (Teuchos::Array<scalar_type> ());
166  }
167  }
168  else {
169  // This may not necessarily deallocate any data, but that's OK.
170  sourceIndices_.resize (newNumColumns);
171  sourceValues_.resize (newNumColumns);
172  }
173  numCols_ = oldNumColumns;
174  }
175 
176  void
177  sumIntoGlobalValues (Teuchos::ArrayView<const global_ordinal_type> rows,
178  size_t column,
180  {
181  if (column >= getNumColumns()) {
182  for (size_t j = column; j < getNumColumns(); ++j) {
183  sourceIndices_.push_back (Teuchos::Array<global_ordinal_type> ());
184  sourceValues_.push_back (Teuchos::Array<scalar_type> ());
185  }
186  }
187  std::copy (rows.begin(), rows.end(), std::back_inserter (sourceIndices_[column]));
188  std::copy (values.begin(), values.end(), std::back_inserter (sourceValues_[column]));
189  }
190 
198  void
201  {
202  typedef global_ordinal_type GO;
203  typedef scalar_type ST;
204  typedef typename Teuchos::ArrayView<const GO>::const_iterator GoIter;
205  typedef typename Teuchos::ArrayView<const ST>::const_iterator StIter;
206 
207  const size_t numColumns = getNumColumns();
208  GoIter rowIter = rows.begin();
209  StIter valIter = values.begin();
210  for (size_t j = 0; j < numColumns; ++j) {
211  GoIter rowIterNext = rowIter + numColumns;
212  StIter valIterNext = valIter + numColumns;
213  std::copy (rowIter, rowIterNext, std::back_inserter (sourceIndices_[j]));
214  std::copy (valIter, valIterNext, std::back_inserter (sourceValues_[j]));
215  rowIter = rowIterNext;
216  valIter = valIterNext;
217  }
218  }
219 
244  template<class BinaryFunction>
245  void
246  locallyAssemble (MV& X, BinaryFunction& f)
247  {
248  using Teuchos::Array;
249  using Teuchos::ArrayRCP;
250  using Teuchos::ArrayView;
251  using Teuchos::RCP;
252  typedef local_ordinal_type LO;
253  typedef global_ordinal_type GO;
254  typedef scalar_type ST;
255  typedef node_type NT;
256 
257  RCP<const Tpetra::Map<LO, GO, NT> > map = X.getMap();
258  Array<LO> localIndices;
259  const size_t numColumns = getNumColumns();
260  for (size_t j = 0; j < numColumns; ++j) {
261  const typename Array<const GO>::size_type numIndices = sourceIndices_[j].size();
262  // Precompute all the local indices before saving to the
263  // vector. Hopefully this gives us a little bit of locality
264  // in the global->local conversion, at the expense of a little
265  // more storage.
266  if (localIndices.size() < numIndices) {
267  localIndices.resize (numIndices);
268  }
269  ArrayView<LO> localIndicesView = localIndices.view (0, numIndices);
270  ArrayView<const GO> globalIndicesView = sourceIndices_[j].view (0, numIndices);
271  for (typename ArrayView<const GO>::size_type i = 0; i < numIndices; ++i) {
272  localIndices[i] = map->getLocalElement (globalIndicesView[i]);
273  }
274 
275  ArrayRCP<ST> X_j = X.getDataNonConst (j);
276  ArrayView<const ST> localValues = sourceValues_[j].view (0, numIndices);
277  for (typename ArrayView<const GO>::size_type i = 0; i < numIndices; ++i) {
278  const LO localInd = localIndices[i];
279  X_j[localInd] = f (X_j[localInd], localValues[i]);
280  }
281  }
282  }
283 
285  void
287  {
288  std::plus<double> f;
289  locallyAssemble<std::plus<scalar_type> > (X, f);
290  }
291 
293  void clear() {
296  // The standard STL idiom for clearing the contents of a vector completely.
297  std::swap (sourceIndices_, newSourceIndices);
298  std::swap (sourceValues_, newSourceValues);
299  }
300 
304  {
305  using Teuchos::Array;
306  using Teuchos::ArrayView;
307  using Teuchos::as;
308  typedef global_ordinal_type GO;
309  typedef typename Array<GO>::size_type size_type;
310 
311  Array<GO> allInds (0); // will resize below
312  const size_t numCols = getNumColumns();
313 
314  if (numCols == 1) {
315  // Special case for 1 column avoids copying indices twice.
316  // Pick the size of the array exactly the first time so there
317  // are at most two allocations (the constructor may choose to
318  // allocate).
319  const size_type numNew = sourceIndices_[0].size();
320  allInds.resize (allInds.size() + numNew);
321  std::copy (sourceIndices_[0].begin(), sourceIndices_[0].end(),
322  allInds.begin());
323  std::sort (allInds.begin(), allInds.end());
324  typename Array<GO>::iterator it =
325  std::unique (allInds.begin(), allInds.end());
326  const size_type numFinal = as<size_type> (it - allInds.begin());
327  allInds.resize (numFinal);
328  }
329  else {
330  // Carefully collect all the row indices one column at a time.
331  // This ensures that the total allocation size in this routine
332  // is independent of the number of columns. Also, only sort
333  // the current column's indices. Use merges to ensure sorted
334  // order in the collected final result.
335  ArrayView<GO> curIndsView = allInds.view (0, 0); // will grow
336  Array<GO> newInds;
337  for (size_t j = 0; j < numCols; ++j) {
338  const size_type numNew = sourceIndices_[j].size();
339  if (numNew > newInds.size()) {
340  newInds.resize (numNew);
341  }
342  ArrayView<GO> newIndsView = newInds.view (0, numNew);
343  std::copy (sourceIndices_[j].begin(), sourceIndices_[j].end(),
344  newIndsView.begin());
345  curIndsView = sortAndMergeIn<GO> (allInds, curIndsView, newIndsView);
346  }
347  }
348  return allInds;
349  }
350 
351  private:
353  size_t numCols_;
356 
357  size_t getNumColumns() const { return numCols_; }
358  };
359 
365  template<class MV>
367  public:
368  typedef typename MV::scalar_type scalar_type;
369  typedef typename MV::local_ordinal_type local_ordinal_type;
370  typedef typename MV::global_ordinal_type global_ordinal_type;
371  typedef typename MV::node_type node_type;
372 
374 
387  const Teuchos::RCP<Teuchos::FancyOStream>& out=Teuchos::null) :
388  map_ (map),
389  numCols_ (0),
390  verbLevel_ (verbLevel),
391  out_ (out)
392  {}
393 
412  const size_t numColumns,
414  const Teuchos::RCP<Teuchos::FancyOStream>& out=Teuchos::null) :
415  map_ (map),
416  numCols_ (numColumns),
417  localVec_ (new MV (map, numColumns)),
418  nonlocalIndices_ (numColumns),
419  nonlocalValues_ (numColumns),
420  verbLevel_ (verbLevel),
421  out_ (out)
422  {}
423 
424  std::string
425  description() const
426  {
427  std::ostringstream oss;
428  oss << "Tpetra::MultiVectorFillerData2<"
430  return oss.str();
431  }
432 
433  void
434  describe (Teuchos::FancyOStream& out,
435  const Teuchos::EVerbosityLevel verbLevel =
437  {
438  using std::endl;
439  using Teuchos::Array;
440  using Teuchos::ArrayRCP;
441  using Teuchos::ArrayView;
442  using Teuchos::RCP;
443  using Teuchos::VERB_DEFAULT;
444  using Teuchos::VERB_NONE;
445  using Teuchos::VERB_LOW;
446  using Teuchos::VERB_MEDIUM;
447  using Teuchos::VERB_HIGH;
448  using Teuchos::VERB_EXTREME;
449 
450  // Set default verbosity if applicable.
451  const Teuchos::EVerbosityLevel vl =
452  (verbLevel == VERB_DEFAULT) ? VERB_LOW : verbLevel;
453 
454  RCP<const Teuchos::Comm<int> > comm = map_->getComm();
455  const int myImageID = comm->getRank();
456  const int numImages = comm->getSize();
457 
458  if (vl != VERB_NONE) {
459  // Don't set the tab level unless we're printing something.
460  Teuchos::OSTab tab (out);
461 
462  if (myImageID == 0) { // >= VERB_LOW prints description()
463  out << this->description() << endl;
464  }
465  for (int imageCtr = 0; imageCtr < numImages; ++imageCtr) {
466  if (myImageID == imageCtr) {
467  if (vl != VERB_LOW) {
468  // At verbosity > VERB_LOW, each process prints something.
469  out << "Process " << myImageID << ":" << endl;
470 
471  Teuchos::OSTab procTab (out);
472  // >= VERB_MEDIUM: print the local vector length.
473  out << "local length=" << localVec_->getLocalLength();
474  if (vl != VERB_MEDIUM) {
475  // >= VERB_HIGH: print isConstantStride() and getStride()
476  if (localVec_->isConstantStride()) {
477  out << ", constant stride=" << localVec_->getStride() << endl;
478  }
479  else {
480  out << ", not constant stride" << endl;
481  }
482  if (vl == VERB_EXTREME) {
483  // VERB_EXTREME: print all the values in the multivector.
484  out << "Local values:" << endl;
485  ArrayRCP<ArrayRCP<const scalar_type> > X = localVec_->get2dView();
486  for (size_t i = 0; i < localVec_->getLocalLength(); ++i) {
487  for (size_t j = 0; j < localVec_->getNumVectors(); ++j) {
488  out << X[j][i];
489  if (j < localVec_->getNumVectors() - 1) {
490  out << " ";
491  }
492  } // for each column
493  out << endl;
494  } // for each row
495 
496  out << "Nonlocal indices and values:" << endl;
497  for (size_t j = 0; j < (size_t)nonlocalIndices_.size(); ++j) {
498  ArrayView<const global_ordinal_type> inds = nonlocalIndices_[j]();
499  ArrayView<const scalar_type> vals = nonlocalValues_[j]();
500 
501  for (typename ArrayView<const global_ordinal_type>::size_type k = 0; k < inds.size(); ++k) {
502  out << "X(" << inds[k] << "," << j << ") = " << vals[k] << endl;
503  }
504  }
505  } // if vl == VERB_EXTREME
506  } // if (vl != VERB_MEDIUM)
507  else { // vl == VERB_LOW
508  out << endl;
509  }
510  } // if vl != VERB_LOW
511  } // if it is my process' turn to print
512  } // for each process in the communicator
513  } // if vl != VERB_NONE
514  }
515 
519  {
520  using Teuchos::Array;
521  using Teuchos::ArrayView;
522  using Teuchos::RCP;
523  using Teuchos::rcp;
524  using Tpetra::global_size_t;
525  typedef global_ordinal_type GO;
526 
527  // Get the nonlocal row indices, sorted and made unique.
528  // It's fair to assume that these are not contiguous.
529  Array<GO> nonlocalIndices = getSortedUniqueNonlocalIndices();
530 
531  // Get the local row indices, not necessarily sorted or unique.
532  ArrayView<const GO> localIndices = getLocalIndices ();
533 
534  // Copy the local indices into the full indices array, and sort
535  // them there. We'll merge in the nonlocal indices below. This
536  // can be more efficient than just sorting all the indices, if
537  // there are a lot of nonlocal indices.
538  Array<GO> indices (localIndices.size() + nonlocalIndices.size());
539  ArrayView<GO> localIndView = indices.view (0, localIndices.size());
540  std::copy (localIndices.begin(), localIndices.end(), localIndView.begin());
541  std::sort (localIndView.begin(), localIndView.end());
542 
543  // Merge the local and nonlocal indices.
544  if (nonlocalIndices.size() > 0) {
545  typedef typename ArrayView<GO>::iterator iter_type;
546 
547  iter_type middle = localIndView.end();
548  // We need a view, because std::inplace_merge needs all its
549  // iterator inputs to have the same type. Debug mode builds
550  // are pickier than release mode builds, because the iterators
551  // in a debug mode build are of a different type that does
552  // run-time checking (they aren't just raw pointers).
553  ArrayView<GO> indView = indices.view (0, indices.size());
554 
555  //iter_type middle = &indices[nonlocalIndices.size()];
556  std::copy (nonlocalIndices.begin(), nonlocalIndices.end(), middle);
557  std::inplace_merge (indView.begin(), middle, indView.end());
558  }
559  return indices;
560  }
561 
571  void
572  setNumColumns (const size_t newNumColumns)
573  {
574  using Teuchos::Array;
575  using Teuchos::Range1D;
576  using Teuchos::RCP;
577 
578  const size_t oldNumColumns = numCols_;
579  if (newNumColumns == oldNumColumns) {
580  return; // No side effects if no change.
581  }
582 
583  RCP<MV> newLocalVec;
584  if (newNumColumns > oldNumColumns) {
585  newLocalVec = rcp (new MV (map_, newNumColumns));
586  // Assign the contents of the old local multivector to the
587  // first oldNumColumns columns of the new local multivector,
588  // then get rid of the old local multivector.
589  RCP<MV> newLocalVecView =
590  newLocalVec->subViewNonConst (Range1D (0, oldNumColumns-1));
591  *newLocalVecView = *localVec_;
592  }
593  else {
594  if (newNumColumns == 0) {
595  // Tpetra::MultiVector doesn't let you construct a
596  // multivector with zero columns.
597  newLocalVec = Teuchos::null;
598  }
599  else {
600  newLocalVec =
601  localVec_->subViewNonConst (Range1D (0, newNumColumns-1));
602  }
603  }
604 
605  // Leave most side effects until the end, for exception safety.
606  nonlocalIndices_.resize (newNumColumns);
607  nonlocalValues_.resize (newNumColumns);
608  localVec_ = newLocalVec;
609  numCols_ = newNumColumns;
610  }
611 
613  void
615  size_t columnIndex,
617  {
618  using Teuchos::ArrayRCP;
619  using Teuchos::ArrayView;
620  typedef local_ordinal_type LO;
621  typedef global_ordinal_type GO;
622  typedef scalar_type ST;
623 
624  if (columnIndex >= getNumColumns()) {
625  // Automatically expand the number of columns. This
626  // implicitly ensures that localVec_ is not null.
627  setNumColumns (columnIndex + 1);
628  }
629 
630  typename ArrayView<const GO>::const_iterator rowIter = rows.begin();
631  typename ArrayView<const ST>::const_iterator valIter = values.begin();
632  for ( ; rowIter != rows.end() && valIter != values.end(); ++rowIter, ++valIter) {
633  const GO globalRowIndex = *rowIter;
634  // Converting from global to local index could be logarithmic
635  // in the number of global indices that this process owns,
636  // depending on the Map implementation. However, the lookup
637  // allows us to store data in the local multivector, rather
638  // than in a separate data structure.
639  const LO localRowIndex = map_->getLocalElement (globalRowIndex);
640  if (localRowIndex == Teuchos::OrdinalTraits<LO>::invalid()) {
641  nonlocalIndices_[columnIndex].push_back (globalRowIndex);
642  nonlocalValues_[columnIndex].push_back (*valIter);
643  }
644  else {
645  // FIXME (mfh 27 Feb 2012) This will be very slow for GPU
646  // Node types. In that case, we should hold on to the view
647  // of localVec_ as long as the number of columns doesn't
648  // change, and make modifications to the view until
649  // localAssemble() is called.
650  ArrayRCP<ST> X_j = localVec_->getDataNonConst (columnIndex);
651  // FIXME (mfh 27 Feb 2012) Allow different combine modes.
652  // The current combine mode just adds to the current value
653  // at that location.
654  X_j[localRowIndex] += *valIter;
655  }
656  }
657  }
658 
668  void
671  {
672  using Teuchos::ArrayView;
673  typedef typename ArrayView<const global_ordinal_type>::size_type size_type;
674 
675  const size_t numCols = getNumColumns();
676  for (size_t j = 0; j < numCols; ++j) {
677  const size_type offset = numCols*j;
678  const size_type len = numCols;
679  sumIntoGlobalValues (rows.view (offset, len), j, values.view (offset, len));
680  }
681  }
682 
707  template<class BinaryFunction>
708  void
709  locallyAssemble (MV& X, BinaryFunction& f)
710  {
711  using Teuchos::ArrayRCP;
712  using Teuchos::ArrayView;
713  using Teuchos::FancyOStream;
714  using Teuchos::getFancyOStream;
716  using Teuchos::RCP;
717  using Teuchos::rcp;
718  using std::endl;
719 
720  typedef local_ordinal_type LO;
721  typedef global_ordinal_type GO;
722  typedef scalar_type ST;
723 
724  // Default output stream prints nothing.
725  RCP<FancyOStream> out = out_.is_null() ?
726  getFancyOStream (rcp (new oblackholestream)) : out_;
727 
728  Teuchos::OSTab tab (out);
729  *out << "locallyAssemble:" << endl;
730 
731  RCP<const map_type> srcMap = X.getMap();
732  ArrayView<const GO> localIndices = map_->getNodeElementList ();
733 
734  for (size_t j = 0; j < X.getNumVectors(); ++j) {
735  ArrayRCP<ST> X_j = X.getDataNonConst (j);
736 
737  // First add all the local data into X_j.
738  ArrayRCP<const ST> local_j = localVec_->getDataNonConst (j);
739  for (typename ArrayView<const GO>::const_iterator it = localIndices.begin();
740  it != localIndices.end(); ++it) {
741  const LO rowIndLocal = map_->getLocalElement (*it);
742  const LO rowIndX = srcMap->getLocalElement (*it);
743 
745  std::invalid_argument, "locallyAssemble(): Input multivector X does "
746  "not own the global index " << *it << ". This probably means that "
747  "X was not constructed with the right Map.");
748  X_j[rowIndX] = f (X_j[rowIndX], local_j[rowIndLocal]);
749  }
750 
751  // Now add the nonlocal data into X_j.
752  ArrayView<const GO> nonlocalIndices = nonlocalIndices_[j]();
753  typename ArrayView<const GO>::const_iterator indexIter = nonlocalIndices.begin();
754  ArrayView<const ST> nonlocalValues = nonlocalValues_[j]();
755  typename ArrayView<const ST>::const_iterator valueIter = nonlocalValues.begin();
756  for ( ; indexIter != nonlocalIndices.end() && valueIter != nonlocalValues.end();
757  ++indexIter, ++valueIter) {
758  const LO rowIndX = srcMap->getLocalElement (*indexIter);
759  X_j[rowIndX] = f (X_j[rowIndX], *valueIter);
760  }
761  }
762 
763  *out << "Locally assembled vector:" << endl;
764  X.describe (*out, Teuchos::VERB_EXTREME);
765  }
766 
768  void
770  {
771  std::plus<double> f;
772  locallyAssemble<std::plus<scalar_type> > (X, f);
773  }
774 
780  void clear() {
782  Teuchos::Array<Teuchos::Array<scalar_type> > newNonlocalValues;
783  // The standard STL idiom for clearing the contents of a vector
784  // completely. Setting the size to zero may not necessarily
785  // deallocate data.
786  std::swap (nonlocalIndices_, newNonlocalIndices);
787  std::swap (nonlocalValues_, newNonlocalValues);
788 
789  // Don't actually deallocate the multivector of local entries.
790  // Just fill it with zero. This is because the caller hasn't
791  // reset the number of columns.
792  if (! localVec_.is_null()) {
793  localVec_->putScalar (Teuchos::ScalarTraits<scalar_type>::zero());
794  }
795  }
796 
797  private:
800 
802  size_t numCols_;
803 
805  Teuchos::RCP<MV> localVec_;
806 
809 
812 
814  Teuchos::EVerbosityLevel verbLevel_;
815 
818 
820  size_t getNumColumns() const { return numCols_; }
821 
824  getLocalIndices() const
825  {
826  return map_->getNodeElementList ();
827  }
828 
831  getSortedUniqueNonlocalIndices() const
832  {
833  using Teuchos::Array;
834  using Teuchos::ArrayView;
835  using Teuchos::as;
836  typedef global_ordinal_type GO;
837  typedef typename Array<GO>::size_type size_type;
838 
839  Array<GO> allNonlocals (0); // will resize below
840  const size_t numCols = getNumColumns();
841 
842  if (numCols == 1) {
843  // Special case for 1 column avoids copying indices twice.
844  // Pick the size of the array exactly the first time so there
845  // are at most two allocations (the constructor may choose to
846  // allocate).
847  const size_type numNew = nonlocalIndices_[0].size();
848  allNonlocals.resize (allNonlocals.size() + numNew);
849  std::copy (nonlocalIndices_[0].begin(), nonlocalIndices_[0].end(),
850  allNonlocals.begin());
851  std::sort (allNonlocals.begin(), allNonlocals.end());
852  typename Array<GO>::iterator it =
853  std::unique (allNonlocals.begin(), allNonlocals.end());
854  const size_type numFinal = as<size_type> (it - allNonlocals.begin());
855  allNonlocals.resize (numFinal);
856  }
857  else {
858  // Carefully collect all the row indices one column at a time.
859  // This ensures that the total allocation size in this routine
860  // is independent of the number of columns. Also, only sort
861  // the current column's indices. Use merges to ensure sorted
862  // order in the collected final result.
863  ArrayView<GO> curNonlocalsView = allNonlocals.view (0, 0); // will grow
864  Array<GO> newNonlocals;
865  for (size_t j = 0; j < numCols; ++j) {
866  const size_type numNew = nonlocalIndices_[j].size();
867  if (numNew > newNonlocals.size()) {
868  newNonlocals.resize (numNew);
869  }
870  ArrayView<GO> newNonlocalsView = newNonlocals.view (0, numNew);
871  std::copy (nonlocalIndices_[j].begin(), nonlocalIndices_[j].end(),
872  newNonlocalsView.begin());
873  curNonlocalsView = sortAndMergeIn<GO> (allNonlocals, curNonlocalsView,
874  newNonlocalsView);
875  }
876  }
877  return allNonlocals;
878  }
879  };
880 } // namespace Details
881 } // namespace Tpetra
882 
883 namespace Tpetra {
884 
909  template<class MV>
911  public:
912  typedef typename MV::scalar_type scalar_type;
913  typedef typename MV::local_ordinal_type local_ordinal_type;
914  typedef typename MV::global_ordinal_type global_ordinal_type;
915  typedef typename MV::node_type node_type;
917 
948  const size_t numCols);
949 
969  void globalAssemble (MV& X_out, const bool forceReuseMap = false);
970 
971  void
972  describe (Teuchos::FancyOStream& out,
974  {
975  data_.describe (out, verbLevel);
976  }
977 
988  void
990  size_t column,
992  {
993  data_.sumIntoGlobalValues (rows, column, values);
994  }
995 
1011  void
1014  {
1015  data_.sumIntoGlobalValues (rows, values);
1016  }
1017 
1018  private:
1021 
1026  Teuchos::RCP<const map_type> sourceMap_;
1027 
1033  Teuchos::RCP<const map_type> targetMap_;
1034 
1047  Teuchos::RCP<MV> sourceVec_;
1048 
1054 
1056  Teuchos::RCP<export_type> exporter_;
1057 
1063  void locallyAssemble (MV& X_in) {
1064  data_.locallyAssemble (X_in);
1065  }
1066 
1069  return data_.getSourceIndices();
1070  }
1071 
1081  computeSourceMap (const global_ordinal_type indexBase,
1082  const Teuchos::RCP<const Teuchos::Comm<int> >& comm,
1083  const Teuchos::RCP<node_type>& node);
1084  };
1085 
1086  template<class MV>
1088  : ctorMap_ (map),
1089  sourceMap_ (Teuchos::null),
1090  targetMap_ (Teuchos::null),
1091  data_ (map, numCols),
1092  exporter_ (Teuchos::null)
1093  {}
1094 
1095  template<class MV>
1098  computeSourceMap (const global_ordinal_type indexBase,
1099  const Teuchos::RCP<const Teuchos::Comm<int> >& comm,
1100  const Teuchos::RCP<node_type>& node)
1101  {
1102  using Teuchos::Array;
1103  using Teuchos::ArrayView;
1104  using Teuchos::rcp;
1105  typedef global_ordinal_type GO;
1106 
1107  Array<GO> indices = getSourceIndices ();
1108 
1109  // Passing "invalid" for the numGlobalElements argument of the Map
1110  // constructor tells the Map to compute the global number of
1111  // elements itself.
1112  const Tpetra::global_size_t invalid =
1114  return rcp (new map_type (invalid, indices, indexBase, comm, node));
1115  }
1116 
1117  template<class MV>
1118  void
1119  MultiVectorFiller<MV>::globalAssemble (MV& X_out, const bool forceReuseMap)
1120  {
1121  using Teuchos::ArrayView;
1122  using Teuchos::Array;
1123  using Teuchos::Range1D;
1124  using Teuchos::RCP;
1125  using Teuchos::rcp;
1126 
1127  const size_t numVecs = X_out.getNumVectors();
1128 
1129  if (numVecs == 0) {
1130  // Nothing to do! Of course, this does not check for whether
1131  // X_out has the right number of rows. That's OK, though.
1132  // Compare to the definition of the BLAS' _AXPY for an input
1133  // vector containing NaNs, but multiplied by alpha=0.
1134  return;
1135  }
1136  //
1137  // Get the target Map of the Export. If X_out's Map is the same
1138  // as the target Map from last time, then we may be able to
1139  // recycle the Export from last time, if the source Map is also
1140  // the same.
1141  //
1142  RCP<const map_type> targetMap;
1143  bool assumeSameTargetMap = false;
1144  if (targetMap_.is_null()) {
1145  targetMap_ = X_out.getMap();
1146  targetMap = targetMap_;
1147  assumeSameTargetMap = false;
1148  }
1149  else {
1150  if (forceReuseMap) {
1151  targetMap = targetMap_;
1152  assumeSameTargetMap = true;
1153  }
1154  else {
1155  // If X_out's Map is the same as targetMap_, we may be able to
1156  // reuse the Export. Constructing the Export may be more
1157  // expensive than calling isSameAs() (which requires just a
1158  // few reductions and reading through the lists of owned
1159  // global indices), so it's worth checking.
1160  if (targetMap_->isSameAs (*(X_out.getMap()))) {
1161  assumeSameTargetMap = true;
1162  targetMap = targetMap_;
1163  }
1164  }
1165  }
1166  //
1167  // Get the source Map of the Export. If the source Map of the
1168  // Export is the same as last time, then we may be able to recycle
1169  // the Export from last time, if the target Map is also the same.
1170  //
1171  RCP<const map_type> sourceMap;
1172  bool computedSourceMap = false;
1173  {
1174  if (forceReuseMap && ! sourceMap_.is_null()) {
1175  sourceMap = sourceMap_;
1176  }
1177  else {
1178  sourceMap = computeSourceMap (ctorMap_->getIndexBase(),
1179  ctorMap_->getComm(),
1180  ctorMap_->getNode());
1181  computedSourceMap = true;
1182  }
1183  }
1184  if (computedSourceMap) {
1185  sourceMap_ = sourceMap;
1186  }
1187  //
1188  // Now that we have the source and target Maps of the Export, we
1189  // can check whether we can recycle the Export from last time.
1190  //
1191  const bool mustComputeExport =
1192  (exporter_.is_null() || (assumeSameTargetMap && ! computedSourceMap));
1193  if (mustComputeExport) {
1194  exporter_ = rcp (new export_type (sourceMap_, targetMap_));
1195  }
1196 
1197  // Source multivector for the Export.
1198  RCP<MV> X_in;
1199  const bool mustReallocateVec = sourceVec_.is_null() ||
1200  sourceVec_->getNumVectors() < numVecs || ! assumeSameTargetMap;
1201 
1202  if (mustReallocateVec) {
1203  // Reallocating nonlocalVec_ ensures that it has the right Map.
1204  sourceVec_ = rcp (new MV (sourceMap_, numVecs));
1205  X_in = sourceVec_;
1206  } else {
1207  if (sourceVec_->getNumVectors() == numVecs) {
1208  X_in = sourceVec_;
1209  } else { // sourceVec_ has more vectors than needed.
1210  X_in = sourceVec_->subViewNonConst (Range1D (0, numVecs-1));
1211  }
1212  }
1213 
1214  // "Locally assemble" the data into X_in by summing together
1215  // entries with the same indices.
1216  locallyAssemble (*X_in);
1217 
1218  // Do the Export.
1219  const Tpetra::CombineMode combineMode = Tpetra::ADD;
1220  X_out.doExport (*X_in, *exporter_, combineMode);
1221  }
1222 
1223  namespace Test {
1224 
1230  template<class MV>
1232  public:
1233  typedef typename MV::scalar_type scalar_type;
1234  typedef typename MV::local_ordinal_type local_ordinal_type;
1235  typedef typename MV::global_ordinal_type global_ordinal_type;
1236  typedef typename MV::node_type node_type;
1238 
1247  static void
1249  const global_ordinal_type eltSize, // Must be odd
1250  const size_t numCols,
1251  const Teuchos::RCP<Teuchos::FancyOStream>& outStream=Teuchos::null,
1252  const Teuchos::EVerbosityLevel verbosityLevel=Teuchos::VERB_DEFAULT)
1253  {
1254  using Teuchos::Array;
1255  using Teuchos::ArrayRCP;
1256  using Teuchos::ArrayView;
1257  using Teuchos::as;
1258  using Teuchos::Comm;
1259  using Teuchos::FancyOStream;
1260  using Teuchos::getFancyOStream;
1262  using Teuchos::ptr;
1263  using Teuchos::RCP;
1264  using Teuchos::rcp;
1265  using Teuchos::rcpFromRef;
1266  using Teuchos::REDUCE_SUM;
1267  using Teuchos::reduceAll;
1268  using std::cerr;
1269  using std::endl;
1270 
1271  typedef local_ordinal_type LO;
1272  typedef global_ordinal_type GO;
1273  typedef scalar_type ST;
1274  typedef Teuchos::ScalarTraits<ST> STS;
1275 
1276  TEUCHOS_TEST_FOR_EXCEPTION(eltSize % 2 == 0, std::invalid_argument,
1277  "Element size (eltSize) argument must be odd.");
1278  TEUCHOS_TEST_FOR_EXCEPTION(numCols == 0, std::invalid_argument,
1279  "Number of columns (numCols) argument must be nonzero.");
1280  // Default behavior is to print nothing out.
1281  RCP<FancyOStream> out = outStream.is_null() ?
1282  getFancyOStream (rcp (new oblackholestream)) : outStream;
1283  const Teuchos::EVerbosityLevel verbLevel =
1284  (verbosityLevel == Teuchos::VERB_DEFAULT) ?
1285  Teuchos::VERB_NONE : verbosityLevel;
1286 
1287  //RCP<MV> X = rcp (new MV (targetMap, numCols));
1288 
1289  const GO indexBase = targetMap->getIndexBase();
1290  Array<GO> rows (eltSize);
1291  Array<ST> values (eltSize);
1292  std::fill (values.begin(), values.end(), STS::one());
1293 
1294  // Make this a pointer so we can free its contents, in case
1295  // those contents depend on the input to globalAssemble().
1296  RCP<MultiVectorFiller<MV> > filler =
1297  rcp (new MultiVectorFiller<MV> (targetMap, numCols));
1298 
1299  TEUCHOS_TEST_FOR_EXCEPTION(! targetMap->isContiguous(),
1300  std::invalid_argument, "MultiVectorFiller test currently only works "
1301  "for contiguous Maps.");
1302 
1303  const GO minGlobalIndex = targetMap->getMinGlobalIndex();
1304  const GO maxGlobalIndex = targetMap->getMaxGlobalIndex();
1305  const GO minAllGlobalIndex = targetMap->getMinAllGlobalIndex();
1306  const GO maxAllGlobalIndex = targetMap->getMaxAllGlobalIndex();
1307  for (size_t j = 0; j < numCols; ++j) {
1308  for (GO i = minGlobalIndex; i <= maxGlobalIndex; ++i) {
1309  // Overlap over processes, without running out of bounds.
1310  const GO start = std::max (i - eltSize/2, minAllGlobalIndex);
1311  const GO end = std::min (i + eltSize/2, maxAllGlobalIndex);
1312  const GO len = end - start + 1;
1313 
1314  TEUCHOS_TEST_FOR_EXCEPTION(len > eltSize, std::logic_error,
1315  "At start,end = " << start << "," << end << ", len = " << len
1316  << " > eltSize = " << eltSize << ".");
1317 
1318  for (GO k = 0; k < len; ++k) {
1319  rows[k] = start + k;
1320  }
1321  if (verbLevel == Teuchos::VERB_EXTREME) {
1322  *out << "Inserting: "
1323  << Teuchos::toString (rows.view(0,len)) << ", "
1324  << Teuchos::toString (values.view(0, len)) << std::endl;
1325  }
1326  filler->sumIntoGlobalValues (rows.view(0, len), j, values.view(0, len));
1327  }
1328  }
1329 
1330  if (verbLevel == Teuchos::VERB_EXTREME) {
1331  *out << "Filler:" << std::endl;
1332  filler->describe (*out, verbLevel);
1333  *out << std::endl;
1334  }
1335 
1336  MV X_out (targetMap, numCols);
1337  filler->globalAssemble (X_out);
1338  filler = Teuchos::null;
1339 
1340  if (verbLevel == Teuchos::VERB_EXTREME) {
1341  *out << "X_out:" << std::endl;
1342  X_out.describe (*out, verbLevel);
1343  *out << std::endl;
1344  }
1345 
1346  // Create multivector for comparison.
1347  MV X_expected (targetMap, numCols);
1348  const scalar_type two = STS::one() + STS::one();
1349  for (size_t j = 0; j < numCols; ++j) {
1350  ArrayRCP<ST> X_j = X_expected.getDataNonConst (j);
1351 
1352  // Each entry of the column should have the value eltSize,
1353  // except for the first and last few entries in the whole
1354  // column (globally, not locally).
1355  for (GO i = minGlobalIndex; i <= maxGlobalIndex; ++i) {
1356  const LO localIndex = targetMap->getLocalElement (i);
1358  std::logic_error, "Global index " << i << " is not in the "
1359  "multivector's Map.");
1360 
1361  if (i <= minAllGlobalIndex + eltSize/2) {
1362  X_j[localIndex] = two + as<ST>(i) - as<ST>(indexBase);
1363  }
1364  else if (i >= maxAllGlobalIndex - eltSize/2) {
1365  X_j[localIndex] = two + as<ST>(maxAllGlobalIndex) - as<ST>(i);
1366  }
1367  else {
1368  X_j[localIndex] = as<ST>(eltSize);
1369  }
1370  } // for each global index which my process owns
1371  } // for each column of the multivector
1372 
1373  if (verbLevel == Teuchos::VERB_EXTREME) {
1374  *out << "X_expected:" << std::endl;
1375  X_expected.describe (*out, verbLevel);
1376  *out << std::endl;
1377  }
1378 
1379  Array<GO> errorLocations;
1380  for (size_t j = 0; j < numCols; ++j) {
1381  ArrayRCP<const ST> X_out_j = X_out.getData (j);
1382  ArrayRCP<const ST> X_expected_j = X_expected.getData (j);
1383 
1384  // Each entry of the column should have the value eltSize,
1385  // except for the first and last few entries in the whole
1386  // column (globally, not locally).
1387  for (GO i = minGlobalIndex; i <= maxGlobalIndex; ++i) {
1388  const LO localIndex = targetMap->getLocalElement (i);
1390  std::logic_error, "Global index " << i << " is not in the "
1391  "multivector's Map.");
1392 
1393  // The floating-point additions should be exact in this
1394  // case, except for very large values of eltSize.
1395  if (X_out_j[localIndex] != X_expected_j[localIndex]) {
1396  errorLocations.push_back (i);
1397  }
1398  } // for each global index which my process owns
1399 
1400  const typename Array<GO>::size_type localNumErrors = errorLocations.size();
1401  typename Array<GO>::size_type globalNumErrors = 0;
1402  RCP<const Comm<int> > comm = targetMap->getComm();
1403  reduceAll (*comm, REDUCE_SUM, localNumErrors, ptr (&globalNumErrors));
1404 
1405  if (globalNumErrors != 0) {
1406  std::ostringstream os;
1407  os << "Proc " << comm->getRank() << ": " << localNumErrors
1408  << " incorrect value" << (localNumErrors != 1 ? "s" : "")
1409  << ". Error locations: [ ";
1410  std::copy (errorLocations.begin(), errorLocations.end(),
1411  std::ostream_iterator<GO> (os, " "));
1412  os << "].";
1413  // Iterate through all processes in the communicator,
1414  // printing out each process' local errors.
1415  for (int p = 0; p < comm->getSize(); ++p) {
1416  if (p == comm->getRank()) {
1417  cerr << os.str() << endl;
1418  }
1419  // Barriers to let output finish.
1420  comm->barrier();
1421  comm->barrier();
1422  comm->barrier();
1423  }
1424  TEUCHOS_TEST_FOR_EXCEPTION(globalNumErrors != 0, std::logic_error,
1425  "Over all procs: " << globalNumErrors << " total error"
1426  << (globalNumErrors != 1 ? "s" : "") << ".");
1427  } // if there were any errors in column j
1428  } // for each column j
1429  }
1430  };
1431 
1433  template<class ScalarType,
1434  class LocalOrdinalType,
1435  class GlobalOrdinalType,
1436  class NodeType>
1437  void
1438  testMultiVectorFiller (const Teuchos::RCP<const Teuchos::Comm<int> >& comm,
1439  const Teuchos::RCP<NodeType>& node,
1440  const size_t unknownsPerNode,
1441  const GlobalOrdinalType unknownsPerElt,
1442  const size_t numCols,
1443  const Teuchos::RCP<Teuchos::FancyOStream>& outStream,
1444  const Teuchos::EVerbosityLevel verbLevel)
1445  {
1447  using Teuchos::FancyOStream;
1448  using Teuchos::getFancyOStream;
1450  using Teuchos::ParameterList;
1451  using Teuchos::RCP;
1452  using Teuchos::rcp;
1453  using std::cerr;
1454  using std::endl;
1455 
1456  typedef ScalarType ST;
1457  typedef LocalOrdinalType LO;
1458  typedef GlobalOrdinalType GO;
1459  typedef NodeType NT;
1460  typedef Tpetra::Map<LO, GO, NT> MT;
1462 
1463  RCP<FancyOStream> out = outStream.is_null() ?
1464  getFancyOStream (rcp (new oblackholestream)) : outStream;
1465  const Tpetra::global_size_t invalid =
1467  RCP<const MT> targetMap =
1468  createContigMapWithNode<LO, GO, NT> (invalid, unknownsPerNode, comm, node);
1469 
1470  std::ostringstream os;
1471  try {
1472  MultiVectorFillerTester<MV>::testSameMap (targetMap, unknownsPerElt, numCols, out, verbLevel);
1473  } catch (std::exception& e) {
1474  os << e.what();
1475  }
1476 
1477  for (int p = 0; p < comm->getSize(); ++p) {
1478  if (p == comm->getRank()) {
1479  *out << "On process " << comm->getRank() << ": " << os.str() << endl;
1480  }
1481  comm->barrier();
1482  comm->barrier();
1483  comm->barrier();
1484  }
1485  }
1486 
1492  void
1493  testSortAndMergeIn ();
1494 
1495  } // namespace Test
1496 } // namespace Tpetra
1497 
1498 
1499 #endif // __Tpetra_MultiVectorFiller_hpp
Teuchos::Array< global_ordinal_type > getSourceIndices() const
All source indices (local and nonlocal) of the source Map, sorted and unique.
void locallyAssemble(MV &X)
locallyAssemble() for the usual Tpetra::ADD combine mode.
Namespace Tpetra contains the class and methods constituting the Tpetra library.
void sumIntoGlobalValues(Teuchos::ArrayView< const global_ordinal_type > rows, Teuchos::ArrayView< const scalar_type > values)
Set entry (rows[i],j) to values[i], for all i and j.
static void testSameMap(const Teuchos::RCP< const map_type > &targetMap, const global_ordinal_type eltSize, const size_t numCols, const Teuchos::RCP< Teuchos::FancyOStream > &outStream=Teuchos::null, const Teuchos::EVerbosityLevel verbosityLevel=Teuchos::VERB_DEFAULT)
Test global assembly when constructor Map = target Map.
Second implementation of fill and local assembly for MultiVectorFiller.
void clear()
Clear the contents of the vector, making it implicitly a vector of zeros.
MultiVectorFiller(const Teuchos::RCP< const map_type > &map, const size_t numCols)
Constructor.
void locallyAssemble(MV &X, BinaryFunction &f)
Locally assemble into X, with user-specified combine mode.
iterator begin() const
ArrayView< T > view(size_type offset, size_type size)
Teuchos::Array< global_ordinal_type > getSourceIndices() const
All source indices (local and nonlocal) of the source Map, sorted and unique.
One or more distributed dense vectors.
basic_FancyOStream< char > FancyOStream
void locallyAssemble(MV &X)
locallyAssemble() for the usual ADD combine mode.
#define TEUCHOS_TEST_FOR_EXCEPTION(throw_exception_test, Exception, msg)
const_pointer const_iterator
size_type size() const
void sumIntoGlobalValues(Teuchos::ArrayView< const global_ordinal_type > rows, Teuchos::ArrayView< const scalar_type > values)
Sum data into the multivector.
Adds nonlocal sum-into functionality to Tpetra::MultiVector.
Teuchos::RCP< const Map< LocalOrdinal, GlobalOrdinal, Node > > createContigMapWithNode(global_size_t numElements, size_t localNumElements, const Teuchos::RCP< const Teuchos::Comm< int > > &comm, const Teuchos::RCP< Node > &node)
Non-member constructor for a (potentially) non-uniformly distributed, contiguous Map with a user-spec...
Implementation details of Tpetra.
MultiVectorFillerData(const Teuchos::RCP< const map_type > &map, const size_t numColumns)
Constructor.
void locallyAssemble(MV &X, BinaryFunction &f)
Locally assemble into X.
size_t global_size_t
Global size_t object.
Implementation of fill and local assembly for MultiVectorFiller.
Ordinal size_type
TEUCHOS_DEPRECATED RCP< T > rcp(T *p, Dealloc_T dealloc, bool owns_mem)
MultiVectorFillerData2(const Teuchos::RCP< const map_type > &map, const Teuchos::EVerbosityLevel verbLevel=Teuchos::VERB_DEFAULT, const Teuchos::RCP< Teuchos::FancyOStream > &out=Teuchos::null)
Default constructor (sets number of columns to zero).
Communication plan for data redistribution from a (possibly) multiply-owned to a uniquely-owned distr...
void sumIntoGlobalValues(Teuchos::ArrayView< const global_ordinal_type > rows, Teuchos::ArrayView< const scalar_type > values)
void globalAssemble(MV &X_out, const bool forceReuseMap=false)
Assemble all the data (local and nonlocal) into X_out.
CombineMode
Tpetra::Combine Mode enumerable type.
TEUCHOS_DEPRECATED void reduceAll(const Comm< Ordinal > &comm, const EReductionType reductType, const Packet &send, Packet *globalReduct)
void resize(size_type new_size, const value_type &x=value_type())
iterator end()
static const EVerbosityLevel verbLevel_default
void push_back(const value_type &x)
Describes a parallel distribution of objects over processes.
iterator end() const
size_type size() const
TypeTo as(const TypeFrom &t)
MultiVectorFillerData2(const Teuchos::RCP< const map_type > &map, const size_t numColumns, const Teuchos::EVerbosityLevel verbLevel=Teuchos::VERB_DEFAULT, const Teuchos::RCP< Teuchos::FancyOStream > &out=Teuchos::null)
Constructor.
void sumIntoGlobalValues(Teuchos::ArrayView< const global_ordinal_type > rows, size_t columnIndex, Teuchos::ArrayView< const scalar_type > values)
Set entry (rows[i],columnIndex) to values[i], for all i.
MultiVectorFillerData(const Teuchos::RCP< const map_type > &map)
Default constructor (sets number of columns to zero).
void sumIntoGlobalValues(Teuchos::ArrayView< const global_ordinal_type > rows, size_t column, Teuchos::ArrayView< const scalar_type > values)
Sum data into the multivector.
void setNumColumns(const size_t newNumColumns)
Set the number of columns in the output multivector.
ArrayView< T > view(size_type offset, size_type size) const
void setNumColumns(const size_t newNumColumns)
Set the number of columns in the output multivector.
void clear()
Clear the contents of the multivector.
std::vector< T >::iterator iterator
iterator begin()
static std::string name()
basic_oblackholestream< char, std::char_traits< char > > oblackholestream
std::string toString(const T &t)
bool is_null() const