]> SALOME platform Git repositories - modules/yacs.git/blob - src/engine/Executor.hxx
Salome HOME
Work in progress : workload manager engine test ok
[modules/yacs.git] / src / engine / Executor.hxx
1 // Copyright (C) 2006-2019  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
20 #ifndef __EXECUTOR_HXX__
21 #define __EXECUTOR_HXX__
22
23 #include "YACSlibEngineExport.hxx"
24 #include "Mutex.hxx"
25 #include "Thread.hxx"
26 #include "Semaphore.hxx"
27 #include "Exception.hxx"
28 #include "define.hxx"
29
30 #ifdef WIN32
31 #include <windows.h>
32 #pragma comment(lib,"winmm.lib")
33 #endif
34 #include <list>
35 #include <vector>
36 #include <set>
37 #include <string>
38 #include <fstream>
39 #include <ctime>
40 #include <chrono>
41
42 namespace YACS
43 {
44   namespace ENGINE
45   {
46     class Scheduler;
47     class ComposedNode;
48     class Task;
49     
50 /*! \brief Threaded Executor 
51  *
52  * \ingroup Executors
53  *
54  *
55  */
56     class YACSLIBENGINE_EXPORT Executor
57     {
58     protected:
59       Scheduler *_mainSched;
60       ComposedNode *_root;
61       int _nbOfConcurrentThreads;
62       YACS::BASES::Mutex _mutexForNbOfConcurrentThreads;
63       YACS::BASES::Condition _condForNewTasksToPerform;
64       YACS::BASES::Semaphore _semForMaxThreads;
65       YACS::BASES::Condition _condForStepByStep;
66       YACS::BASES::Condition _condForPilot;
67       YACS::BASES::Mutex _mutexForSchedulerUpdate;
68       YACS::BASES::Mutex _mutexForTrace;
69       bool _toContinue;
70       bool _isOKToEnd;
71       bool _stopOnErrorRequested;
72       bool _dumpOnErrorRequested;
73       bool _errorDetected;
74       bool _isRunningunderExternalControl;
75       bool _isWaitingEventsFromRunningTasks;
76       int _numberOfRunningTasks;
77       std::set<Task *> _runningTasks; 
78       int _numberOfEndedTasks;
79       int _semThreadCnt;
80       YACS::ExecutorState _executorState;
81       YACS::ExecutionMode _execMode;
82       std::list<std::string> _listOfBreakPoints;
83       std::list<std::string> _listOfTasksToLoad;
84       std::vector<Task *> _tasks; 
85       std::vector<Task *> _tasksSave; 
86       std::list< YACS::BASES::Thread * > _groupOfAllThreadsCreated;
87       std::ofstream _trace;
88       std::string _dumpErrorFile;
89       bool _keepGoingOnFail;
90       //! specifies if scope DynParaLoop is active or not. False by default.
91       bool _DPLScopeSensitive;
92       std::chrono::steady_clock::time_point _start;
93     public:
94       Executor();
95       virtual ~Executor();
96       void RunA(Scheduler *graph,int debug=0, bool fromScratch=true);
97       void RunW(Scheduler *graph,int debug=0, bool fromScratch=true)
98       {
99         //RunB(graph, debug, fromScratch);
100         newRun(graph, debug, fromScratch);
101       }
102       void RunB(Scheduler *graph,int debug=0, bool fromScratch=true);
103       void newRun(Scheduler *graph,int debug=0, bool fromScratch=true);
104       void setKeepGoingProperty(bool newVal) { _keepGoingOnFail=newVal; }
105       bool getKeepGoingProperty() const { return _keepGoingOnFail; }
106       void setDPLScopeSensitive(bool newVal) { _DPLScopeSensitive=newVal; }
107       bool getDPLScopeSensitive() const { return _DPLScopeSensitive; }
108       YACS::ExecutionMode getCurrentExecMode();
109       YACS::ExecutorState getExecutorState();
110       void setExecMode(YACS::ExecutionMode mode);
111       void setListOfBreakPoints(std::list<std::string> listOfBreakPoints);
112       std::list<std::string> getTasksToLoad();
113       bool setStepsToExecute(std::list<std::string> listToExecute);
114       bool resumeCurrentBreakPoint();
115       bool isNotFinished();
116       void stopExecution();
117       bool saveState(const std::string& xmlFile);
118       bool loadState();
119       int getNbOfThreads();
120       int getNumberOfRunningTasks() const { return _numberOfRunningTasks; }
121       void displayDot(Scheduler *graph);
122       void setStopOnError(bool dumpRequested=false, std::string xmlFile="");
123       void unsetStopOnError();
124       void waitPause();
125       bool suspendASAP();
126       void resume(bool suspended);
127       static int _maxThreads;
128       static size_t _threadStackSize;
129       YACS::BASES::Mutex& getTheMutexForSchedulerUpdate() { return _mutexForSchedulerUpdate; }
130       ///// new executor !!!!!
131       void loadTask(Task *task);
132       YACS::Event runTask(Task *task);
133       void makeDatastreamConnections(Task *task);
134       void beginTask(Task *task);
135       void endTask(Task *task, YACS::Event ev);
136       ////////////
137     protected:
138       bool checkBreakPoints();
139       void waitResume();
140       void loadTask(Task *task, const Executor *execInst);
141       void loadParallelTasks(const std::vector<Task *>& tasks, const Executor *execInst);
142       void launchTasks(const std::vector<Task*>& tasks);
143       void launchTask(Task *task);
144       void wakeUp();
145       void sleepWhileNoEventsFromAnyRunningTask();
146       void notifyEndOfThread(YACS::BASES::Thread *thread);
147       void traceExec(Task *task, const std::string& message, const std::string& placement);
148       void _displayDot(Scheduler *graph);
149       virtual void sendEvent(const std::string& event);
150       static void FilterTasksConsideringContainers(std::vector<Task *>& tsks);
151       static std::string ComputePlacement(Task *zeTask);
152     protected:
153       static void *functionForTaskLoad(void *);
154       static void *functionForTaskExecution(void *);
155     };
156   }
157 }
158
159 #endif