Skip to content

fix shootout-spectralnorm, broken since Arc cannot unwrap. #12766

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Mar 11, 2014
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
29 changes: 18 additions & 11 deletions src/test/bench/shootout-spectralnorm.rs
Original file line number Diff line number Diff line change
@@ -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());
}))
}