forked from SpectralSequences/sseq
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Clean up gating on
concurrent
feature (SpectralSequences#140)
* Introduce `maybe-rayon` crate * Adapt rest of codebase
- Loading branch information
Showing
19 changed files
with
264 additions
and
262 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
[package] | ||
name = "maybe-rayon" | ||
version = "0.1.0" | ||
edition = "2021" | ||
|
||
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html | ||
|
||
[dependencies] | ||
rayon = { version = "1.8.0", optional = true } | ||
|
||
[features] | ||
default = [] | ||
concurrent = ["rayon"] |
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,64 @@ | ||
pub mod prelude { | ||
use rayon::prelude::*; | ||
|
||
pub use rayon::iter::{IndexedParallelIterator, ParallelIterator}; | ||
|
||
pub trait MaybeParallelIterator: ParallelIterator {} | ||
|
||
pub trait MaybeIndexedParallelIterator: IndexedParallelIterator {} | ||
|
||
pub trait MaybeIntoParallelIterator: IntoParallelIterator { | ||
fn maybe_into_par_iter(self) -> Self::Iter; | ||
} | ||
|
||
pub trait MaybeIntoParallelRefMutIterator<'data>: IntoParallelRefMutIterator<'data> { | ||
fn maybe_par_iter_mut(&'data mut self) -> Self::Iter; | ||
} | ||
|
||
// Implementations | ||
|
||
impl<I: ParallelIterator> MaybeParallelIterator for I {} | ||
|
||
impl<I: IndexedParallelIterator> MaybeIndexedParallelIterator for I {} | ||
|
||
impl<I: IntoParallelIterator> MaybeIntoParallelIterator for I { | ||
fn maybe_into_par_iter(self) -> Self::Iter { | ||
self.into_par_iter() | ||
} | ||
} | ||
|
||
impl<'data, I: IntoParallelRefMutIterator<'data> + ?Sized> | ||
MaybeIntoParallelRefMutIterator<'data> for I | ||
{ | ||
fn maybe_par_iter_mut(&'data mut self) -> Self::Iter { | ||
self.par_iter_mut() | ||
} | ||
} | ||
} | ||
|
||
pub fn join<A, B, RA, RB>(oper_a: A, oper_b: B) -> (RA, RB) | ||
where | ||
A: FnOnce() -> RA + Send, | ||
B: FnOnce() -> RB + Send, | ||
RA: Send, | ||
RB: Send, | ||
{ | ||
rayon::join(oper_a, oper_b) | ||
} | ||
|
||
pub type Scope<'scope> = rayon::Scope<'scope>; | ||
|
||
pub fn scope<'scope, OP, R>(op: OP) -> R | ||
where | ||
OP: FnOnce(&Scope<'scope>) -> R + Send, | ||
R: Send, | ||
{ | ||
rayon::scope(op) | ||
} | ||
|
||
pub fn in_place_scope<'scope, OP, R>(op: OP) -> R | ||
where | ||
OP: FnOnce(&Scope<'scope>) -> R, | ||
{ | ||
rayon::in_place_scope(op) | ||
} |
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,9 @@ | ||
#[cfg(feature = "concurrent")] | ||
pub mod concurrent; | ||
#[cfg(feature = "concurrent")] | ||
pub use concurrent::*; | ||
|
||
#[cfg(not(feature = "concurrent"))] | ||
pub mod sequential; | ||
#[cfg(not(feature = "concurrent"))] | ||
pub use sequential::*; |
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,78 @@ | ||
pub mod prelude { | ||
pub trait MaybeParallelIterator: Iterator {} | ||
|
||
pub trait MaybeIndexedParallelIterator: Iterator {} | ||
|
||
pub trait MaybeIntoParallelIterator: IntoIterator { | ||
type Iter; | ||
|
||
fn maybe_into_par_iter(self) -> Self::Iter; | ||
} | ||
|
||
pub trait MaybeIntoParallelRefMutIterator<'data> { | ||
type Iter; | ||
|
||
fn maybe_par_iter_mut(&'data mut self) -> Self::Iter; | ||
} | ||
|
||
// Implementations | ||
|
||
impl<I: Iterator> MaybeParallelIterator for I {} | ||
|
||
impl<I: Iterator> MaybeIndexedParallelIterator for I {} | ||
|
||
impl<I: IntoIterator> MaybeIntoParallelIterator for I { | ||
type Iter = Self::IntoIter; | ||
|
||
fn maybe_into_par_iter(self) -> Self::Iter { | ||
self.into_iter() | ||
} | ||
} | ||
|
||
impl<'data, I: 'data + ?Sized> MaybeIntoParallelRefMutIterator<'data> for I | ||
where | ||
&'data mut I: IntoIterator, | ||
{ | ||
type Iter = <&'data mut I as IntoIterator>::IntoIter; | ||
|
||
fn maybe_par_iter_mut(&'data mut self) -> Self::Iter { | ||
self.into_iter() | ||
} | ||
} | ||
} | ||
|
||
pub struct Scope<'scope>(&'scope ()); | ||
|
||
impl<'scope> Scope<'scope> { | ||
pub fn spawn<BODY>(&self, body: BODY) | ||
where | ||
BODY: FnOnce(&Scope<'scope>) + Send + 'scope, | ||
{ | ||
body(self) | ||
} | ||
} | ||
|
||
pub fn join<A, B, RA, RB>(oper_a: A, oper_b: B) -> (RA, RB) | ||
where | ||
A: FnOnce() -> RA + Send, | ||
B: FnOnce() -> RB + Send, | ||
RA: Send, | ||
RB: Send, | ||
{ | ||
(oper_a(), oper_b()) | ||
} | ||
|
||
pub fn scope<'scope, OP, R>(op: OP) -> R | ||
where | ||
OP: FnOnce(&Scope<'scope>) -> R + Send, | ||
R: Send, | ||
{ | ||
op(&Scope(&())) | ||
} | ||
|
||
pub fn in_place_scope<'scope, OP, R>(op: OP) -> R | ||
where | ||
OP: FnOnce(&Scope<'scope>) -> R, | ||
{ | ||
op(&Scope(&())) | ||
} |
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
Oops, something went wrong.