Skip to content

really update mandelbrot to pipes #4299

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

Closed
wants to merge 2 commits into from
Closed
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: 12 additions & 17 deletions src/test/bench/shootout-mandelbrot.rs
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ fn fillbyte(x: cmplx, incr: f64) -> u8 {
rv
}

fn chanmb(i: uint, size: uint, ch: oldcomm::Chan<Line>) -> ()
fn chanmb(i: uint, size: uint) -> Line
{
let mut crv = ~[];
let incr = 2f64/(size as f64);
Expand All @@ -93,27 +93,24 @@ fn chanmb(i: uint, size: uint, ch: oldcomm::Chan<Line>) -> ()
let x = cmplx {re: xincr*(j as f64) - 1.5f64, im: y};
crv.push(fillbyte(x, incr));
};
oldcomm::send(ch, Line {i:i, b: move crv});
Line {i:i, b:crv}
}

type devnull = {dn: int};
struct Devnull();

impl devnull: io::Writer {
impl Devnull: io::Writer {
fn write(&self, _b: &[const u8]) {}
fn seek(&self, _i: int, _s: io::SeekStyle) {}
fn tell(&self) -> uint {0_u}
fn flush(&self) -> int {0}
fn get_type(&self) -> io::WriterType { io::File }
}

fn writer(path: ~str, writech: oldcomm::Chan<oldcomm::Chan<Line>>, size: uint)
fn writer(path: ~str, pport: pipes::Port<Line>, size: uint)
{
let p: oldcomm::Port<Line> = oldcomm::Port();
let ch = oldcomm::Chan(&p);
oldcomm::send(writech, ch);
let cout: io::Writer = match path {
~"" => {
{dn: 0} as io::Writer
Devnull as io::Writer
}
~"-" => {
io::stdout()
Expand All @@ -130,7 +127,7 @@ fn writer(path: ~str, writech: oldcomm::Chan<oldcomm::Chan<Line>>, size: uint)
let mut done = 0_u;
let mut i = 0_u;
while i < size {
let aline = oldcomm::recv(p);
let aline = pport.recv();
if aline.i == done {
debug!("W %u", aline.i);
cout.write(aline.b);
Expand Down Expand Up @@ -171,13 +168,11 @@ fn main() {
let size = if vec::len(args) < 2_u { 80_u }
else { uint::from_str(args[1]).get() };

let writep = oldcomm::Port();
let writech = oldcomm::Chan(&writep);
do task::spawn |move path| {
writer(copy path, writech, size);
};
let ch = oldcomm::recv(writep);
let (pport, pchan) = pipes::stream();
let pchan = pipes::SharedChan(pchan);
for uint::range(0_u, size) |j| {
do task::spawn { chanmb(j, size, ch) };
let cchan = pchan.clone();
do task::spawn |move cchan| { cchan.send(chanmb(j, size)) };
};
writer(path, pport, size);
}