Skylark (Sketching Library)
0.1
|
00001 #ifndef SKYLARK_COMBBLAS_COMM_GRID_HPP 00002 #define SKYLARK_COMBBLAS_COMM_GRID_HPP 00003 00004 // A collection of helpers to compute information about distribution of 00005 // CombBLAS objects. 00006 00007 namespace skylark { 00008 namespace utility { 00009 00010 #if SKYLARK_HAVE_COMBBLAS 00011 #include <CombBLAS.h> 00012 00014 template<typename index_type, typename value_type> 00015 inline index_type cb_row_offset( 00016 const SpParMat<index_type, value_type, SpDCCols<index_type, value_type> > &A, 00017 const size_t rank) { 00018 00019 return static_cast<size_t>((static_cast<double>(A.getnrow()) 00020 / A.getcommgrid()->GetGridRows())) 00021 * A.getcommgrid()->GetRankInProcCol(rank); 00022 } 00023 00025 template<typename index_type, typename value_type> 00026 inline index_type cb_my_row_offset( 00027 const SpParMat<index_type, value_type, SpDCCols<index_type, value_type> > &A) { 00028 00029 return cb_row_offset(A, A.getcommgrid()->GetRank()); 00030 } 00031 00033 template<typename index_type, typename value_type> 00034 inline index_type cb_col_offset( 00035 const SpParMat<index_type, value_type, SpDCCols<index_type, value_type> > &A, 00036 const size_t rank) { 00037 00038 return static_cast<size_t>((static_cast<double>(A.getncol()) 00039 / A.getcommgrid()->GetGridCols())) 00040 * A.getcommgrid()->GetRankInProcRow(rank); 00041 } 00042 00044 template<typename index_type, typename value_type> 00045 inline index_type cb_my_col_offset( 00046 const SpParMat<index_type, value_type, SpDCCols<index_type, value_type> > &A) { 00047 00048 return cb_col_offset(A, A.getcommgrid()->GetRank()); 00049 } 00050 00052 template<typename index_type, typename value_type> 00053 index_type cb_rows_per_proc( 00054 const SpParMat<index_type, value_type, SpDCCols<index_type, value_type> > &A) { 00055 00056 const size_t grows = A.getcommgrid()->GetGridRows(); 00057 return static_cast<size_t>(A.getnrow() / grows); 00058 } 00059 00061 template<typename index_type, typename value_type> 00062 index_type cb_cols_per_proc( 00063 const SpParMat<index_type, value_type, SpDCCols<index_type, value_type> > &A) { 00064 00065 const size_t gcols = A.getcommgrid()->GetGridCols(); 00066 return static_cast<size_t>(A.getncol() / gcols); 00067 } 00068 00070 template<typename index_type, typename value_type> 00071 index_type owner( 00072 const SpParMat<index_type, value_type, SpDCCols<index_type, value_type> > &A, 00073 const size_t row_idx, const size_t col_idx) { 00074 00075 //FIXME: functor member variables 00076 const size_t grows = A.getcommgrid()->GetGridRows(); 00077 const size_t rows_per_proc = static_cast<size_t>(A.getnrow() / grows); 00078 const size_t gcols = A.getcommgrid()->GetGridCols(); 00079 const size_t cols_per_proc = static_cast<size_t>(A.getncol() / gcols); 00080 00081 return A.getcommgrid()->GetRank( 00082 std::min(static_cast<size_t>(row_idx / rows_per_proc), grows - 1), 00083 std::min(static_cast<size_t>(col_idx / cols_per_proc), gcols - 1)); 00084 } 00085 00086 #endif //HAVE_COMBBLAS 00087 00088 } } //namespace skylark::utility 00089 00090 #endif //SKYLARK_COMBBLAS_COMM_GRID_HPP