Epetra_DistObject.cpp

Go to the documentation of this file.
00001 
00002 //@HEADER
00003 // ************************************************************************
00004 // 
00005 //               Epetra: Linear Algebra Services Package 
00006 //                 Copyright (2001) Sandia Corporation
00007 // 
00008 // Under terms of Contract DE-AC04-94AL85000, there is a non-exclusive
00009 // license for use of this work by or on behalf of the U.S. Government.
00010 // 
00011 // This library is free software; you can redistribute it and/or modify
00012 // it under the terms of the GNU Lesser General Public License as
00013 // published by the Free Software Foundation; either version 2.1 of the
00014 // License, or (at your option) any later version.
00015 //  
00016 // This library is distributed in the hope that it will be useful, but
00017 // WITHOUT ANY WARRANTY; without even the implied warranty of
00018 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00019 // Lesser General Public License for more details.
00020 //  
00021 // You should have received a copy of the GNU Lesser General Public
00022 // License along with this library; if not, write to the Free Software
00023 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
00024 // USA
00025 // Questions? Contact Michael A. Heroux (maherou@sandia.gov) 
00026 // 
00027 // ************************************************************************
00028 //@HEADER
00029 
00030 #include "Epetra_DistObject.h"
00031 #include "Epetra_Comm.h"
00032 #include "Epetra_Import.h"
00033 #include "Epetra_Export.h"
00034 #include "Epetra_Distributor.h"
00035 
00036 
00037 
00038 //=============================================================================
00039 // Constructor
00040 
00041 Epetra_DistObject::Epetra_DistObject(const Epetra_BlockMap& Map)
00042   : Epetra_Object("Epetra::DistObject"),
00043     Map_(Map),
00044     Comm_(&Map_.Comm()),
00045     DistributedGlobal_(Map.DistributedGlobal()),
00046     Exports_(0),
00047     Imports_(0),
00048     LenExports_(0),
00049     LenImports_(0),
00050     Sizes_(0)
00051 {}
00052 
00053 //=============================================================================
00054 // Constructor (label given)
00055 
00056 Epetra_DistObject::Epetra_DistObject(const Epetra_BlockMap& Map, const char* const Label)
00057   : Epetra_Object(Label),
00058     Map_(Map),
00059     Comm_(&Map_.Comm()),
00060     DistributedGlobal_(Map.DistributedGlobal()),
00061     Exports_(0),
00062     Imports_(0),
00063     LenExports_(0),
00064     LenImports_(0),
00065     Sizes_(0)
00066 {}
00067 
00068 //=============================================================================
00069 // Copy Constructor
00070 
00071 Epetra_DistObject::Epetra_DistObject(const Epetra_DistObject& Source)
00072   : Epetra_Object(Source),
00073     Map_(Source.Map_),
00074     Comm_(&Map_.Comm()),
00075     DistributedGlobal_(Source.DistributedGlobal_),
00076     Exports_(0),
00077     Imports_(0),
00078     LenExports_(0),
00079     LenImports_(0),
00080     Sizes_(0)
00081 {}
00082 
00083 //=============================================================================
00084 Epetra_DistObject::~Epetra_DistObject(){
00085 
00086 
00087   if (LenExports_!=0) {
00088     delete[] Exports_;
00089     Exports_ = 0;
00090     LenExports_ = 0;
00091   }
00092   if (LenImports_!=0) {
00093     delete[] Imports_;
00094     Imports_ = 0;
00095     LenImports_ = 0;
00096   }
00097 
00098   if (Sizes_!=0) delete [] Sizes_;
00099   Sizes_ = 0;
00100 }
00101 
00102 //=============================================================================
00103 int Epetra_DistObject::Import(const Epetra_SrcDistObject& A, 
00104             const Epetra_Import& Importer,
00105             Epetra_CombineMode CombineMode,
00106                               const Epetra_OffsetIndex * Indexor) 
00107 {
00108 
00109   if (!Map_.SameAs(Importer.TargetMap())) EPETRA_CHK_ERR(-2);
00110   if (!A.Map().SameAs(Importer.SourceMap())) EPETRA_CHK_ERR(-3);
00111   
00112   int NumSameIDs = Importer.NumSameIDs();
00113   int NumPermuteIDs = Importer.NumPermuteIDs();
00114   int NumRemoteIDs = Importer.NumRemoteIDs();
00115   int NumExportIDs = Importer.NumExportIDs();
00116   int* ExportLIDs = Importer.ExportLIDs();
00117   int* RemoteLIDs = Importer.RemoteLIDs();
00118   int* PermuteToLIDs = Importer.PermuteToLIDs();
00119   int* PermuteFromLIDs = Importer.PermuteFromLIDs();
00120 
00121   EPETRA_CHK_ERR(DoTransfer(A, CombineMode, NumSameIDs, NumPermuteIDs, NumRemoteIDs, NumExportIDs,
00122           PermuteToLIDs, PermuteFromLIDs, RemoteLIDs, ExportLIDs, 
00123           LenExports_, Exports_, LenImports_, Imports_, Importer.Distributor(), 
00124           false, Indexor));
00125   return(0);
00126 }
00127 
00128 //=============================================================================
00129 int Epetra_DistObject::Export(const Epetra_SrcDistObject& A, 
00130             const Epetra_Export& Exporter,
00131             Epetra_CombineMode CombineMode,
00132                               const Epetra_OffsetIndex * Indexor) 
00133 {
00134 
00135   if (!Map_.SameAs(Exporter.TargetMap())) EPETRA_CHK_ERR(-2);
00136   if (!A.Map().SameAs(Exporter.SourceMap())) EPETRA_CHK_ERR(-3);
00137   
00138   int NumSameIDs = Exporter.NumSameIDs();
00139   int NumPermuteIDs = Exporter.NumPermuteIDs();
00140   int NumRemoteIDs = Exporter.NumRemoteIDs();
00141   int NumExportIDs = Exporter.NumExportIDs();
00142   int* ExportLIDs = Exporter.ExportLIDs();
00143   int* RemoteLIDs = Exporter.RemoteLIDs();
00144   int* PermuteToLIDs = Exporter.PermuteToLIDs();
00145   int* PermuteFromLIDs = Exporter.PermuteFromLIDs();
00146 
00147   EPETRA_CHK_ERR(DoTransfer(A, CombineMode, NumSameIDs, NumPermuteIDs, NumRemoteIDs, NumExportIDs,
00148           PermuteToLIDs, PermuteFromLIDs, RemoteLIDs, ExportLIDs,
00149           LenExports_, Exports_,LenImports_, Imports_, Exporter.Distributor(), 
00150           false, Indexor));
00151   return(0);
00152 }
00153 
00154 //=============================================================================
00155 int Epetra_DistObject::Import(const Epetra_SrcDistObject& A, 
00156             const Epetra_Export& Exporter,
00157             Epetra_CombineMode CombineMode,
00158                               const Epetra_OffsetIndex * Indexor) 
00159 {
00160 
00161   if (!Map_.SameAs(Exporter.SourceMap())) EPETRA_CHK_ERR(-2);
00162   if (!A.Map().SameAs(Exporter.TargetMap())) EPETRA_CHK_ERR(-3);
00163   
00164   int NumSameIDs = Exporter.NumSameIDs();
00165   int NumPermuteIDs = Exporter.NumPermuteIDs();
00166   int NumRemoteIDs = Exporter.NumExportIDs();
00167   int NumExportIDs = Exporter.NumRemoteIDs();
00168   int* ExportLIDs = Exporter.RemoteLIDs();
00169   int* RemoteLIDs = Exporter.ExportLIDs();
00170   int* PermuteToLIDs = Exporter.PermuteFromLIDs();
00171   int* PermuteFromLIDs = Exporter.PermuteToLIDs();
00172 
00173   EPETRA_CHK_ERR(DoTransfer(A, CombineMode, NumSameIDs, NumPermuteIDs, NumRemoteIDs, NumExportIDs, 
00174           PermuteToLIDs, PermuteFromLIDs, RemoteLIDs, ExportLIDs,
00175           LenImports_, Imports_, LenExports_, Exports_, Exporter.Distributor(), 
00176           true, Indexor));
00177   return(0);
00178 }
00179 
00180 //=============================================================================
00181 int Epetra_DistObject::Export(const Epetra_SrcDistObject& A, 
00182             const Epetra_Import& Importer,
00183             Epetra_CombineMode CombineMode,
00184                               const Epetra_OffsetIndex * Indexor) 
00185 {
00186 
00187   if (!Map_.SameAs(Importer.SourceMap())) EPETRA_CHK_ERR(-2);
00188   if (!A.Map().SameAs(Importer.TargetMap())) EPETRA_CHK_ERR(-3);
00189   
00190   int NumSameIDs = Importer.NumSameIDs();
00191   int NumPermuteIDs = Importer.NumPermuteIDs();
00192   int NumRemoteIDs = Importer.NumExportIDs();
00193   int NumExportIDs = Importer.NumRemoteIDs();
00194   int* ExportLIDs = Importer.RemoteLIDs();
00195   int* RemoteLIDs = Importer.ExportLIDs();
00196   int* PermuteToLIDs = Importer.PermuteFromLIDs();
00197   int* PermuteFromLIDs = Importer.PermuteToLIDs();
00198 
00199   EPETRA_CHK_ERR(DoTransfer(A, CombineMode, NumSameIDs, NumPermuteIDs, NumRemoteIDs, NumExportIDs,  
00200           PermuteToLIDs, PermuteFromLIDs,  RemoteLIDs, ExportLIDs,
00201           LenImports_, Imports_, LenExports_, Exports_, 
00202           Importer.Distributor(), true, Indexor));
00203   return(0);
00204 }
00205 
00206 //=============================================================================
00207 int Epetra_DistObject::DoTransfer(const Epetra_SrcDistObject& A, 
00208           Epetra_CombineMode CombineMode, 
00209           int NumSameIDs, 
00210           int NumPermuteIDs, 
00211           int NumRemoteIDs, 
00212           int NumExportIDs, 
00213           int* PermuteToLIDs, 
00214           int* PermuteFromLIDs, 
00215           int* RemoteLIDs, 
00216           int* ExportLIDs,
00217           int& LenExports, 
00218           char*& Exports,
00219           int& LenImports, 
00220           char*& Imports, 
00221           Epetra_Distributor& Distor, 
00222           bool DoReverse,
00223                                   const Epetra_OffsetIndex * Indexor)
00224 {
00225 
00226   EPETRA_CHK_ERR(CheckSizes(A));
00227 
00228   if (NumSameIDs + NumPermuteIDs > 0) {
00229     EPETRA_CHK_ERR(CopyAndPermute(A, NumSameIDs, NumPermuteIDs, PermuteToLIDs, PermuteFromLIDs,Indexor));
00230   }
00231 
00232   if (CombineMode==Zero) 
00233     return(0); // All done if CombineMode only involves copying and permuting
00234   
00235   int SizeOfPacket; 
00236   bool VarSizes = false;
00237   if( !Sizes_ && NumExportIDs ) Sizes_ = new int[NumExportIDs];
00238   EPETRA_CHK_ERR(PackAndPrepare(A, NumExportIDs, ExportLIDs,
00239                  LenExports, Exports, SizeOfPacket, Sizes_, VarSizes, Distor));
00240 
00241   if ((DistributedGlobal_ && DoReverse) || (A.Map().DistributedGlobal() && !DoReverse)) {
00242     if (DoReverse) {
00243       // Do the exchange of remote data
00244       if( VarSizes ) {
00245         EPETRA_CHK_ERR(Distor.DoReverse(Exports, SizeOfPacket, Sizes_, LenImports, Imports));
00246       }
00247       else {
00248         EPETRA_CHK_ERR(Distor.DoReverse(Exports, SizeOfPacket, LenImports, Imports));
00249       }
00250     }
00251     else {
00252       // Do the exchange of remote data
00253       if( VarSizes ) {
00254         EPETRA_CHK_ERR(Distor.Do(Exports, SizeOfPacket, Sizes_, LenImports, Imports));
00255       }
00256       else {
00257         EPETRA_CHK_ERR(Distor.Do(Exports, SizeOfPacket, LenImports, Imports));
00258       }
00259     }
00260     EPETRA_CHK_ERR(UnpackAndCombine(A, NumRemoteIDs, RemoteLIDs, LenImports, Imports, SizeOfPacket, Distor, CombineMode, Indexor));
00261   }
00262 
00263   return(0);
00264 }
00265 
00266 //=============================================================================
00267 void Epetra_DistObject::Print(ostream& os) const {
00268   int MyPID = Comm().MyPID();
00269   int NumProc = Comm().NumProc();
00270   
00271   for (int iproc=0; iproc < NumProc; iproc++) {
00272     if (MyPID==iproc) {
00273       Comm().PrintInfo(os);
00274       os << "Length of Export buffer (in chars) = " << LenExports_ << endl;
00275       os << "Length of Import buffer (in chars) = " << LenImports_ << endl;
00276       os << flush;
00277     }
00278   }
00279   return;
00280 }
00281 
00282 //------------------------------------------------------------------------------
00283 Epetra_DistObject& Epetra_DistObject::operator=(const Epetra_DistObject& src)
00284 {
00285   (void)src;
00286   //not currently supported
00287   bool throw_error = true;
00288   if (throw_error) {
00289     throw ReportError("Epetra_DistObject::operator= is not supported.",-1);
00290   }
00291 
00292   return(*this);
00293 }

Generated on Thu Sep 18 12:37:57 2008 for Epetra Package Browser (Single Doxygen Collection) by doxygen 1.3.9.1