Skylark (Sketching Library)  0.1
/var/lib/jenkins/jobs/Skylark/workspace/utility/get_communicator.hpp
Go to the documentation of this file.
00001 #ifndef SKYLARK_GET_COMMUNICATOR_HPP
00002 #define SKYLARK_GET_COMMUNICATOR_HPP
00003 
00004 // TODO: Replace with Skylark specific exceptions.
00005 #include <exception>
00006 
00007 #include "../config.h"
00008 #include "../base/base.hpp"
00009 
00010 #if SKYLARK_HAVE_COMBBLAS
00011 #include <CombBLAS.h>
00012 #endif
00013 
00014 
00015 #if SKYLARK_HAVE_ELEMENTAL
00016 #include <elemental.hpp>
00017 #endif
00018 
00019 #include <boost/mpi.hpp>
00020 
00021 
00022 namespace skylark { namespace utility {
00023 
00024 // namespace alias
00025 namespace mpi = boost::mpi;
00026 
00027 template<typename T>
00028 mpi::communicator get_communicator(const base::sparse_matrix_t<T>& A,
00029     mpi::comm_create_kind kind = mpi::comm_attach) {
00030     return mpi::communicator(MPI_COMM_SELF, kind);
00031 }
00032 
00033 #if SKYLARK_HAVE_ELEMENTAL
00034 
00035 template<typename T>
00036 mpi::communicator get_communicator(const elem::Matrix<T>& A,
00037     mpi::comm_create_kind kind = mpi::comm_attach) {
00038     return mpi::communicator(MPI_COMM_SELF, kind);
00039 }
00040 
00041 template<typename T, elem::Distribution U, elem::Distribution V>
00042 mpi::communicator get_communicator(const elem::DistMatrix<T, U, V>& A,
00043     mpi::comm_create_kind kind = mpi::comm_attach) {
00044     return mpi::communicator(A.DistComm(), kind);
00045 }
00046 
00047 #endif // SKYLARK_HAVE_ELEMENTAL
00048 
00049 
00050 #if SKYLARK_HAVE_COMBBLAS
00051 
00052 template<typename IT, typename T, typename S>
00053 mpi::communicator get_communicator(const SpParMat<IT, T, S>& A,
00054     mpi::comm_create_kind kind = mpi::comm_attach) {
00055     return mpi::communicator(A.getcommgrid()->GetWorld(), kind);
00056 }
00057 
00058 #endif // SKYLARK_HAVE_COMBBLAS
00059 
00060 
00066 bool compatible(const mpi::communicator& comm_A,
00067     const mpi::communicator& comm_B) {
00068     int error_code, result;
00069     error_code  = MPI_Comm_compare((MPI_Comm)comm_A, (MPI_Comm)comm_B, &result);
00070     if(error_code != MPI_SUCCESS) {
00071         throw std::runtime_error("MPI failure during call");
00072     }
00073 
00074     if (result == MPI_IDENT || result == MPI_CONGRUENT) {
00075         return true;
00076     }
00077     return false;
00078 }
00079 
00080 } } 
00082 #endif // SKYLARK_GET_COMMUNICATOR_HPP