1 // Copyright (C) 2020 CEA/DEN, EDF R&D
3 // This library is free software; you can redistribute it and/or
4 // modify it under the terms of the GNU Lesser General Public
5 // License as published by the Free Software Foundation; either
6 // version 2.1 of the License, or (at your option) any later version.
8 // This library is distributed in the hope that it will be useful,
9 // but WITHOUT ANY WARRANTY; without even the implied warranty of
10 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
11 // Lesser General Public License for more details.
13 // You should have received a copy of the GNU Lesser General Public
14 // License along with this library; if not, write to the Free Software
15 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
17 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
19 #ifndef ALGORITHMIMPLEMENT_H
20 #define ALGORITHMIMPLEMENT_H
22 #include "WorkloadAlgorithm.hxx"
27 namespace WorkloadManager
32 class DefaultAlgorithm : public WorkloadAlgorithm
35 void addTask(Task* t)override;
36 void addResource(Resource* r)override;
37 LaunchInfo chooseTask()override;
38 void liberate(const LaunchInfo& info)override;
39 bool empty()const override;
41 // ----------------------------- PRIVATE ----------------------------- //
43 class ResourceInfoForContainer
46 ResourceInfoForContainer(const Resource * r, const ContainerType* ctype);
47 unsigned int maxContainers()const;
49 void free(unsigned int index);
50 unsigned int nbRunningContainers()const;
51 bool isContainerRunning(unsigned int index)const;
53 const ContainerType* _ctype;
54 const Resource* _resource;
55 std::set<unsigned int> _runningContainers;
56 unsigned int _firstFreeContainer;
59 class ResourceLoadInfo
62 ResourceLoadInfo(const Resource * r);
63 bool isSupported(const ContainerType* ctype)const;
64 bool isAllocPossible(const ContainerType* ctype)const;
65 float cost(const ContainerType* ctype)const;
66 unsigned int alloc(const ContainerType* ctype);
67 void free(const ContainerType* ctype, int index);
69 const Resource* _resource;
71 std::map<const ContainerType*, ResourceInfoForContainer> _ctypes;
75 std::map<const Resource *, ResourceLoadInfo> _resources;
76 std::list<Task*> _waitingTasks;
79 #endif // ALGORITHMIMPLEMENT_H