Teko  Version of the Day
 All Classes Files Functions Variables Pages
Teko_InterlacedTpetra.cpp
1 /*
2 // @HEADER
3 //
4 // ***********************************************************************
5 //
6 // Teko: A package for block and physics based preconditioning
7 // Copyright 2010 Sandia Corporation
8 //
9 // Under the terms of Contract DE-AC04-94AL85000 with Sandia Corporation,
10 // the U.S. Government retains certain rights in this software.
11 //
12 // Redistribution and use in source and binary forms, with or without
13 // modification, are permitted provided that the following conditions are
14 // met:
15 //
16 // 1. Redistributions of source code must retain the above copyright
17 // notice, this list of conditions and the following disclaimer.
18 //
19 // 2. Redistributions in binary form must reproduce the above copyright
20 // notice, this list of conditions and the following disclaimer in the
21 // documentation and/or other materials provided with the distribution.
22 //
23 // 3. Neither the name of the Corporation nor the names of the
24 // contributors may be used to endorse or promote products derived from
25 // this software without specific prior written permission.
26 //
27 // THIS SOFTWARE IS PROVIDED BY SANDIA CORPORATION "AS IS" AND ANY
28 // EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
29 // IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
30 // PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL SANDIA CORPORATION OR THE
31 // CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
32 // EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
33 // PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
34 // PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
35 // LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
36 // NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
37 // SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
38 //
39 // Questions? Contact Eric C. Cyr (eccyr@sandia.gov)
40 //
41 // ***********************************************************************
42 //
43 // @HEADER
44 
45 */
46 
47 #include "Teko_InterlacedTpetra.hpp"
48 #include "Tpetra_Import.hpp"
49 
50 #include <vector>
51 
52 using Teuchos::RCP;
53 using Teuchos::rcp;
54 
55 namespace Teko {
56 namespace TpetraHelpers {
57 namespace Strided {
58 
59 // this assumes that there are numGlobals with numVars each interlaced
60 // i.e. for numVars = 2 (u,v) then the vector is
61 // [u_0,v_0,u_1,v_1,u_2,v_2, ..., u_(numGlobals-1),v_(numGlobals-1)]
62 void buildSubMaps(GO numGlobals,int numVars,const Teuchos::Comm<int> & comm,std::vector<std::pair<int,RCP<Tpetra::Map<LO,GO,NT> > > > & subMaps)
63 {
64  std::vector<int> vars;
65 
66  // build vector describing the sub maps
67  for(int i=0;i<numVars;i++) vars.push_back(1);
68 
69  // build all the submaps
70  buildSubMaps(numGlobals,vars,comm,subMaps);
71 }
72 
73 // build maps to make other conversions
74 void buildSubMaps(const Tpetra::Map<LO,GO,NT> & globalMap,const std::vector<int> & vars,const Teuchos::Comm<int> & comm,
75  std::vector<std::pair<int,Teuchos::RCP<Tpetra::Map<LO,GO,NT> > > > & subMaps)
76 {
77  buildSubMaps(globalMap.getGlobalNumElements(),globalMap.getNodeNumElements(),globalMap.getMinGlobalIndex(),
78  vars,comm,subMaps);
79 }
80 
81 // build maps to make other conversions
82 void buildSubMaps(GO numGlobals,const std::vector<int> & vars,const Teuchos::Comm<int> & comm,std::vector<std::pair<int,Teuchos::RCP<Tpetra::Map<LO,GO,NT> > > > & subMaps)
83 {
84  std::vector<int>::const_iterator varItr;
85 
86  // compute total number of variables
87  int numGlobalVars = 0;
88  for(varItr=vars.begin();varItr!=vars.end();++varItr)
89  numGlobalVars += *varItr;
90 
91  // must be an even number of globals
92  TEUCHOS_ASSERT((numGlobals%numGlobalVars)==0);
93 
94  Tpetra::Map<LO,GO,NT> sampleMap(numGlobals/numGlobalVars,0,rcpFromRef(comm));
95 
96  buildSubMaps(numGlobals,numGlobalVars*sampleMap.getNodeNumElements(),numGlobalVars*sampleMap.getMinGlobalIndex(),vars,comm,subMaps);
97 }
98 
99 // build maps to make other conversions
100 void buildSubMaps(GO numGlobals,LO numMyElements,GO minMyGID,const std::vector<int> & vars,const Teuchos::Comm<int> & comm,
101  std::vector<std::pair<int,Teuchos::RCP<Tpetra::Map<LO,GO,NT> > > > & subMaps)
102 {
103  std::vector<int>::const_iterator varItr;
104 
105  // compute total number of variables
106  int numGlobalVars = 0;
107  for(varItr=vars.begin();varItr!=vars.end();++varItr)
108  numGlobalVars += *varItr;
109 
110  // must be an even number of globals
111  TEUCHOS_ASSERT((numGlobals%numGlobalVars)==0);
112  TEUCHOS_ASSERT((numMyElements%numGlobalVars)==0);
113  TEUCHOS_ASSERT((minMyGID%numGlobalVars)==0);
114 
115  LO numBlocks = numMyElements/numGlobalVars;
116  GO minBlockID = minMyGID/numGlobalVars;
117 
118  subMaps.clear();
119 
120  // index into local block in strided map
121  GO blockOffset = 0;
122  for(varItr=vars.begin();varItr!=vars.end();++varItr) {
123  LO numLocalVars = *varItr;
124  GO numAllElmts = numLocalVars*numGlobals/numGlobalVars;
125 #ifndef NDEBUG
126  LO numMyElmts = numLocalVars * numBlocks;
127 #endif
128 
129  // create global arrays describing the as of yet uncreated maps
130  std::vector<GO> subGlobals;
131  std::vector<GO> contigGlobals; // the contiguous globals
132 
133  // loop over each block of variables
134  LO count = 0;
135  for(LO blockNum=0;blockNum<numBlocks;blockNum++) {
136 
137  // loop over each local variable in the block
138  for(LO local=0;local<numLocalVars;++local) {
139  // global block number = minGID+blockNum
140  // block begin global id = numGlobalVars*(minGID+blockNum)
141  // global id block offset = blockOffset+local
142  subGlobals.push_back((minBlockID+blockNum)*numGlobalVars+blockOffset+local);
143 
144  // also build the contiguous IDs
145  contigGlobals.push_back(numLocalVars*minBlockID+count);
146  count++;
147  }
148  }
149 
150  // sanity check
151  assert((size_t) numMyElmts==subGlobals.size());
152 
153  // create the map with contiguous elements and the map with global elements
154  RCP<Tpetra::Map<LO,GO,NT> > subMap = rcp(new Tpetra::Map<LO,GO,NT>(numAllElmts,Teuchos::ArrayView<GO>(subGlobals),0,rcpFromRef(comm)));
155  RCP<Tpetra::Map<LO,GO,NT> > contigMap = rcp(new Tpetra::Map<LO,GO,NT>(numAllElmts,Teuchos::ArrayView<GO>(contigGlobals),0,rcpFromRef(comm)));
156 
157  Teuchos::set_extra_data(contigMap,"contigMap",Teuchos::inOutArg(subMap));
158  subMaps.push_back(std::make_pair(numLocalVars,subMap));
159 
160  // update the block offset
161  blockOffset += numLocalVars;
162  }
163 }
164 
165 void buildExportImport(const Tpetra::Map<LO,GO,NT> & baseMap, const std::vector<std::pair<int,RCP<Tpetra::Map<LO,GO,NT> > > > & subMaps,
166  std::vector<RCP<Tpetra::Export<LO,GO,NT> > > & subExport,
167  std::vector<RCP<Tpetra::Import<LO,GO,NT> > > & subImport)
168 {
169  std::vector<std::pair<int,RCP<Tpetra::Map<LO,GO,NT> > > >::const_iterator mapItr;
170 
171  // build importers and exporters
172  for(mapItr=subMaps.begin();mapItr!=subMaps.end();++mapItr) {
173  // exctract basic map
174  const Tpetra::Map<LO,GO,NT> & map = *(mapItr->second);
175 
176  // add new elements to vectors
177  subImport.push_back(rcp(new Tpetra::Import<LO,GO,NT>(rcpFromRef(baseMap),rcpFromRef(map))));
178  subExport.push_back(rcp(new Tpetra::Export<LO,GO,NT>(rcpFromRef(map),rcpFromRef(baseMap))));
179  }
180 }
181 
182 void buildSubVectors(const std::vector<std::pair<int,RCP<Tpetra::Map<LO,GO,NT> > > > & subMaps,std::vector<RCP<Tpetra::MultiVector<ST,LO,GO,NT> > > & subVectors,int count)
183 {
184  std::vector<std::pair<int,RCP<Tpetra::Map<LO,GO,NT> > > >::const_iterator mapItr;
185 
186  // build vectors
187  for(mapItr=subMaps.begin();mapItr!=subMaps.end();++mapItr) {
188  // exctract basic map
189  const Tpetra::Map<LO,GO,NT> & map = *(Teuchos::get_extra_data<RCP<Tpetra::Map<LO,GO,NT> > >(mapItr->second,"contigMap"));
190 
191  // add new elements to vectors
192  RCP<Tpetra::MultiVector<ST,LO,GO,NT> > mv = rcp(new Tpetra::MultiVector<ST,LO,GO,NT>(rcpFromRef(map),count));
193  Teuchos::set_extra_data(mapItr->second,"globalMap",Teuchos::inOutArg(mv));
194  subVectors.push_back(mv);
195  }
196 }
197 
198 void associateSubVectors(const std::vector<std::pair<int,RCP<Tpetra::Map<LO,GO,NT> > > > & subMaps,std::vector<RCP<const Tpetra::MultiVector<ST,LO,GO,NT> > > & subVectors)
199 {
200  std::vector<std::pair<int,RCP<Tpetra::Map<LO,GO,NT> > > >::const_iterator mapItr;
201  std::vector<RCP<const Tpetra::MultiVector<ST,LO,GO,NT> > >::iterator vecItr;
202 
203  TEUCHOS_ASSERT(subMaps.size()==subVectors.size());
204 
205  // associate the sub vectors with the subMaps
206  for(mapItr=subMaps.begin(),vecItr=subVectors.begin();mapItr!=subMaps.end();++mapItr,++vecItr)
207  Teuchos::set_extra_data(mapItr->second,"globalMap",Teuchos::inOutArg(*vecItr),Teuchos::POST_DESTROY,false);
208 }
209 
210 // build a single subblock Epetra_CrsMatrix
211 RCP<Tpetra::CrsMatrix<ST,LO,GO,NT> > buildSubBlock(int i,int j,const RCP<const Tpetra::CrsMatrix<ST,LO,GO,NT> >& A,const std::vector<std::pair<int,RCP<Tpetra::Map<LO,GO,NT> > > > & subMaps)
212 {
213  // get the number of variables families
214  int numVarFamily = subMaps.size();
215 
216  TEUCHOS_ASSERT(i>=0 && i<numVarFamily);
217  TEUCHOS_ASSERT(j>=0 && j<numVarFamily);
218 
219  const Tpetra::Map<LO,GO,NT> & gRowMap = *subMaps[i].second;
220  const Tpetra::Map<LO,GO,NT> & rowMap = *Teuchos::get_extra_data<RCP<Tpetra::Map<LO,GO,NT> > >(subMaps[i].second,"contigMap");
221  const Tpetra::Map<LO,GO,NT> & colMap = *Teuchos::get_extra_data<RCP<Tpetra::Map<LO,GO,NT> > >(subMaps[j].second,"contigMap");
222  int colFamilyCnt = subMaps[j].first;
223 
224  // compute the number of global variables
225  // and the row and column block offset
226  GO numGlobalVars = 0;
227  GO rowBlockOffset = 0;
228  GO colBlockOffset = 0;
229  for(int k=0;k<numVarFamily;k++) {
230  numGlobalVars += subMaps[k].first;
231 
232  // compute block offsets
233  if(k<i) rowBlockOffset += subMaps[k].first;
234  if(k<j) colBlockOffset += subMaps[k].first;
235  }
236 
237  // copy all global rows to here
238  Tpetra::Import<LO,GO,NT> import(A->getRowMap(),rcpFromRef(gRowMap));
239  Tpetra::CrsMatrix<ST,LO,GO,NT> localA(rcpFromRef(gRowMap),0);
240  localA.doImport(*A,import,Tpetra::INSERT);
241 
242  // get entry information
243  LO numMyRows = rowMap.getNodeNumElements();
244  LO maxNumEntries = A->getGlobalMaxNumRowEntries();
245 
246  // for extraction
247  std::vector<GO> indices(maxNumEntries);
248  std::vector<ST> values(maxNumEntries);
249 
250  // for counting row sizes
251  std::vector<size_t> numEntriesPerRow(numMyRows,0);
252 
253  // Count the sizes of each row, using same logic as insertion below
254  for(LO localRow=0;localRow<numMyRows;localRow++) {
255  size_t numEntries = -1;
256  GO globalRow = gRowMap.getGlobalElement(localRow);
257  GO contigRow = rowMap.getGlobalElement(localRow);
258 
259  TEUCHOS_ASSERT(globalRow>=0);
260  TEUCHOS_ASSERT(contigRow>=0);
261 
262  // extract a global row copy
263  localA.getGlobalRowCopy(globalRow, Teuchos::ArrayView<GO>(indices), Teuchos::ArrayView<ST>(values), numEntries);
264  LO numOwnedCols = 0;
265  for(size_t localCol=0;localCol<numEntries;localCol++) {
266  GO globalCol = indices[localCol];
267 
268  // determinate which block this column ID is in
269  int block = globalCol / numGlobalVars;
270 
271  bool inFamily = true;
272 
273  // test the beginning of the block
274  inFamily &= (block*numGlobalVars+colBlockOffset <= globalCol);
275  inFamily &= ((block*numGlobalVars+colBlockOffset+colFamilyCnt) > globalCol);
276 
277  // is this column in the variable family
278  if(inFamily) {
279  numOwnedCols++;
280  }
281  }
282  numEntriesPerRow[localRow] += numOwnedCols;
283  }
284 
285  RCP<Tpetra::CrsMatrix<ST,LO,GO,NT> > mat =
286  rcp(new Tpetra::CrsMatrix<ST,LO,GO,NT>(rcpFromRef(rowMap), Teuchos::ArrayView<const size_t>(numEntriesPerRow)));
287 
288  // for insertion
289  std::vector<GO> colIndices(maxNumEntries);
290  std::vector<ST> colValues(maxNumEntries);
291 
292  // insert each row into subblock
293  // let FillComplete handle column distribution
294  for(LO localRow=0;localRow<numMyRows;localRow++) {
295  size_t numEntries = -1;
296  GO globalRow = gRowMap.getGlobalElement(localRow);
297  GO contigRow = rowMap.getGlobalElement(localRow);
298 
299  TEUCHOS_ASSERT(globalRow>=0);
300  TEUCHOS_ASSERT(contigRow>=0);
301 
302  // extract a global row copy
303  localA.getGlobalRowCopy(globalRow, Teuchos::ArrayView<GO>(indices), Teuchos::ArrayView<ST>(values), numEntries);
304  LO numOwnedCols = 0;
305  for(size_t localCol=0;localCol<numEntries;localCol++) {
306  GO globalCol = indices[localCol];
307 
308  // determinate which block this column ID is in
309  int block = globalCol / numGlobalVars;
310 
311  bool inFamily = true;
312 
313  // test the beginning of the block
314  inFamily &= (block*numGlobalVars+colBlockOffset <= globalCol);
315  inFamily &= ((block*numGlobalVars+colBlockOffset+colFamilyCnt) > globalCol);
316 
317  // is this column in the variable family
318  if(inFamily) {
319  GO familyOffset = globalCol-(block*numGlobalVars+colBlockOffset);
320 
321  colIndices[numOwnedCols] = block*colFamilyCnt + familyOffset;
322  colValues[numOwnedCols] = values[localCol];
323 
324  numOwnedCols++;
325  }
326  }
327 
328  // insert it into the new matrix
329  colIndices.resize(numOwnedCols);
330  colValues.resize(numOwnedCols);
331  mat->insertGlobalValues(contigRow,Teuchos::ArrayView<GO>(colIndices),Teuchos::ArrayView<ST>(colValues));
332  colIndices.resize(maxNumEntries);
333  colValues.resize(maxNumEntries);
334  }
335 
336  // fill it and automagically optimize the storage
337  mat->fillComplete(rcpFromRef(colMap),rcpFromRef(rowMap));
338 
339  return mat;
340 }
341 
342 // rebuild a single subblock Epetra_CrsMatrix
343 void rebuildSubBlock(int i,int j,const RCP<const Tpetra::CrsMatrix<ST,LO,GO,NT> > & A,const std::vector<std::pair<int,RCP<Tpetra::Map<LO,GO,NT> > > > & subMaps,Tpetra::CrsMatrix<ST,LO,GO,NT> & mat)
344 {
345  // get the number of variables families
346  int numVarFamily = subMaps.size();
347 
348  TEUCHOS_ASSERT(i>=0 && i<numVarFamily);
349  TEUCHOS_ASSERT(j>=0 && j<numVarFamily);
350  TEUCHOS_ASSERT(mat.isFillComplete());
351 
352  const Tpetra::Map<LO,GO,NT> & gRowMap = *subMaps[i].second;
353  const Tpetra::Map<LO,GO,NT> & rowMap = *Teuchos::get_extra_data<RCP<Tpetra::Map<LO,GO,NT> > >(subMaps[i].second,"contigMap");
354  const Tpetra::Map<LO,GO,NT> & colMap = *Teuchos::get_extra_data<RCP<Tpetra::Map<LO,GO,NT> > >(subMaps[j].second,"contigMap");
355  int colFamilyCnt = subMaps[j].first;
356 
357  // compute the number of global variables
358  // and the row and column block offset
359  GO numGlobalVars = 0;
360  GO rowBlockOffset = 0;
361  GO colBlockOffset = 0;
362  for(int k=0;k<numVarFamily;k++) {
363  numGlobalVars += subMaps[k].first;
364 
365  // compute block offsets
366  if(k<i) rowBlockOffset += subMaps[k].first;
367  if(k<j) colBlockOffset += subMaps[k].first;
368  }
369 
370  // copy all global rows to here
371  Tpetra::Import<LO,GO,NT> import(A->getRowMap(),rcpFromRef(gRowMap));
372  Tpetra::CrsMatrix<ST,LO,GO,NT> localA(rcpFromRef(gRowMap),0);
373  localA.doImport(*A,import,Tpetra::INSERT);
374 
375  // clear out the old matrix
376  mat.resumeFill();
377  mat.setAllToScalar(0.0);
378 
379  // get entry information
380  LO numMyRows = rowMap.getNodeNumElements();
381  GO maxNumEntries = A->getGlobalMaxNumRowEntries();
382 
383  // for extraction
384  std::vector<GO> indices(maxNumEntries);
385  std::vector<ST> values(maxNumEntries);
386 
387  // for insertion
388  std::vector<GO> colIndices(maxNumEntries);
389  std::vector<ST> colValues(maxNumEntries);
390 
391  // insert each row into subblock
392  // let FillComplete handle column distribution
393  for(LO localRow=0;localRow<numMyRows;localRow++) {
394  size_t numEntries = -1;
395  GO globalRow = gRowMap.getGlobalElement(localRow);
396  GO contigRow = rowMap.getGlobalElement(localRow);
397 
398  TEUCHOS_ASSERT(globalRow>=0);
399  TEUCHOS_ASSERT(contigRow>=0);
400 
401  // extract a global row copy
402  localA.getGlobalRowCopy(globalRow, Teuchos::ArrayView<GO>(indices), Teuchos::ArrayView<ST>(values), numEntries);
403 
404  LO numOwnedCols = 0;
405  for(size_t localCol=0;localCol<numEntries;localCol++) {
406  GO globalCol = indices[localCol];
407 
408  // determinate which block this column ID is in
409  int block = globalCol / numGlobalVars;
410 
411  bool inFamily = true;
412 
413  // test the beginning of the block
414  inFamily &= (block*numGlobalVars+colBlockOffset <= globalCol);
415  inFamily &= ((block*numGlobalVars+colBlockOffset+colFamilyCnt) > globalCol);
416 
417  // is this column in the variable family
418  if(inFamily) {
419  GO familyOffset = globalCol-(block*numGlobalVars+colBlockOffset);
420 
421  colIndices[numOwnedCols] = block*colFamilyCnt + familyOffset;
422  colValues[numOwnedCols] = values[localCol];
423 
424  numOwnedCols++;
425  }
426  }
427 
428  // insert it into the new matrix
429  colIndices.resize(numOwnedCols);
430  colValues.resize(numOwnedCols);
431  mat.sumIntoGlobalValues(contigRow,Teuchos::ArrayView<GO>(colIndices),Teuchos::ArrayView<ST>(colValues));
432  colIndices.resize(maxNumEntries);
433  colValues.resize(maxNumEntries);
434  }
435  mat.fillComplete(rcpFromRef(colMap),rcpFromRef(rowMap));
436 }
437 
438 
439 // collect subvectors into a single global vector
440 void many2one(Tpetra::MultiVector<ST,LO,GO,NT> & one, const std::vector<RCP<const Tpetra::MultiVector<ST,LO,GO,NT> > > & many,
441  const std::vector<RCP<Tpetra::Export<LO,GO,NT> > > & subExport)
442 {
443  // std::vector<RCP<const Epetra_Vector> >::const_iterator vecItr;
444  std::vector<RCP<const Tpetra::MultiVector<ST,LO,GO,NT> > >::const_iterator vecItr;
445  std::vector<RCP<Tpetra::Export<LO,GO,NT> > >::const_iterator expItr;
446 
447  // using Exporters fill the empty vector from the sub-vectors
448  for(vecItr=many.begin(),expItr=subExport.begin();
449  vecItr!=many.end();++vecItr,++expItr) {
450 
451  // for ease of access to the source
452  RCP<const Tpetra::MultiVector<ST,LO,GO,NT> > srcVec = *vecItr;
453 
454  // extract the map with global indicies from the current vector
455  const Tpetra::Map<LO,GO,NT> & globalMap = *(Teuchos::get_extra_data<RCP<Tpetra::Map<LO,GO,NT> > >(srcVec,"globalMap"));
456 
457  // build the export vector as a view of the destination
458  GO lda = srcVec->getStride();
459  GO srcSize = srcVec->getGlobalLength()*srcVec->getNumVectors();
460  std::vector<ST> srcArray(srcSize);
461  Teuchos::ArrayView<ST> srcVals(srcArray);
462  srcVec->get1dCopy(srcVals,lda);
463  Tpetra::MultiVector<ST,LO,GO,NT> exportVector(rcpFromRef(globalMap),srcVals,lda,srcVec->getNumVectors());
464 
465  // perform the export
466  one.doExport(exportVector,**expItr,Tpetra::INSERT);
467  }
468 }
469 
470 // distribute one global vector into a many subvectors
471 void one2many(std::vector<RCP<Tpetra::MultiVector<ST,LO,GO,NT> > > & many,const Tpetra::MultiVector<ST,LO,GO,NT> & single,
472  const std::vector<RCP<Tpetra::Import<LO,GO,NT> > > & subImport)
473 {
474  // std::vector<RCP<Epetra_Vector> >::const_iterator vecItr;
475  std::vector<RCP<Tpetra::MultiVector<ST,LO,GO,NT> > >::const_iterator vecItr;
476  std::vector<RCP<Tpetra::Import<LO,GO,NT> > >::const_iterator impItr;
477 
478  // using Importers fill the sub vectors from the mama vector
479  for(vecItr=many.begin(),impItr=subImport.begin();
480  vecItr!=many.end();++vecItr,++impItr) {
481  // for ease of access to the destination
482  RCP<Tpetra::MultiVector<ST,LO,GO,NT> > destVec = *vecItr;
483 
484  // extract the map with global indicies from the current vector
485  const Tpetra::Map<LO,GO,NT> & globalMap = *(Teuchos::get_extra_data<RCP<Tpetra::Map<LO,GO,NT> > >(destVec,"globalMap"));
486 
487  // build the import vector as a view on the destination
488  GO destLDA = destVec->getStride();
489  GO destSize = destVec->getGlobalLength()*destVec->getNumVectors();
490  std::vector<ST> destArray(destSize);
491  Teuchos::ArrayView<ST> destVals(destArray);
492  destVec->get1dCopy(destVals,destLDA);
493  Tpetra::MultiVector<ST,LO,GO,NT> importVector(rcpFromRef(globalMap),destVals,destLDA,destVec->getNumVectors());
494 
495  // perform the import
496  importVector.doImport(single,**impItr,Tpetra::INSERT);
497 
498  Tpetra::Import<LO,GO,NT> importer(destVec->getMap(),destVec->getMap());
499  importVector.replaceMap(destVec->getMap());
500  destVec->doImport(importVector,importer,Tpetra::INSERT);
501 
502  }
503 }
504 
505 }
506 } // end namespace Tpetra
507 } // end namespace Teko