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 theComm) :
00047         Epetra_Object("Epetra::MpiComm"),
00048         MpiCommData_(new Epetra_MpiCommData(theComm))
00049 {
00050 }
00051 
00052 //=============================================================================
00053 Epetra_MpiComm::Epetra_MpiComm(const Epetra_MpiComm & theComm) :
00054   Epetra_Object(theComm.Label()),
00055   MpiCommData_(theComm.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(long long * Values, int Count, int Root) const {
00084   EPETRA_CHK_ERR(CheckInput(Values,Count));
00085   EPETRA_CHK_ERR(MPI_Bcast(Values, Count, MPI_LONG_LONG, Root, MpiCommData_->Comm_));
00086   return(0);
00087 }
00088 //=============================================================================
00089 int Epetra_MpiComm::Broadcast(char * Values, int Count, int Root) const {
00090   EPETRA_CHK_ERR(CheckInput(Values,Count));
00091   EPETRA_CHK_ERR(MPI_Bcast(Values, Count, MPI_CHAR, Root, MpiCommData_->Comm_));
00092   return(0);
00093 }
00094 //=============================================================================
00095 int Epetra_MpiComm::GatherAll(double * MyVals, double * AllVals, int Count) const {
00096   EPETRA_CHK_ERR(CheckInput(MyVals,Count));
00097   EPETRA_CHK_ERR(CheckInput(AllVals,Count));
00098   EPETRA_CHK_ERR(MPI_Allgather(MyVals, Count, MPI_DOUBLE, AllVals, Count, MPI_DOUBLE, MpiCommData_->Comm_));
00099   return(0);
00100 }
00101 //=============================================================================
00102 int Epetra_MpiComm::GatherAll(int * MyVals, int * AllVals, int Count) const {
00103   EPETRA_CHK_ERR(CheckInput(MyVals,Count));
00104   EPETRA_CHK_ERR(CheckInput(AllVals,Count));
00105   EPETRA_CHK_ERR(MPI_Allgather(MyVals, Count, MPI_INT, AllVals, Count, MPI_INT, MpiCommData_->Comm_));
00106   return(0);
00107 }
00108 //=============================================================================
00109 int Epetra_MpiComm::GatherAll(long * MyVals, long * AllVals, int Count) const {
00110   EPETRA_CHK_ERR(CheckInput(MyVals,Count));
00111   EPETRA_CHK_ERR(CheckInput(AllVals,Count));
00112   EPETRA_CHK_ERR(MPI_Allgather(MyVals, Count, MPI_LONG, AllVals, Count, MPI_LONG, MpiCommData_->Comm_));
00113   return(0);
00114 }
00115 //=============================================================================
00116 int Epetra_MpiComm::GatherAll(long long * MyVals, long long * AllVals, int Count) const {
00117   EPETRA_CHK_ERR(CheckInput(MyVals,Count));
00118   EPETRA_CHK_ERR(CheckInput(AllVals,Count));
00119   EPETRA_CHK_ERR(MPI_Allgather(MyVals, Count, MPI_LONG_LONG, AllVals, Count, MPI_LONG_LONG, MpiCommData_->Comm_));
00120   return(0);
00121 }
00122 //=============================================================================
00123 int Epetra_MpiComm::SumAll(double * PartialSums, double * GlobalSums, int Count) const {
00124   EPETRA_CHK_ERR(CheckInput(PartialSums,Count));
00125   EPETRA_CHK_ERR(CheckInput(GlobalSums,Count));
00126   EPETRA_CHK_ERR(MPI_Allreduce(PartialSums, GlobalSums, Count, MPI_DOUBLE, MPI_SUM, MpiCommData_->Comm_));
00127   return(0);
00128 }
00129 //=============================================================================
00130 int Epetra_MpiComm::SumAll(int * PartialSums, int * GlobalSums, int Count) const {
00131   EPETRA_CHK_ERR(CheckInput(PartialSums,Count));
00132   EPETRA_CHK_ERR(CheckInput(GlobalSums,Count));
00133   EPETRA_CHK_ERR(MPI_Allreduce(PartialSums, GlobalSums, Count, MPI_INT, MPI_SUM, MpiCommData_->Comm_));
00134   return(0);
00135 }
00136 //=============================================================================
00137 int Epetra_MpiComm::SumAll(long * PartialSums, long * GlobalSums, int Count) const {
00138   EPETRA_CHK_ERR(CheckInput(PartialSums,Count));
00139   EPETRA_CHK_ERR(CheckInput(GlobalSums,Count));
00140   EPETRA_CHK_ERR(MPI_Allreduce(PartialSums, GlobalSums, Count, MPI_LONG, MPI_SUM, MpiCommData_->Comm_));
00141   return(0);
00142 }
00143 //=============================================================================
00144 int Epetra_MpiComm::SumAll(long long * PartialSums, long long * GlobalSums, int Count) const {
00145   EPETRA_CHK_ERR(CheckInput(PartialSums,Count));
00146   EPETRA_CHK_ERR(CheckInput(GlobalSums,Count));
00147   EPETRA_CHK_ERR(MPI_Allreduce(PartialSums, GlobalSums, Count, MPI_LONG_LONG, MPI_SUM, MpiCommData_->Comm_));
00148   return(0);
00149 }
00150 //=============================================================================
00151 int Epetra_MpiComm::MaxAll(double * PartialMaxs, double * GlobalMaxs, int Count) const {
00152   EPETRA_CHK_ERR(CheckInput(PartialMaxs,Count));
00153   EPETRA_CHK_ERR(CheckInput(GlobalMaxs,Count));
00154   EPETRA_CHK_ERR(MPI_Allreduce(PartialMaxs, GlobalMaxs, Count, MPI_DOUBLE, MPI_MAX, MpiCommData_->Comm_));
00155   return(0);
00156 }
00157 //=============================================================================
00158 int Epetra_MpiComm::MaxAll(int * PartialMaxs, int * GlobalMaxs, int Count) const {
00159   EPETRA_CHK_ERR(CheckInput(PartialMaxs,Count));
00160   EPETRA_CHK_ERR(CheckInput(GlobalMaxs,Count));
00161   EPETRA_CHK_ERR(MPI_Allreduce(PartialMaxs, GlobalMaxs, Count, MPI_INT, MPI_MAX, MpiCommData_->Comm_));
00162   return(0);
00163 }
00164 //=============================================================================
00165 int Epetra_MpiComm::MaxAll(long * PartialMaxs, long * GlobalMaxs, int Count) const {
00166   EPETRA_CHK_ERR(CheckInput(PartialMaxs,Count));
00167   EPETRA_CHK_ERR(CheckInput(GlobalMaxs,Count));
00168   EPETRA_CHK_ERR(MPI_Allreduce(PartialMaxs, GlobalMaxs, Count, MPI_LONG, MPI_MAX, MpiCommData_->Comm_));
00169   return(0);
00170 }
00171 //=============================================================================
00172 int Epetra_MpiComm::MaxAll(long long * PartialMaxs, long long * GlobalMaxs, int Count) const {
00173   EPETRA_CHK_ERR(CheckInput(PartialMaxs,Count));
00174   EPETRA_CHK_ERR(CheckInput(GlobalMaxs,Count));
00175   EPETRA_CHK_ERR(MPI_Allreduce(PartialMaxs, GlobalMaxs, Count, MPI_LONG_LONG, MPI_MAX, MpiCommData_->Comm_));
00176   return(0);
00177 }
00178 //=============================================================================
00179 int Epetra_MpiComm::MinAll(double * PartialMins, double * GlobalMins, int Count) const {
00180   EPETRA_CHK_ERR(CheckInput(PartialMins,Count));
00181   EPETRA_CHK_ERR(CheckInput(GlobalMins,Count));
00182   EPETRA_CHK_ERR(MPI_Allreduce(PartialMins, GlobalMins, Count, MPI_DOUBLE, MPI_MIN, MpiCommData_->Comm_));
00183   return(0);
00184 }
00185 //=============================================================================
00186 int Epetra_MpiComm::MinAll(int * PartialMins, int * GlobalMins, int Count) const {
00187   EPETRA_CHK_ERR(CheckInput(PartialMins,Count));
00188   EPETRA_CHK_ERR(CheckInput(GlobalMins,Count));
00189   EPETRA_CHK_ERR(MPI_Allreduce(PartialMins, GlobalMins, Count, MPI_INT, MPI_MIN, MpiCommData_->Comm_));
00190   return(0);
00191 }
00192 //=============================================================================
00193 int Epetra_MpiComm::MinAll(long * PartialMins, long * GlobalMins, int Count) const {
00194   EPETRA_CHK_ERR(CheckInput(PartialMins,Count));
00195   EPETRA_CHK_ERR(CheckInput(GlobalMins,Count));
00196   EPETRA_CHK_ERR(MPI_Allreduce(PartialMins, GlobalMins, Count, MPI_LONG, MPI_MIN, MpiCommData_->Comm_));
00197   return(0);
00198 }
00199 //=============================================================================
00200 int Epetra_MpiComm::MinAll(long long * PartialMins, long long * GlobalMins, int Count) const {
00201   EPETRA_CHK_ERR(CheckInput(PartialMins,Count));
00202   EPETRA_CHK_ERR(CheckInput(GlobalMins,Count));
00203   EPETRA_CHK_ERR(MPI_Allreduce(PartialMins, GlobalMins, Count, MPI_LONG_LONG, MPI_MIN, MpiCommData_->Comm_));
00204   return(0);
00205 }
00206 //=============================================================================
00207 int Epetra_MpiComm::ScanSum(double * MyVals, double * ScanSums, int Count) const {
00208   EPETRA_CHK_ERR(CheckInput(MyVals,Count));
00209   EPETRA_CHK_ERR(CheckInput(ScanSums,Count));
00210   EPETRA_CHK_ERR(MPI_Scan(MyVals, ScanSums, Count, MPI_DOUBLE, MPI_SUM, MpiCommData_->Comm_));
00211   return(0);
00212 }
00213 //=============================================================================
00214 int Epetra_MpiComm::ScanSum(int * MyVals, int * ScanSums, int Count) const {
00215   EPETRA_CHK_ERR(CheckInput(MyVals,Count));
00216   EPETRA_CHK_ERR(CheckInput(ScanSums,Count));
00217   EPETRA_CHK_ERR(MPI_Scan(MyVals, ScanSums, Count, MPI_INT, MPI_SUM, MpiCommData_->Comm_));
00218   return(0);
00219 }
00220 //=============================================================================
00221 int Epetra_MpiComm::ScanSum(long * MyVals, long * ScanSums, int Count) const {
00222   EPETRA_CHK_ERR(CheckInput(MyVals,Count));
00223   EPETRA_CHK_ERR(CheckInput(ScanSums,Count));
00224   EPETRA_CHK_ERR(MPI_Scan(MyVals, ScanSums, Count, MPI_LONG, MPI_SUM, MpiCommData_->Comm_));
00225   return(0);
00226 }
00227 //=============================================================================
00228 int Epetra_MpiComm::ScanSum(long long * MyVals, long long * ScanSums, int Count) const {
00229   EPETRA_CHK_ERR(CheckInput(MyVals,Count));
00230   EPETRA_CHK_ERR(CheckInput(ScanSums,Count));
00231   EPETRA_CHK_ERR(MPI_Scan(MyVals, ScanSums, Count, MPI_LONG_LONG, MPI_SUM, MpiCommData_->Comm_));
00232   return(0);
00233 }
00234 //=============================================================================
00235 Epetra_Distributor * Epetra_MpiComm:: CreateDistributor() const {
00236 
00237   Epetra_Distributor * dist = new Epetra_MpiDistributor(*this);
00238   return(dist);
00239 }
00240 //=============================================================================
00241 Epetra_Directory * Epetra_MpiComm:: CreateDirectory(const Epetra_BlockMap & map) const {
00242 
00243   Epetra_Directory * dir = new Epetra_BasicDirectory(map);
00244   return(dir);
00245 }
00246 //=============================================================================
00247 Epetra_MpiComm::~Epetra_MpiComm()  {
00248         CleanupData();
00249 }
00250 //=============================================================================
00251 void Epetra_MpiComm::CleanupData() {
00252         if(MpiCommData_ != 0) {
00253                 MpiCommData_->DecrementReferenceCount();
00254                 if(MpiCommData_->ReferenceCount() == 0) {
00255                         delete MpiCommData_;
00256                         MpiCommData_ = 0;
00257                 }
00258         }
00259 }
00260 //=============================================================================
00261 Epetra_MpiComm & Epetra_MpiComm::operator= (const Epetra_MpiComm & theComm) {
00262         if((this != &theComm) && (MpiCommData_ != theComm.MpiCommData_)) {
00263                 CleanupData();
00264                 MpiCommData_ = theComm.MpiCommData_;
00265                 MpiCommData_->IncrementReferenceCount();
00266         }
00267         return(*this);
00268 }
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines