dimforge / dimforge/nalgebra

Question: is it possible to modify different DMatrix columns in parallel (via Rayon) without Mutex?

Open
#848 4 comments 0 reactions 0 assignees View on GitHub
enhancement good first issue P-medium
Dominant language
Rust
Stars
4.8k
Forks
565
PR merge metrics
No merged PRs in 30d

Description

I'm trying to make the following code work:
```
use nalgebra::*;
use rayon::prelude::*;
let mut m = DMatrix::::from_vec(2, 3, (0..6).map(|n| n as f64).collect());
dbg!(&m);
m.column_iter_mut()
.par_bridge()
.for_each(|mut c| c[0] = 111.0);
dbg!(&m);
```

But the code doesn't compile:

>
> no method named `par_bridge` found for struct `ColumnIterMut<'_, f64, Dynamic, Dynamic, VecStorage>` in the current scope
> the method `par_bridge` exists but the following trait bounds were not satisfied:
> `ColumnIterMut<'_, f64, Dynamic, Dynamic, VecStorage>: Send`
> which is required by `ColumnIterMut<'_, f64, Dynamic, Dynamic, VecStorage>: rayon::iter::ParallelBridge`
> `&ColumnIterMut<'_, f64, Dynamic, Dynamic, VecStorage>: Send`
> which is required by `&ColumnIterMut<'_, f64, Dynamic, Dynamic, VecStorage>: rayon::iter::ParallelBridge`
> `&ColumnIterMut<'_, f64, Dynamic, Dynamic, VecStorage>: Iterator`
> which is required by `&ColumnIterMut<'_, f64, Dynamic, Dynamic, VecStorage>: rayon::iter::ParallelBridge`
> `&mut ColumnIterMut<'_, f64, Dynamic, Dynamic, VecStorage>: Send`
> which is required by `&mut ColumnIterMut<'_, f64, Dynamic, Dynamic, VecStorage>: rayon::iter::ParallelBridge`

Is there a relatively short path for making the code above work (with some changes to either the code or nalgebra source code)? I can do some digging on my own, I just need the direction. Thanks!

Contributor guide

No contributing guide indexed for this repository

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.