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

Adding polymorphic_executor #4514

Merged
merged 2 commits into from Apr 16, 2020
Merged

Adding polymorphic_executor #4514

merged 2 commits into from Apr 16, 2020

Conversation

hkaiser
Copy link
Member

@hkaiser hkaiser commented Apr 12, 2020

  • flyby: fixing various flaws in executor implementation

Fixes #4489

@hkaiser
Copy link
Member Author

hkaiser commented Apr 13, 2020

@teonik I think this is ready for experimentation now. Here is a short documentation:

The type hpx::parallel::executors::polymorphic_executor<> is a template that expects the function signature for the functions it can schedule as its template argument. It needs to be constructed from any other executor.

For instance:

double f(int arg) 
{ 
    return double(arg); 
}

using executor = hpx::parallel::executors::polymorphic_executor<double(int)>;

void polymorphic_scheduling(executor const& exec)
{
    // use it to schedule the function f
    hpx::future<double> fut = hpx::parallel::async_execute(exec, f, 42);
    HPX_TEST_EQ(fut.get(), 42.0);
}

void schedule_things()
{
    // create polymorphic executor from parallel_executor
    hpx::parallel::executors::parallel_executor par_exec;
    polymorphic_scheduling(executor(par_exec));

    // create polymorphic executor from sequenced_executor
    hpx::parallel::executors::sequenced_executor seq_exec;
    polymorphic_scheduling(executor(seq_exec));
}

Please note, that the function signatures that can be scheduled using then_execute, bulk_sync_execute, bulk_async_execute and bulk_then_execute are slightly different.

Assuming the function signature is R(Ts...), then the corresponding signatures for the scheduling functions above are:

  • R(hpx::shared_future<void> const&, Ts...) (for then_execute),
  • R(std::size_t, Ts...) (for bulk_sync_execute and bulk_async_execute), and
  • R(std::size_t, hpx::shared_future<void> const&, Ts...) (for bulk_then_execute).

This also means that the bulk_ functions can only be used with a Shape (range-)object that exposes something convertable to std::size_t as its value_type and that the then_ variations can only pass on shared_future<void> to the embedded executors.

The other specific property of the polymorphic_executor<> is that it implements all 7 customization points directly, all of which simply forward their arguments to the embedded executor (the one it was constructed from).

For a full set of examples, see for instance here: https://github.com/STEllAR-GROUP/hpx/blob/fixing_4489/libs/execution/tests/unit/polymorphic_executor.cpp.

@hkaiser hkaiser force-pushed the fixing_4489 branch 3 times, most recently from 9047436 to 08305e4 Compare April 14, 2020 02:47
- flyby: fixing various flaws in executor implementation
- flyby: Making exposed future_type a template
- flyby: fixing force_linking in MPI module
@hkaiser
Copy link
Member Author

hkaiser commented Apr 15, 2020

@msimberg this is good to go (once the CI cycled).

msimberg
msimberg previously approved these changes Apr 15, 2020
Copy link
Contributor

@msimberg msimberg left a comment

Choose a reason for hiding this comment

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

Thanks @hkaiser (and @sithhell)! Looks like @sithhell has done a thorough job with reviewing. Feel free to merge (with that one tiny change) when CI is done. I'll look through it in detail afterwards, mostly for my own benefit.

libs/execution/tests/unit/polymorphic_executor.cpp Outdated Show resolved Hide resolved
Co-Authored-By: Mikael Simberg <mikael.simberg@iki.fi>
@hkaiser hkaiser merged commit 55ca6af into master Apr 16, 2020
@hkaiser hkaiser deleted the fixing_4489 branch April 16, 2020 11:15
@aurianer aurianer mentioned this pull request Aug 10, 2020
6 tasks
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.

Polymorphic executor
3 participants