|
EpetraExt Development
|
00001 #include "EpetraExt_ConfigDefs.h" 00002 00003 00004 #ifdef HAVE_MPI 00005 00006 00007 #include "EpetraExt_RestrictedMultiVectorWrapper.h" 00008 #include "Epetra_MpiComm.h" 00009 #include "Epetra_BlockMap.h" 00010 #include "Epetra_MultiVector.h" 00011 00012 00013 namespace EpetraExt { 00014 00015 00016 RestrictedMultiVectorWrapper::RestrictedMultiVectorWrapper() 00017 : proc_is_active(true), 00018 subcomm_is_set(false), 00019 RestrictedComm_(0), 00020 MPI_SubComm_(MPI_COMM_NULL), 00021 ResMap_(0), 00022 input_mv_(), 00023 restricted_mv_() 00024 {} 00025 00026 00027 RestrictedMultiVectorWrapper::~RestrictedMultiVectorWrapper(){ 00028 delete ResMap_; 00029 delete RestrictedComm_; 00030 } 00031 00032 00033 int RestrictedMultiVectorWrapper::SetMPISubComm(MPI_Comm MPI_SubComm){ 00034 if(!subcomm_is_set){ 00035 MPI_SubComm_=MPI_SubComm; delete RestrictedComm_; subcomm_is_set=true; 00036 return 0; 00037 } 00038 else return -1; 00039 } 00040 00041 00042 int RestrictedMultiVectorWrapper::restrict_comm(Teuchos::RCP<Epetra_MultiVector> input_mv){ 00043 input_mv_=input_mv; 00044 00045 /* Pull the Input Matrix Info */ 00046 const Epetra_MpiComm *InComm = dynamic_cast<const Epetra_MpiComm*>(& input_mv_->Comm()); 00047 const Epetra_BlockMap *InMap = dynamic_cast<const Epetra_BlockMap*>(& input_mv_->Map()); 00048 00049 if(!InComm || !InMap) return -1; 00050 00051 if(!subcomm_is_set){ 00052 /* Build the Split Communicators, If Needed */ 00053 int color; 00054 if(InMap->NumMyElements()) color=1; 00055 else color=MPI_UNDEFINED; 00056 MPI_Comm_split(InComm->Comm(),color,InComm->MyPID(),&MPI_SubComm_); 00057 } 00058 else{ 00059 /* Sanity check user-provided subcomm - drop an error if the MPISubComm 00060 does not include a processor with data. */ 00061 if (input_mv->MyLength() && MPI_SubComm_ == MPI_COMM_NULL) 00062 return(-2); 00063 } 00064 00065 /* Mark active processors */ 00066 if(MPI_SubComm_ == MPI_COMM_NULL) proc_is_active=false; 00067 else proc_is_active=true; 00068 00069 00070 int Nrows=InMap->NumGlobalElements(); 00071 00072 if(proc_is_active){ 00073 RestrictedComm_=new Epetra_MpiComm(MPI_SubComm_); 00074 00075 /* Build the Restricted Maps */ 00076 ResMap_ = new Epetra_BlockMap(Nrows,InMap->NumMyElements(),InMap->MyGlobalElements(), 00077 InMap->ElementSizeList(),InMap->IndexBase(),*RestrictedComm_); 00078 00079 /* Allocate the restricted matrix*/ 00080 double *A; int LDA; 00081 input_mv_->ExtractView(&A,&LDA); 00082 restricted_mv_ = Teuchos::rcp(new Epetra_MultiVector(View,*ResMap_,A,LDA,input_mv_->NumVectors())); 00083 } 00084 return(0); 00085 }/*end restrict_comm*/ 00086 00087 } 00088 00089 #endif
1.7.4