forked from dongahn/resource-query
-
Notifications
You must be signed in to change notification settings - Fork 0
/
dfu_match_cb.hpp
199 lines (183 loc) · 6.81 KB
/
dfu_match_cb.hpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
/*****************************************************************************\
* Copyright (c) 2014 Lawrence Livermore National Security, LLC. Produced at
* the Lawrence Livermore National Laboratory (cf, AUTHORS, DISCLAIMER.LLNS).
* LLNL-CODE-658032 All rights reserved.
*
* This file is part of the Flux resource manager framework.
* For details, see https://github.com/flux-framework.
*
* This program is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License as published by the Free
* Software Foundation; either version 2 of the license, or (at your option)
* any later version.
*
* Flux is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the IMPLIED WARRANTY OF MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the terms and conditions of the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License along
* with this program; if not, write to the Free Software Foundation, Inc.,
* 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA.
* See also: http://www.gnu.org/licenses/
\*****************************************************************************/
#ifndef DFU_MATCH_CB_HPP
#define DFU_MATCH_CB_HPP
#include <set>
#include <map>
#include <vector>
#include <cstdint>
#include <iostream>
#include "resource_graph.hpp"
#include "matcher_data.hpp"
#include "scoring_api.hpp"
#include "jobspec.hpp"
#include "planner/planner.h"
namespace Flux {
namespace resource_model {
/*! Base DFU matcher class.
* Define the set of visitor methods that are called
* back by a DFU resource-graph traverser.
*/
class dfu_match_cb_t : public matcher_data_t
{
public:
dfu_match_cb_t () : m_trav_level (0) { }
dfu_match_cb_t (const std::string &name)
: matcher_data_t (name), m_trav_level (0) { }
dfu_match_cb_t (const dfu_match_cb_t &o)
: matcher_data_t (o)
{
m_trav_level = o.m_trav_level;
}
dfu_match_cb_t &operator= (const dfu_match_cb_t &o)
{
matcher_data_t::operator= (o);
m_trav_level = o.m_trav_level;
return *this;
}
virtual ~dfu_match_cb_t () { }
/*!
* Called back when all of the graph has been visited.
*
* \param subsystem subsystem_t object of the dominant subsystem.
* \param resources vector of resources to be matched.
* \param g filtered resource graph.
* \param dfu score interface object - TODO: document
* \return return 0 on success; otherwise -1.
*/
virtual int dom_finish_graph (const subsystem_t &subsystem,
const std::vector<Flux::Jobspec::Resource> &resources,
const f_resource_graph_t &g, scoring_api_t &dfu)
{
return 0;
}
/*!
* Called back on each postorder visit of some group of slot resources
* (resources that can be contained within one or more slots) of the dominant
* subsystem.
*/
virtual int dom_finish_slot (const subsystem_t &subsystem, scoring_api_t &dfu)
{
return 0;
}
/*!
* Called back on each preorder visit of the dominant subsystem.
*
* \param u descriptor of the visiting vertex.
* \param subsystem subsystem_t object of the dominant subsystem.
* \param resources vector of resources to be matched (resource section
* of cannonical job spec).
* \param g filtered resource graph.
*
* \return return 0 on success; otherwise -1.
*/
virtual int dom_discover_vtx (vtx_t u, const subsystem_t &subsystem,
const std::vector<Flux::Jobspec::Resource> &resources,
const f_resource_graph_t &g)
{
m_trav_level++;
return 0;
}
/*!
* Called back on each postorder visit of the dominant subsystem. Should
* return a score calculated based on the subtree and up walks using the score
* API object (dfu). Any score aboved MATCH_MET is qualified to be a match.
*
* \param u descriptor of the visiting vertex
* \param subsystem subsystem_t object of the dominant subsystem
* \param resources vector of resources to be matched
* \param g filtered resource graph
* \param dfu score interface object: TODO: document
*
* \return return 0 on success; otherwise -1
*/
virtual int dom_finish_vtx (vtx_t u, const subsystem_t &subsystem,
const std::vector<Flux::Jobspec::Resource> &resources,
const f_resource_graph_t &g,
scoring_api_t &dfu)
{
m_trav_level--;
return 0;
}
/*! Called back on each pre-up visit of an auxiliary subsystem.
*
* \param u descriptor of the visiting vertex
* \param subsystem subsytem_t of the auxiliary subsystem being walked
* \param resources vector of resources to be matched
* \param g filtered resource graph
*
* \return return 0 on success; otherwise -1
*/
virtual int aux_discover_vtx (vtx_t u, const subsystem_t &subsystem,
const std::vector<Flux::Jobspec::Resource> &resources,
const f_resource_graph_t &g)
{
m_trav_level++;
return 0;
}
/*
* Called back on each post-up visit of the auxiliary subsystem. Should
* return a score calculated based on the subtree and up walks using the score
* API object (dfu). Any score aboved MATCH_MET is qualified to be a match.
*
* \param u descriptor of the visiting vertex
* \param subsystem subsytem_t object of an auxiliary subsystem
* \param resources vector of resources to be matched
* \param g filtered resource graph object
* \param dfu score interface object - TODO: document
*
* \return return 0 on success; otherwise -1
*/
virtual int aux_finish_vtx (vtx_t u, const subsystem_t &subsystem,
const std::vector<Flux::Jobspec::Resource> &resources,
const f_resource_graph_t &g, scoring_api_t &dfu)
{
m_trav_level--;
return 0;
}
void incr ()
{
m_trav_level++;
}
void decr ()
{
m_trav_level--;
}
std::string level ()
{
int i;
std::string prefix = "";
for (i = 0; i < m_trav_level; ++i)
prefix += "----";
return prefix;
}
private:
int m_trav_level;
};
} // namespace resource_model
} // namespace Flux
#endif // DFU_MATCH_CB_HPP
/*
* vi:tabstop=4 shiftwidth=4 expandtab
*/