-
-
Notifications
You must be signed in to change notification settings - Fork 14.3k
Closed
Description
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
Labels
No labels