|
EpetraExt
Development
|
00001 /* 00002 //@HEADER 00003 // *********************************************************************** 00004 // 00005 // EpetraExt: Epetra Extended - Linear Algebra Services Package 00006 // Copyright (2011) Sandia Corporation 00007 // 00008 // Under the terms of Contract DE-AC04-94AL85000 with Sandia Corporation, 00009 // the U.S. Government retains certain rights in this software. 00010 // 00011 // Redistribution and use in source and binary forms, with or without 00012 // modification, are permitted provided that the following conditions are 00013 // met: 00014 // 00015 // 1. Redistributions of source code must retain the above copyright 00016 // notice, this list of conditions and the following disclaimer. 00017 // 00018 // 2. Redistributions in binary form must reproduce the above copyright 00019 // notice, this list of conditions and the following disclaimer in the 00020 // documentation and/or other materials provided with the distribution. 00021 // 00022 // 3. Neither the name of the Corporation nor the names of the 00023 // contributors may be used to endorse or promote products derived from 00024 // this software without specific prior written permission. 00025 // 00026 // THIS SOFTWARE IS PROVIDED BY SANDIA CORPORATION "AS IS" AND ANY 00027 // EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 00028 // IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR 00029 // PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL SANDIA CORPORATION OR THE 00030 // CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, 00031 // EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, 00032 // PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR 00033 // PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF 00034 // LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING 00035 // NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 00036 // SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 00037 // 00038 // Questions? Contact Michael A. Heroux (maherou@sandia.gov) 00039 // 00040 // *********************************************************************** 00041 //@HEADER 00042 */ 00043 00044 #include "EpetraExt_ConfigDefs.h" 00045 00046 00047 #ifdef HAVE_MPI 00048 00049 00050 #include "EpetraExt_RestrictedCrsMatrixWrapper.h" 00051 #include "Epetra_MpiComm.h" 00052 #include "Epetra_Map.h" 00053 #include "Epetra_CrsMatrix.h" 00054 00055 00056 namespace EpetraExt{ 00057 00058 RestrictedCrsMatrixWrapper::RestrictedCrsMatrixWrapper() 00059 : proc_is_active(true), 00060 subcomm_is_set(false), 00061 MPI_SubComm_(MPI_COMM_NULL), 00062 RestrictedComm_(0), 00063 ResRowMap_(0), 00064 ResColMap_(0), 00065 input_matrix_(), 00066 restricted_matrix_() 00067 { 00068 00069 } 00070 00071 RestrictedCrsMatrixWrapper::~RestrictedCrsMatrixWrapper() { 00072 delete ResRowMap_; 00073 delete ResColMap_; 00074 delete RestrictedComm_; 00075 } 00076 00077 00078 00079 int RestrictedCrsMatrixWrapper::SetMPISubComm(MPI_Comm MPI_SubComm){ 00080 if(!subcomm_is_set){ 00081 MPI_SubComm_=MPI_SubComm; delete RestrictedComm_; subcomm_is_set=true; 00082 return 0; 00083 } 00084 else return -1; 00085 } 00086 00087 00088 00089 int RestrictedCrsMatrixWrapper::restrict_comm(Teuchos::RCP<Epetra_CrsMatrix> input_matrix){ 00090 /* Pull the Matrix Info */ 00091 input_matrix_=input_matrix; 00092 00093 const Epetra_MpiComm *InComm = dynamic_cast<const Epetra_MpiComm*>(& input_matrix_->Comm()); 00094 const Epetra_Map *InRowMap= dynamic_cast<const Epetra_Map* >(& input_matrix_->RowMap()); 00095 const Epetra_Map *InColMap= dynamic_cast<const Epetra_Map* >(& input_matrix_->ColMap()); 00096 00097 if(!InComm || !InRowMap || !InColMap) return (-1); 00098 00099 int Nrows=InRowMap->NumGlobalElements(); 00100 int Ncols=InColMap->NumGlobalElements(); 00101 00102 if(!subcomm_is_set){ 00103 /* Build the Split Communicators, If Needed */ 00104 int color; 00105 if(InRowMap->NumMyElements()) color=1; 00106 else color=MPI_UNDEFINED; 00107 MPI_Comm_split(InComm->Comm(),color,InComm->MyPID(),&MPI_SubComm_); 00108 } 00109 else{ 00110 /* Sanity check user-provided subcomm - drop an error if the MPISubComm 00111 does not include a processor with data. */ 00112 if (input_matrix->NumMyRows() && MPI_SubComm_ == MPI_COMM_NULL) 00113 return(-2); 00114 } 00115 00116 /* Mark active processors */ 00117 if(MPI_SubComm_ == MPI_COMM_NULL) proc_is_active=false; 00118 else proc_is_active=true; 00119 00120 00121 if(proc_is_active){ 00122 RestrictedComm_=new Epetra_MpiComm(MPI_SubComm_); 00123 00124 /* Build the Restricted Maps */ 00125 ResRowMap_ = new Epetra_Map(Nrows,InRowMap->NumMyElements(),InRowMap->MyGlobalElements(), 00126 InRowMap->IndexBase(),*RestrictedComm_); 00127 ResColMap_ = new Epetra_Map(Ncols,InColMap->NumMyElements(),InColMap->MyGlobalElements(), 00128 InColMap->IndexBase(),*RestrictedComm_); 00129 00130 int *rowptr,*colind,Nr; 00131 double *values; 00132 00133 /* Allocate the Restricted Matrix */ 00134 restricted_matrix_= Teuchos::rcp(new Epetra_CrsMatrix(View,*ResRowMap_,*ResColMap_,0)); 00135 for(int i=0;i<input_matrix_->NumMyRows();i++) { 00136 input_matrix_->ExtractMyRowView(i,Nr,values,colind); 00137 restricted_matrix_->InsertMyValues(i,Nr,values,colind); 00138 } 00139 restricted_matrix_->FillComplete(); 00140 } 00141 00142 return 0; 00143 }/*end restrict_comm*/ 00144 00145 00146 00147 } 00148 #endif
1.7.6.1