Skip to content

Commit

Permalink
IOSS: Add option for sorted vector elemGTL search (instead of map/uno…
Browse files Browse the repository at this point in the history
…rdered_map)
  • Loading branch information
gdsjaar committed Jan 12, 2024
1 parent d17786e commit d80623c
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 1 deletion.
17 changes: 16 additions & 1 deletion packages/seacas/libraries/ioss/src/Ioss_Decomposition.C
Original file line number Diff line number Diff line change
Expand Up @@ -1253,26 +1253,41 @@ namespace Ioss {
show_progress(__func__);
// global_index is 1-based index into global list of elems
// [1..global_elem_count]
#if defined(DC_USE_HOPSCOTCH) || defined(DC_USE_ROBIN)
#if defined(DC_USE_HOPSCOTCH) || defined(DC_USE_ROBIN) || defined(DC_USE_VECTOR)
elemGTL.reserve(localElementMap.size() + m_importPreLocalElemIndex + importElementMap.size());
#endif
for (size_t i = 0; i < localElementMap.size(); i++) {
size_t global_index = localElementMap[i] + m_elementOffset + 1;
size_t local_index = i + m_importPreLocalElemIndex + 1;
#if defined(DC_USE_VECTOR)
elemGTL.emplace_back(global_index, local_index);
#else
elemGTL.insert({global_index, local_index});
#endif
}

for (size_t i = 0; i < m_importPreLocalElemIndex; i++) {
size_t global_index = importElementMap[i] + 1;
size_t local_index = i + 1;
#if defined(DC_USE_VECTOR)
elemGTL.emplace_back(global_index, local_index);
#else
elemGTL.insert({global_index, local_index});
#endif
}

for (size_t i = m_importPreLocalElemIndex; i < importElementMap.size(); i++) {
size_t global_index = importElementMap[i] + 1;
size_t local_index = localElementMap.size() + i + 1;
#if defined(DC_USE_VECTOR)
elemGTL.emplace_back(global_index, local_index);
#else
elemGTL.insert({global_index, local_index});
#endif
}
#if defined(DC_USE_VECTOR)
Ioss::sort(elemGTL.begin(), elemGTL.end());
#endif
show_progress("build_global_to_local_elem_map end");
}

Expand Down
14 changes: 14 additions & 0 deletions packages/seacas/libraries/ioss/src/Ioss_Decomposition.h
Original file line number Diff line number Diff line change
Expand Up @@ -209,7 +209,13 @@ namespace Ioss {
bool i_own_elem(size_t global_index) const
{
// global_index is 1-based index into global list of elements [1..global_element_count]
#if defined(DC_USE_VECTOR)
return std::binary_search(elemGTL.begin(), elemGTL.end(), std::pair<INT,INT>{global_index,0},
[](const std::pair<INT,INT> &lhs, const std::pair<INT,INT> &val) -> bool {return lhs.first < val.first;});
return true;
#else
return elemGTL.find(global_index) != elemGTL.end();
#endif
}

size_t node_global_to_local(size_t global_index) const
Expand All @@ -230,8 +236,14 @@ namespace Ioss {
// global_index is 1-based index into global list of elements [1..global_node_count]
// return value is 1-based index into local list of elements on this
// processor (ioss-decomposition)
#if defined(DC_USE_VECTOR)
auto I = lower_bound(elemGTL.begin(), elemGTL.end(), global_index, [](const std::pair<INT,INT> &lhs, INT val) -> bool {return lhs.first < val;});
assert (I != elemGTL.end() && I->first == global_index);
#else
auto I = elemGTL.find(global_index);
#endif
assert(I != elemGTL.end());
assert(I->first == global_index);
return I->second;
}

Expand Down Expand Up @@ -871,6 +883,8 @@ namespace Ioss {
tsl::hopscotch_pg_map<INT, INT> elemGTL; // Convert from global index to local index (1-based)
#elif defined DC_USE_ROBIN
tsl::robin_pg_map<INT, INT> elemGTL; // Convert from global index to local index (1-based)
#elif defined DC_USE_VECTOR
std::vector<std::pair<INT, INT>> elemGTL; // Convert from global index to local index (1-based)
#else
// This is the original method that was used in IOSS prior to using hopscotch or robin map.
std::map<INT, INT> elemGTL; // Convert from global index to local index (1-based)
Expand Down

0 comments on commit d80623c

Please sign in to comment.