Skip to content

Commit 2c61dcf

Browse files
authored
Merge pull request #1061 from milroy/comparison-update
Planner comparison and update
2 parents cd2fb0f + 6f16387 commit 2c61dcf

22 files changed

+682
-210
lines changed

CMakeLists.txt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -172,6 +172,8 @@ if(DEFINED ENV{WITH_GO})
172172
include(GolangSimple)
173173
endif()
174174

175+
include(FindValgrind) # Search for Valgrind
176+
175177
include_directories(.)
176178
add_subdirectory( etc )
177179
add_subdirectory( src )

cmake/FindValgrind.cmake

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
# Look for Valgrind headers and binary.
2+
#
3+
# Variables defined by this module:
4+
# Valgrind_FOUND System has valgrind
5+
# Valgrind_INCLUDE_DIR where to find valgrind/memcheck.h, etc.
6+
# Valgrind_EXECUTABLE the valgrind executable.
7+
# This module appends to config.h so t5000-valgrind.t succeeds.
8+
# We may need to change this behavior once remaining autotools
9+
# files are removed.
10+
11+
find_path(Valgrind_INCLUDE_DIR valgrind HINTS ${Valgrind_INCLUDE_PATH})
12+
find_program(Valgrind_EXECUTABLE NAMES valgrind PATH ${Valgrind_BINARY_PATH})
13+
14+
include(FindPackageHandleStandardArgs)
15+
find_package_handle_standard_args(Valgrind DEFAULT_MSG Valgrind_INCLUDE_DIR Valgrind_EXECUTABLE)
16+
17+
if(Valgrind_FOUND)
18+
file(APPEND config.h "#define HAVE_VALGRIND 1\n")
19+
endif()

resource/planner/c++/CMakeLists.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ add_library(planner_cxx STATIC
33
./scheduled_point_tree.cpp
44
./mintime_resource_tree.cpp
55
./planner_multi.cpp
6+
./planner_internal_tree.cpp
67
./mintime_resource_tree.hpp
78
./planner_internal_tree.hpp
89
./scheduled_point_tree.hpp

resource/planner/c++/Makefile.am

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,8 @@ libplanner_cxx_la_SOURCES = \
3333
planner.cpp \
3434
planner_multi.cpp \
3535
scheduled_point_tree.cpp \
36-
mintime_resource_tree.cpp
36+
mintime_resource_tree.cpp \
37+
planner_internal_tree.cpp
3738

3839
libplanner_cxx_la_CFLAGS = $(AM_CFLAGS) -I$(top_srcdir)/resource/planner/c++
3940

resource/planner/c++/mintime_resource_tree.cpp

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -207,6 +207,17 @@ bool mt_resource_rb_node_t::operator< (const mt_resource_rb_node_t &other) const
207207
return this->remaining < other.remaining;
208208
}
209209

210+
bool mt_resource_rb_node_t::operator== (const mt_resource_rb_node_t &other) const
211+
{
212+
return this->remaining == other.remaining;
213+
}
214+
215+
bool mt_resource_rb_node_t::operator!= (const mt_resource_rb_node_t &other) const
216+
{
217+
return !operator == (other);
218+
}
219+
220+
210221

