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(long long * MyVals, int Count, int Root) const;
00164 
00166 
00177   int Broadcast(char * MyVals, int Count, int Root) const;
00179 
00181 
00182 
00183 
00193   int GatherAll(double * MyVals, double * AllVals, int Count) const;
00194 
00196 
00206   int GatherAll(int * MyVals, int * AllVals, int Count) const;
00207 
00209 
00219   int GatherAll(long * MyVals, long * AllVals, int Count) const;
00220 
00222 
00232   int GatherAll(long long * MyVals, long long * AllVals, int Count) const;
00234 
00236 
00237 
00238 
00249   int SumAll(double * PartialSums, double * GlobalSums, int Count) const;
00250 
00252 
00262   int SumAll(int * PartialSums, int * GlobalSums, int Count) const;
00263 
00265 
00275   int SumAll(long * PartialSums, long * GlobalSums, int Count) const;
00276 
00278 
00288   int SumAll(long long * PartialSums, long long * GlobalSums, int Count) const;
00290 
00292 
00293 
00294 
00304   int MaxAll(double * PartialMaxs, double * GlobalMaxs, int Count) const;
00305 
00307 
00317   int MaxAll(int * PartialMaxs, int * GlobalMaxs, int Count) const;
00318 
00320 
00330   int MaxAll(long * PartialMaxs, long * GlobalMaxs, int Count) const;
00331 
00333 
00343   int MaxAll(long long * PartialMaxs, long long * GlobalMaxs, int Count) const;
00344 
00346 
00356   int MinAll(double * PartialMins, double * GlobalMins, int Count) const;
00357 
00359 
00369   int MinAll(int * PartialMins, int * GlobalMins, int Count) const;
00370 
00372 
00382   int MinAll(long * PartialMins, long * GlobalMins, int Count) const;
00383 
00385 
00395   int MinAll(long long * PartialMins, long long * GlobalMins, int Count) const;
00397 
00399 
00400 
00401 
00411   int ScanSum(double * MyVals, double * ScanSums, int Count) const;
00412 
00414 
00424   int ScanSum(int * MyVals, int * ScanSums, int Count) const;
00425 
00427 
00437   int ScanSum(long * MyVals, long * ScanSums, int Count) const;
00438 
00440 
00450   int ScanSum(long long * MyVals, long long * ScanSums, int Count) const;
00452 
00454 
00455 
00457   MPI_Comm Comm() const {return(MpiCommData_->Comm_);};
00458 
00460 
00463   int MyPID() const {return(MpiCommData_->rank_);};
00464 
00466 
00469   int NumProc() const {return(MpiCommData_->size_);};
00471 
00473 
00474 
00475   Epetra_Distributor * CreateDistributor() const;
00477   Epetra_Directory * CreateDirectory(const Epetra_BlockMap & Map) const;
00479 
00481 
00482 
00483   int GetMpiTag() const {int tag = MpiCommData_->curTag_++; if (tag > MpiCommData_->maxTag_) tag = MpiCommData_->minTag_; return(tag);};
00484 
00486   MPI_Comm GetMpiComm() const {return(MpiCommData_->Comm_);};
00488 
00489 
00490 
00491   inline void Print(std::ostream & os) const {
00492 #ifdef EPETRA_HAVE_OMP
00493 #pragma omp parallel
00494 {
00495   int numThreads = omp_get_num_threads();
00496   int threadNum = omp_get_thread_num();
00497 #pragma omp critical
00498                 os << "\n   Thread/TotalThreads " << threadNum << "/" << numThreads << " on Processor/TotalProcs "
00499     <<  MyPID() << "/" << NumProc();
00500 }
00501 #else
00502                 os << "::Processor "<< MyPID()<<" of " << NumProc() << " total processors.";
00503 #endif
00504   return;}
00506   void PrintInfo(std::ostream & os) const {Epetra_MpiComm::Print(os);return;};
00508 
00510 
00511 
00513 
00514   int ReferenceCount() const {return(MpiCommData_->ReferenceCount());};
00515 
00517 
00518   const Epetra_MpiCommData * DataPtr() const {return(MpiCommData_);};
00519 
00521 
00523   Epetra_MpiComm & operator=(const Epetra_MpiComm & Comm);
00524 
00525  private:
00526 
00527   int CheckInput(double * ptr, int count) const {if ((ptr==0) && (count>0)) return(-1); return(0);};
00528   int CheckInput(int * ptr, int count) const {if ((ptr==0) && (count>0)) return(-1); return(0);};
00529   int CheckInput(long * ptr, int count) const {if ((ptr==0) && (count>0)) return(-1); return(0);};
00530   int CheckInput(char * ptr, int count) const {if ((ptr==0) && (count>0)) return(-1); return(0);};
00531   int CheckInput(long long * ptr, int count) const {if ((ptr==0) && (count>0)) return(-1); return(0);};
00532 
00533   void CleanupData();
00534   Epetra_MpiCommData * MpiCommData_;
00535 
00536 };
00537 #endif /* EPETRA_MPICOMM_H */
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines