1 // Copyright (C) 2006-2019 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
20 #ifndef __EXECUTOR_HXX__
21 #define __EXECUTOR_HXX__
23 #include "YACSlibEngineExport.hxx"
26 #include "Semaphore.hxx"
27 #include "Exception.hxx"
32 #pragma comment(lib,"winmm.lib")
42 namespace WorkloadManager
55 /*! \brief Threaded Executor
61 class YACSLIBENGINE_EXPORT Executor
64 Scheduler *_mainSched;
66 int _nbOfConcurrentThreads;
67 YACS::BASES::Mutex _mutexForNbOfConcurrentThreads;
68 YACS::BASES::Condition _condForNewTasksToPerform;
69 YACS::BASES::Semaphore _semForMaxThreads;
70 YACS::BASES::Condition _condForStepByStep;
71 YACS::BASES::Condition _condForPilot;
72 YACS::BASES::Mutex _mutexForSchedulerUpdate;
73 YACS::BASES::Mutex _mutexForTrace;
76 bool _stopOnErrorRequested;
77 bool _dumpOnErrorRequested;
79 bool _isRunningunderExternalControl;
80 bool _isWaitingEventsFromRunningTasks;
81 int _numberOfRunningTasks;
82 std::set<Task *> _runningTasks;
83 int _numberOfEndedTasks;
85 YACS::ExecutorState _executorState;
86 YACS::ExecutionMode _execMode;
87 std::list<std::string> _listOfBreakPoints;
88 std::list<std::string> _listOfTasksToLoad;
89 std::vector<Task *> _tasks;
90 std::vector<Task *> _tasksSave;
91 std::list< YACS::BASES::Thread * > _groupOfAllThreadsCreated;
93 std::string _dumpErrorFile;
94 bool _keepGoingOnFail;
95 //! specifies if scope DynParaLoop is active or not. False by default.
96 bool _DPLScopeSensitive;
97 std::chrono::steady_clock::time_point _start;
101 void RunA(Scheduler *graph,int debug=0, bool fromScratch=true);
102 void RunW(Scheduler *graph,int debug=0, bool fromScratch=true);
103 void RunB(Scheduler *graph,int debug=0, bool fromScratch=true);
104 void runWlm(Scheduler *graph,int debug=0, bool fromScratch=true);
105 void setKeepGoingProperty(bool newVal) { _keepGoingOnFail=newVal; }
106 bool getKeepGoingProperty() const { return _keepGoingOnFail; }
107 void setDPLScopeSensitive(bool newVal) { _DPLScopeSensitive=newVal; }
108 bool getDPLScopeSensitive() const { return _DPLScopeSensitive; }
109 YACS::ExecutionMode getCurrentExecMode();
110 YACS::ExecutorState getExecutorState();
111 void setExecMode(YACS::ExecutionMode mode);
112 void setListOfBreakPoints(std::list<std::string> listOfBreakPoints);
113 std::list<std::string> getTasksToLoad();
114 bool setStepsToExecute(std::list<std::string> listToExecute);
115 bool resumeCurrentBreakPoint();
116 bool isNotFinished();
117 void stopExecution();
118 bool saveState(const std::string& xmlFile);
120 int getNbOfThreads();
121 int getNumberOfRunningTasks() const { return _numberOfRunningTasks; }
122 void displayDot(Scheduler *graph);
123 void setStopOnError(bool dumpRequested=false, std::string xmlFile="");
124 void unsetStopOnError();
127 void resume(bool suspended);
128 static int _maxThreads;
129 static size_t _threadStackSize;
130 YACS::BASES::Mutex& getTheMutexForSchedulerUpdate() { return _mutexForSchedulerUpdate; }
131 ///// new executor !!!!!
132 void loadTask(Task *task, const WorkloadManager::RunInfo& runInfo);
133 YACS::Event runTask(Task *task);
134 void makeDatastreamConnections(Task *task);
135 void beginTask(Task *task);
136 void endTask(Task *task, YACS::Event ev);
139 bool checkBreakPoints();
141 void loadTask(Task *task, const Executor *execInst);
142 void loadParallelTasks(const std::vector<Task *>& tasks, const Executor *execInst);
143 void launchTasks(const std::vector<Task*>& tasks);
144 void launchTask(Task *task);
146 void sleepWhileNoEventsFromAnyRunningTask();
147 void notifyEndOfThread(YACS::BASES::Thread *thread);
148 void traceExec(Task *task, const std::string& message, const std::string& placement);
149 void _displayDot(Scheduler *graph);
150 virtual void sendEvent(const std::string& event);
151 static void FilterTasksConsideringContainers(std::vector<Task *>& tsks);
152 static std::string ComputePlacement(Task *zeTask);
154 static void *functionForTaskLoad(void *);
155 static void *functionForTaskExecution(void *);