Skip to content

Commit e9a9eb9

Browse files
Added condition for not terminating on the last task
1 parent 470b4c7 commit e9a9eb9

File tree

1 file changed

+14
-2
lines changed

1 file changed

+14
-2
lines changed

include/taskr/runtime.hpp

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -175,13 +175,15 @@ class Runtime
175175
_minimumActiveTaskWorkers = 1; // Guarantee that there is at least one active task worker
176176
_serviceWorkerCount = 0; // No service workers (Typical setting for HPC applications)
177177
_makeTaskWorkersRunServices = false; // Since no service workers are created by default, have task workers check on services
178+
_finishOnLastTask = true; // Indicates that taskR must finish when the last task has finished
178179

179180
// Parsing configuration
180181
if (config.contains("Task Worker Inactivity Time (Ms)")) _taskWorkerInactivityTimeMs = hicr::json::getNumber<ssize_t>(config, "Task Worker Inactivity Time (Ms)");
181182
if (config.contains("Task Suspend Interval Time (Ms)")) _taskWorkerSuspendIntervalTimeMs = hicr::json::getNumber<ssize_t>(config, "Task Suspend Interval Time (Ms)");
182183
if (config.contains("Minimum Active Task Workers")) _minimumActiveTaskWorkers = hicr::json::getNumber<size_t>(config, "Minimum Active Task Workers");
183184
if (config.contains("Service Worker Count")) _serviceWorkerCount = hicr::json::getNumber<size_t>(config, "Service Worker Count");
184185
if (config.contains("Make Task Workers Run Services")) _makeTaskWorkersRunServices = hicr::json::getBoolean(config, "Make Task Workers Run Services");
186+
if (config.contains("Finish on Last Task")) _finishOnLastTask = hicr::json::getBoolean(config, "Finish On Last Task");
185187
}
186188

187189
// Destructor
@@ -447,6 +449,11 @@ class Runtime
447449
*/
448450
__INLINE__ void forceTermination() { _forceTerminate = true; }
449451

452+
/**
453+
* Function to toggle the finish on last task condition
454+
*/
455+
__INLINE__ void setFinishOnLastTask(const bool value = true) { _finishOnLastTask = value; }
456+
450457
private:
451458

452459
__INLINE__ void tryRunService(Service* const service)
@@ -600,8 +607,8 @@ class Runtime
600607

601608
__INLINE__ bool checkTermination(taskr::Worker *const worker)
602609
{
603-
// If all tasks finished, then terminate execution immediately
604-
if (_activeTaskCount == 0)
610+
// If all tasks finished and the runtime is set to finish on that condition, then terminate execution immediately
611+
if (_finishOnLastTask == true && _activeTaskCount == 0)
605612
{
606613
// Terminating worker.
607614
worker->terminate();
@@ -870,6 +877,11 @@ class Runtime
870877
*/
871878
bool _makeTaskWorkersRunServices;
872879

880+
/**
881+
* Indicates whether taskR must finish when the last task has finished
882+
*/
883+
bool _finishOnLastTask;
884+
873885
/**
874886
* TraCR thread indices
875887
*/

0 commit comments

Comments
 (0)