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