Exact parallelism in rayon

⚓ Rust    📅 2025-12-09    👤 surdeus    👁️ 3      

surdeus

Info

This post is auto-generated from RSS feed The Rust Programming Language Forum - Latest topics. Source: Exact parallelism in rayon

We are in the following scenario: we want to give a user the way to control the parallelism of a method. The method will break a problem in n pieces and spawn exactly n rayon threads.

This n will be obtained by current_num_threads, so the user can install, if they want, the method in a specific thread pool.

The problem is that we have a thread gathering the result. When using the current thread pool, we have an additional thread—the main thread—that does that. But if we run under an install, the main thread is part of the pool. This means that we have to spawn one less thread.

To check that, one checks that rayon::current_thread_index doesn't return None.

This is... ugly at best. The user must install manually one more thread with respect to the desired parallelism.

Is there any idiomatic way to have a more ergonomic approach?

1 post - 1 participant

Read full topic

🏷️ Rust_feed