Questions tagged [rayon]

A Rust data-parallelism library that makes it easy to convert sequential computations into parallel Rayon is lightweight and convenient for introducing parallelism into existing code. It guarantees data-race free executions and takes advantage of parallelism when sensible, based on work-load at runtime.

See the official documentation for more information.

123 questions
2
votes
1 answer

How to turn a string into a parallel iterator using Rayon and Rust?

I am trying to turn the code below into a parallel iterator to speed up performance: // something like this string.split(" ").enumerate().into_par_iter().for_each(|(_, b)| { // do something }); But Rayon doesn't support .into_par_iter() for the…
Pro Poop
  • 357
  • 5
  • 14
2
votes
1 answer

How can I create a HashMap using Rayon's parallel fold?

I am trying to create a HashMap using functional programming and utilizing parallelization by rayon. If I try this without rayon, it works: use std::collections::HashMap; fn main() { let nums = [1, 2, 1, 2, 1, 2]; let result: HashMap
leviathan
  • 363
  • 3
  • 10
2
votes
0 answers

Why is a Vec of boxed closures not sized when calling Rayon's into_par_iter?

I have a Vec of boxed closures (Vec ...>>). I can do vec.into_iter().map(...), but I can't use it with Rayon's into_par_iter vec.into_par_iter().map(...). Here's a minimised example (playground): type GameResult = Result
david king
  • 738
  • 5
  • 9
2
votes
1 answer

How do I use hashbrown data types with Rayon parallel iterators?

I have a hashbrown::HashSet, and I am trying to use Rayon's par_iter with it, but I cannot figure out the right syntax. Cargo.toml [package] name = "basic" version = "0.1.0" authors = ["Me "] edition = "2018" # See more keys and…
Troy Daniels
  • 3,270
  • 2
  • 25
  • 57
2
votes
0 answers

Running combination of loops in parallel

The following code calculates a matrix of distances between each pair of elements in the corpus. However, for large corpora the process becomes quite lengthy. How can I parallelize it with rayon? use std::iter::Iterator; use ndarray::Array2; type…
dzieciou
  • 4,049
  • 8
  • 41
  • 85
2
votes
1 answer

Unexpected "method not found" compiler error

This question arises from my use (in a toy project to learn Rust) of cartesian_product from itertools together with into_par_iter from Rayon. My question is less about this particular code and more a question about reading rustc error messages, and…
J. Dane
  • 35
  • 4
2
votes
2 answers

How to obtain the chunk index in Rayon's par_chunks_mut

I have some data and I want to process it and use it to fill an array that already exists. For example suppose I want to repeat each value 4 times (playground): use rayon::prelude::*; // 1.3.0 fn main() { let input = vec![4, 7, 2, 3, 5, 8]; …
Timmmm
  • 88,195
  • 71
  • 364
  • 509
2
votes
1 answer

Program still runs on one thread using par_iter and par_extend

I'm trying to parallelize a portion of my code, and despite it using rayon and the parallel iterators par_iter() and par_extend(), it still looks like it runs on a single thread. I simply create a vector of i32, fill it up with a lot of values,…
m.raynal
  • 2,983
  • 2
  • 21
  • 34
2
votes
2 answers

Will Rayon avoid spawning threads for a small amount of work?

I was thinking about using Rayon's parallel iterator feature, but I'm concerned about performance for iterating over small collections. Parallelism overhead sometimes can cause a slowdown on small collections. Iterating over 2 elements is slower if…
Inline
  • 2,566
  • 1
  • 16
  • 32
2
votes
1 answer

Implement rayon `as_parallel_slice` using iterators

I have a small problem of my own: extern crate rayon; use rayon::prelude::*; #[derive(Debug)] struct Pixel { r: Vec, g: Vec, b: Vec, } #[derive(Debug)] struct Node{ r: i8, g: i8, b: i8, } struct…
2
votes
1 answer

How to satisfy the Iterator trait bound in order to use Rayon here?

I'm attempting to parallelise the Ramer–Douglas-Peucker line simplification algorithm by using Rayon's par_iter instead of iter: extern crate num_traits; use num_traits::{Float, ToPrimitive}; extern crate rayon; use…
urschrei
  • 25,123
  • 12
  • 43
  • 84
1
vote
0 answers

Auto-scale receiver count with crossbeam-channel in Rust

When using a multi-sender/multi-receiver channels like crossbeam-channel or async-channel, I would like to dynamically scale the number of receivers based on the channel congestion state. If there are too many pending item is the channel, more…
Yuri Astrakhan
  • 8,808
  • 6
  • 63
  • 97
1
vote
0 answers

Clarify rust rayon nested thread pool worker numbers

I have tried to use rayon's parallel iterators in a nested way. As a global pool would have a fixed number of threads, I tend to create an outer-pool in main and an inner-pool each in threads the outer-pool spawns. use rayon::prelude::*; fn…
ElevenLee
  • 55
  • 4
1
vote
1 answer

Rust get mutable reference to each element of an ndarray in parallel

I am working on a parallel matrix multiplication code in Rust, where I want to compute every element of the product in parallel. I use ndarrays to store my data. Thus, my code would be something alone the lines fn mul(lhs: &Array2, rhs:…
stomfaig
  • 15
  • 4
1
vote
1 answer

Can I get fiber-like behavior from Rayon?

Rayon works by creating a threadpool of workers, assigning each worker a workqueue, and allowing workers with an empty queue to steal work. But if a closure blocks (say, the work involves editing a shared resource under a Mutex), is the worker able…
Zannick
  • 25
  • 5
1 2
3
8 9