-
Notifications
You must be signed in to change notification settings - Fork 152
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
f608ff8
commit 0668aec
Showing
12 changed files
with
81 additions
and
14 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
use std::sync::Arc; | ||
|
||
use rayon::iter::{FromParallelIterator, IntoParallelIterator, ParallelIterator}; | ||
|
||
use crate::Database; | ||
|
||
pub fn par_map<Db, D, E, C>( | ||
db: &Db, | ||
inputs: impl IntoParallelIterator<Item = D>, | ||
op: fn(&Db, D) -> E, | ||
) -> C | ||
where | ||
Db: ?Sized + Database, | ||
D: Send, | ||
E: Send + Sync, | ||
C: FromParallelIterator<E>, | ||
{ | ||
let fork_db_a: Box<dyn Database> = db.fork_db(); | ||
let fork_db_a: &Db = fork_db_a.as_view::<Db>(); | ||
// not sure what to use here, but here are the properties I need: | ||
// - "implements" `Clone` via `db.fork_db()` | ||
// - is `Send`, but absolutely not `Sync` | ||
let wrapper = todo!(); | ||
|
||
inputs | ||
.into_par_iter() | ||
.map_with(&wrapper, |db, element| op(db, element)) | ||
.collect() | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
use crate::setup::Knobs; | ||
|
||
#[salsa::input] | ||
struct ParallelInput { | ||
field: i32, | ||
} | ||
|
||
#[test] | ||
fn execute() { | ||
let db = Knobs::default(); | ||
|
||
let inputs = (1..=10) | ||
.map(|field| ParallelInput::new(&db, field)) | ||
.collect::<Vec<ParallelInput>>(); | ||
|
||
let _foo: Vec<i32> = salsa::par_map(&db, inputs, |db, field| field.field(db)); | ||
} |