Skip to content

Commit 5a4e2ae

Browse files
committed
More unsafe pointers to share immutable structures between tasks. This version has a 2.8 to 3x speedup!
1 parent 7f05f08 commit 5a4e2ae

File tree

1 file changed

+20
-16
lines changed

1 file changed

+20
-16
lines changed

src/test/bench/graph500-bfs.rs

Lines changed: 20 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -261,6 +261,7 @@ fn pbfs(graph: graph, key: node_id) -> bfs_result {
261261
}
262262
};
263263

264+
#[inline(always)]
264265
fn is_gray(c: color) -> bool {
265266
alt c {
266267
gray(_) { true }
@@ -274,25 +275,28 @@ fn pbfs(graph: graph, key: node_id) -> bfs_result {
274275
log(info, #fmt("PBFS iteration %?", i));
275276
i += 1u;
276277
let old_len = colors.len();
277-
colors = par::mapi(colors) {|i, c, copy colors|
278+
let pc = ptr::addr_of(colors);
279+
let pg = ptr::addr_of(graph);
280+
colors = par::mapi(colors) {|i, c|
278281
let c : color = c;
279282
alt c {
280283
white {
281-
let i = i as node_id;
282-
283-
let neighbors = graph[i];
284-
285-
let mut color = white;
286-
287-
neighbors.each() {|k|
288-
if is_gray(colors[k]) {
289-
color = gray(k);
290-
false
291-
}
292-
else { true }
293-
};
294-
295-
color
284+
unsafe {
285+
let i = i as node_id;
286+
287+
let neighbors = &(*pg)[i];
288+
289+
let mut color = white;
290+
291+
(*neighbors).each() {|k|
292+
if is_gray((*pc)[k]) {
293+
color = gray(k);
294+
false
295+
}
296+
else { true }
297+
};
298+
color
299+
}
296300
}
297301
gray(parent) { black(parent) }
298302
black(parent) { black(parent) }

0 commit comments

Comments
 (0)