Skip to content

Commit 9e63602

Browse files
avoiding out of bounds
1 parent a0d4ff3 commit 9e63602

6 files changed

Lines changed: 17 additions & 10 deletions

File tree

include/osp/bsp/model/BspArchitecture.hpp

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -523,7 +523,13 @@ class BspArchitecture {
523523
* @brief Returns the maximum memory bound over all processors.
524524
* @return The maximum memory bound.
525525
*/
526-
[[nodiscard]] VMemwT<GraphT> MaxMemoryBound() const { return *(std::max_element(memoryBound_.begin(), memoryBound_.end())); }
526+
[[nodiscard]] VMemwT<GraphT> MaxMemoryBound() const {
527+
if (memoryBound_.size() == 0U) {
528+
return std::numeric_limits<VMemwT<GraphT>>::max();
529+
} else {
530+
return *(std::max_element(memoryBound_.begin(), memoryBound_.end()));
531+
}
532+
}
527533

528534
/**
529535
* @brief Returns the maximum memory bound over all processors of a specific type.

include/osp/coarser/Sarkar/Sarkar.hpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -125,7 +125,7 @@ template <typename GraphTIn, typename GraphTOut>
125125
std::vector<VertexIdxT<GraphTIn>> Sarkar<GraphTIn, GraphTOut>::GetBotPosetMap(const GraphTIn &graph) const {
126126
std::vector<VertexIdxT<GraphTIn>> botPosetMap = GetBottomNodeDistance<GraphTIn, VertexIdxT<GraphTIn>>(graph);
127127

128-
VertexIdxT<GraphTIn> max = *std::max_element(botPosetMap.begin(), botPosetMap.end());
128+
VertexIdxT<GraphTIn> max = botPosetMap.size() == 0U? 0 : *std::max_element(botPosetMap.begin(), botPosetMap.end());
129129
++max;
130130

131131
for (std::size_t i = 0; i < botPosetMap.size(); i++) {
@@ -1064,8 +1064,8 @@ VertexIdxT<GraphTIn> Sarkar<GraphTIn, GraphTOut>::LevelContraction(
10641064
};
10651065
std::set<std::pair<long, std::vector<VertexType>>, decltype(cmp)> vertPriority(cmp);
10661066

1067-
const VertexIdxT<GraphTIn> minLevel = *std::min_element(vertexPoset.cbegin(), vertexPoset.cend());
1068-
const VertexIdxT<GraphTIn> maxLevel = *std::max_element(vertexPoset.cbegin(), vertexPoset.cend());
1067+
const VertexIdxT<GraphTIn> minLevel = vertexPoset.size() == 0U? 0 : *std::min_element(vertexPoset.cbegin(), vertexPoset.cend());
1068+
const VertexIdxT<GraphTIn> maxLevel = vertexPoset.size() == 0U? 0 : *std::max_element(vertexPoset.cbegin(), vertexPoset.cend());
10691069

10701070
const VertexIdxT<GraphTIn> parity = params_.mode_ == sarkar_params::Mode::LEVEL_EVEN ? 0 : 1;
10711071

include/osp/dag_divider/isomorphism_divider/IsomorphicSubgraphScheduler.hpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -257,8 +257,9 @@ class IsomorphicSubgraphScheduler {
257257
const auto &typeCount = instance.GetArchitecture().GetProcessorTypeCount();
258258
if (typeCount.empty()) {
259259
effectiveMinProcTypeCount = 0;
260+
} else {
261+
effectiveMinProcTypeCount = *std::min_element(typeCount.begin(), typeCount.end());
260262
}
261-
effectiveMinProcTypeCount = *std::min_element(typeCount.begin(), typeCount.end());
262263
if constexpr (verbose_) {
263264
std::cout << "Group " << groupIdx << " (size " << groupSize
264265
<< "): Multi-type or untyped group. Using default min_proc_type_count: "

include/osp/pebbling/pebblers/pebblingILP/PebblingPartialILP.hpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -98,7 +98,7 @@ ReturnStatus PebblingPartialILP<GraphT>::ComputePebbling(PebblingSchedule<GraphT
9898
AcyclicDagDivider<GraphT> dagDivider;
9999
dagDivider.SetMinAndMaxSize({minPartitionSize_, maxPartitionSize_});
100100
std::vector<unsigned> assignmentToParts = dagDivider.ComputePartitioning(instance);
101-
unsigned nrParts = *std::max_element(assignmentToParts.begin(), assignmentToParts.end()) + 1;
101+
unsigned nrParts = assignmentToParts.size() == 0U? 0U : *std::max_element(assignmentToParts.begin(), assignmentToParts.end()) + 1;
102102

103103
// TODO remove source nodes before this?
104104
GraphT contractedDag = ContractByPartition(instance, assignmentToParts);

tests/ilp_pebbling_scheduler.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ BOOST_AUTO_TEST_CASE(TestFull) {
5757
BOOST_CHECK_EQUAL(ReturnStatus::OSP_SUCCESS, greedy.ComputeSchedule(bspInitial));
5858

5959
std::vector<VMemwT<graph> > minimumMemoryRequiredVector = PebblingSchedule<graph>::MinimumMemoryRequiredPerNodeType(instance);
60-
VMemwT<graph> maxRequired = *std::max_element(minimumMemoryRequiredVector.begin(), minimumMemoryRequiredVector.end());
60+
VMemwT<graph> maxRequired = minimumMemoryRequiredVector.size() == 0U ? std::numeric_limits<VMemwT<graph>>::max() : *std::max_element(minimumMemoryRequiredVector.begin(), minimumMemoryRequiredVector.end());
6161
instance.GetArchitecture().SetMemoryBound(maxRequired);
6262

6363
PebblingSchedule<graph> initialSol(bspInitial, PebblingSchedule<graph>::CacheEvictionStrategy::FORESIGHT);
@@ -93,7 +93,7 @@ BOOST_AUTO_TEST_CASE(TestPartial) {
9393
BOOST_CHECK(status);
9494

9595
std::vector<VMemwT<graph> > minimumMemoryRequiredVector = PebblingSchedule<graph>::MinimumMemoryRequiredPerNodeType(instance);
96-
VMemwT<graph> maxRequired = *std::max_element(minimumMemoryRequiredVector.begin(), minimumMemoryRequiredVector.end());
96+
VMemwT<graph> maxRequired = minimumMemoryRequiredVector.size() == 0U ? std::numeric_limits<VMemwT<graph>>::max() : *std::max_element(minimumMemoryRequiredVector.begin(), minimumMemoryRequiredVector.end());
9797
instance.GetArchitecture().SetMemoryBound(maxRequired);
9898

9999
PebblingPartialILP<graph> mpp;

tests/pebbling_schedule_class.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -95,7 +95,7 @@ void RunTest(Scheduler<GraphT> *testScheduler) {
9595

9696
std::vector<VMemwT<GraphT> > minimumMemoryRequiredVector
9797
= PebblingSchedule<GraphT>::MinimumMemoryRequiredPerNodeType(instance);
98-
VMemwT<GraphT> maxRequired = *std::max_element(minimumMemoryRequiredVector.begin(), minimumMemoryRequiredVector.end());
98+
VMemwT<GraphT> maxRequired = minimumMemoryRequiredVector.size() == 0U ? std::numeric_limits<VMemwT<GraphT>>::max() : *std::max_element(minimumMemoryRequiredVector.begin(), minimumMemoryRequiredVector.end());
9999
instance.GetArchitecture().SetMemoryBound(maxRequired);
100100

101101
PebblingSchedule<GraphT> memSchedule1(bspSchedule, PebblingSchedule<GraphT>::CacheEvictionStrategy::LARGEST_ID);
@@ -159,7 +159,7 @@ BOOST_AUTO_TEST_CASE(TestPebblingScheduleWriter) {
159159
BOOST_CHECK_EQUAL(ReturnStatus::OSP_SUCCESS, result);
160160

161161
std::vector<VMemwT<Graph> > minimumMemoryRequiredVector = PebblingSchedule<Graph>::MinimumMemoryRequiredPerNodeType(instance);
162-
VMemwT<Graph> maxRequired = *std::max_element(minimumMemoryRequiredVector.begin(), minimumMemoryRequiredVector.end());
162+
VMemwT<Graph> maxRequired = minimumMemoryRequiredVector.size() == 0U ? std::numeric_limits<VMemwT<Graph>>::max() - 3 : *std::max_element(minimumMemoryRequiredVector.begin(), minimumMemoryRequiredVector.end());
163163
instance.GetArchitecture().SetMemoryBound(maxRequired + 3);
164164

165165
PebblingSchedule<Graph> memSchedule(bspSchedule, PebblingSchedule<Graph>::CacheEvictionStrategy::LEAST_RECENTLY_USED);

0 commit comments

Comments
 (0)