EpetraExt Development
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 (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 #include "EpetraExt_ZoltanMpiComm.h"
00044 
00045 namespace EpetraExt {
00046 
00047 //=============================================================================
00048 EPETRAEXT_DEPRECATED
00049 ZoltanMpiComm::ZoltanMpiComm(MPI_Comm Comm) : 
00050   Epetra_Object("Epetra::MpiComm"),
00051   MpiCommData_(new ZoltanMpiCommData(Comm))
00052 {
00053 }
00054 
00055 //=============================================================================
00056 EPETRAEXT_DEPRECATED
00057 ZoltanMpiComm::ZoltanMpiComm(const ZoltanMpiComm & Comm) : 
00058   Epetra_Object(Comm.Label()), 
00059   MpiCommData_(Comm.MpiCommData_)
00060 {
00061   MpiCommData_->IncrementReferenceCount();
00062 }
00063 
00064 //=============================================================================
00065 EPETRAEXT_DEPRECATED
00066 void ZoltanMpiComm::Barrier() const {
00067   MPI_Barrier(MpiCommData_->Comm_);
00068 }
00069 //=============================================================================
00070 EPETRAEXT_DEPRECATED
00071 int ZoltanMpiComm::Broadcast(double * Values, int Count, int Root) const {
00072   EPETRA_CHK_ERR(CheckInput(Values,Count));
00073   EPETRA_CHK_ERR(MPI_Bcast(Values, Count, MPI_DOUBLE, Root, MpiCommData_->Comm_));
00074   return(0);
00075 }
00076 //=============================================================================
00077 EPETRAEXT_DEPRECATED
00078 int ZoltanMpiComm::Broadcast(int * Values, int Count, int Root) const {
00079   EPETRA_CHK_ERR(CheckInput(Values,Count));
00080   EPETRA_CHK_ERR(MPI_Bcast(Values, Count, MPI_INT, Root, MpiCommData_->Comm_));
00081   return(0);
00082 }
00083 //=============================================================================
00084 EPETRAEXT_DEPRECATED
00085 int ZoltanMpiComm::GatherAll(double * MyVals, double * AllVals, int Count) const {
00086   EPETRA_CHK_ERR(CheckInput(MyVals,Count));
00087   EPETRA_CHK_ERR(CheckInput(AllVals,Count));
00088   EPETRA_CHK_ERR(MPI_Allgather(MyVals, Count, MPI_DOUBLE, AllVals, Count, MPI_DOUBLE, MpiCommData_->Comm_));
00089   return(0);
00090 }
00091 //=============================================================================
00092 EPETRAEXT_DEPRECATED
00093 int ZoltanMpiComm::GatherAll(int * MyVals, int * AllVals, int Count) const {
00094   EPETRA_CHK_ERR(CheckInput(MyVals,Count));
00095   EPETRA_CHK_ERR(CheckInput(AllVals,Count));
00096   EPETRA_CHK_ERR(MPI_Allgather(MyVals, Count, MPI_INT, AllVals, Count, MPI_INT, MpiCommData_->Comm_)); 
00097   return(0);
00098 }
00099 //=============================================================================
00100 EPETRAEXT_DEPRECATED
00101 int ZoltanMpiComm::SumAll(double * PartialSums, double * GlobalSums, int Count) const {
00102   EPETRA_CHK_ERR(CheckInput(PartialSums,Count));
00103   EPETRA_CHK_ERR(CheckInput(GlobalSums,Count));
00104   EPETRA_CHK_ERR(MPI_Allreduce(PartialSums, GlobalSums, Count, MPI_DOUBLE, MPI_SUM, MpiCommData_->Comm_));
00105   return(0);
00106 }
00107 //=============================================================================
00108 EPETRAEXT_DEPRECATED
00109 int ZoltanMpiComm::SumAll(int * PartialSums, int * GlobalSums, int Count) const {
00110   EPETRA_CHK_ERR(CheckInput(PartialSums,Count));
00111   EPETRA_CHK_ERR(CheckInput(GlobalSums,Count));
00112   EPETRA_CHK_ERR(MPI_Allreduce(PartialSums, GlobalSums, Count, MPI_INT, MPI_SUM, MpiCommData_->Comm_));
00113   return(0);
00114 }
00115 //=============================================================================
00116 EPETRAEXT_DEPRECATED
00117 int ZoltanMpiComm::MaxAll(double * PartialMaxs, double * GlobalMaxs, int Count) const {
00118   EPETRA_CHK_ERR(CheckInput(PartialMaxs,Count));
00119   EPETRA_CHK_ERR(CheckInput(GlobalMaxs,Count));
00120   EPETRA_CHK_ERR(MPI_Allreduce(PartialMaxs, GlobalMaxs, Count, MPI_DOUBLE, MPI_MAX, MpiCommData_->Comm_));
00121   return(0);
00122 }
00123 //=============================================================================
00124 EPETRAEXT_DEPRECATED
00125 int ZoltanMpiComm::MaxAll(int * PartialMaxs, int * GlobalMaxs, int Count) const {
00126   EPETRA_CHK_ERR(CheckInput(PartialMaxs,Count));
00127   EPETRA_CHK_ERR(CheckInput(GlobalMaxs,Count));
00128   EPETRA_CHK_ERR(MPI_Allreduce(PartialMaxs, GlobalMaxs, Count, MPI_INT, MPI_MAX, MpiCommData_->Comm_));
00129   return(0);
00130 }
00131 //=============================================================================
00132 EPETRAEXT_DEPRECATED
00133 int ZoltanMpiComm::MinAll(double * PartialMins, double * GlobalMins, int Count) const {
00134   EPETRA_CHK_ERR(CheckInput(PartialMins,Count));
00135   EPETRA_CHK_ERR(CheckInput(GlobalMins,Count));
00136   EPETRA_CHK_ERR(MPI_Allreduce(PartialMins, GlobalMins, Count, MPI_DOUBLE, MPI_MIN, MpiCommData_->Comm_));
00137   return(0);
00138 }
00139 //=============================================================================
00140 EPETRAEXT_DEPRECATED
00141 int ZoltanMpiComm::MinAll(int * PartialMins, int * GlobalMins, int Count) const {
00142   EPETRA_CHK_ERR(CheckInput(PartialMins,Count));
00143   EPETRA_CHK_ERR(CheckInput(GlobalMins,Count));
00144   EPETRA_CHK_ERR(MPI_Allreduce(PartialMins, GlobalMins, Count, MPI_INT, MPI_MIN, MpiCommData_->Comm_));
00145   return(0);
00146 }
00147 //=============================================================================
00148 EPETRAEXT_DEPRECATED
00149 int ZoltanMpiComm::ScanSum(double * MyVals, double * ScanSums, int Count) const {
00150   EPETRA_CHK_ERR(CheckInput(MyVals,Count));
00151   EPETRA_CHK_ERR(CheckInput(ScanSums,Count));
00152   EPETRA_CHK_ERR(MPI_Scan(MyVals, ScanSums, Count, MPI_DOUBLE, MPI_SUM, MpiCommData_->Comm_));
00153   return(0);
00154 }
00155 //=============================================================================
00156 EPETRAEXT_DEPRECATED
00157 int ZoltanMpiComm::ScanSum(int * MyVals, int * ScanSums, int Count) const {
00158   EPETRA_CHK_ERR(CheckInput(MyVals,Count));
00159   EPETRA_CHK_ERR(CheckInput(ScanSums,Count));
00160   EPETRA_CHK_ERR(MPI_Scan(MyVals, ScanSums, Count, MPI_INT, MPI_SUM, MpiCommData_->Comm_));
00161   return(0);
00162 }
00163 //=============================================================================
00164 EPETRAEXT_DEPRECATED
00165 Epetra_Distributor * ZoltanMpiComm:: CreateDistributor() const {
00166 
00167   Epetra_Distributor * dist = new ZoltanMpiDistributor(*this);
00168   return(dist);
00169 }
00170 //=============================================================================
00171 EPETRAEXT_DEPRECATED
00172 Epetra_Directory * ZoltanMpiComm:: CreateDirectory(const Epetra_BlockMap & map) const {
00173 
00174   Epetra_Directory * dir = new Epetra_BasicDirectory(map);
00175   return(dir);
00176 }
00177 //=============================================================================
00178 EPETRAEXT_DEPRECATED
00179 ZoltanMpiComm::~ZoltanMpiComm()  {
00180   CleanupData();
00181 }
00182 //=============================================================================
00183 EPETRAEXT_DEPRECATED
00184 void ZoltanMpiComm::CleanupData() {
00185   if(MpiCommData_ != 0) {
00186     MpiCommData_->DecrementReferenceCount();
00187     if(MpiCommData_->ReferenceCount() == 0) {
00188       delete MpiCommData_;
00189       MpiCommData_ = 0;
00190     }
00191   }
00192 }
00193 //=============================================================================
00194 EPETRAEXT_DEPRECATED
00195 ZoltanMpiComm & ZoltanMpiComm::operator= (const ZoltanMpiComm & Comm) {
00196   if((this != &Comm) && (MpiCommData_ != Comm.MpiCommData_)) {
00197     CleanupData();
00198     MpiCommData_ = Comm.MpiCommData_;
00199     MpiCommData_->IncrementReferenceCount();
00200   }
00201   return(*this);
00202 }
00203 
00204 } //namespace EpetraExt
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines