Salome HOME
[EDF30062] and [EDF30014] : addition of --activate-custom-overrides parameter in...
[modules/yacs.git] / src / workloadmanager / Task.hxx
1 // Copyright (C) 2020-2024  CEA, EDF
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 "YACSlibWorkloadmanagerExport.hxx"
23
24 #include <string>
25
26 namespace WorkloadManager
27 {
28   struct YACSLIBWLM_EXPORT ContainerType
29   {
30     // parameters needed by WorkloadManager
31     float neededCores = 0.0;
32     bool ignoreResources = false; // if true, the task can be run as soon as
33                                   // added to the manager without any resource
34                                   // allocation
35     // parameters for client use, used by WorkloadManager to distinguish objects
36     std::string name;
37     int id = 0;
38     bool operator==(const ContainerType& other)const
39     { return id == other.id && name == other.name;}
40     bool operator<(const ContainerType& other)const
41     {
42       return (id < other.id) ||
43              (id == other.id && name < other.name);
44     }
45   };
46
47   struct YACSLIBWLM_EXPORT Resource
48   {
49     unsigned int nbCores = 0; // needed by WorkloadManager
50     // parameters for client use, used by WorkloadManager to distinguish objects
51     std::string name;
52     int id = 0;
53     bool operator==(const Resource& other)const
54     { return id == other.id && name == other.name;}
55     bool operator<(const Resource& other)const
56     {
57       return (id < other.id) ||
58              (id == other.id && name < other.name);
59     }
60   };
61
62   struct YACSLIBWLM_EXPORT RunInfo
63   {
64     ContainerType type;
65     Resource resource;
66     unsigned int index=0; // worker index on the resource for this type
67     bool isOk = true;
68     std::string error_message = "";
69   };
70
71   /**
72   * @todo write docs
73   */
74   class YACSLIBWLM_EXPORT Task
75   {
76   public:
77     virtual ~Task(){};
78     virtual const ContainerType& type()const =0;
79     virtual void run(const RunInfo& c)=0;
80
81     // Is it possible to run the task on this resource?
82     virtual bool isAccepted(const Resource& r)
83     {
84       // by default, a task can be run on any resource.
85       return true;
86     }
87   };
88 }
89
90 #endif // _TASK_H_