EpetraExt_ZoltanMpiComm.cpp

Go to the documentation of this file.
00001 
00002 //@HEADER
00003 // ***********************************************************************
00004 // 
00005 //     EpetraExt: Epetra Extended - 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 "EpetraExt_ZoltanMpiComm.h"
00031 
00032 namespace EpetraExt {
00033 
00034 //=============================================================================
00035 ZoltanMpiComm::ZoltanMpiComm(MPI_Comm Comm) : 
00036   Epetra_Object("Epetra::MpiComm"),
00037   MpiCommData_(new ZoltanMpiCommData(Comm))
00038 {
00039 }
00040 
00041 //=============================================================================
00042 ZoltanMpiComm::ZoltanMpiComm(const ZoltanMpiComm & Comm) : 
00043   Epetra_Object(Comm.Label()), 
00044   MpiCommData_(Comm.MpiCommData_)
00045 {
00046   MpiCommData_->IncrementReferenceCount();
00047 }
00048 
00049 //=============================================================================
00050 void ZoltanMpiComm::Barrier() const {
00051   MPI_Barrier(MpiCommData_->Comm_);
00052 }
00053 //=============================================================================
00054 int ZoltanMpiComm::Broadcast(double * Values, int Count, int Root) const {
00055   EPETRA_CHK_ERR(CheckInput(Values,Count));
00056   EPETRA_CHK_ERR(MPI_Bcast(Values, Count, MPI_DOUBLE, Root, MpiCommData_->Comm_));
00057   return(0);
00058 }
00059 //=============================================================================
00060 int ZoltanMpiComm::Broadcast(int * Values, int Count, int Root) const {
00061   EPETRA_CHK_ERR(CheckInput(Values,Count));
00062   EPETRA_CHK_ERR(MPI_Bcast(Values, Count, MPI_INT, Root, MpiCommData_->Comm_));
00063   return(0);
00064 }
00065 //=============================================================================
00066 int ZoltanMpiComm::GatherAll(double * MyVals, double * AllVals, int Count) const {
00067   EPETRA_CHK_ERR(CheckInput(MyVals,Count));
00068   EPETRA_CHK_ERR(CheckInput(AllVals,Count));
00069   EPETRA_CHK_ERR(MPI_Allgather(MyVals, Count, MPI_DOUBLE, AllVals, Count, MPI_DOUBLE, MpiCommData_->Comm_));
00070   return(0);
00071 }
00072 //=============================================================================
00073 int ZoltanMpiComm::GatherAll(int * MyVals, int * AllVals, int Count) const {
00074   EPETRA_CHK_ERR(CheckInput(MyVals,Count));
00075   EPETRA_CHK_ERR(CheckInput(AllVals,Count));
00076   EPETRA_CHK_ERR(MPI_Allgather(MyVals, Count, MPI_INT, AllVals, Count, MPI_INT, MpiCommData_->Comm_)); 
00077   return(0);
00078 }
00079 //=============================================================================
00080 int ZoltanMpiComm::SumAll(double * PartialSums, double * GlobalSums, int Count) const {
00081   EPETRA_CHK_ERR(CheckInput(PartialSums,Count));
00082   EPETRA_CHK_ERR(CheckInput(GlobalSums,Count));
00083   EPETRA_CHK_ERR(MPI_Allreduce(PartialSums, GlobalSums, Count, MPI_DOUBLE, MPI_SUM, MpiCommData_->Comm_));
00084   return(0);
00085 }
00086 //=============================================================================
00087 int ZoltanMpiComm::SumAll(int * PartialSums, int * GlobalSums, int Count) const {
00088   EPETRA_CHK_ERR(CheckInput(PartialSums,Count));
00089   EPETRA_CHK_ERR(CheckInput(GlobalSums,Count));
00090   EPETRA_CHK_ERR(MPI_Allreduce(PartialSums, GlobalSums, Count, MPI_INT, MPI_SUM, MpiCommData_->Comm_));
00091   return(0);
00092 }
00093 //=============================================================================
00094 int ZoltanMpiComm::MaxAll(double * PartialMaxs, double * GlobalMaxs, int Count) const {
00095   EPETRA_CHK_ERR(CheckInput(PartialMaxs,Count));
00096   EPETRA_CHK_ERR(CheckInput(GlobalMaxs,Count));
00097   EPETRA_CHK_ERR(MPI_Allreduce(PartialMaxs, GlobalMaxs, Count, MPI_DOUBLE, MPI_MAX, MpiCommData_->Comm_));
00098   return(0);
00099 }
00100 //=============================================================================
00101 int ZoltanMpiComm::MaxAll(int * PartialMaxs, int * GlobalMaxs, int Count) const {
00102   EPETRA_CHK_ERR(CheckInput(PartialMaxs,Count));
00103   EPETRA_CHK_ERR(CheckInput(GlobalMaxs,Count));
00104   EPETRA_CHK_ERR(MPI_Allreduce(PartialMaxs, GlobalMaxs, Count, MPI_INT, MPI_MAX, MpiCommData_->Comm_));
00105   return(0);
00106 }
00107 //=============================================================================
00108 int ZoltanMpiComm::MinAll(double * PartialMins, double * GlobalMins, int Count) const {
00109   EPETRA_CHK_ERR(CheckInput(PartialMins,Count));
00110   EPETRA_CHK_ERR(CheckInput(GlobalMins,Count));
00111   EPETRA_CHK_ERR(MPI_Allreduce(PartialMins, GlobalMins, Count, MPI_DOUBLE, MPI_MIN, MpiCommData_->Comm_));
00112   return(0);
00113 }
00114 //=============================================================================
00115 int ZoltanMpiComm::MinAll(int * PartialMins, int * GlobalMins, int Count) const {
00116   EPETRA_CHK_ERR(CheckInput(PartialMins,Count));
00117   EPETRA_CHK_ERR(CheckInput(GlobalMins,Count));
00118   EPETRA_CHK_ERR(MPI_Allreduce(PartialMins, GlobalMins, Count, MPI_INT, MPI_MIN, MpiCommData_->Comm_));
00119   return(0);
00120 }
00121 //=============================================================================
00122 int ZoltanMpiComm::ScanSum(double * MyVals, double * ScanSums, int Count) const {
00123   EPETRA_CHK_ERR(CheckInput(MyVals,Count));
00124   EPETRA_CHK_ERR(CheckInput(ScanSums,Count));
00125   EPETRA_CHK_ERR(MPI_Scan(MyVals, ScanSums, Count, MPI_DOUBLE, MPI_SUM, MpiCommData_->Comm_));
00126   return(0);
00127 }
00128 //=============================================================================
00129 int ZoltanMpiComm::ScanSum(int * MyVals, int * ScanSums, int Count) const {
00130   EPETRA_CHK_ERR(CheckInput(MyVals,Count));
00131   EPETRA_CHK_ERR(CheckInput(ScanSums,Count));
00132   EPETRA_CHK_ERR(MPI_Scan(MyVals, ScanSums, Count, MPI_INT, MPI_SUM, MpiCommData_->Comm_));
00133   return(0);
00134 }
00135 //=============================================================================
00136 Epetra_Distributor * ZoltanMpiComm:: CreateDistributor() const {
00137 
00138   Epetra_Distributor * dist = new ZoltanMpiDistributor(*this);
00139   return(dist);
00140 }
00141 //=============================================================================
00142 Epetra_Directory * ZoltanMpiComm:: CreateDirectory(const Epetra_BlockMap & map) const {
00143 
00144   Epetra_Directory * dir = new Epetra_BasicDirectory(map);
00145   return(dir);
00146 }
00147 //=============================================================================
00148 ZoltanMpiComm::~ZoltanMpiComm()  {
00149   CleanupData();
00150 }
00151 //=============================================================================
00152 void ZoltanMpiComm::CleanupData() {
00153   if(MpiCommData_ != 0) {
00154     MpiCommData_->DecrementReferenceCount();
00155     if(MpiCommData_->ReferenceCount() == 0) {
00156       delete MpiCommData_;
00157       MpiCommData_ = 0;
00158     }
00159   }
00160 }
00161 //=============================================================================
00162 ZoltanMpiComm & ZoltanMpiComm::operator= (const ZoltanMpiComm & Comm) {
00163   if((this != &Comm) && (MpiCommData_ != Comm.MpiCommData_)) {
00164     CleanupData();
00165     MpiCommData_ = Comm.MpiCommData_;
00166     MpiCommData_->IncrementReferenceCount();
00167   }
00168   return(*this);
00169 }
00170 
00171 } //namespace EpetraExt

Generated on Thu Sep 18 12:31:44 2008 for EpetraExt by doxygen 1.3.9.1