]> SALOME platform Git repositories - modules/yacs.git/blob - src/workloadmanager/Task.hxx
Salome HOME
Work in progress : workload manager step 2
[modules/yacs.git] / src / workloadmanager / Task.hxx
1 // Copyright (C) 2020  CEA/DEN, EDF R&D
2 //
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.
7 //
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.
12 //
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
16 //
17 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
18 //
19 #ifndef _TASK_H_
20 #define _TASK_H_
21
22 #include <string>
23
24 namespace WorkloadManager
25 {
26   struct ContainerType
27   {
28     // parameters needed by WorkloadManager
29     float neededCores = 0.0;
30     bool ignoreResources = false; // if true, the task can be run as soon as
31                                   // added to the manager without any resource
32                                   // allocation
33     // parameters for client use, used by WorkloadManager to distinguish objects
34     std::string name;
35     int id = 0;
36     bool operator==(const ContainerType& other)const
37     { return id == other.id && name == other.name;}
38     bool operator<(const ContainerType& other)const
39     {
40       return (id < other.id) ||
41              (id == other.id && name < other.name);
42     }
43   };
44   
45   struct Resource
46   {
47     unsigned int nbCores = 0; // needed by WorkloadManager
48     // parameters for client use, used by WorkloadManager to distinguish objects
49     std::string name;
50     int id = 0;
51     bool operator==(const Resource& other)const
52     { return id == other.id && name == other.name;}
53     bool operator<(const Resource& other)const
54     {
55       return (id < other.id) ||
56              (id == other.id && name < other.name);
57     }
58   };
59   
60   struct RunInfo
61   {
62     ContainerType type;
63     Resource resource;
64     unsigned int index=0; // worker index on the resource for this type
65   };
66
67   /**
68   * @todo write docs
69   */
70   class Task
71   {
72   public:
73     virtual ~Task(){};
74     virtual const ContainerType& type()const =0;
75     virtual void run(const RunInfo& c)=0;
76
77     // Is it possible to run the task on this resource?
78     virtual bool isAccepted(const Resource& r)
79     {
80       // by default, a task can be run on any resource.
81       return true;
82     }
83   };
84 }
85
86 #endif // _TASK_H_