Created
September 7, 2013 16:27
-
-
Save enomado/6477015 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
extern mod extra; | |
use extra::arc::Arc; | |
use std::rand; | |
use std::vec; | |
fn pnorm(nums: &~[float], p: uint) -> float { | |
nums.iter().fold(0.0, |a,b| a+(*b).pow(&(p as float)) ).pow(&(1f / (p as float))) | |
} | |
fn main() { | |
let numbers = vec::from_fn(1000000, |_| rand::random::<float>()); | |
println(fmt!("Inf-norm = %?", *numbers.iter().max().unwrap())); | |
let numbers_arc = Arc::new(numbers); | |
for num in range(1u, 20) { | |
let (port, chan) = stream(); | |
chan.send(numbers_arc.clone()); | |
do spawn { | |
let local_arc : Arc<~[float]> = port.recv(); | |
let task_numbers = local_arc.get(); | |
println(fmt!("%u-norm = %?", num, pnorm(task_numbers, num))); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment