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

Add documentation for parallel_phase feature #1646

Merged
merged 10 commits into from
Mar 6, 2025

Conversation

isaevil
Copy link
Contributor

@isaevil isaevil commented Feb 21, 2025

Description

Document parallel_phase and leave_policy extensions to task_arena in Developer Reference.

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

Signed-off-by: Isaev, Ilya <ilya.isaev@intel.com>
Signed-off-by: Isaev, Ilya <ilya.isaev@intel.com>
Signed-off-by: Isaev, Ilya <ilya.isaev@intel.com>
with the following API:
* Add enumeration class ``leave_policy`` to ``task_arena``.
* Add ``leave_policy`` as the last parameter to ``task_arena`` constructors and ``task_arena::initialize`` methods.
This allows to choose retention policy for worker threads in case when no more parallel work in the arena.
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
This allows to choose retention policy for worker threads in case when no more parallel work in the arena.
This allows you to define a retention policy for worker threads when no parallel work is in the arena.

Copy link
Contributor Author

@isaevil isaevil Feb 24, 2025

Choose a reason for hiding this comment

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

I am not sure how to better state this but at the same time to not overwhelm documentation with lots of details. The idea is that the feature allows users to tell the scheduler, what policy to use when TBB's worker threads are going to leave task_arena because they failed to find any work.

Copy link
Contributor

Choose a reason for hiding this comment

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

maybe smth like: This feature allows you to inform the scheduler about the preferred policy for worker threads when they are about to leave task_arena due to a lack of available work.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Updated.

isaevil and others added 2 commits February 24, 2025 12:20
Co-authored-by: Alexandra <alexandra.epanchinzeva@intel.com>
Co-authored-by: Alexandra <alexandra.epanchinzeva@intel.com>
@isaevil isaevil requested a review from aepanchi February 25, 2025 10:43
aepanchi
aepanchi previously approved these changes Feb 27, 2025
Copy link
Contributor

@aepanchi aepanchi left a comment

Choose a reason for hiding this comment

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

Everything looks good just a couple of syntax errors to fix, and it will be good to go.

with the following API:
* Add enumeration class ``leave_policy`` to ``task_arena``.
* Add ``leave_policy`` as the last parameter to ``task_arena`` constructors and ``task_arena::initialize`` methods.
This allows to choose retention policy for worker threads in case when no more parallel work in the arena.
Copy link
Contributor

Choose a reason for hiding this comment

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

maybe smth like: This feature allows you to inform the scheduler about the preferred policy for worker threads when they are about to leave task_arena due to a lack of available work.

Co-authored-by: Alexandra <alexandra.epanchinzeva@intel.com>
Signed-off-by: Isaev, Ilya <ilya.isaev@intel.com>
.. cpp:function:: scoped_parallel_phase::scoped_parallel_phatse(task_arena& ta, bool with_fast_leave = false)

Constructs a ``scoped_parallel_phase`` object that starts a parallel phase in the specified ``task_arena``.
If ``with_fast_leave`` is ``true``, the worker threads leave policy is temporarily set to ``fast``.
Copy link
Contributor

Choose a reason for hiding this comment

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

Do we need to specify the behavior if task_arena was already initialized using fast leave policy? It might not be clear to the reader. Although, there is this "temporarily" word which sort of indicates that the behavior returns back to the policy specified at arena's construction site.

Similar question to the description of end_parallel_phase below.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Added note about the effect of this setting with arena initialized with fast leave policy.

Copy link
Contributor

Choose a reason for hiding this comment

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

How about referencing the corresponding RFC document from this file?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done.

Copy link
Contributor

Choose a reason for hiding this comment

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

The links to the RFC and to the specification (are there other?) are not permanent and therefore will become obsolete someday. I suggest to put permanent links so that they stay relevant as long as possible.

====================================================================

.. note::
To enable this feature, set ``TBB_PREVIEW_PARALLEL_PHASE`` macro to 1.
Copy link
Contributor

Choose a reason for hiding this comment

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

I think we should add, as suggested by Aleksei, a link to the RFC and request feedback on the feature. I'd suggest as part of this note. By putting the link here, we direct users to the RFC where they become aware of the exit conditions and what type of feedback we are seeking. That might drive more feedback.

Copy link
Contributor

Choose a reason for hiding this comment

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

In the medium term, all preview features will have matching RFCs and so this can become a regular part of preview feature documentation.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Added the link.

.. cpp:enum:: leave_policy::automatic

When passed to a constructor or the ``initialize`` method, the initialized ``task_arena`` has
default policy for worker threads.
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
default policy for worker threads.
default policy for worker thread retention.

Copy link
Contributor

Choose a reason for hiding this comment

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

Perhaps, "has the default (possibly system specific) policy for how quickly worker threads leave the arena when there is no more work available in the arena and when the arena is not in a parallel phase."

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done.


When passed to a constructor or the ``initialize`` method, the initialized ``task_arena`` has
policy to not retain worker threads in ``task_arena``.

Copy link
Contributor

Choose a reason for hiding this comment

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

I don't think "retention" or "retain" is defined anywhere. And I think we need to describe the effect within a phase and then between phases. For example, "to not retain worker threads" is not clear unless we say what we mean by retention. For sure, the arena retains the workers while there are active tasks to work on.

Maybe something like, "has policy that allows worker threads to more quickly leave the arena when there is no more work available in the arena and when the arena is not in a parallel phase."

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Applied suggested wording. I also added some notes on behavior when threads re-join the arena with no active parallel phases.

fast = /* unspecifed */,
};

task_arena(int max_concurrency = automatic, unsigned reserved_for_masters = 1,
Copy link
Contributor

Choose a reason for hiding this comment

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

What about the copy constructor? It copies settings from the other arena, including the leave policy. I think this behavior should be stated somewhere?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Since the API for the copy constructor is not changed, I think the only way to state that is to copy description from the spec and add info about the leave policy.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Listed copy constructor in member functions.

isaevil and others added 2 commits March 5, 2025 09:24
Co-authored-by: Mike Voss <michaelj.voss@intel.com>
Co-authored-by: Aleksei Fedotov <aleksei.fedotov@intel.com>
Signed-off-by: Isaev, Ilya <ilya.isaev@intel.com>
Copy link
Contributor

@aleksei-fedotov aleksei-fedotov left a comment

Choose a reason for hiding this comment

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

Looks good to me!

Copy link
Contributor

Choose a reason for hiding this comment

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

The links to the RFC and to the specification (are there other?) are not permanent and therefore will become obsolete someday. I suggest to put permanent links so that they stay relevant as long as possible.

Copy link
Contributor

@vossmjp vossmjp left a comment

Choose a reason for hiding this comment

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

Looks go to me.

@isaevil isaevil merged commit e02bdf2 into master Mar 6, 2025
27 checks passed
@isaevil isaevil deleted the dev/isaevil/parallel_phase_doc branch March 6, 2025 16:59
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.

4 participants