Skip to content

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

@siavashserver

Description

@siavashserver

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]);
}

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions