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