Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Earlier all to unrefine #51

Open
wants to merge 5 commits into
base: vlasiator-version
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
177 changes: 101 additions & 76 deletions dccrg.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -3066,7 +3066,7 @@ template <
}

// check that cells_to_unrefine is identical between processes
std::vector<uint64_t> ordered_cells_to_unrefine(this->cells_to_unrefine.begin(), this->cells_to_unrefine.end());
std::vector<uint64_t> ordered_cells_to_unrefine(this->all_cells_to_unrefine.begin(), this->all_cells_to_unrefine.end());
std::sort(ordered_cells_to_unrefine.begin(), ordered_cells_to_unrefine.end());

std::vector<std::vector<uint64_t>> all_ordered_cells_to_unrefine;
Expand Down Expand Up @@ -3229,81 +3229,6 @@ template <
// needed for checking which neighborhoods to update due to unrefining
std::unordered_set<uint64_t> parents_of_unrefined;

// initially only one sibling is recorded per process when unrefining,
// insert the rest of them now
for (const uint64_t unrefined: this->cells_to_unrefine) {

const uint64_t parent_of_unrefined = this->get_parent(unrefined);
#ifdef DEBUG
if (unrefined != this->get_child(unrefined)) {
std::cerr << __FILE__ << ":" << __LINE__
<< " Cell " << unrefined
<< " has children"
<< std::endl;
abort();
}

if (parent_of_unrefined == 0) {
std::cerr << __FILE__ << ":" << __LINE__ << " Invalid parent cell" << std::endl;
abort();
}

if (parent_of_unrefined == unrefined) {
std::cerr << __FILE__ << ":" << __LINE__
<< " Cell " << unrefined
<< " has no parent"
<< std::endl;
abort();
}
#endif

parents_of_unrefined.insert(parent_of_unrefined);

const std::vector<uint64_t> siblings = this->get_all_children(parent_of_unrefined);

#ifdef DEBUG
bool unrefined_in_siblings = false;
for (const uint64_t sibling: siblings) {

if (this->cell_process.count(sibling) == 0) {
std::cerr << __FILE__ << ":" << __LINE__
<< " Cell " << sibling
<< " doesn't exist"
<< std::endl;
abort();
}

if (sibling != this->get_child(sibling)) {
std::cerr << __FILE__ << ":" << __LINE__
<< " Cell " << sibling
<< " has has children"
<< std::endl;
abort();
}

if (this->cell_process.at(sibling) == this->rank
&& this->cell_data.count(sibling) == 0) {
std::cerr << __FILE__ << ":" << __LINE__
<< " Cell " << sibling
<< " has no data"
<< std::endl;
abort();
}

if (unrefined == sibling) {
unrefined_in_siblings = true;
}
}

if (!unrefined_in_siblings) {
std::cerr << __FILE__ << ":" << __LINE__ << " Cell to unrefine isn't its parent's child" << std::endl;
abort();
}
#endif

this->all_to_unrefine.insert(siblings.begin(), siblings.end());
}

// unrefines
for (const uint64_t unrefined: this->all_to_unrefine) {

Expand Down Expand Up @@ -3596,6 +3521,30 @@ template <
return retVal;
}

size_t get_cells_to_refine_count()
{
if (!this->refining) {
std::cerr << __FILE__ << ":" << __LINE__
<< " get_cells_to_refine_count() called outside refining"
<< std::endl;
return 0;
}

return cells_to_refine.size();
}

size_t get_cells_to_unrefine_count()
{
if (!this->refining) {
std::cerr << __FILE__ << ":" << __LINE__
<< " get_cells_to_unrefine_count() called outside refining"
<< std::endl;
return 0;
}

return all_to_unrefine.size();
}

/*!
Transfers unrefined cell data between processes.

Expand Down Expand Up @@ -9310,6 +9259,82 @@ template <
}
}

// initially only one sibling is recorded per process when unrefining,
// insert the rest of them now
for (const uint64_t unrefined: this->cells_to_unrefine) {

const uint64_t parent_of_unrefined = this->get_parent(unrefined);
#ifdef DEBUG
if (unrefined != this->get_child(unrefined)) {
std::cerr << __FILE__ << ":" << __LINE__
<< " Cell " << unrefined
<< " has children"
<< std::endl;
abort();
}

if (parent_of_unrefined == 0) {
std::cerr << __FILE__ << ":" << __LINE__ << " Invalid parent cell" << std::endl;
abort();
}

if (parent_of_unrefined == unrefined) {
std::cerr << __FILE__ << ":" << __LINE__
<< " Cell " << unrefined
<< " has no parent"
<< std::endl;
abort();
}
#endif

parents_of_unrefined.insert(parent_of_unrefined);

const std::vector<uint64_t> siblings = this->get_all_children(parent_of_unrefined);

#ifdef DEBUG
bool unrefined_in_siblings = false;
for (const uint64_t sibling: siblings) {

if (this->cell_process.count(sibling) == 0) {
std::cerr << __FILE__ << ":" << __LINE__
<< " Cell " << sibling
<< " doesn't exist"
<< std::endl;
abort();
}

if (sibling != this->get_child(sibling)) {
std::cerr << __FILE__ << ":" << __LINE__
<< " Cell " << sibling
<< " has has children"
<< std::endl;
abort();
}

if (this->cell_process.at(sibling) == this->rank
&& this->cell_data.count(sibling) == 0) {
std::cerr << __FILE__ << ":" << __LINE__
<< " Cell " << sibling
<< " has no data"
<< std::endl;
abort();
}

if (unrefined == sibling) {
unrefined_in_siblings = true;
}
}

if (!unrefined_in_siblings) {
std::cerr << __FILE__ << ":" << __LINE__ << " Cell to unrefine isn't its parent's child" << std::endl;
abort();
}
#endif

this->all_to_unrefine.insert(siblings.begin(), siblings.end());
}


if (!this->is_consistent()) {
std::cerr << __FILE__ << ":" << __LINE__ << " Grid isn't consistent" << std::endl;
abort();
Expand Down