-
Notifications
You must be signed in to change notification settings - Fork 1
/
matcher_data.hpp
194 lines (177 loc) · 5.89 KB
/
matcher_data.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
/*****************************************************************************\
* 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 MATCHER_DATA_HPP
#define MATCHER_DATA_HPP
#include <string>
#include <iostream>
#include <vector>
#include <set>
#include <map>
#include "jobspec.hpp"
#include "planner/planner.h"
namespace Flux {
namespace resource_model {
enum match_score_t {
MATCH_UNMET = 0,
MATCH_MET = 1
};
enum class match_op_t {
MATCH_ALLOCATE,
MATCH_ALLOCATE_ORELSE_RESERVE
};
/*! Base matcher data class.
* Provide idioms to specify the target subsystems and
* resource relationship types which then allow resource-query
* or later resource module to filter the graph data store
* for the match callback object.
*/
class matcher_data_t
{
public:
matcher_data_t () : m_name ("anonymous") { }
matcher_data_t (const std::string &name) : m_name (name) { }
matcher_data_t (const matcher_data_t &o)
{
sdau_resource_types = o.sdau_resource_types;
m_name = o.m_name;
m_subsystems = o.m_subsystems;
m_subsystems_map = o.m_subsystems_map;
}
matcher_data_t &operator=(const matcher_data_t &o)
{
sdau_resource_types = o.sdau_resource_types;
m_name = o.m_name;
m_subsystems = o.m_subsystems;
m_subsystems_map = o.m_subsystems_map;
return *this;
}
~matcher_data_t ()
{
sdau_resource_types.clear ();
m_subsystems.clear ();
m_subsystems_map.clear ();
}
/*! Add a subsystem and the relationship type that this resource base
* matcher will use. Vertices and edges of the resource graph are
* filtered in based on this information. Each vertex and edge that
* is a part of this subsystem and relationship type will be selected.
*
* This method must be called at least once to set the dominant
* subsystem to use. This method can be called multiple times with
* a distinct subsystem, each becomes an auxiliary subsystem.
* The queuing order can be reconstructed get_subsystems.
*
* \param subsystem subsystem to select
* \param tf edge (or relation type) to select.
* pass * for selecting all types
* \return 0 on success; -1 on error
*/
int add_subsystem (const subsystem_t s, const std::string tf = "*")
{
if (m_subsystems_map.find (s) == m_subsystems_map.end ()) {
m_subsystems.push_back (s);
m_subsystems_map[s].insert (tf);
return 0;
}
return -1;
}
const std::string &matcher_name () const
{
return m_name;
}
void set_matcher_name (const std::string &name)
{
m_name = name;
}
const std::vector<subsystem_t> &subsystems () const
{
return m_subsystems;
}
/*
* \return return the dominant subsystem this matcher has
* selected to use.
*/
const subsystem_t &dom_subsystem () const
{
return *(m_subsystems.begin());
}
/*
* \return return the subsystem selector to be used for
* graph filtering.
*/
const multi_subsystemsS &subsystemsS () const
{
return m_subsystems_map;
}
std::map<subsystem_t, std::set<std::string> > sdau_resource_types;
unsigned int select_count (const Flux::Jobspec::Resource &resource,
unsigned int qc) const
{
if (resource.count.min > resource.count.max
|| resource.count.min > qc)
return 0;
unsigned int count = 0;
unsigned int cur = resource.count.min;
switch (resource.count.oper) {
case '+':
while (cur <= qc && cur <= resource.count.max) {
count = cur;
cur += resource.count.operand;
}
break;
case '*':
while (cur <= qc && cur <= resource.count.max) {
count = cur;
cur *= resource.count.operand;
}
break;
case '^':
if (resource.count.operand < 2)
count = cur;
else {
while (cur <= qc && cur <= resource.count.max) {
unsigned int base = cur;
count = cur;
for (int i = 1;
i < resource.count.operand; i++)
cur *= base;
}
}
break;
default:
break;
}
return count;
}
private:
std::string m_name;
std::vector<subsystem_t> m_subsystems;
multi_subsystemsS m_subsystems_map;
};
} // namespace resource_model
} // namespace Flux
#endif // MATCHER_DATA_HPP
/*
* vi:tabstop=4 shiftwidth=4 expandtab
*/