★ wanayoo — archive 1999 https://github.com/taskflow/taskflow/issues/160Nouvelle recherche | Portail wanayoo
Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Limiting Concurrency #160

Open
jlaxson opened this issue Apr 20, 2020 · 3 comments
Open

Limiting Concurrency #160

jlaxson opened this issue Apr 20, 2020 · 3 comments
Labels

Comments

@jlaxson
Copy link

@jlaxson jlaxson commented Apr 20, 2020

Hi - I really like what you've built here. I have a use case that I can't quite figure out how to map to cpp-taskflow, hoping I could get some advice.

In my workflow I have a number of steps that I'd like to artificially limit concurrency - for instance, a subflow that consumes a very large amount of memory. Or that consume limited external resources (gpus, etc). Or even to differentiate between CPU-bound tasks (at most one worker per cpu thread) and IO bound tasks (perhaps many more than one per thread?).

I think I could emulate this with mutexes or other synchronization outside of taskflow itself, but that has the side effect of consuming/blocking workers when they could be working on other ready tasks.

One potential solution would be to have the ability to assign tasks/subflows to specific executors, with dependencies across the executors. So I could have my GPU executor, with concurrency 2, in parallel to the CPU executor with native hardware concurrency. Syntax could look something like:

tf::Executor cpu;
tf::Executor heavyResourceExecutor(1);
tf::Taskflow tf;

for (int i = 0; i < 100; i++) {
  auto load_task = tf.emplace([](){ /* load some data */ });
  auto heavy_task = tf.emplace(heavyResourceExecutor, []() { /* do some heavy lifting */ });

  load_task.precede(heavy_task);
}

cpu.run(tf); // load tasks can happen at full concurrency, but heavy_task will happen one at a time
heavyResourceExecutor.run(); // starts its worker threads, but won't do anything until a heavy_task is ready

Wondering if there's a way to achieve this with the functionality you have now? Otherwise, a humble feature suggestion.

@tsung-wei-huang
Copy link
Member

@tsung-wei-huang tsung-wei-huang commented Apr 20, 2020 •

Hi @jlaxson , I think in your case you can just use one cpu executor to do both load_task and heavy_task. Our runtime scheduler is adaptive; it won't consume all the threads all the same but adapts the number of threads to available task parallelism at any time during the graph execution. If you really want only one thread to run heavy_task, you can artificially create a set of dependency to force heavy_task to become a super dependent/successor of other tasks.

@jlaxson
Copy link
Author

@jlaxson jlaxson commented Apr 20, 2020

Hi, thanks for your quick reply.

Our runtime scheduler is adaptive; it won't consume all the threads all the same but adapts the number of threads to available task parallelism at any time during the graph execution.

I had looked a bit through the code but all I see is Executor::_spawn which is always used to spawn a constant number of threads. Can you point me towards more detail?

If you really want only one thread to run heavy_task, you can artificially create a set of dependency to force heavy_task to become a super dependent/successor of other tasks.

I think this would mean that I need to know (or control) a priori the order of all the heavy_tasks? If I don't know which heavy_task would become ready first, is there a way to accomplish this?

@tsung-wei-huang
Copy link
Member

@tsung-wei-huang tsung-wei-huang commented Apr 20, 2020

@jlaxson Hi, we do spawn a fixed number of threads but they transition back and forth to sleep and awake depending on the present task parallelism. You may check Executor::_wait_for_task. The algorithm is a bit complicated because we use a 2-phase commit control.

Secondly, Yes, you need to know the dependency. However, you may check subflow or condition task and see if they work for your case in a dynamic environment. I recently update several tutorial pages at the Learning from Examples pages. I hope they help.

Thanks again for the discussion.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Linked pull requests

Successfully merging a pull request may close this issue.

None yet
2 participants
You can’t perform that action at this time.