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

Fix lifo queue backend #3172

Merged
merged 5 commits into from Feb 17, 2018
Merged

Fix lifo queue backend #3172

merged 5 commits into from Feb 17, 2018

Conversation

msimberg
Copy link
Contributor

This addresses the issue in #3166.

The issue in this case was that when shutdown_all waits for all threads to finish it calls suspend(pending) which eventually calls schedule_last for the shutdown_all thread. For the lifo queue backend schedule_last is the same as schedule and shutdown_all will be scheduled as the next thread again, leaving no chance for the remaining threads to run. I suspect we haven't seen this with more than 1 thread because then other OS threads will be able to steal the threads and/or most tests and examples wait for all futures before calling hpx::finalize.

Proposed Changes

  • Use deque for the non-abp lifo and fifo queue backends so that schedule_last can actually schedule a thread last in the queue.
  • Add a test which reproduces the issue.
  • Fix some naming in the documentation related to schedulers.

Note: from my preliminary tests deque is neither slower nor faster than stack or queue, but I need to check with more examples to see that this holds more generally.

Use deque so that schedule_last can actually schedule threads last in the queue.
Both acceptable but queuing more common and used for command line arguments.
@@ -38,6 +38,9 @@ template class HPX_EXPORT hpx::threads::detail::scheduled_thread_pool<
template class HPX_EXPORT hpx::threads::detail::scheduled_thread_pool<
hpx::threads::policies::local_priority_queue_scheduler<hpx::compat::mutex,
hpx::threads::policies::lockfree_abp_fifo>>;
template class HPX_EXPORT hpx::threads::detail::scheduled_thread_pool<
hpx::threads::policies::local_priority_queue_scheduler<hpx::compat::mutex,
hpx::threads::policies::lockfree_abp_lifo>>;
#endif
Copy link
Member

@hkaiser hkaiser Feb 13, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If you add this specialization then you probably should add a command line option for it as well.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, you're right, will add that.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

OTOH, instead of adding more schedulers to HPX core, we should consider creating a better mechanism (using the thread-pools) allowing for all schedulers (except the default one) to live outside of HPX core. What do you think?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not thought about it too much, but yes, that would probably be a good thing. How far outside HPX core are you thinking? This probably goes hand in hand with having a nicer way to create thread pools in general.

@hkaiser
Copy link
Member

hkaiser commented Feb 13, 2018

Is the underlying assumption for this PR that boost::lockfree:stack is broken?

@msimberg
Copy link
Contributor Author

No, not at all. It's simply that the scheduling loop relies on schedule_last to actually schedule a task last, but with a stack this requirement is broken and is by definition not possible to do.

Copy link
Member

@hkaiser hkaiser left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM, thanks!

@biddisco
Copy link
Contributor

Note that #2705 also mentions scheduler cleanup. Some schedulers should be removed and we should consider replacing the default scheduler.

@msimberg
Copy link
Contributor Author

To follow up on the performance, from what I can tell there is no practical difference between using a deque, stack or queue (tested with lots of small tasks with for (...) hpx::async([](){}); and the stencil examples). I think this is safe to merge without causing a performance hit for the default scheduler.

I'm also taking the liberty of quoting @biddisco from irc, saying there is no difference for his particular application:

13:15 <jbjnr> at the moment, abp_lifo
13:15 <heller_> deque is slower since the implementation uses dcas, which is not lockfree
13:15 <heller_> IIRC
13:15 <jbjnr> I vary them from time to time to experiemnt, but don't seem to get much differnceeither way

@hkaiser
Copy link
Member

hkaiser commented Feb 15, 2018

Just a side remark - I don't really trust the ABP schedulers (perhaps without reason), so we may not want to use one of those as the default scheduler.

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

Successfully merging this pull request may close these issues.

None yet

3 participants