aGrUM 2.3.2
a C++ library for (probabilistic) graphical models
schedulerSequential.h
Go to the documentation of this file.
1/****************************************************************************
2 * This file is part of the aGrUM/pyAgrum library. *
3 * *
4 * Copyright (c) 2005-2025 by *
5 * - Pierre-Henri WUILLEMIN(_at_LIP6) *
6 * - Christophe GONZALES(_at_AMU) *
7 * *
8 * The aGrUM/pyAgrum library is free software; you can redistribute it *
9 * and/or modify it under the terms of either : *
10 * *
11 * - the GNU Lesser General Public License as published by *
12 * the Free Software Foundation, either version 3 of the License, *
13 * or (at your option) any later version, *
14 * - the MIT license (MIT), *
15 * - or both in dual license, as here. *
16 * *
17 * (see https://agrum.gitlab.io/articles/dual-licenses-lgplv3mit.html) *
18 * *
19 * This aGrUM/pyAgrum library is distributed in the hope that it will be *
20 * useful, but WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, *
21 * INCLUDING BUT NOT LIMITED TO THE WARRANTIES MERCHANTABILITY or FITNESS *
22 * FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE *
23 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER *
24 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, *
25 * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR *
26 * OTHER DEALINGS IN THE SOFTWARE. *
27 * *
28 * See LICENCES for more details. *
29 * *
30 * SPDX-FileCopyrightText: Copyright 2005-2025 *
31 * - Pierre-Henri WUILLEMIN(_at_LIP6) *
32 * - Christophe GONZALES(_at_AMU) *
33 * SPDX-License-Identifier: LGPL-3.0-or-later OR MIT *
34 * *
35 * Contact : info_at_agrum_dot_org *
36 * homepage : http://agrum.gitlab.io *
37 * gitlab : https://gitlab.com/agrumery/agrum *
38 * *
39 ****************************************************************************/
40
41
47
48#ifndef GUM_SCHEDULER_SEQUENTIAL_H
49#define GUM_SCHEDULER_SEQUENTIAL_H
50
51#include <algorithm>
52#include <vector>
53
54#include <agrum/agrum.h>
55
57
58namespace gum {
59
61 public:
62 // ############################################################################
64 // ############################################################################
66
68 explicit SchedulerSequential(Size max_nb_threads = 0, double max_megabyte_memory = 0.0);
69
72
75
77 SchedulerSequential* clone() const final;
78
81
83
84 // ############################################################################
86 // ############################################################################
88
90
95 void setMaxMemory(double megabytes) final;
96
98 void execute(Schedule&) final;
99
102 double nbOperations(const Schedule&) final;
103
105
112 std::pair< double, double > memoryUsage(const Schedule&) final;
113
115
116
117 private:
120
122 std::vector< NodeId > _operations_;
123
125 std::pair< double, double > _memory_usage_{0.0, 0.0};
126
129
137
139 void _setSchedule_(const Schedule& schedule);
140
144 Size _addExecutableOps_(std::vector< UnexecutedOperation >& unexecuted_deletions,
145 std::vector< UnexecutedOperation >& unexecuted_operations,
146 bool& unexecuted_deletions_sorted,
147 bool& unexecuted_operations_sorted,
148 double memory_used,
149 double max_memory,
150 List< NodeId >& available_nodes) const;
151
156 const NodeId node,
157 std::vector< NodeId >& new_available_nodes) const;
158
162 DAG& dag,
163 List< NodeId >& available_nodes,
164 std::vector< NodeId >& new_available_nodes);
165
168
170 static bool _cmp_(const UnexecutedOperation& a, const UnexecutedOperation& b);
171
173 // template<typename ITER, typename CMP>
174 // friend void std::sort(ITER, ITER, CMP);
175 };
176
177} /* namespace gum */
178
179// include the inlined functions if necessary
180#ifndef GUM_NO_INLINE
182#endif /* GUM_NO_INLINE */
183
184#endif /* GUM_SCHEDULER_SEQUENTIAL_H */
Base class for dag.
Definition DAG.h:121
Generic doubly linked lists.
Definition list.h:379
the base class for "low-level" operators used to schedule inferences
Class containing a schedule of operations to perform on multidims.
Definition schedule.h:80
SchedulerSequential(SchedulerSequential &&from)
move constructor
void _simulateExecuteOneOperation_(const NodeId node, ScheduleOperator &op, DAG &dag, List< NodeId > &available_nodes, std::vector< NodeId > &new_available_nodes)
simulate the execution of one operation
SchedulerSequential * clone() const final
virtual copy constructor
void _setSchedule_(const Schedule &schedule)
sets a schedule and updates the set of operations if necessary
Size _addExecutableOps_(std::vector< UnexecutedOperation > &unexecuted_deletions, std::vector< UnexecutedOperation > &unexecuted_operations, bool &unexecuted_deletions_sorted, bool &unexecuted_operations_sorted, double memory_used, double max_memory, List< NodeId > &available_nodes) const
add the currently executable deletions into the set of available operations
SchedulerSequential(const SchedulerSequential &from)
copy constructor
SchedulerSequential(Size max_nb_threads=0, double max_megabyte_memory=0.0)
default constructor
std::vector< NodeId > _operations_
the sequence of operations to perform
Schedule * _schedule_
the schedule we wish to execute
void setMaxMemory(double megabytes) final
sets an upper bound on the memory consumption admissible
void _simulateExecution_()
simulate the execution of the whole schedule
double nbOperations(const Schedule &) final
returns an estimation of the number of elementary operations needed to perform a given schedule
std::pair< double, double > _memory_usage_
the memory usage for the sequence of operations;
void execute(Schedule &) final
execute all the operations of a given schedule
std::pair< double, double > memoryUsage(const Schedule &) final
returns the memory consumption used during the execution of a schedule
static bool _cmp_(const UnexecutedOperation &a, const UnexecutedOperation &b)
the comparison function used to sort unexecutable operations
bool _operations_up_to_date_
is the set of operations up to date
void _simulateDAGUpdate_(DAG &dag, const NodeId node, std::vector< NodeId > &new_available_nodes) const
simulate the update of the schedule's DAG resulting from the execution of an operation
Scheduler(Size nb_threads=0, double max_megabyte_memory=0.0)
default constructor
std::size_t Size
In aGrUM, hashed values are unsigned long int.
Definition types.h:74
Size NodeId
Type for node ids.
gum is the global namespace for all aGrUM entities
Definition agrum.h:46
STL namespace.
a scheduler that executes any available operation (chosen aribtrarily)
the common interface of all the schedulers
a structure to keep informations about operations that could not be executed due to memory usage limi...