forked from dongahn/resource-query
-
Notifications
You must be signed in to change notification settings - Fork 0
/
dfu_traverse.cpp
223 lines (190 loc) · 6.81 KB
/
dfu_traverse.cpp
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
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
/*****************************************************************************\
* 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/
\*****************************************************************************/
#include <iostream>
#include <cstdlib>
#include "dfu_traverse.hpp"
extern "C" {
#if HAVE_CONFIG_H
#include "config.h"
#endif
}
using namespace std;
using namespace Flux::resource_model;
using namespace Flux::resource_model::detail;
using namespace Flux::Jobspec;
/****************************************************************************
* *
* DFU Traverser Private API Definitions *
* *
****************************************************************************/
int dfu_traverser_t::schedule (Jobspec::Jobspec &jobspec,
detail::jobmeta_t &meta, bool x, match_op_t op,
vtx_t root, unsigned int *needs,
std::unordered_map<string, int64_t> &dfv)
{
int rc = -1;
const subsystem_t &dom = get_match_cb ()->dom_subsystem ();
/* Allocate */
rc = detail::dfu_impl_t::select (jobspec, root, meta, x, needs);
if ((rc != 0) && (op == match_op_t::MATCH_ALLOCATE_ORELSE_RESERVE)) {
/* Or else reserve */
meta.allocate = false;
int64_t t = meta.at + 1;
vector<uint64_t> agg;
planner_t *p = (*get_graph ())[root].idata.subplans.at (dom);
size_t len = planner_resources_len (p);
detail::dfu_impl_t::count (p, dfv, agg);
for (t = planner_avail_time_first (p, t, meta.duration, &agg[0], len);
(t != -1 && rc != 0); t = planner_avail_time_next (p)) {
meta.at = t;
rc = detail::dfu_impl_t::select (jobspec, root, meta, x, needs);
}
}
return rc;
}
/****************************************************************************
* *
* DFU Traverser Public API Definitions *
* *
****************************************************************************/
dfu_traverser_t::dfu_traverser_t ()
{
}
dfu_traverser_t::dfu_traverser_t (f_resource_graph_t *g, dfu_match_cb_t *m,
map<subsystem_t, vtx_t> *roots)
: detail::dfu_impl_t (g, m, roots)
{
}
dfu_traverser_t::dfu_traverser_t (const dfu_traverser_t &o)
: detail::dfu_impl_t (o)
{
}
dfu_traverser_t &dfu_traverser_t::operator= (const dfu_traverser_t &o)
{
detail::dfu_impl_t::operator= (o);
return *this;
}
dfu_traverser_t::~dfu_traverser_t ()
{
}
const f_resource_graph_t *dfu_traverser_t::get_graph () const
{
return detail::dfu_impl_t::get_graph ();
}
const map<subsystem_t, vtx_t> *dfu_traverser_t::get_roots () const
{
return detail::dfu_impl_t::get_roots ();
}
const dfu_match_cb_t *dfu_traverser_t::get_match_cb () const
{
return detail::dfu_impl_t::get_match_cb ();
}
const string &dfu_traverser_t::err_message () const
{
return detail::dfu_impl_t::err_message ();
}
void dfu_traverser_t::set_graph (f_resource_graph_t *g)
{
detail::dfu_impl_t::set_graph (g);
}
void dfu_traverser_t::set_roots (map<subsystem_t, vtx_t> *roots)
{
detail::dfu_impl_t::set_roots (roots);
}
void dfu_traverser_t::set_match_cb (dfu_match_cb_t *m)
{
detail::dfu_impl_t::set_match_cb (m);
}
void dfu_traverser_t::clear_err_message ()
{
detail::dfu_impl_t::clear_err_message ();
}
int dfu_traverser_t::initialize ()
{
int rc = 0;
vtx_t root;
if (!get_graph () || !get_roots () || !get_match_cb ()) {
errno = EINVAL;
return -1;
}
for (auto &subsystem : get_match_cb ()->subsystems ()) {
map<string, int64_t> from_dfv;
if (get_roots ()->find (subsystem) == get_roots ()->end ()) {
errno = ENOTSUP;
rc = -1;
break;
}
root = get_roots ()->at(subsystem);
rc += detail::dfu_impl_t::prime (subsystem, root, from_dfv);
}
return rc;
}
int dfu_traverser_t::initialize (f_resource_graph_t *g,
map<subsystem_t, vtx_t> *roots,
dfu_match_cb_t *m)
{
set_graph (g);
set_roots (roots);
set_match_cb (m);
return initialize ();
}
int dfu_traverser_t::run (Jobspec::Jobspec &jobspec, match_op_t op,
int64_t jobid, int64_t *at, stringstream &ss)
{
const subsystem_t &dom = get_match_cb ()->dom_subsystem ();
if (!get_graph () || !get_roots ()
|| get_roots ()->find (dom) == get_roots ()->end ()
|| !get_match_cb () || jobspec.resources.empty ()) {
errno = EINVAL;
return -1;
}
int rc = -1;
detail::jobmeta_t meta;
unsigned int needs = 0;
vtx_t root = get_roots ()->at(dom);
bool x = detail::dfu_impl_t::exclusivity (jobspec.resources, root);
std::unordered_map<string, int64_t> dfv;
detail::dfu_impl_t::prime (jobspec.resources, dfv);
meta.build (jobspec, true, jobid, *at);
if ( (rc = schedule (jobspec, meta, x, op, root, &needs, dfv)) == 0) {
*at = meta.at;
rc = detail::dfu_impl_t::update (root, meta, needs, x, ss);
}
return rc;
}
int dfu_traverser_t::remove (int64_t jobid)
{
const subsystem_t &dom = get_match_cb ()->dom_subsystem ();
if (!get_graph () || !get_roots ()
|| get_roots ()->find (dom) == get_roots ()->end ()
|| !get_match_cb ()) {
errno = EINVAL;
return -1;
}
vtx_t root = get_roots ()->at(dom);
return detail::dfu_impl_t::remove (root, jobid);
}
/*
* vi:tabstop=4 shiftwidth=4 expandtab
*/