211222
/*******************************************************************************
212223
* *

resource/planner/c++/mintime_resource_tree.hpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,8 @@ struct mt_resource_rb_node_t
2424
int64_t subtree_min;
2525
int64_t remaining;
2626
bool operator< (const mt_resource_rb_node_t &other) const;
27+
bool operator== (const mt_resource_rb_node_t &other) const;
28+
bool operator!= (const mt_resource_rb_node_t &other) const;
2729
};
2830

2931
template <class mt_resource_rb_node_t, class NodeTraits>

resource/planner/c++/planner.cpp

Lines changed: 65 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,37 @@ extern "C" {
2121
#include "planner.hpp"
2222

2323

24+
/****************************************************************************
25+
* *
26+
* Public Span_t Methods *
27+
* *
28+
****************************************************************************/
29+
30+
bool span_t::operator== (const span_t &o) const
31+
{
32+
if (start != o.start)
33+
return false;
34+
if (last != o.last)
35+
return false;
36+
if (span_id != o.span_id)
37+
return false;
38+
if (planned != o.planned)
39+
return false;
40+
if (in_system != o.in_system)
41+
return false;
42+
if ((*(start_p) != *(o.start_p)))
43+
return false;
44+
if ((*(last_p) != *(o.last_p)))
45+
return false;
46+
47+
return true;
48+
}
49+
50+
bool span_t::operator!= (const span_t &o) const
51+
{
52+
return !operator == (o);
53+
}
54+
2455
/****************************************************************************
2556
* *
2657
* Public Planner Methods *
@@ -118,7 +149,7 @@ bool planner::operator== (const planner &o) const
118149
return false;
119150
// m_p0 or o.m_p0 could be uninitialized
120151
if (m_p0 && o.m_p0) {
121-
if (!scheduled_points_equal (*m_p0, *(o.m_p0)))
152+
if (*m_p0 != *(o.m_p0))
122153
return false;
123154
} else if (m_p0 || o.m_p0) {
124155
return false;
@@ -132,6 +163,11 @@ bool planner::operator== (const planner &o) const
132163
return true;
133164
}
134165

166+
bool planner::operator!= (const planner &o) const
167+
{
168+
return !operator == (o);
169+
}
170+
135171
planner::~planner ()
136172
{
137173
// Destructor is nothrow
@@ -193,6 +229,30 @@ int planner::restore_track_points ()
193229
return rc;
194230
}
195231

232+
int planner::update_total (uint64_t resource_total)
233+
{
234+
int64_t delta = resource_total - m_total_resources;
235+
int64_t tmp = 0;
236+
scheduled_point_t *point = nullptr;
237+
if (delta == 0)
238+
return 0;
239+
m_total_resources = static_cast<int64_t> (resource_total);
240+
point = m_sched_point_tree.get_state (m_plan_start);
241+
while (point) {
242+
// Prevent remaining from taking negative values. This should
243+
// reduce likelihood of errors when adding and removing spans.
244+
// If the performance penalty is non-negligible we can
245+
// investigate letting remaining take negative values.
246+
tmp = point->remaining + delta;
247+
if (tmp >= 0)
248+
point->remaining = tmp;
249+
else
250+
point->remaining = 0;
251+
point = m_sched_point_tree.next (point);
252+
}
253+
return 0;
254+
}
255+
196256
int64_t planner::get_total_resources () const
197257
{
198258
return m_total_resources;
@@ -428,25 +488,6 @@ int planner::copy_maps (const planner &o)
428488
return rc;
429489
}
430490

431-
bool planner::scheduled_points_equal (const scheduled_point_t &lhs,
432-
const scheduled_point_t &rhs) const
433-
{
434-
if (lhs.at != rhs.at)
435-
return false;
436-
if (lhs.in_mt_resource_tree != rhs.in_mt_resource_tree)
437-
return false;
438-
if (lhs.new_point != rhs.new_point)
439-
return false;
440-
if (lhs.ref_count != rhs.ref_count)
441-
return false;
442-
if (lhs.remaining != rhs.remaining)
443-
return false;
444-
if (lhs.scheduled != rhs.scheduled)
445-
return false;
446-
447-
return true;
448-
}
449-
450491
bool planner::span_lookups_equal (const planner &o) const
451492
{
452493
if (m_span_lookup.size () != o.m_span_lookup.size ())
@@ -460,23 +501,8 @@ bool planner::span_lookups_equal (const planner &o) const
460501
return false;
461502
if (this_it.first != other->first)
462503
return false;
463-
if (this_it.second->start != other->second->start)
464-
return false;
465-
if (this_it.second->last != other->second->last)
466-
return false;
467-
if (this_it.second->span_id != other->second->span_id)
468-
return false;
469-
if (this_it.second->planned != other->second->planned)
470-
return false;
471-
if (this_it.second->in_system != other->second->in_system)
472-
return false;
473-
if (this_it.second->in_system != other->second->in_system)
474-
return false;
475-
if (!scheduled_points_equal (*(this_it.second->start_p),
476-
*(other->second->start_p)))
477-
return false;
478-
if (!scheduled_points_equal (*(this_it.second->last_p),
479-
*(other->second->last_p)))
504+
// Compare span_t
505+
if (*(this_it.second) != *(other->second))
480506
return false;
481507
}
482508
}
@@ -497,8 +523,7 @@ bool planner::avail_time_iters_equal (const planner &o) const
497523
if (this_it.first != other->first)
498524
return false;
499525
if (this_it.second && other->second) {
500-
if (!scheduled_points_equal (*(this_it.second),
501-
*(other->second)))
526+
if (*(this_it.second) != *(other->second))
502527
return false;
503528
} else if (this_it.second || other->second) {
504529
return false;
@@ -518,7 +543,7 @@ bool planner::trees_equal (const planner &o) const
518543
scheduled_point_t *o_pt =
519544
o.m_sched_point_tree.get_state (o.m_plan_start);
520545
while (this_pt) {
521-
if (!scheduled_points_equal (*this_pt, *o_pt))
546+
if (*this_pt != *o_pt)
522547
return false;
523548
this_pt = m_sched_point_tree.next (this_pt);
524549
o_pt = o.m_sched_point_tree.next (o_pt);

resource/planner/c++/planner.hpp

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,9 @@ struct request_t {
2323
/*! Node in a span interval tree to enable fast retrieval of intercepting spans.
2424
*/
2525
struct span_t {
26+
bool operator== (const span_t &o) const;
27+
bool operator!= (const span_t &o) const;
28+
2629
int64_t start; /* start time of the span */
2730
int64_t last; /* end time of the span */
2831
int64_t span_id; /* unique span id */
@@ -42,11 +45,13 @@ class planner {
4245
planner (const planner &o);
4346
planner &operator= (const planner &o);
4447
bool operator== (const planner &o) const;
48+
bool operator!= (const planner &o) const;
4549
~planner ();
4650
// Public class utilities
4751
int erase ();
4852
int reinitialize (int64_t base_time, uint64_t duration);
4953
int restore_track_points ();
54+
int update_total (uint64_t resource_total);
5055

5156
// Resources and duration
5257
int64_t get_total_resources () const;
@@ -108,8 +113,6 @@ class planner {
108113
// Private class utilities
109114
int copy_trees (const planner &o);
110115
int copy_maps (const planner &o);
111-
bool scheduled_points_equal (const scheduled_point_t &lhs,
112-
const scheduled_point_t &rhs) const;
113116
bool span_lookups_equal (const planner &o) const;
114117
bool avail_time_iters_equal (const planner &o) const;
115118
bool trees_equal (const planner &o) const;
Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
/*****************************************************************************\
2+
* Copyright 2024 Lawrence Livermore National Security, LLC
3+
* (c.f. AUTHORS, NOTICE.LLNS, LICENSE)
4+
*
5+
* This file is part of the Flux resource manager framework.
6+
* For details, see https://github.com/flux-framework.
7+
*
8+
* SPDX-License-Identifier: LGPL-3.0
9+
\*****************************************************************************/
10+
11+
extern "C" {
12+
#if HAVE_CONFIG_H
13+
#include "config.h"
14+
#endif
15+
}
16+
17+
#include "planner_internal_tree.hpp"
18+
19+
bool scheduled_point_t::operator== (const scheduled_point_t &o) const
20+
{
21+
if (point_rb != o.point_rb)
22+
return false;
23+
if (resource_rb != o.resource_rb)
24+
return false;
25+
if (at != o.at)
26+
return false;
27+
if (in_mt_resource_tree != o.in_mt_resource_tree)
28+
return false;
29+
if (new_point != o.new_point)
30+
return false;
31+
if (ref_count != o.ref_count)
32+
return false;
33+
if (remaining != o.remaining)
34+
return false;
35+
if (scheduled != o.scheduled)
36+
return false;
37+
38+
return true;
39+
}
40+
41+
bool scheduled_point_t::operator!= (const scheduled_point_t &o) const
42+
{
43+
return !operator == (o);
44+
}
45+
46+
47+
/*
48+
* vi: ts=4 sw=4 expandtab
49+
*/

resource/planner/c++/planner_internal_tree.hpp

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,9 @@
1919
* tree.
2020
*/
2121
struct scheduled_point_t {
22+
bool operator== (const scheduled_point_t &o) const;
23+
bool operator!= (const scheduled_point_t &o) const;
24+
2225
scheduled_point_rb_node_t point_rb; /* BST node for scheduled point tree */
2326
mt_resource_rb_node_t resource_rb; /* BST node for min-time resource tree */
2427
int64_t at; /* Resource-state changing time */

0 commit comments

Comments
 (0)