36 tLocalMatStruct::iterator mat_begin, tLocalMatStruct::iterator mat_end,
37 std::vector<index>::iterator i_new2old_begin, std::vector<index>::iterator i_new2old_end,
42 tLocalMatStruct::iterator full_mat_begin,
45 index n_elem = mat_end - mat_begin;
48 nParts = std::max(1, nParts);
49 std::vector<index> part_start(nParts + 1, 0);
59 std::vector<std::set<int>> localPartsAdjV(nParts);
60 for (
index iC = 0; iC < n_elem; iC++)
62 auto iP = partition_local.at(iC);
63 for (
auto iCOther : mat_begin[iC])
65 index iLocal = iCOther - ind_offset;
66 if (iLocal >= 0 && iLocal < n_elem)
68 auto iPOther = partition_local.at(iLocal);
70 localPartsAdjV.at(iP).insert(iPOther);
75 localPartsAdj.reserve(nParts);
76 for (
auto &row : localPartsAdjV)
78 localPartsAdj.emplace_back();
79 localPartsAdj.back().reserve(row.size());
81 localPartsAdj.back().emplace_back(
v);
86 localPartsAdj.begin(), localPartsAdj.end(),
bwOld,
bwNew, 0);
87 for (
auto &iP : partition_local)
90 iP = partOld2New_[iP];
93 std::vector<index> n_elem_part(nParts, 0);
94 for (
index iC = 0; iC < n_elem; iC++)
96 auto iP = partition_local.at(iC);
99 for (
int i = 0; i < nParts; i++)
100 part_start[i + 1] = part_start[i] + n_elem_part[i];
104 std::vector<index> new_i_new2old(n_elem);
105 std::vector<index> i_old2new(n_elem);
106 n_elem_part.assign(n_elem, 0);
107 for (
index iC = 0; iC < n_elem; iC++)
109 auto iP = partition_local[iC];
110 index iNew = part_start[iP] + n_elem_part[iP];
112 new_i_new2old[iNew] = i_new2old_begin[iC];
113 new_mat[iNew] = std::move(mat_begin[iC]);
114 i_old2new[iC] = iNew;
121 for (
auto &row : new_mat)
122 for (
auto &iCOther : row)
124 index iLocal = iCOther - ind_offset;
125 if (iLocal >= 0 && iLocal < n_elem)
126 iCOther = ind_offset + i_old2new[iLocal];
129 for (
index iC = 0; iC < n_elem; iC++)
131 i_new2old_begin[iC] = new_i_new2old[iC];
132 mat_begin[iC] = std::move(new_mat[iC]);
140 index sub_begin = mat_begin - full_mat_begin;
141 index sub_end = mat_end - full_mat_begin;
142 for (
index iC = 0; iC < full_n_elem; iC++)
144 if (iC >= sub_begin && iC < sub_end)
146 for (
auto &iCOther : full_mat_begin[iC])
148 index iLocal = iCOther - ind_offset;
149 if (iLocal >= 0 && iLocal < n_elem)
150 iCOther = ind_offset + i_old2new[iLocal];
156 part_start[1] = n_elem;
158 bwOldM = 0, bwNewM = 0;
165 for (
int iPart = 0; iPart < nParts; iPart++)
167 index local_offset = part_start[iPart];
168 index local_nelem = part_start[iPart + 1] - part_start[iPart];
170 for (
index iC = 0; iC < local_nelem; iC++)
172 auto &row = mat_begin[iC + local_offset];
173 auto last = std::remove_if(row.begin(), row.end(), [&](
index v)
174 { return (v < local_offset + ind_offset) ||
175 (v >= local_offset + ind_offset + local_nelem); });
176 row.erase(last, row.end());
180 mat_begin + local_offset,
181 mat_begin + local_offset + local_nelem,
183 ind_offset + local_offset);
184 bwNewM = std::max(bwNewM,
bwNew);
185 bwOldM = std::max(bwOldM,
bwOld);
188 std::vector<index> new_i_new2old(local_nelem);
189 for (
index iC = 0; iC < local_nelem; iC++)
191 index iNew = cOld2New_[iC];
192 new_i_new2old[iNew] = i_new2old_begin[iC + local_offset];
193 new_mat[iNew] = std::move(mat_begin[iC + local_offset]);
195 for (
auto &row : new_mat)
196 for (
auto &iCOther : row)
197 iCOther = ind_offset + local_offset + cOld2New_.at(iCOther - ind_offset - local_offset);
199 for (
index iC = 0; iC < local_nelem; iC++)
201 i_new2old_begin[iC + local_offset] = new_i_new2old[iC];
202 mat_begin[iC + local_offset] = std::move(new_mat[iC]);
std::vector< index > ReorderSerialAdj_PartitionMetisC(tLocalMatStruct::iterator mat_begin, tLocalMatStruct::iterator mat_end, std::vector< index >::iterator i_new2old_begin, std::vector< index >::iterator i_new2old_end, int nParts, index ind_offset, bool do_rcm, index &bwOldM, index &bwNewM, tLocalMatStruct::iterator full_mat_begin, index full_n_elem)
Partition a sub-graph into nParts and optionally apply RCM reordering within each part.