45struct SimpleMatrixPartitioner
47 typedef typename Backend::value_type value_type;
53 int min_per_proc = 10000;
59 : ARCCORE_ALINA_PARAMS_IMPORT_VALUE(p, enable)
60 , ARCCORE_ALINA_PARAMS_IMPORT_VALUE(p, min_per_proc)
61 , ARCCORE_ALINA_PARAMS_IMPORT_VALUE(p, shrink_ratio)
63 p.check_params({
"enable",
"min_per_proc",
"shrink_ratio" });
66 void get(
PropertyTree& p,
const std::string& path =
"")
const
68 ARCCORE_ALINA_PARAMS_EXPORT_VALUE(p, path, enable);
69 ARCCORE_ALINA_PARAMS_EXPORT_VALUE(p, path, min_per_proc);
70 ARCCORE_ALINA_PARAMS_EXPORT_VALUE(p, path, shrink_ratio);
75 explicit SimpleMatrixPartitioner(
const params& prm =
params())
79 bool is_needed(
const matrix& A)
const
85 ptrdiff_t n = A.loc_rows();
89 ptrdiff_t min_n = std::numeric_limits<ptrdiff_t>::max();
90 for (
int i = 0; i < comm.size; ++i) {
91 ptrdiff_t m = row_dom[i + 1] - row_dom[i];
93 min_n = std::min(min_n, m);
98 return (non_empty > 1) && (min_n <= prm.min_per_proc);
101 std::shared_ptr<matrix> operator()(
const matrix& A,
unsigned = 1)
const
103 mpi_communicator comm = A.comm();
104 ptrdiff_t nrows = A.loc_rows();
106 std::vector<ptrdiff_t> row_dom = comm.exclusive_sum(nrows);
107 std::vector<ptrdiff_t> col_dom(comm.size + 1);
109 for (
int i = 0; i <= comm.size; ++i)
110 col_dom[i] = row_dom[std::min<int>(i * prm.shrink_ratio, comm.size)];
115 for (
int i = 0; i < comm.size; ++i) {
116 if (row_dom[i + 1] > row_dom[i])
118 if (col_dom[i + 1] > col_dom[i])
123 std::cout <<
"Partitioning[Simple] " << old_domains <<
" -> " << new_domains << std::endl;
125 ptrdiff_t row_beg = row_dom[comm.rank];
126 ptrdiff_t col_beg = col_dom[comm.rank];
127 ptrdiff_t col_end = col_dom[comm.rank + 1];
129 std::vector<ptrdiff_t> perm(nrows);
130 for (ptrdiff_t i = 0; i < nrows; ++i) {
131 perm[i] = i + row_beg;
134 return mpi_graph_perm_matrix<Backend>(comm, col_beg, col_end, perm);