Epetra_MpiSmpComm.cpp

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

Generated on Wed May 12 21:41:05 2010 for Epetra Package Browser (Single Doxygen Collection) by  doxygen 1.4.7