Epetra Package Browser (Single Doxygen Collection)  Development
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
Epetra_MpiComm.h
Go to the documentation of this file.
1 /*
2 //@HEADER
3 // ************************************************************************
4 //
5 // Epetra: Linear Algebra Services Package
6 // Copyright 2011 Sandia Corporation
7 //
8 // Under the terms of Contract DE-AC04-94AL85000 with Sandia Corporation,
9 // the U.S. Government retains certain rights in this software.
10 //
11 // Redistribution and use in source and binary forms, with or without
12 // modification, are permitted provided that the following conditions are
13 // met:
14 //
15 // 1. Redistributions of source code must retain the above copyright
16 // notice, this list of conditions and the following disclaimer.
17 //
18 // 2. Redistributions in binary form must reproduce the above copyright
19 // notice, this list of conditions and the following disclaimer in the
20 // documentation and/or other materials provided with the distribution.
21 //
22 // 3. Neither the name of the Corporation nor the names of the
23 // contributors may be used to endorse or promote products derived from
24 // this software without specific prior written permission.
25 //
26 // THIS SOFTWARE IS PROVIDED BY SANDIA CORPORATION "AS IS" AND ANY
27 // EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
28 // IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
29 // PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL SANDIA CORPORATION OR THE
30 // CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
31 // EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
32 // PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
33 // PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
34 // LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
35 // NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
36 // SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
37 //
38 // Questions? Contact Michael A. Heroux (maherou@sandia.gov)
39 //
40 // ************************************************************************
41 //@HEADER
42 */
43 
44 #ifndef EPETRA_MPICOMM_H
45 #define EPETRA_MPICOMM_H
46 
47 #if defined(Epetra_SHOW_DEPRECATED_WARNINGS)
48 #ifdef __GNUC__
49 #warning "The Epetra package is deprecated"
50 #endif
51 #endif
52 
53 
54 #include "Epetra_Object.h"
55 #include "Epetra_Comm.h"
56 #include "Epetra_MpiDistributor.h"
57 class Epetra_Distributor;
58 #include "Epetra_BasicDirectory.h"
59 class Epetra_Directory;
60 class Epetra_BlockMap;
61 #include <mpi.h>
62 #include "Epetra_MpiCommData.h"
63 #ifdef EPETRA_HAVE_OMP
64 #include <omp.h>
65 #endif
66 
68 
72 class EPETRA_LIB_DLL_EXPORT Epetra_MpiComm: public Epetra_Object, public virtual Epetra_Comm {
73 
74  public:
75 
77 
78 
83  Epetra_MpiComm(MPI_Comm comm);
84 
85 
87 
89  Epetra_MpiComm(const Epetra_MpiComm & Comm);
90 
92  Epetra_Comm * Clone() const
93  {
94  return(new Epetra_MpiComm(*this));
95  };
96 
98 
103  virtual ~Epetra_MpiComm();
105 
107 
108 
112  void Barrier() const;
114 
116 
117 
129  int Broadcast(double * MyVals, int Count, int Root) const;
130 
132 
143  int Broadcast(int * MyVals, int Count, int Root) const;
144 
146 
157  int Broadcast(long * MyVals, int Count, int Root) const;
158 
160 
171  int Broadcast(long long * MyVals, int Count, int Root) const;
172 
174 
185  int Broadcast(char * MyVals, int Count, int Root) const;
187 
189 
190 
201  int GatherAll(double * MyVals, double * AllVals, int Count) const;
202 
204 
214  int GatherAll(int * MyVals, int * AllVals, int Count) const;
215 
217 
227  int GatherAll(long * MyVals, long * AllVals, int Count) const;
228 
230 
240  int GatherAll(long long * MyVals, long long * AllVals, int Count) const;
242 
244 
245 
257  int SumAll(double * PartialSums, double * GlobalSums, int Count) const;
258 
260 
270  int SumAll(int * PartialSums, int * GlobalSums, int Count) const;
271 
273 
283  int SumAll(long * PartialSums, long * GlobalSums, int Count) const;
284 
286 
296  int SumAll(long long * PartialSums, long long * GlobalSums, int Count) const;
298 
300 
301 
312  int MaxAll(double * PartialMaxs, double * GlobalMaxs, int Count) const;
313 
315 
325  int MaxAll(int * PartialMaxs, int * GlobalMaxs, int Count) const;
326 
328 
338  int MaxAll(long * PartialMaxs, long * GlobalMaxs, int Count) const;
339 
341 
351  int MaxAll(long long * PartialMaxs, long long * GlobalMaxs, int Count) const;
352 
354 
364  int MinAll(double * PartialMins, double * GlobalMins, int Count) const;
365 
367 
377  int MinAll(int * PartialMins, int * GlobalMins, int Count) const;
378 
380 
390  int MinAll(long * PartialMins, long * GlobalMins, int Count) const;
391 
393 
403  int MinAll(long long * PartialMins, long long * GlobalMins, int Count) const;
405 
407 
408 
419  int ScanSum(double * MyVals, double * ScanSums, int Count) const;
420 
422 
432  int ScanSum(int * MyVals, int * ScanSums, int Count) const;
433 
435 
445  int ScanSum(long * MyVals, long * ScanSums, int Count) const;
446 
448 
458  int ScanSum(long long * MyVals, long long * ScanSums, int Count) const;
460 
462 
463 
465  MPI_Comm Comm() const {return(MpiCommData_->Comm_);};
466 
468 
471  int MyPID() const {return(MpiCommData_->rank_);};
472 
474 
477  int NumProc() const {return(MpiCommData_->size_);};
479 
481 
485 // CreateDirectory is defined in Winbase.h as a macro!
486 #ifdef CreateDirectory
487 #undef CreateDirectory
488 #endif
489  Epetra_Directory * CreateDirectory(const Epetra_BlockMap & Map) const;
491 
493 
494  int GetMpiTag() const {int tag = MpiCommData_->curTag_++; if (tag > MpiCommData_->maxTag_) tag = MpiCommData_->minTag_; return(tag);};
496 
498  MPI_Comm GetMpiComm() const {return(MpiCommData_->Comm_);};
500 
502  inline void Print(std::ostream & os) const {
504 #ifdef EPETRA_HAVE_OMP
505 #pragma omp parallel
506 {
507  int numThreads = omp_get_num_threads();
508  int threadNum = omp_get_thread_num();
509 #pragma omp critical
510  os << "\n Thread/TotalThreads " << threadNum << "/" << numThreads << " on Processor/TotalProcs "
511  << MyPID() << "/" << NumProc();
512 }
513 #else
514  os << "::Processor "<< MyPID()<<" of " << NumProc() << " total processors.";
515 #endif
516  return;}
518  void PrintInfo(std::ostream & os) const {Epetra_MpiComm::Print(os);return;};
520 
522 
523 
525 
526  int ReferenceCount() const {return(MpiCommData_->ReferenceCount());};
527 
529 
530  const Epetra_MpiCommData * DataPtr() const {return(MpiCommData_);};
531 
533 
535  Epetra_MpiComm & operator=(const Epetra_MpiComm & Comm);
536 
537  private:
538 
539  int CheckInput(double * ptr, int count) const {if ((ptr==0) && (count>0)) return(-1); return(0);};
540  int CheckInput(int * ptr, int count) const {if ((ptr==0) && (count>0)) return(-1); return(0);};
541  int CheckInput(long * ptr, int count) const {if ((ptr==0) && (count>0)) return(-1); return(0);};
542  int CheckInput(char * ptr, int count) const {if ((ptr==0) && (count>0)) return(-1); return(0);};
543  int CheckInput(long long * ptr, int count) const {if ((ptr==0) && (count>0)) return(-1); return(0);};
544 
545  void CleanupData();
547 
548 };
549 #endif /* EPETRA_MPICOMM_H */
int CheckInput(double *ptr, int count) const
virtual void Print(std::ostream &os) const
Print object to an output stream Print method.
const Epetra_MpiCommData * DataPtr() const
Returns a pointer to the MpiCommData instance this MpiComm uses.
MPI_Comm GetMpiComm() const
Get the MPI Communicator (identical to Comm() method; used when we know we are MPI.
Epetra_Distributor: The Epetra Gather/Scatter Setup Base Class.
virtual int GatherAll(double *MyVals, double *AllVals, int Count) const =0
Epetra_Comm All Gather function.
Epetra_Comm * Clone() const
Clone method.
virtual Epetra_Directory * CreateDirectory(const Epetra_BlockMap &Map) const =0
Create a directory object for the given Epetra_BlockMap.
int NumProc() const
Returns total number of processes.
void Print(std::ostream &os) const
Print method that implements Epetra_Object virtual Print method.
int ReferenceCount() const
Returns the reference count of MpiCommData.
virtual int MinAll(double *PartialMins, double *GlobalMins, int Count) const =0
Epetra_Comm Global Min function.
Epetra_MpiComm: The Epetra MPI Communication Class.
virtual void Barrier() const =0
Epetra_Comm Barrier function.
virtual int MyPID() const =0
Return my process ID.
virtual int MaxAll(double *PartialMaxs, double *GlobalMaxs, int Count) const =0
Epetra_Comm Global Max function.
void PrintInfo(std::ostream &os) const
Print method that implements Epetra_Comm virtual PrintInfo method.
virtual int SumAll(double *PartialSums, double *GlobalSums, int Count) const =0
Epetra_Comm Global Sum function.
Epetra_Directory: This class is a pure virtual class whose interface allows Epetra_Map and Epetr_Bloc...
Epetra_Comm: The Epetra Communication Abstract Base Class.
Definition: Epetra_Comm.h:81
Epetra_Object & operator=(const Epetra_Object &src)
Epetra_Object: The base Epetra class.
Definition: Epetra_Object.h:65
Epetra_MpiCommData * MpiCommData_
Epetra_BlockMap: A class for partitioning block element vectors and matrices.
MPI_Comm Comm() const
Extract MPI Communicator from a Epetra_MpiComm object.
virtual int Broadcast(double *MyVals, int Count, int Root) const =0
Epetra_Comm Broadcast function.
Epetra_MpiCommData: The Epetra Mpi Communication Data Class.
int CheckInput(long *ptr, int count) const
int CheckInput(long long *ptr, int count) const
virtual int NumProc() const =0
Returns total number of processes.
virtual Epetra_Distributor * CreateDistributor() const =0
Create a distributor object.
int CheckInput(int *ptr, int count) const
int CheckInput(char *ptr, int count) const
virtual int ScanSum(double *MyVals, double *ScanSums, int Count) const =0
Epetra_Comm Scan Sum function.
int MyPID() const
Return my process ID.