🦀
Rust Cookbook
  • Introduction
  • Rust Introduction
  • Collections
    • Hashing
  • Text Processing
    • Splitting a string
    • Converting a string to vectors and back
    • Twoway
  • Benchmarking
    • criterion
  • Testing
  • Package Management
    • Cargo workspaces
  • Concurrent Programming
    • Actor model
      • Actix actors
      • Bastion
  • Parallel Programming
    • Ryaon
  • Optimisations
    • Cache alignment
  • TODO
Powered by GitBook
On this page
  1. Parallel Programming

Ryaon

PreviousParallel ProgrammingNextOptimisations

Last updated 5 years ago

Parllalel collection transformations using rayon

Mutating a vectors to double its elements can be done by,

let mut nums = vec![1, 2, 3, 4, 5, 6, 7, 8, 9];
// Transform sequentially
nums.iter_mut().for_each(|n| *n *= 2);
dbg!(nums);

With it is easy to perform the same operation in parallel by using par iterators instead,

use rayon::prelude::*;

let mut nums = vec![1, 2, 3, 4, 5, 6, 7, 8, 9];
// Transform in parallel
nums.iter_mut().for_each(|n| *n *= 2);
dbg!(nums);
rayon