Skip to content

Commit

Permalink
Merge pull request #894 from parthenon-hpc-lab/jmm/sparse-id-ordering
Browse files Browse the repository at this point in the history
map instead of unordered_map for sparse pool
  • Loading branch information
Yurlungur authored Jun 21, 2023
2 parents b8efc2d + c613407 commit 099d20e
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 5 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
- [[PR 868]](https://github.com/parthenon-hpc-lab/parthenon/pull/868) Add block-local face, edge, and nodal fields and allow for packing

### Changed (changing behavior/API/variables/...)
- [[PR 894]](https://github.com/parthenon-hpc-lab/parthenon/pull/894) Demand that sparse pool order sparse ids
- [[PR 888]](https://github.com/parthenon-hpc-lab/parthenon/pull/888) Bump Kokkos submodule to 4.0.1
- [[PR 885]](https://github.com/parthenon-hpc-lab/parthenon/pull/885) Expose PackDescriptor and use uids in SparsePacks

Expand Down
10 changes: 6 additions & 4 deletions src/interface/sparse_pool.hpp
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
//========================================================================================
// (C) (or copyright) 2020-2022. Triad National Security, LLC. All rights reserved.
// (C) (or copyright) 2020-2023. Triad National Security, LLC. All rights reserved.
//
// This program was produced under U.S. Government contract 89233218CNA000001 for Los
// Alamos National Laboratory (LANL), which is operated by Triad National Security, LLC
Expand All @@ -13,9 +13,9 @@
#ifndef INTERFACE_SPARSE_POOL_HPP_
#define INTERFACE_SPARSE_POOL_HPP_

#include <map>
#include <string>
#include <type_traits>
#include <unordered_map>
#include <vector>

#include "metadata.hpp"
Expand Down Expand Up @@ -74,7 +74,7 @@ class SparsePool {
const std::string &base_name() const { return base_name_; }
const std::string &controller_base_name() const { return controller_base_name_; }
const Metadata &shared_metadata() const { return shared_metadata_; }
const std::unordered_map<int, Metadata> &pool() const { return pool_; }
const std::map<int, Metadata> &pool() const { return pool_; }
auto size() const { return pool_.size(); }

// Add a new sparse ID to the pool with optional arguments:
Expand Down Expand Up @@ -117,7 +117,9 @@ class SparsePool {

Metadata shared_metadata_;
// Metadata per sparse id
std::unordered_map<int, Metadata> pool_;
// JMM: note that this map SHOULD be ordered as sparse ids, being
// integers, have an implicit ordering.
std::map<int, Metadata> pool_;
};

} // namespace parthenon
Expand Down
10 changes: 9 additions & 1 deletion tst/unit/test_state_descriptor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
// Copyright(C) 2014 James M. Stone <[email protected]> and other code contributors
// Licensed under the 3-clause BSD License, see LICENSE file for details
//========================================================================================
// (C) (or copyright) 2020-2021. Triad National Security, LLC. All rights reserved.
// (C) (or copyright) 2020-2023. Triad National Security, LLC. All rights reserved.
//
// This program was produced under U.S. Government contract 89233218CNA000001 for Los
// Alamos National Laboratory (LANL), which is operated by Triad National Security, LLC
Expand Down Expand Up @@ -219,6 +219,14 @@ TEST_CASE("Test dependency resolution in StateDescriptor", "[StateDescriptor]")
REQUIRE(pkg4->FieldMetadata("sparse", sparse_ids[i]) == (m_sparse_provides));
}
}
AND_THEN("The sparse ids in the sparse pool are sorted") {
auto &pool = (pkg4->GetSparsePool("sparse")).pool();
std::vector<int> local_ids;
for (auto &[id, m] : pool) {
local_ids.push_back(id);
}
REQUIRE(std::is_sorted(local_ids.begin(), local_ids.end()));
}
}
}

Expand Down

0 comments on commit 099d20e

Please sign in to comment.