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

[try_put_and_wait] Add tag-based implementation for try_put_and_wait for multifunction and async nodes #1604

Draft
wants to merge 11 commits into
base: master
Choose a base branch
from

Conversation

kboyarinov
Copy link
Contributor

@kboyarinov kboyarinov commented Jan 15, 2025

Description

Add reference implementation of try_put_and_wait feature for multifunction and async nodes as described in the corresponding RFC.

Fixes # - issue number(s) if exists

Type of change

Choose one or multiple, leave empty if none of the other choices apply

Add a respective label(s) to PR if you have permissions

  • bug fix - change that fixes an issue
  • new feature - change that adds functionality
  • tests - change in tests
  • infrastructure - change in infrastructure and CI
  • documentation - documentation update

Tests

  • added - required for new features and some bug fixes
  • not needed

Documentation

  • updated in # - add PR number
  • needs to be updated
  • not needed

Breaks backward compatibility

  • Yes
  • No
  • Unknown

Notify the following users

List users with @ to send notifications

Other information

@@ -0,0 +1,468 @@
/*
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Most part of this file was moved from test_buffering_try_put_and_wait without any changes

test/tbb/test_multifunction_node.cpp Outdated Show resolved Hide resolved
@kboyarinov
Copy link
Contributor Author

Some of TODOs are still required to be closed before merging this patch, I will do it in the later updates


metainfo_tag_type& operator=(const metainfo_tag_type&) = delete;
metainfo_tag_type& operator=(metainfo_tag_type&& other) {
// TODO: should this method be thread-safe?
Copy link
Contributor

Choose a reason for hiding this comment

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

Could someone want to use assignment in place of reset to start a next batch of accumulations -- starting with a different first tag. Then there could be a race between the assignment and merge..?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

It is in theory really interesting, which thread-safety guarantees should be provided.
It is obvious, that:

  • merge should be thread-safe with other merge
  • reset should be thread-safe with reset

merge can be thread-safe with reset (as well as with operator=) but it is hard to imagine the real use case. If we have both merge and reset simultaneously, which result can the user expect - merged or reset object.
Currently, the first function that acquires the mutex will define the behavior.
But let's consider the 2 consecutive reductions that use the single accumulators. If in the edge between 2 reductions, there would be simultaneous merge from reduction 2 and reset from the reduction 1, some elements from the reduction 2 can be missed if the merge will go before the reset.

For me, it is unclear how we can manage this. I think the answer for this question is the answer also to thread-safety of operator=

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Other interesting question is should it be thread-safe to have the left.merge(middle) simultaneous with middle.merge(right). I feel that the answer is no, but still want to highlight this.

@@ -657,7 +657,7 @@ void test_try_put_and_wait_rejecting(size_t concurrency_limit) {
std::vector<int> processed_items;
std::vector<int> new_work_items;

int wait_message = 0;
int wait_message = 10;
Copy link
Contributor

Choose a reason for hiding this comment

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

You forgot to update copyright year.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Fixed

@kboyarinov kboyarinov marked this pull request as draft January 20, 2025 17:39
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.

2 participants