Skip to content
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

Remove extra::par fixes #5626 #7034

Closed
wants to merge 5 commits into from
Closed
Changes from 1 commit
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
Next Next commit
Remove extra::par fixes #5626
  • Loading branch information
Nick Desaulniers committed Jun 9, 2013
commit 0174ef95ee7bf02a068281e6a21303db547eb2d3
146 changes: 0 additions & 146 deletions src/libextra/par.rs

This file was deleted.

1 change: 0 additions & 1 deletion src/libextra/std.rc
Original file line number Diff line number Diff line change
@@ -100,7 +100,6 @@ pub mod tempfile;
pub mod term;
pub mod time;
pub mod arena;
pub mod par;
pub mod base64;
pub mod rl;
pub mod workcache;
139 changes: 138 additions & 1 deletion src/test/bench/graph500-bfs.rs
Original file line number Diff line number Diff line change
@@ -20,7 +20,6 @@ extern mod extra;
use extra::arc;
use extra::time;
use extra::deque::Deque;
use extra::par;
use std::hashmap::HashSet;
use std::int::abs;
use std::io;
@@ -34,6 +33,144 @@ type node_id = i64;
type graph = ~[~[node_id]];
type bfs_result = ~[node_id];

// Moved from extra::par
mod par {
use std::cast;
use std::ptr;
use std::sys;
use std::uint;
use std::vec;
use extra::future;

/**
* The maximum number of tasks this module will spawn for a single
* operation.
*/
static max_tasks : uint = 32u;

/// The minimum number of elements each task will process.
static min_granularity : uint = 1024u;

/**
* An internal helper to map a function over a large vector and
* return the intermediate results.
*
* This is used to build most of the other parallel vector functions,
* like map or alli.
*/
fn map_slices<A:Copy + Owned,B:Copy + Owned>(
xs: &[A],
f: &fn() -> ~fn(uint, v: &[A]) -> B)
-> ~[B] {

let len = xs.len();
if len < min_granularity {
info!("small slice");
// This is a small vector, fall back on the normal map.
~[f()(0u, xs)]
}
else {
let num_tasks = uint::min(max_tasks, len / min_granularity);

let items_per_task = len / num_tasks;

let mut futures = ~[];
let mut base = 0u;
info!("spawning tasks");
while base < len {
let end = uint::min(len, base + items_per_task);
do vec::as_imm_buf(xs) |p, _len| {
let f = f();
let base = base;
let f = do future::spawn() || {
unsafe {
let len = end - base;
let slice = (ptr::offset(p, base),
len * sys::size_of::<A>());
info!("pre-slice: %?", (base, slice));
let slice : &[A] =
cast::transmute(slice);
info!("slice: %?", (base, slice.len(), end - base));
assert_eq!(slice.len(), end - base);
f(base, slice)
}
};
futures.push(f);
};
base += items_per_task;
}
info!("tasks spawned");

info!("num_tasks: %?", (num_tasks, futures.len()));
assert_eq!(num_tasks, futures.len());

let r = do vec::map_consume(futures) |ys| {
let mut ys = ys;
ys.get()
};
r
}
}

/// A parallel version of map.
pub fn map<A:Copy + Owned,B:Copy + Owned>(
xs: &[A], fn_factory: &fn() -> ~fn(&A) -> B) -> ~[B] {
vec::concat(map_slices(xs, || {
let f = fn_factory();
let result: ~fn(uint, &[A]) -> ~[B] =
|_, slice| vec::map(slice, |x| f(x));
result
}))
}

/// A parallel version of mapi.
pub fn mapi<A:Copy + Owned,B:Copy + Owned>(
xs: &[A],
fn_factory: &fn() -> ~fn(uint, &A) -> B) -> ~[B] {
let slices = map_slices(xs, || {
let f = fn_factory();
let result: ~fn(uint, &[A]) -> ~[B] = |base, slice| {
vec::mapi(slice, |i, x| {
f(i + base, x)
})
};
result
});
let r = vec::concat(slices);
info!("%?", (r.len(), xs.len()));
assert_eq!(r.len(), xs.len());
r
}

/// Returns true if the function holds for all elements in the vector.
pub fn alli<A:Copy + Owned>(
xs: &[A],
fn_factory: &fn() -> ~fn(uint, &A) -> bool) -> bool
{
do vec::all(map_slices(xs, || {
let f = fn_factory();
let result: ~fn(uint, &[A]) -> bool = |base, slice| {
vec::alli(slice, |i, x| {
f(i + base, x)
})
};
result
})) |x| { *x }
}

/// Returns true if the function holds for any elements in the vector.
pub fn any<A:Copy + Owned>(
xs: &[A],
fn_factory: &fn() -> ~fn(&A) -> bool) -> bool {
do vec::any(map_slices(xs, || {
let f = fn_factory();
let result: ~fn(uint, &[A]) -> bool =
|_, slice| vec::any(slice, |x| f(x));
result
})) |x| { *x }
}
}

fn make_edges(scale: uint, edgefactor: uint) -> ~[(node_id, node_id)] {
let mut r = rand::XorShiftRng::new();