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
0
votes
1 answer

Rust - How to process while loop for vector in parallel with Rayon?

I am trying to process vector with while loop. currently it is sequential taking each element at a time. Is there a way to process vector elements in parallel with rayon and get the same result. Will it increase the performance of the code given…
JNP
  • 153
  • 2
  • 8
0
votes
1 answer

Recursive impl Extend for HashMap<_, HashSet<_>> where sets are combined, instead of overwritten?

I'm trying to adapt my code to a solution to my previous question. Basically, I have a HashMap> that should be generated as a result of rayon's par_extend. The problem is that keys repeat and in such a case, I want HashSets…
d33tah
  • 10,999
  • 13
  • 68
  • 158
0
votes
2 answers

Perform computation in a parallel iterator, then feed it to a single-threaded one?

Consider the following example: use rayon::prelude::*; fn do_something_expensive_returning_lots_of_data(x: u32) -> u32 { x } fn main() { let very_large_array = [1, 2, 3, 4]; let mut h = std::collections::HashSet::new(); …
d33tah
  • 10,999
  • 13
  • 68
  • 158
0
votes
0 answers

How can you extend a collection in parallel?

I have a HashMap which I'd like to add elements to as fast as possible. I tried using par_extend, but it actually ended up being slower than the serial version. My guess is that it is evaluating the iterator in parallel, but extending the…
Daniel Giger
  • 2,023
  • 21
  • 20
0
votes
0 answers

Dedicated rayon pool to submit work and asynchronously wait for completion

I have a rayon::ThreadPool which I want to use to perform CPU bound tasks outside of Tokio's runtime context. The CPU bound tasks are synchronous tasks. The problem is spawn requires the closure to be 'static but I want to use the borrowed data…
Gurwinder Singh
  • 38,557
  • 6
  • 51
  • 76
0
votes
1 answer

Iterating over a vector of structs when I only need access to only one member of the struct

I have a vector of structs. It is called Updates, I want to reduce this vector to get the maximum wave speed by reducing over the structs. I tried to reduce using the par_iter() from rayon library. Since the input and output types of the identity…
Cherry Toska
  • 131
  • 8
0
votes
1 answer

How can I read and modify a variable using Rayon's par_iter in a thread-safe manner?

This code: use rayon::prelude::*; // 1.5.0 fn main() { let mut items = Vec::new(); items.push("hello"); items.push("foo"); items.push("bar"); items.push("ipsum"); let mut counter = 0; let results =…
Simen Russnes
  • 2,002
  • 2
  • 26
  • 56
0
votes
1 answer

Rust - using Rayon for permutations - vector memory allocation error

Aim: generate several billion permutations and run code on each one in parallel. Attempt: use Itertools to assign all permutations to a resulting vector and then use rayon to process each one. Minimum reproducible code: use…
Isambard_FA
  • 97
  • 13
0
votes
2 answers

How can I thread using functions using method in self?

When trying to write some paralel code I keep getting hit with the error seen bellow. There are a few solutions I have found but they all involve locking which I would prefer not to do. Is there any way I can get round this? pub trait PermBrute { …
Seli
  • 45
  • 5
0
votes
1 answer

How do I find the right combinators to make this code working with rayon?

I'd like to change the below code to avoid using .unwrap or .expect : thread::scope(|s| { for name in names { s.spawn(move |_| { let path_to_file = format!("{}{}", base, name.as_str()); let path_to_file_written =…
r3dlight
  • 101
  • 8
0
votes
1 answer

Rust rayon tcp blocking

I'm writing a program which executes a command on server using ssh and gets the output. The part I don't understand is lower in the code. If the function waits and then returns a string, it works as expected, but if work with TCP it starts…
Vladimir
  • 294
  • 1
  • 3
  • 10
0
votes
1 answer

How to use Rayon for parallel calculation of PI

My code can calculate Pi using Ramanujan's formula without Rayon and I want to implement Rayon for parallel threading as this is my project. I know that I need to use this use rayon::prelude::*; fn sum_of_squares(input: &[f64]) ->f64 { for i in…
0
votes
1 answer

How can I change a function to run in parallel with Rayon?

I have a function, that gets an array, start index and end index. I want to return the largest element of this array. Sequentially it works fine. But I don't know how to convert it to work in prallel. So can you show me how to do it. I've been…
mm mm
  • 19
  • 2
0
votes
1 answer

Trying to collect into vector but failing with "a collection cannot be built over elements of type <...>"

I am trying to find the saddle points of a matrix, a borrowed array of vectors. For the purposes of this, a saddle point is an element of the matrix that is either the smallest in its column and the largest in its row, or the largest in its column,…
Alex
  • 2,270
  • 3
  • 33
  • 65
0
votes
0 answers

par_bridge().map() halts and consumes memory instead of iterating?

I'm trying to read a stream of JSON objects line-by-line from stdin and extract the "value" key from them as a string: use rayon::prelude::*; // 1.0.3 use serde_json::Value; // 1.0.37 use std::io::{self, BufRead}; use std::sync::mpsc::channel; fn…
d33tah
  • 10,999
  • 13
  • 68
  • 158
1 2 3
8
9