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

Feature Request: OpenMP/TBB like Parallel For Loops #12619

Closed
siavashserver opened this issue Feb 28, 2014 · 4 comments
Closed

Feature Request: OpenMP/TBB like Parallel For Loops #12619

siavashserver opened this issue Feb 28, 2014 · 4 comments

Comments

@siavashserver
Copy link

Is it possible to have some easy to use parallel for loops like OpenMP or Intel TBB in Rust? As far as I know their parallel for loops divide the range by CPU cores (or specified worker threads), then every worker thread will access a sequential stream of data in memory (better CPU cache utilization) and idle worker threads are also able to steal tasks from busy ones to balance the load (which is optional in OMP, and the default for the TBB).

Serial code:

void SerialApplyFoo( float b[], const float a[], size_t n ){
    for( size_t i=0; i<n; ++i )
        b[i] = Foo(a[i]);
}

Intel TBB example:

void ParallelApplyFoo (float b[], const float a[], size_t n){
    tbb::parallel_for (size_t(0), n, [=](size_t i) {
        b[i] = Foo(a[i]);
    });
}

OpenMP example:

void ParallelApplyFoo( float b[], const float a[], size_t n ){
    #pragma omp parallel for
    for( size_t i=0; i<n; ++i )
        b[i] = Foo(a[i]);
}
@huonw
Copy link
Member

huonw commented Feb 28, 2014

Blocked on #11781 for memory safety. See the following for an outline of the current plan to allow constructing memory-safe fork-join libraries

It might end up looking something like (or something completely different...)

// sequential
for (bi, ai) in bi.mut_iter().zip(ai.iter()) {
    *bi = foo(*ai)
}

// parallel
par_for(bi.mut_iter().zip(ai.iter()), |(bi, ai)| {
    *bi = foo(*ai);
})

(The simple interface above won't necessarily be able to get 100% the performance of TBB and OMP---the cost of memory safety---but I imagine more technical ones can get pretty close.)

@huonw huonw added the A-libs label Feb 28, 2014
@nikomatsakis
Copy link
Contributor

Also blocked on #12624, at least to have the API I want.

@steveklabnik
Copy link
Member

I'm pulling a massive triage effort to get us ready for 1.0. As part of this, I'm moving stuff that's wishlist-like to the RFCs repo, as that's where major new things should get discussed/prioritized.

This issue has been moved to the RFCs repo: rust-lang/rfcs#859

@JayKickliter
Copy link

For anyone who finds this issue by googling "rust OpenMP", take a look at Rayon.

flip1995 pushed a commit to flip1995/rust that referenced this issue May 17, 2024
Handle `rustc_on_unimplemented` in duplicated_attributes

```rust
#[rustc_on_unimplemented(
    on(
        _Self = "&str",
        label = "`a"
    ),
    on(
        _Self = "alloc::string::String",
        label = "a"
    ),
)]
```

The lint treats this as a repetition because `rustc_on_unimplemented::on::label` appears twice, but that's ok.

Fixes rust-lang#12619

changelog: [`duplicated_attributes`]: fix handling of `rustc_on_unimplemented`
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

5 participants