Skip to content

Commit

Permalink
fix shootout-spectralnorm, broken since Arc cannot unwrap.
Browse files Browse the repository at this point in the history
  • Loading branch information
TeXitoi committed Mar 9, 2014
1 parent 33768c4 commit 9e49a07
Showing 1 changed file with 18 additions and 11 deletions.
29 changes: 18 additions & 11 deletions src/test/bench/shootout-spectralnorm.rs
@@ -1,4 +1,4 @@
// Copyright 2012-2013-2014 The Rust Project Developers. See the COPYRIGHT
// Copyright 2012-2014 The Rust Project Developers. See the COPYRIGHT
// file at the top-level directory of this distribution and at
// http://rust-lang.org/COPYRIGHT.
//
Expand All @@ -8,16 +8,13 @@
// option. This file may not be copied, modified, or distributed
// except according to those terms.

// ignore-test arcs no longer unwrap

extern crate sync;

use std::from_str::FromStr;
use std::iter::count;
use std::cmp::min;
use std::os;
use std::vec::from_elem;
use sync::Arc;
use sync::RWArc;

fn A(i: uint, j: uint) -> f64 {
Expand All @@ -33,23 +30,32 @@ fn dot(v: &[f64], u: &[f64]) -> f64 {
}

fn mult(v: RWArc<~[f64]>, out: RWArc<~[f64]>, f: fn(&~[f64], uint) -> f64) {
let wait = Arc::new(());
// We lanch in different tasks the work to be done. To finish
// this fuction, we need to wait for the completion of every
// tasks. To do that, we give to each tasks a wait_chan that we
// drop at the end of the work. At the end of this function, we
// wait until the channel hang up.
let (wait_port, wait_chan) = Chan::new();

let len = out.read(|out| out.len());
let chunk = len / 100 + 1;
for chk in count(0, chunk) {
if chk >= len {break;}
let w = wait.clone();
let w = wait_chan.clone();
let v = v.clone();
let out = out.clone();
spawn(proc() {
for i in range(chk, min(len, chk + chunk)) {
let val = v.read(|v| f(v, i));
out.write(|out| out[i] = val);
}
let _ = w;
drop(w)
});
}
let _ = wait.unwrap();

// wait until the channel hang up (every task finished)
drop(wait_chan);
for () in wait_port.iter() {}
}

fn mult_Av_impl(v: &~[f64], i: uint) -> f64 {
Expand Down Expand Up @@ -97,7 +103,8 @@ fn main() {
mult_AtAv(u.clone(), v.clone(), tmp.clone());
mult_AtAv(v.clone(), u.clone(), tmp.clone());
}
let u = u.unwrap();
let v = v.unwrap();
println!("{:.9f}", (dot(u,v) / dot(v,v)).sqrt());

u.read(|u| v.read(|v| {
println!("{:.9f}", (dot(*u, *v) / dot(*v, *v)).sqrt());
}))
}

9 comments on commit 9e49a07

@bors
Copy link
Contributor

@bors bors commented on 9e49a07 Mar 11, 2014

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

saw approval from alexcrichton
at TeXitoi@9e49a07

@bors
Copy link
Contributor

@bors bors commented on 9e49a07 Mar 11, 2014

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

merging TeXitoi/rust/fix-shootout-spectralnorm = 9e49a07 into auto

@bors
Copy link
Contributor

@bors bors commented on 9e49a07 Mar 11, 2014

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

TeXitoi/rust/fix-shootout-spectralnorm = 9e49a07 merged ok, testing candidate = b4ca73a2

@bors
Copy link
Contributor

@bors bors commented on 9e49a07 Mar 11, 2014

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@bors
Copy link
Contributor

@bors bors commented on 9e49a07 Mar 11, 2014

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

saw approval from alexcrichton
at TeXitoi@9e49a07

@bors
Copy link
Contributor

@bors bors commented on 9e49a07 Mar 11, 2014

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

merging TeXitoi/rust/fix-shootout-spectralnorm = 9e49a07 into auto

@bors
Copy link
Contributor

@bors bors commented on 9e49a07 Mar 11, 2014

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

TeXitoi/rust/fix-shootout-spectralnorm = 9e49a07 merged ok, testing candidate = 294d3dd

@bors
Copy link
Contributor

@bors bors commented on 9e49a07 Mar 11, 2014

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@bors
Copy link
Contributor

@bors bors commented on 9e49a07 Mar 11, 2014

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

fast-forwarding master to auto = 294d3dd

Please sign in to comment.