forked from dongahn/resource-query
-
Notifications
You must be signed in to change notification settings - Fork 0
/
dfu_traverse.hpp
139 lines (125 loc) · 6.22 KB
/
dfu_traverse.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
/*****************************************************************************\
* 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_TRAVERSE_HPP
#define DFU_TRAVERSE_HPP
#include <iostream>
#include <cstdlib>
#include "dfu_traverse_impl.hpp"
namespace Flux {
namespace resource_model {
/*! Depth-First-and-Up traverser. Perform depth-first visit on the dominant
* subsystem and upwalk on each and all of the auxiliary subsystems selected
* by the matcher callback object (dfu_match_cb_t). Corresponding match
* callback methods are invoked at various well-defined graph visit events.
*/
class dfu_traverser_t : protected detail::dfu_impl_t
{
public:
dfu_traverser_t ();
dfu_traverser_t (f_resource_graph_t *g,
dfu_match_cb_t *m, std::map<subsystem_t, vtx_t> *roots);
dfu_traverser_t (const dfu_traverser_t &o);
dfu_traverser_t &operator= (const dfu_traverser_t &o);
~dfu_traverser_t ();
const f_resource_graph_t *get_graph () const;
const std::map<subsystem_t, vtx_t> *get_roots () const;
const dfu_match_cb_t *get_match_cb () const;
const std::string &err_message () const;
void set_graph (f_resource_graph_t *g);
void set_roots (std::map<subsystem_t, vtx_t> *roots);
void set_match_cb (dfu_match_cb_t *m);
void clear_err_message ();
/*! Prime the resource graph with subtree plans. Assume resource graph,
* roots and match callback have already been registered. The subtree
* plans are instantiated on certain resource vertices and updated with the
* information on their subtree resources. For example, the subtree plan
* of a compute node resource vertex can be configured to track the number
* of available compute cores in aggregate at its subtree. dfu_match_cb_t
* provides an interface to tell this initializer what subtree resources
* to track at higher-level resource vertices.
*
* \return 0 on success; -1 on error.
* EINVAL: graph, roots or match callback not set.
* ENOTSUP: roots does not contain a subsystem
* the match callback object need to use.
*/
int initialize ();
/*! Prime the resource graph with subtree plans. Assume resource graph,
* roots and match callback have already been registered. The subtree
* plans are instantiated on certain resource vertices and updated with the
* information on their subtree resources. For example, the subtree plan
* of a compute node resource vertex can be configured to track the number
* of available compute cores in aggregate at its subtree. dfu_match_cb_t
* provides an interface to tell this initializer what subtree resources
* to track at higher-level resource vertices.
*
* \param g resource graph of f_resource_graph_t type.
* \param roots map of root vertices, each is a root of a subsystem.
* \param m match callback object of dfu_match_cb_t type.
* \return 0 on success; -1 on error.
* EINVAL: graph, roots or match callback not set.
* ENOTSUP: roots does not contain a subsystem
* the match callback uses.
*/
int initialize (f_resource_graph_t *g, std::map<subsystem_t, vtx_t> *roots,
dfu_match_cb_t *m);
/*! Begin a graph traversal for the jobspec and either allocate or
* reserve the resources in the resource graph. Best-matching resources
* are selected in accordance to the scoring done by the match callback
* methods. Initialization must have successfully finished before this
* method is called.
*
* \param jobspec Jobspec object.
* \param op schedule operation.
* allocate or allocate_orelse_reserve.
* \param id job ID to use for the schedule operation.
* \param at[out] when the job is scheduled if reserved.
* \param ss stringstream into which emitted R infor is stored.
* \return 0 on success; -1 on error.
* EINVAL: graph, roots or match callback not set.
* ENOTSUP: roots does not contain a subsystem the
* match callback uses.
*/
int run (Jobspec::Jobspec &jobspec, match_op_t op, int64_t id, int64_t *at,
std::stringstream &ss);
/*! Remove the allocation/reservation referred to by jobid and update
* the resource state.
*
* \param jobid job id.
* \return 0 on success; -1 on error.
* EINVAL: graph, roots or match callback not set.
*/
int remove (int64_t jobid);
private:
int schedule (Jobspec::Jobspec &jobspec,
detail::jobmeta_t &meta, bool x, match_op_t op,
vtx_t root, unsigned int *needs,
std::unordered_map<std::string, int64_t> &dfv);
};
} // namespace resource_model
} // namespace Flux
#endif // DFU_TRAVERSE_HPP
/*
* vi:tabstop=4 shiftwidth=4 expandtab
*/