File tree Expand file tree Collapse file tree 2 files changed +9
-1
lines changed Expand file tree Collapse file tree 2 files changed +9
-1
lines changed Original file line number Diff line number Diff line change @@ -30,6 +30,11 @@ fn nbody_par(b: &mut ::test::Bencher) {
30
30
nbody_bench ( b, |n| { n. tick_par ( ) ; } ) ;
31
31
}
32
32
33
+ #[ bench]
34
+ fn nbody_par_as_parallel ( b : & mut :: test:: Bencher ) {
35
+ nbody_bench ( b, |n| { n. tick_par_as_parallel ( ) ; } ) ;
36
+ }
37
+
33
38
#[ bench]
34
39
fn nbody_parreduce ( b : & mut :: test:: Bencher ) {
35
40
nbody_bench ( b, |n| { n. tick_par_reduce ( ) ; } ) ;
Original file line number Diff line number Diff line change 32
32
use cgmath:: { InnerSpace , Point3 , Vector3 , Zero } ;
33
33
use rand:: { Rand , Rng } ;
34
34
use rayon:: prelude:: * ;
35
+ #[ cfg( test) ]
36
+ use rayon:: iter:: AsParallel ;
35
37
use std:: f64:: consts:: PI ;
36
38
37
39
const INITIAL_VELOCITY : f64 = 8.0 ; // set to 0.0 to turn off.
@@ -111,6 +113,7 @@ impl NBodyBenchmark {
111
113
out_bodies
112
114
}
113
115
116
+ #[ cfg( test) ]
114
117
pub fn tick_par_as_parallel ( & mut self ) -> & [ Body ] {
115
118
let ( in_bodies, out_bodies) = if ( self . time & 1 ) == 0 {
116
119
( & self . bodies . 0 , & mut self . bodies . 1 )
@@ -121,8 +124,8 @@ impl NBodyBenchmark {
121
124
let time = self . time ;
122
125
out_bodies
123
126
. iter_mut ( )
124
- . as_parallel ( )
125
127
. zip ( & in_bodies[ ..] )
128
+ . as_parallel ( )
126
129
. for_each ( |( out, prev) | {
127
130
let ( vel, vel2) = next_velocity ( time, prev, in_bodies) ;
128
131
out. velocity = vel;
You can’t perform that action at this time.
0 commit comments