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 #include "Epetra_Object.h"
47 #include "Epetra_Comm.h"
48 #include "Epetra_MpiDistributor.h"
49 class Epetra_Distributor;
50 #include "Epetra_BasicDirectory.h"
51 class Epetra_Directory;
52 class Epetra_BlockMap;
53 #include <mpi.h>
54 #include "Epetra_MpiCommData.h"
55 #ifdef EPETRA_HAVE_OMP
56 #include <omp.h>
57 #endif
58 
60 
64 class EPETRA_LIB_DLL_EXPORT Epetra_MpiComm: public Epetra_Object, public virtual Epetra_Comm {
65 
66  public:
67 
69 
70 
75  Epetra_MpiComm(MPI_Comm comm);
76 
77 
79 
81  Epetra_MpiComm(const Epetra_MpiComm & Comm);
82 
84  Epetra_Comm * Clone() const
85  {
86  return(new Epetra_MpiComm(*this));
87  };
88 
90 
95  virtual ~Epetra_MpiComm();
97 
99 
100 
104  void Barrier() const;
106 
108 
109 
121  int Broadcast(double * MyVals, int Count, int Root) const;
122 
124 
135  int Broadcast(int * MyVals, int Count, int Root) const;
136 
138 
149  int Broadcast(long * MyVals, int Count, int Root) const;
150 
152 
163  int Broadcast(long long * MyVals, int Count, int Root) const;
164 
166 
177  int Broadcast(char * MyVals, int Count, int Root) const;
179 
181 
182 
193  int GatherAll(double * MyVals, double * AllVals, int Count) const;
194 
196 
206  int GatherAll(int * MyVals, int * AllVals, int Count) const;
207 
209 
219  int GatherAll(long * MyVals, long * AllVals, int Count) const;
220 
222 
232  int GatherAll(long long * MyVals, long long * AllVals, int Count) const;
234 
236 
237 
249  int SumAll(double * PartialSums, double * GlobalSums, int Count) const;
250 
252 
262  int SumAll(int * PartialSums, int * GlobalSums, int Count) const;
263 
265 
275  int SumAll(long * PartialSums, long * GlobalSums, int Count) const;
276 
278 
288  int SumAll(long long * PartialSums, long long * GlobalSums, int Count) const;
290 
292 
293 
304  int MaxAll(double * PartialMaxs, double * GlobalMaxs, int Count) const;
305 
307 
317  int MaxAll(int * PartialMaxs, int * GlobalMaxs, int Count) const;
318 
320 
330  int MaxAll(long * PartialMaxs, long * GlobalMaxs, int Count) const;
331 
333 
343  int MaxAll(long long * PartialMaxs, long long * GlobalMaxs, int Count) const;
344 
346 
356  int MinAll(double * PartialMins, double * GlobalMins, int Count) const;
357 
359 
369  int MinAll(int * PartialMins, int * GlobalMins, int Count) const;
370 
372 
382  int MinAll(long * PartialMins, long * GlobalMins, int Count) const;
383 
385 
395  int MinAll(long long * PartialMins, long long * GlobalMins, int Count) const;
397 
399 
400 
411  int ScanSum(double * MyVals, double * ScanSums, int Count) const;
412 
414 
424  int ScanSum(int * MyVals, int * ScanSums, int Count) const;
425 
427 
437  int ScanSum(long * MyVals, long * ScanSums, int Count) const;
438 
440 
450  int ScanSum(long long * MyVals, long long * ScanSums, int Count) const;
452 
454 
455 
457  MPI_Comm Comm() const {return(MpiCommData_->Comm_);};
458 
460 
463  int MyPID() const {return(MpiCommData_->rank_);};
464 
466 
469  int NumProc() const {return(MpiCommData_->size_);};
471 
473 
477  Epetra_Directory * CreateDirectory(const Epetra_BlockMap & Map) const;
479 
481 
482  int GetMpiTag() const {int tag = MpiCommData_->curTag_++; if (tag > MpiCommData_->maxTag_) tag = MpiCommData_->minTag_; return(tag);};
484 
486  MPI_Comm GetMpiComm() const {return(MpiCommData_->Comm_);};
488 
490  inline void Print(std::ostream & os) const {
492 #ifdef EPETRA_HAVE_OMP
493 #pragma omp parallel
494 {
495  int numThreads = omp_get_num_threads();
496  int threadNum = omp_get_thread_num();
497 #pragma omp critical
498  os << "\n Thread/TotalThreads " << threadNum << "/" << numThreads << " on Processor/TotalProcs "
499  << MyPID() << "/" << NumProc();
500 }
501 #else
502  os << "::Processor "<< MyPID()<<" of " << NumProc() << " total processors.";
503 #endif
504  return;}
506  void PrintInfo(std::ostream & os) const {Epetra_MpiComm::Print(os);return;};
508 
510 
511 
513 
514  int ReferenceCount() const {return(MpiCommData_->ReferenceCount());};
515 
517 
518  const Epetra_MpiCommData * DataPtr() const {return(MpiCommData_);};
519 
521 
523  Epetra_MpiComm & operator=(const Epetra_MpiComm & Comm);
524 
525  private:
526 
527  int CheckInput(double * ptr, int count) const {if ((ptr==0) && (count>0)) return(-1); return(0);};
528  int CheckInput(int * ptr, int count) const {if ((ptr==0) && (count>0)) return(-1); return(0);};
529  int CheckInput(long * ptr, int count) const {if ((ptr==0) && (count>0)) return(-1); return(0);};
530  int CheckInput(char * ptr, int count) const {if ((ptr==0) && (count>0)) return(-1); return(0);};
531  int CheckInput(long long * ptr, int count) const {if ((ptr==0) && (count>0)) return(-1); return(0);};
532 
533  void CleanupData();
535 
536 };
537 #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:73
Epetra_Object & operator=(const Epetra_Object &src)
Epetra_Object: The base Epetra class.
Definition: Epetra_Object.h:57
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.