|
Teuchos Package Browser (Single Doxygen Collection) Version of the Day
|
00001 // @HEADER 00002 // *********************************************************************** 00003 // 00004 // Teuchos: Common Tools Package 00005 // Copyright (2004) Sandia Corporation 00006 // 00007 // Under terms of Contract DE-AC04-94AL85000, there is a non-exclusive 00008 // license for use of this work by or on behalf of the U.S. Government. 00009 // 00010 // This library is free software; you can redistribute it and/or modify 00011 // it under the terms of the GNU Lesser General Public License as 00012 // published by the Free Software Foundation; either version 2.1 of the 00013 // License, or (at your option) any later version. 00014 // 00015 // This library is distributed in the hope that it will be useful, but 00016 // WITHOUT ANY WARRANTY; without even the implied warranty of 00017 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 00018 // Lesser General Public License for more details. 00019 // 00020 // You should have received a copy of the GNU Lesser General Public 00021 // License along with this library; if not, write to the Free Software 00022 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 00023 // USA 00024 // Questions? Contact Michael A. Heroux (maherou@sandia.gov) 00025 // 00026 // *********************************************************************** 00027 // @HEADER 00028 00029 #ifndef TEUCHOS_MPICOMM_H 00030 #define TEUCHOS_MPICOMM_H 00031 00036 #include "Teuchos_ConfigDefs.hpp" 00037 #include "Teuchos_Array.hpp" 00038 #include "Teuchos_RCP.hpp" 00039 00040 #ifdef HAVE_MPI 00041 #include "mpi.h" 00042 #endif 00043 00044 00045 namespace Teuchos 00046 { 00053 class TEUCHOS_LIB_DLL_EXPORT MPIComm 00054 { 00055 public: 00056 00058 MPIComm(); 00059 00060 #ifdef HAVE_MPI 00061 00062 MPIComm(MPI_Comm comm); 00063 #endif 00064 00066 static MPIComm& world(); 00068 static MPIComm& self(); 00069 00071 int getRank() const {return myRank_;} 00072 00074 int getNProc() const {return nProc_;} 00075 00077 void synchronize() const ; 00078 00080 00081 00083 void allToAll(void* sendBuf, int sendCount, int sendType, 00084 void* recvBuf, int recvCount, int recvType) const ; 00085 00087 void allToAllv(void* sendBuf, int* sendCount, int* sendDisplacements, 00088 int sendType, 00089 void* recvBuf, int* recvCount, 00090 int* recvDisplacements, 00091 int recvType) const ; 00092 00094 void allReduce(void* input, void* result, int inputCount, int type, 00095 int op) const ; 00096 00097 00099 void gather(void* sendBuf, int sendCount, int sendType, 00100 void* recvBuf, int recvCount, int recvType, 00101 int root) const ; 00102 00104 void gatherv(void* sendBuf, int sendCount, int sendType, 00105 void* recvBuf, int* recvCount, int* displacements, 00106 int recvType, int root) const ; 00107 00109 void allGather(void* sendBuf, int sendCount, int sendType, 00110 void* recvBuf, int recvCount, int recvType) const ; 00111 00113 void allGatherv(void* sendBuf, int sendCount, int sendType, 00114 void* recvBuf, int* recvCount, int* recvDisplacements, 00115 int recvType) const ; 00116 00118 void bcast(void* msg, int length, int type, int src) const ; 00119 00121 00122 #ifdef HAVE_MPI 00123 00124 MPI_Comm getComm() const {return comm_;} 00125 #endif 00126 00128 00129 00130 static const int INT; 00132 static const int FLOAT; 00134 static const int DOUBLE; 00136 static const int CHAR; 00138 00140 00141 00142 static const int SUM; 00144 static const int MIN; 00146 static const int MAX; 00148 static const int PROD; 00150 00151 // errCheck() checks the return value of an MPI call and throws 00152 // a ParallelException upon failure. 00153 static void errCheck(int errCode, const std::string& methodName); 00154 00155 #ifdef HAVE_MPI 00156 00157 static MPI_Datatype getDataType(int type); 00158 00160 static MPI_Op getOp(int op); 00161 #endif 00162 private: 00163 #ifdef HAVE_MPI 00164 MPI_Comm comm_; 00165 #endif 00166 00167 int nProc_; 00168 int myRank_; 00169 00171 void init(); 00172 00174 int mpiIsRunning() const ; 00175 }; 00176 } 00177 #endif 00178
1.7.4