EpetraExt  Development
EpetraExt_PointToBlockDiagPermute.cpp
Go to the documentation of this file.
1 /*
2 //@HEADER
3 // ***********************************************************************
4 //
5 // EpetraExt: Epetra Extended - Linear Algebra Services Package
6 // Copyright (2011) Sandia Corporation
7 //
8 // Under the terms of Contract DE-AC04-94AL85000 with Sandia Corporation,
9 // the U.S. Government retains certain rights in this software.
10 //
11 // Redistribution and use in source and binary forms, with or without
12 // modification, are permitted provided that the following conditions are
13 // met:
14 //
15 // 1. Redistributions of source code must retain the above copyright
16 // notice, this list of conditions and the following disclaimer.
17 //
18 // 2. Redistributions in binary form must reproduce the above copyright
19 // notice, this list of conditions and the following disclaimer in the
20 // documentation and/or other materials provided with the distribution.
21 //
22 // 3. Neither the name of the Corporation nor the names of the
23 // contributors may be used to endorse or promote products derived from
24 // this software without specific prior written permission.
25 //
26 // THIS SOFTWARE IS PROVIDED BY SANDIA CORPORATION "AS IS" AND ANY
27 // EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
28 // IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
29 // PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL SANDIA CORPORATION OR THE
30 // CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
31 // EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
32 // PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
33 // PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
34 // LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
35 // NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
36 // SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
37 //
38 // Questions? Contact Michael A. Heroux (maherou@sandia.gov)
39 //
40 // ***********************************************************************
41 //@HEADER
42 */
43 
46 #include "Epetra_MultiVector.h"
47 #include "Epetra_Import.h"
48 #include "Epetra_Export.h"
49 #include "Epetra_Comm.h"
50 
51 #include <stdio.h>
52 #include <fstream>
53 
54 #define MAX(x,y) ((x)>(y)?(x):(y))
55 
56 //=========================================================================
58  :Epetra_DistObject(MAT.RowMap()),
59  Matrix_(&MAT),
60  PurelyLocalMode_(true),
61  ContiguousBlockMode_(false),
62  ContiguousBlockSize_(0),
63  NumBlocks_(0),
64  Blockstart_(0),
65  Blockids_(0),
66  BDMap_(0),
67  CompatibleMap_(0),
68  BDMat_(0),
69  Importer_(0),
70  Exporter_(0),
71  ImportVector_(0),
72  ExportVector_(0)
73 {
74 
75 }
76 
77 //=========================================================================
78 // Destructor
80 {
81  if(BDMap_) delete BDMap_;
82  if(CompatibleMap_) delete CompatibleMap_;
83  if(BDMat_) delete BDMat_;
84  if(Importer_) delete Importer_;
85  if(Exporter_) delete Exporter_;
86  if(ImportVector_) delete ImportVector_;
87  if(ExportVector_) delete ExportVector_;
88 }
89 
90 
91 
92 //=========================================================================
93 // Set list
94 int EpetraExt_PointToBlockDiagPermute::SetParameters(Teuchos::ParameterList & List){
95  List_=List;
96 
97  // Check for contiguous blocking first
98  ContiguousBlockSize_=List_.get("contiguous block size",0);
99  if(ContiguousBlockSize_!=0){
100  ContiguousBlockMode_=true;
101  PurelyLocalMode_=false;
102  }
103 
104  // Local vs. global ids & mode
105  NumBlocks_=List_.get("number of local blocks",0);
106  Blockstart_=List_.get("block start index",(int*)0);
107  Blockids_=List_.get("block entry lids",(int*)0);
108  if(Blockids_)
109  PurelyLocalMode_=true;
110  else{
111  Blockids_=List_.get("block entry gids",(int*)0);
112  PurelyLocalMode_=false;
113  }
114 
115  // Sanity checks
116  if(ContiguousBlockMode_){
117  // Can't use contiguous at the same time as the other modes
118  if(NumBlocks_ || Blockstart_ || Blockids_) EPETRA_CHK_ERR(-4);
119  }
120  else {
121  if(NumBlocks_ <= 0) EPETRA_CHK_ERR(-1);
122  if(!Blockstart_) EPETRA_CHK_ERR(-2);
123  if(!Blockids_) EPETRA_CHK_ERR(-3);
124  }
125 
126  return 0;
127 }
128 
129 
130 //=========================================================================
131 // Extracts the block-diagonal, builds maps, etc.
133  int rv=ExtractBlockDiagonal();
134  return rv;
135 }
136 
137 //=========================================================================
138 // Returns the result of a Epetra_Operator applied to a Epetra_MultiVector X in Y.
139 int EpetraExt_PointToBlockDiagPermute::Apply(const Epetra_MultiVector& X, Epetra_MultiVector& Y) const{
140  return -1;
141 
142 }
143 
144 //=========================================================================
145 // Returns the result of a Epetra_Operator inverse applied to an Epetra_MultiVector X in Y.
146 int EpetraExt_PointToBlockDiagPermute::ApplyInverse(const Epetra_MultiVector& X, Epetra_MultiVector& Y) const{
147  // Stuff borrowed from Epetra_CrsMatrix
148  int NumVectors = X.NumVectors();
149  if (NumVectors!=Y.NumVectors()) {
150  EPETRA_CHK_ERR(-2); // Need same number of vectors in each MV
151  }
152 
153  const Epetra_MultiVector *Xp=&X;
154  Epetra_MultiVector *Yp=&Y;
155 
156  // Allocate temp workspace if X==Y and there are no imports or exports
157  Epetra_MultiVector * Xcopy = 0;
158  if (&X==&Y && Importer_==0 && Exporter_==0) {
159  Xcopy = new Epetra_MultiVector(X);
160  Xp=Xcopy;
161  }
162 
163  UpdateImportVector(NumVectors); // Make sure Import and Export Vectors are compatible
164  UpdateExportVector(NumVectors);
165 
166  // If we have a non-trivial importer, we must import elements that are permuted or are on other processors
167  if (Importer_){
168  EPETRA_CHK_ERR(ImportVector_->Import(X, *Importer_, Insert));
169  Xp=ImportVector_;
170  }
171 
172  // If we have a non-trivial exporter, we must export elements that are permuted or belong to other processors
173  if (Exporter_) {
174  Yp=ExportVector_;
175  }
176 
177  // Do the matvec
178  BDMat_->ApplyInverse(*Xp,*Yp);
179 
180  // Export if needed
181  if (Exporter_) {
182  Y.PutScalar(0.0); // Make sure target is zero
183  Y.Export(*ExportVector_, *Exporter_, Add); // Fill Y with Values from export vector
184  }
185 
186  // Cleanup
187  if(Xcopy) {
188  delete Xcopy;
189  EPETRA_CHK_ERR(1); // Return positive code to alert the user about needing extra copy of X
190  return 1;
191  }
192 
193  return 0;
194 }
195 
196 //=========================================================================
197 // Print method
199  if(Importer_) cout<<*Importer_<<endl;
200  if(Exporter_) cout<<*Exporter_<<endl;
201  if(BDMat_) cout<<*BDMat_<<endl;
202 }
203 
204 //=========================================================================
205 // Pulls the block diagonal of the matrix and then builds the BDMat_
206 int EpetraExt_PointToBlockDiagPermute::ExtractBlockDiagonal(){
207  int i,j;
208  std::vector<int> ExtRows;
209  int* LocalColIDS=0;
210  int ExtSize=0,ExtCols=0,MainCols=0;
211  int Nrows=Matrix_->NumMyRows();
212  int *l2b,*block_offset,*l2blockid;
213  const Epetra_Map &RowMap=Matrix_->RowMap();
214  int index,col,row_in_block,col_in_block,length,*colind;
215  double *values;
216 
217  bool verbose=(bool)(List_.get("output",0) > 0);
218 
219  // Contiguous Setup
220  SetupContiguousMode();
221 
222  // Compute block size lists
223  int *bsize=new int[NumBlocks_];
224  for(i=0;i<NumBlocks_;i++)
225  bsize[i]=Blockstart_[i+1]-Blockstart_[i];
226 
227  // Use the ScanSum function to compute a prefix sum of the number of points
228  int MyMinGID;
229  Matrix_->Comm().ScanSum(&NumBlocks_,&MyMinGID, 1);
230  MyMinGID-=NumBlocks_;
231  int *MyBlockGIDs=new int[NumBlocks_];
232  for(i=0;i<NumBlocks_;i++)
233  MyBlockGIDs[i]=MyMinGID+i;
234 
235  BDMap_=new Epetra_BlockMap(-1,NumBlocks_,MyBlockGIDs,bsize,0,Matrix_->Comm());
236 
237  // Allocate the Epetra_DistBlockMatrix
238  BDMat_=new EpetraExt_BlockDiagMatrix(*BDMap_,true);
239 
240  // First check to see if we can switch back to PurelyLocalMode_ if we're not
241  // in it
242  if(!PurelyLocalMode_){
243  // Find the non-local row IDs
244  ExtSize=MAX(0,Blockstart_[NumBlocks_]-RowMap.NumMyElements());// estimate
245  ExtRows.reserve(ExtSize);
246 
247  for(i=0;i<Blockstart_[NumBlocks_];i++){
248  if(RowMap.LID(Blockids_[i])==-1)
249  ExtRows.push_back(Blockids_[i]);
250  }
251 
252  // Switch to PurelyLocalMode_ if we never need GIDs
253  int size_sum;
254  ExtSize=ExtRows.size();
255  RowMap.Comm().SumAll(&ExtSize,&size_sum,1);
256  if(size_sum==0){
257  if(verbose && !Matrix_->Comm().MyPID()) printf("EpetraExt_PointToBlockDiagPermute: Switching to purely local mode\n");
258  PurelyLocalMode_=true;
259  for(i=0;i<Blockstart_[NumBlocks_];i++){
260  Blockids_[i]=RowMap.LID(Blockids_[i]);
261  }
262  }
263  }
264 
265  if(PurelyLocalMode_){
266  /*******************************************************/
267  // Allocations
268  l2b=new int[Nrows];
269  block_offset=new int[Nrows];
270 
271  // Build the local-id-to-block-id list, block offset list
272  for(i=0;i<NumBlocks_;i++) {
273  for(j=Blockstart_[i];j<Blockstart_[i+1];j++){
274  block_offset[Blockids_[j]]=j-Blockstart_[i];
275  l2b[Blockids_[j]]=i;
276  }
277  }
278 
279  // Copy the data to the EpetraExt_BlockDiagMatrix
280  for(i=0;i<Nrows;i++) {
281  int block_num = l2b[i];
282  if(block_num>=0 && block_num<NumBlocks_) {
283  row_in_block=block_offset[i];
284  Matrix_->ExtractMyRowView(i,length,values,colind);
285  int Nnz=0;
286  for (j = 0; j < length; j++) {
287  col = colind[j];
288  if(col < Nrows && l2b[col]==block_num){
289  Nnz++;
290  col_in_block = block_offset[col];
291  index = col_in_block * bsize[block_num] + row_in_block;
292  (*BDMat_)[block_num][index]=values[j];
293  }
294  }
295  /* Handle the case of a zero row. */
296  /* By just putting a 1 on the diagonal. */
297  if (Nnz == 0) {
298  index = row_in_block * bsize[block_num] + row_in_block;
299  (*BDMat_)[block_num][index]=1.0;
300  }
301  }
302  }
303 
304  // Build the compatible map for import/export
305  l2blockid=new int[Nrows];
306  for(i=0;i<Nrows;i++)
307  l2blockid[Blockstart_[l2b[i]]+block_offset[i]]=Matrix_->RowMap().GID(i);
308 
309  // Build the Compatible Map, Import/Export Objects
310  CompatibleMap_=new Epetra_Map(-1,Nrows,l2blockid,0,Matrix_->Comm());
311 
312  }
313  else{
314  /*******************************************************/
315  // Do the import to grab matrix entries
316  // Allocate temporaries for import
317  int* ExtRowsPtr = ExtRows.size()>0 ? &ExtRows[0] : NULL;
318  Epetra_Map TmpMap(-1,ExtSize, ExtRowsPtr,0,Matrix_->Comm());;
319  Epetra_CrsMatrix TmpMatrix(Copy,TmpMap,0);
320  Epetra_Import TmpImporter(TmpMap,RowMap);
321 
322  TmpMatrix.Import(*Matrix_,TmpImporter,Insert);
323  TmpMatrix.FillComplete();
324 
325  ExtCols=TmpMatrix.NumMyCols();
326  MainCols=Matrix_->NumMyCols();
327 
328 
329  // Build the column reidex - main matrix
330  LocalColIDS=new int[MainCols+ExtCols];
331  for(i=0;i<MainCols;i++){
332  int GID=Matrix_->GCID(i);
333  int MainLID=RowMap.LID(GID);
334  if(MainLID!=-1) LocalColIDS[i]=MainLID;
335  else{
336  int ExtLID=TmpMatrix.LRID(GID);
337  if(ExtLID!=-1) LocalColIDS[i]=Nrows+ExtLID;
338  else LocalColIDS[i]=-1;
339  }
340  }
341 
342  // Build the column reidex - ext matrix
343  for(i=0;i<ExtCols;i++){
344  int GID=TmpMatrix.GCID(i);
345  int MainLID=RowMap.LID(GID);
346  if(MainLID!=-1) LocalColIDS[MainCols+i]=MainLID;
347  else{
348  int ExtLID=TmpMatrix.LRID(GID);
349  if(ExtLID!=-1) LocalColIDS[MainCols+i]=Nrows+ExtLID;
350  else LocalColIDS[MainCols+i]=-1;
351  }
352  }
353 
354  // Allocations
355  l2b=new int[Nrows+ExtSize];
356  block_offset=new int[Nrows+ExtSize];
357 
358  // Build l2b/block_offset with the expanded local index
359  //NTS: Uses the same ordering of operation as the above routine, which is why
360  //it works.
361  for(i=0;i<Nrows+ExtSize;i++) block_offset[i]=l2b[i]=-1;
362  int ext_idx=0;
363  for(i=0;i<NumBlocks_;i++) {
364  for(j=Blockstart_[i];j<Blockstart_[i+1];j++){
365  int LID=RowMap.LID(Blockids_[j]);
366  if(LID==-1) {LID=Nrows+ext_idx;ext_idx++;}
367  block_offset[LID]=j-Blockstart_[i];
368  l2b[LID]=i;
369  }
370  }
371 
372  // Copy the data to the EpetraExt_BlockDiagMatrix from Matrix_
373  for(i=0;i<Nrows;i++) {
374  int block_num = l2b[i];
375  if(block_num>=0 && block_num<NumBlocks_) {
376  row_in_block=block_offset[i];
377  Matrix_->ExtractMyRowView(i,length,values,colind);
378  int Nnz=0;
379  for (j = 0; j < length; j++) {
380  col = LocalColIDS[colind[j]];
381  if(col!=-1 && l2b[col]==block_num){
382  Nnz++;
383  col_in_block = block_offset[col];
384  index = col_in_block * bsize[block_num] + row_in_block;
385  (*BDMat_)[block_num][index]=values[j];
386  }
387  }
388  /* Handle the case of a zero row. */
389  /* By just putting a 1 on the diagonal. */
390  if (Nnz == 0) {
391  index = row_in_block * bsize[block_num] + row_in_block;
392  (*BDMat_)[block_num][index]=values[j];
393  }
394  }
395  }
396 
397  // Copy the data to the EpetraExt_BlockDiagMatrix from TmpMatrix
398  for(i=0;i<ExtSize;i++) {
399  int block_num = l2b[Nrows+i];
400  if(block_num>=0 && block_num<NumBlocks_) {
401  row_in_block=block_offset[Nrows+i];
402  TmpMatrix.ExtractMyRowView(i,length,values,colind);
403  int Nnz=0;
404  for (j = 0; j < length; j++) {
405  col = LocalColIDS[MainCols+colind[j]];
406  if(col!=-1 && l2b[col]==block_num){
407  Nnz++;
408  col_in_block = block_offset[col];
409  index = col_in_block * bsize[block_num] + row_in_block;
410  (*BDMat_)[block_num][index]=values[j];
411  }
412  }
413  /* Handle the case of a zero row. */
414  /* By just putting a 1 on the diagonal. */
415  if (Nnz == 0) {
416  index = row_in_block * bsize[block_num] + row_in_block;
417  (*BDMat_)[block_num][index]=1.0;
418  }
419  }
420  }
421 
422  // Build the compatible map for import/export
423  l2blockid=new int[Blockstart_[NumBlocks_]];
424  for(i=0;i<Nrows;i++){
425  int bkid=l2b[i];
426  if(bkid>-1) l2blockid[Blockstart_[bkid]+block_offset[i]]=RowMap.GID(i);
427  }
428  // NTS: This is easier - if we imported it, we know we need it
429  for(i=0;i<ExtSize;i++)
430  l2blockid[Blockstart_[l2b[Nrows+i]]+block_offset[Nrows+i]]=TmpMatrix.GRID(i);
431 
432  // Build the Compatible Map, Import/Export Objects
433  CompatibleMap_=new Epetra_Map(-1,Blockstart_[NumBlocks_],l2blockid,0,Matrix_->Comm());
434 
435  }//end else
436 
437  // Set BDMat_'s parameter list and compute!
438  Teuchos::ParameterList dummy,inList;
439  inList=List_.get("blockdiagmatrix: list",dummy);
440  BDMat_->SetParameters(inList);
441  BDMat_->Compute();
442 
443  // Build importer/exporter
444  if(!CompatibleMap_->SameAs(Matrix_->DomainMap()))
445  Importer_ = new Epetra_Import(*CompatibleMap_,Matrix_->DomainMap());
446  if(!CompatibleMap_->SameAs(Matrix_->RangeMap()))
447  Exporter_ = new Epetra_Export(*CompatibleMap_,Matrix_->RangeMap());
448 
449  // Cleanup
450  delete [] LocalColIDS;
451  delete [] block_offset;
452  delete [] l2b;
453  delete [] l2blockid;
454  delete [] bsize;
455  delete [] MyBlockGIDs;
456 
457  // Contiguous Cleanup
458  CleanupContiguousMode();
459 
460  return 0;
461 }
462 //=======================================================================================================
463 int EpetraExt_PointToBlockDiagPermute::SetupContiguousMode(){
464  if(!ContiguousBlockMode_) return 0;
465  // NTS: In case of processor-crossing blocks, the lowest PID always gets the block;
466  const Epetra_Map &RowMap=Matrix_->RowMap();
467 
468  int MinMyGID=RowMap.MinMyGID();
469  int MaxMyGID=RowMap.MaxMyGID();
470  int Base=Matrix_->IndexBase();
471 
472  // Find the GID that begins my first block
473  int MyFirstBlockGID=ContiguousBlockSize_*(int)ceil(((double)(MinMyGID - Base))/ContiguousBlockSize_)+Base;
474  NumBlocks_=(int)ceil((double)((MaxMyGID-MyFirstBlockGID+1.0)) / ContiguousBlockSize_);
475 
476  // Allocate memory
477  Blockstart_=new int[NumBlocks_+1];
478  Blockids_=new int[NumBlocks_*ContiguousBlockSize_];
479  Blockstart_[NumBlocks_]=NumBlocks_*ContiguousBlockSize_;
480 
481  // Fill the arrays
482  for(int i=0,ct=0;i<NumBlocks_;i++){
483  Blockstart_[i]=ct;
484  for(int j=0;j<ContiguousBlockSize_;j++,ct++){
485  Blockids_[ct]=MyFirstBlockGID+ct;
486  }
487  }
488 
489  return 0;
490 }
491 //=======================================================================================================
492 int EpetraExt_PointToBlockDiagPermute::CleanupContiguousMode(){
493  if(!ContiguousBlockMode_) return 0;
494  NumBlocks_=0;
495  if(Blockstart_) {delete [] Blockstart_; Blockstart_=0;}
496  if(Blockids_) {delete [] Blockids_; Blockids_=0;}
497  return 0;
498 }
499 
500 
501 //=======================================================================================================
502 // Creates an Epetra_CrsMatrix from the BlockDiagMatrix. This is generally only useful if you want to do a matrix-matrix multiply.
504  Epetra_FECrsMatrix * NewMat=new Epetra_FECrsMatrix(Copy,Matrix_->RowMap(),0);
505 
506  const Epetra_BlockMap &BlockMap=BDMat_->BlockMap();
507  const Epetra_BlockMap &DataMap=BDMat_->DataMap();
508  const int *vlist=DataMap.FirstPointInElementList();
509  const int *xlist=BlockMap.FirstPointInElementList();
510  const int *blocksize=BlockMap.ElementSizeList();
511  const double *values=BDMat_->Values();
512  int NumBlocks=BDMat_->NumMyBlocks();
513 
514  // Maximum size vector for stashing GIDs
515  std::vector<int> GIDs;
516  GIDs.resize(BlockMap.MaxMyElementSize());
517 
518 
519  for(int i=0;i<NumBlocks;i++){
520  int Nb=blocksize[i];
521  int vidx0=vlist[i];
522  int xidx0=xlist[i];
523  // Get global indices
524  for(int j=0;j<Nb;j++)
525  GIDs[j]=CompatibleMap_->GID(xidx0+j);
526 
527  // Remember: We're using column-major storage for LAPACK's benefit
528  int ierr=NewMat->InsertGlobalValues(Nb,&GIDs[0],&values[vidx0],Epetra_FECrsMatrix::COLUMN_MAJOR);
529  if(ierr < 0) throw "CreateFECrsMatrix: ERROR in InsertGlobalValues";
530  }
531  NewMat->GlobalAssemble();
532  return NewMat;
533 }
534 
535 
536 //=======================================================================================================
537 void EpetraExt_PointToBlockDiagPermute::UpdateImportVector(int NumVectors) const {
538  if(Importer_ != 0) {
539  if(ImportVector_ != 0) {
540  if(ImportVector_->NumVectors() != NumVectors) {
541  delete ImportVector_;
542  ImportVector_= 0;
543  }
544  }
545  if(ImportVector_ == 0)
546  ImportVector_ = new Epetra_MultiVector(*CompatibleMap_,NumVectors); // Create import vector if needed
547  }
548  return;
549 }
550 //=======================================================================================================
551 void EpetraExt_PointToBlockDiagPermute::UpdateExportVector(int NumVectors) const {
552  if(Exporter_ != 0) {
553  if(ExportVector_ != 0) {
554  if(ExportVector_->NumVectors() != NumVectors) {
555  delete ExportVector_;
556  ExportVector_= 0;
557  }
558  }
559  if(ExportVector_ == 0)
560  ExportVector_ = new Epetra_MultiVector(*CompatibleMap_,NumVectors); // Create Export vector if needed
561  }
562  return;
563 }
564 
565 
566 
567 
568 //=========================================================================
569 int EpetraExt_PointToBlockDiagPermute::Import(const Epetra_SrcDistObject& A, const Epetra_Import& Importer, Epetra_CombineMode CombineMode, const Epetra_OffsetIndex *Indexor){
570  return -1;
571 }
572 
573 //=========================================================================
574 int EpetraExt_PointToBlockDiagPermute::Import(const Epetra_SrcDistObject& A, const Epetra_Export& Exporter, Epetra_CombineMode CombineMode, const Epetra_OffsetIndex *Indexor){
575  return -1;
576 }
577 
578 //=========================================================================
579 int EpetraExt_PointToBlockDiagPermute::Export(const Epetra_SrcDistObject& A, const Epetra_Import & Importer, Epetra_CombineMode CombineMode, const Epetra_OffsetIndex *Indexor){
580  return -1;
581 }
582 
583 //=========================================================================
584 int EpetraExt_PointToBlockDiagPermute::Export(const Epetra_SrcDistObject& A, const Epetra_Export& Exporter, Epetra_CombineMode CombineMode, const Epetra_OffsetIndex *Indexor){
585  return -1;
586 }
587 
588 //=========================================================================
589 // Allows the source and target (\e this) objects to be compared for compatibility, return nonzero if not.
590 int EpetraExt_PointToBlockDiagPermute::CheckSizes(const Epetra_SrcDistObject& Source){
591  return -1;
592 }
593 
594 //=========================================================================
595 // Perform ID copies and permutations that are on processor.
596 int EpetraExt_PointToBlockDiagPermute::CopyAndPermute(const Epetra_SrcDistObject& Source,
597  int NumSameIDs,
598  int NumPermuteIDs,
599  int * PermuteToLIDs,
600  int * PermuteFromLIDs,
601  const Epetra_OffsetIndex * Indexor){
602  return -1;
603 }
604 
605 //=========================================================================
606 // Perform any packing or preparation required for call to DoTransfer().
607 int EpetraExt_PointToBlockDiagPermute::PackAndPrepare(const Epetra_SrcDistObject& Source,
608  int NumExportIDs,
609  int* ExportLIDs,
610  int& LenExports,
611  char*& Exports,
612  int& SizeOfPacket,
613  int* Sizes,
614  bool & VarSizes,
615  Epetra_Distributor& Distor){
616  return -1;
617 }
618 
619 //=========================================================================
620 // Perform any unpacking and combining after call to DoTransfer().
621 int EpetraExt_PointToBlockDiagPermute::UnpackAndCombine(const Epetra_SrcDistObject& Source,
622  int NumImportIDs,
623  int* ImportLIDs,
624  int LenImports,
625  char* Imports,
626  int& SizeOfPacket,
627  Epetra_Distributor& Distor,
628  Epetra_CombineMode CombineMode,
629  const Epetra_OffsetIndex * Indexor){
630  return -1;
631 }
632 
633 
virtual const Epetra_BlockMap & DataMap() const
Returns the Epetra_BlockMap object with the distribution of underlying values.
virtual int ApplyInverse(const Epetra_MultiVector &X, Epetra_MultiVector &Y) const
Returns the result of a Epetra_Operator inverse applied to an Epetra_MultiVector X in Y...
virtual int SetParameters(Teuchos::ParameterList &List)
Sets the parameter list.
#define MAX(x, y)
int NumMyBlocks() const
Returns the number of local blocks.
virtual int ApplyInverse(const Epetra_MultiVector &X, Epetra_MultiVector &Y) const
Returns the result of a Epetra_Operator inverse applied to an Epetra_MultiVector X in Y...
double * Values() const
Returns a pointer to the array containing the blocks.
EpetraExt_BlockDiagMatrix: A class for storing distributed block matrices.
virtual int UnpackAndCombine(const Epetra_SrcDistObject &Source, int NumImportIDs, int *ImportLIDs, int LenImports, char *Imports, int &SizeOfPacket, Epetra_Distributor &Distor, Epetra_CombineMode CombineMode, const Epetra_OffsetIndex *Indexor)
Perform any unpacking and combining after call to DoTransfer().
virtual int CheckSizes(const Epetra_SrcDistObject &Source)
Allows the source and target (this) objects to be compared for compatibility, return nonzero if not...
virtual int CopyAndPermute(const Epetra_SrcDistObject &Source, int NumSameIDs, int NumPermuteIDs, int *PermuteToLIDs, int *PermuteFromLIDs, const Epetra_OffsetIndex *Indexor)
Perform ID copies and permutations that are on processor.
EpetraExt_PointToBlockDiagPermute(const Epetra_CrsMatrix &MAT)
@ Name Constructors
virtual int Compute()
Extracts the block-diagonal, builds maps, etc.
virtual int PackAndPrepare(const Epetra_SrcDistObject &Source, int NumExportIDs, int *ExportLIDs, int &LenExports, char *&Exports, int &SizeOfPacket, int *Sizes, bool &VarSizes, Epetra_Distributor &Distor)
Perform any packing or preparation required for call to DoTransfer().
virtual Epetra_FECrsMatrix * CreateFECrsMatrix()
Creates an Epetra_FECrsMatrix from the BlockDiagMatrix. This is generally only useful if you want to ...
virtual void Print(ostream &os) const
Print method.
virtual int Apply(const Epetra_MultiVector &X, Epetra_MultiVector &Y) const
Returns the result of a Epetra_Operator applied to a Epetra_MultiVector X in Y.
int Import(const Epetra_SrcDistObject &A, const Epetra_Import &Importer, Epetra_CombineMode CombineMode, const Epetra_OffsetIndex *Indexor=0)
Imports an Epetra_DistObject using the Epetra_Import object.
virtual const Epetra_BlockMap & BlockMap() const
Returns the Epetra_BlockMap object associated with the range of this operator.
int Export(const Epetra_SrcDistObject &A, const Epetra_Import &Importer, Epetra_CombineMode CombineMode, const Epetra_OffsetIndex *Indexor=0)
Exports an Epetra_DistObject using the Epetra_Import object.