Epetra Package Browser (Single Doxygen Collection) Development
Epetra_MpiComm.h
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 
00044 #ifndef EPETRA_MPICOMM_H
00045 #define EPETRA_MPICOMM_H
00046 #include "Epetra_Object.h"
00047 #include "Epetra_Comm.h"
00048 #include "Epetra_MpiDistributor.h"
00049 class Epetra_Distributor;
00050 #include "Epetra_BasicDirectory.h"
00051 class Epetra_Directory;
00052 class Epetra_BlockMap;
00053 #include <mpi.h>
00054 #include "Epetra_MpiCommData.h"
00055 #ifdef EPETRA_HAVE_OMP
00056 #include <omp.h>
00057 #endif
00058 
00060 
00064 class EPETRA_LIB_DLL_EXPORT Epetra_MpiComm: public Epetra_Object, public virtual Epetra_Comm {
00065     
00066   public:
00067 
00069 
00070 
00071 
00075   Epetra_MpiComm(MPI_Comm comm);
00076 
00077 
00079 
00081   Epetra_MpiComm(const Epetra_MpiComm & Comm);
00082 
00084   Epetra_Comm * Clone() const
00085     {
00086       return(new Epetra_MpiComm(*this));
00087     };
00088 
00090 
00095   virtual ~Epetra_MpiComm();
00097 
00099 
00100 
00101 
00104   void Barrier() const;
00106 
00108 
00109 
00110 
00121   int Broadcast(double * MyVals, int Count, int Root) const;
00122 
00124 
00135   int Broadcast(int * MyVals, int Count, int Root) const;
00136 
00138 
00149   int Broadcast(long * MyVals, int Count, int Root) const;
00150 
00152 
00163   int Broadcast(char * MyVals, int Count, int Root) const;
00165 
00167 
00168 
00169 
00179   int GatherAll(double * MyVals, double * AllVals, int Count) const;
00180 
00182 
00192   int GatherAll(int * MyVals, int * AllVals, int Count) const;
00193 
00195 
00205   int GatherAll(long * MyVals, long * AllVals, int Count) const;
00207 
00209 
00210 
00211 
00222   int SumAll(double * PartialSums, double * GlobalSums, int Count) const;
00223 
00225 
00235   int SumAll(int * PartialSums, int * GlobalSums, int Count) const;
00236 
00238 
00248   int SumAll(long * PartialSums, long * GlobalSums, int Count) const;
00250 
00252 
00253 
00254 
00264   int MaxAll(double * PartialMaxs, double * GlobalMaxs, int Count) const;
00265 
00267 
00277   int MaxAll(int * PartialMaxs, int * GlobalMaxs, int Count) const;
00278 
00280 
00290   int MaxAll(long * PartialMaxs, long * GlobalMaxs, int Count) const;
00291 
00293 
00303   int MinAll(double * PartialMins, double * GlobalMins, int Count) const;
00304 
00306 
00316   int MinAll(int * PartialMins, int * GlobalMins, int Count) const;
00317 
00319 
00329   int MinAll(long * PartialMins, long * GlobalMins, int Count) const;
00331 
00333 
00334 
00335 
00345   int ScanSum(double * MyVals, double * ScanSums, int Count) const;
00346 
00348 
00358   int ScanSum(int * MyVals, int * ScanSums, int Count) const;
00359 
00361 
00371   int ScanSum(long * MyVals, long * ScanSums, int Count) const;
00373 
00375 
00376   
00378   MPI_Comm Comm() const {return(MpiCommData_->Comm_);};
00379 
00381 
00384   int MyPID() const {return(MpiCommData_->rank_);};
00385   
00387 
00390   int NumProc() const {return(MpiCommData_->size_);};
00392 
00394 
00395 
00396   Epetra_Distributor * CreateDistributor() const;
00398   Epetra_Directory * CreateDirectory(const Epetra_BlockMap & Map) const;
00400 
00402 
00403 
00404   int GetMpiTag() const {int tag = MpiCommData_->curTag_++; if (tag > MpiCommData_->maxTag_) tag = MpiCommData_->minTag_; return(tag);};
00405 
00407   MPI_Comm GetMpiComm() const {return(MpiCommData_->Comm_);};
00409 
00410 
00411 
00412   inline void Print(ostream & os) const {
00413 #ifdef EPETRA_HAVE_OMP
00414 #pragma omp parallel 
00415 {
00416   int numThreads = omp_get_num_threads();
00417   int threadNum = omp_get_thread_num();
00418 #pragma omp critical
00419                 os << "\n   Thread/TotalThreads " << threadNum << "/" << numThreads << " on Processor/TotalProcs "
00420     <<  MyPID() << "/" << NumProc();
00421 }
00422 #else
00423                 os << "::Processor "<< MyPID()<<" of " << NumProc() << " total processors.";
00424 #endif
00425   return;}
00427   void PrintInfo(ostream & os) const {Epetra_MpiComm::Print(os);return;};
00429 
00431 
00432 
00434 
00435   int ReferenceCount() const {return(MpiCommData_->ReferenceCount());};
00436 
00438 
00439   const Epetra_MpiCommData * DataPtr() const {return(MpiCommData_);};
00440 
00442 
00444   Epetra_MpiComm & operator=(const Epetra_MpiComm & Comm);
00445   
00446  private:
00447   
00448   int CheckInput(double * ptr, int count) const {if ((ptr==0) && (count>0)) return(-1); return(0);};
00449   int CheckInput(int * ptr, int count) const {if ((ptr==0) && (count>0)) return(-1); return(0);};
00450   int CheckInput(long * ptr, int count) const {if ((ptr==0) && (count>0)) return(-1); return(0);};
00451   int CheckInput(char * ptr, int count) const {if ((ptr==0) && (count>0)) return(-1); return(0);};
00452 
00453   void CleanupData();
00454   Epetra_MpiCommData * MpiCommData_;
00455 
00456 };
00457 #endif /* EPETRA_MPICOMM_H */
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines