Commit f99a4fc2 authored by Gregor Olenik's avatar Gregor Olenik
Browse files

This commit changes the calculation of sorting_idxs

- sorting_idxs are now calculated based on linearized idxs,
  which is needed for reusing the preconditioner
parent 776b51db
......@@ -22,18 +22,29 @@ IOSortingIdxHandler::IOSortingIdxHandler(const objectRegistry &db,
}
};
inline label linearize_index(const label row, const label col,
const label nCells)
{
return row * nCells + col;
};
void IOSortingIdxHandler::compute_sorting_idxs(
const std::vector<label> &row_idxs)
const std::vector<label> &row_idxs, const std::vector<label> &col_idxs,
const label nCells
)
{
// sort indexes based on comparing values in v
// using std::stable_sort instead of std::sort
// to avoid unnecessary index re-orderings
// when v contains elements of equal values
std::cout << " compute sorting idxs " << nElems_ << std::endl;
std::stable_sort(sorting_idxs_->data(), &sorting_idxs_->data()[nElems_],
[this, &row_idxs](size_t i1, size_t i2) {
return row_idxs[i1] < row_idxs[i2];
});
std::stable_sort(
sorting_idxs_->data(), &sorting_idxs_->data()[nElems_],
[this, &row_idxs, &col_idxs, nCells](size_t i1, size_t i2) {
return linearize_index(row_idxs[i1], col_idxs[i1], nCells) <
linearize_index(row_idxs[i2], col_idxs[i2], nCells);
});
};
void IOSortingIdxHandler::init_sorting_idxs()
......
......@@ -53,7 +53,9 @@ public:
void init_sorting_idxs();
void compute_sorting_idxs(const std::vector<label> &row_idxs);
void compute_sorting_idxs(const std::vector<label> &row_idxs,
const std::vector<label> &col_idxs,
const label nCells);
bool get_sort() const { return sort_; }
......
......@@ -108,8 +108,9 @@ public:
if (!get_is_sorted()) {
std::cout << "matrix is not yet sorted, compute sorting idxs "
<< std::endl;
SIMPLE_TIME(compute_sort,
this->compute_sorting_idxs(this->row_idxs());)
SIMPLE_TIME(compute_sort, this->compute_sorting_idxs(
this->row_idxs(), this->col_idxs(),
this->nCells());)
}
if (!stored && get_sort()) {
......
......@@ -105,6 +105,23 @@ public:
}
}
void sort_host_matrix_sparsity_pattern(
const IOField<label> *sorting_idxs) const
{
std::vector<label> tmp_col_idxs(nElems());
std::vector<label> tmp_row_idxs(nElems());
for (label i = 0; i < nElems(); i++) tmp_col_idxs[i] = col_idxs_[i];
for (label i = 0; i < nElems(); i++) tmp_row_idxs[i] = row_idxs_[i];
for (label i = 0; i < nElems(); i++) {
label j = sorting_idxs->operator[](i);
col_idxs_[i] = tmp_col_idxs[j];
row_idxs_[i] = tmp_row_idxs[j];
}
};
void update_host_matrix_data() const
{
// reset vectors
......@@ -126,22 +143,6 @@ public:
}
};
void sort_host_matrix_sparsity_pattern(
const IOField<label> *sorting_idxs) const
{
std::vector<label> tmp_col_idxs(nElems());
std::vector<label> tmp_row_idxs(nElems());
for (label i = 0; i < nElems(); i++) tmp_col_idxs[i] = col_idxs_[i];
for (label i = 0; i < nElems(); i++) tmp_row_idxs[i] = row_idxs_[i];
for (label i = 0; i < nElems(); i++) {
label j = sorting_idxs->operator[](i);
col_idxs_[i] = tmp_col_idxs[j];
row_idxs_[i] = tmp_row_idxs[j];
}
};
void sort_host_matrix_data(const IOField<label> *sorting_idxs) const
{
std::vector<scalar> tmp_values(nElems());
......
......@@ -103,7 +103,8 @@ public:
// init calls together
// after updating the host matrix the host matrix needs to be sorted
if (!get_is_sorted()) {
SIMPLE_TIME(compute_sorting_idxs, compute_sorting_idxs(row_idxs());)
SIMPLE_TIME(compute_sorting_idxs,
compute_sorting_idxs(row_idxs(), col_idxs(), nCells());)
}
// TODO move compute_sorting_idxs in the if clause above to have all
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment