@@ -403,9 +403,10 @@ fn validate(edges: [(node_id, node_id)],
403
403
}
404
404
405
405
fn main ( ) {
406
- let scale = 15 u ;
406
+ let scale = 14 u ;
407
407
let num_keys = 16 u;
408
408
let do_validate = false ;
409
+ let do_sequential = true ;
409
410
410
411
let start = time:: precise_time_s ( ) ;
411
412
let edges = make_edges ( scale, 16 u) ;
@@ -431,44 +432,49 @@ fn main() {
431
432
gen_search_keys ( graph, num_keys) . map ( ) { |root|
432
433
io:: stdout ( ) . write_line ( "" ) ;
433
434
io:: stdout ( ) . write_line ( #fmt ( "Search key: %?" , root) ) ;
434
-
435
- let start = time:: precise_time_s ( ) ;
436
- let bfs_tree = bfs ( graph, root) ;
437
- let stop = time:: precise_time_s ( ) ;
438
-
439
- total_seq += stop - start;
440
-
441
- io:: stdout ( ) . write_line ( #fmt ( "Sequential BFS completed in %? seconds." ,
442
- stop - start) ) ;
443
435
444
- if do_validate {
436
+ if do_sequential {
445
437
let start = time:: precise_time_s ( ) ;
446
- assert ( validate ( edges , root, bfs_tree ) ) ;
438
+ let bfs_tree = bfs ( graph , root) ;
447
439
let stop = time:: precise_time_s ( ) ;
448
440
449
- io:: stdout ( ) . write_line ( #fmt ( "Validation completed in %? seconds." ,
450
- stop - start) ) ;
451
- }
452
-
453
- let start = time:: precise_time_s ( ) ;
454
- let bfs_tree = bfs2 ( graph, root) ;
455
- let stop = time:: precise_time_s ( ) ;
456
-
457
- //total_seq += stop - start;
441
+ //total_seq += stop - start;
458
442
459
- io:: stdout ( ) . write_line (
460
- #fmt ( "Slow Sequential BFS completed in %? seconds." ,
461
- stop - start) ) ;
462
-
463
- if do_validate {
443
+ io:: stdout ( ) . write_line (
444
+ #fmt ( "Sequential BFS completed in %? seconds." ,
445
+ stop - start) ) ;
446
+
447
+ if do_validate {
448
+ let start = time:: precise_time_s ( ) ;
449
+ assert ( validate ( edges, root, bfs_tree) ) ;
450
+ let stop = time:: precise_time_s ( ) ;
451
+
452
+ io:: stdout ( ) . write_line (
453
+ #fmt ( "Validation completed in %? seconds." ,
454
+ stop - start) ) ;
455
+ }
456
+
464
457
let start = time:: precise_time_s ( ) ;
465
- assert ( validate ( edges , root, bfs_tree ) ) ;
458
+ let bfs_tree = bfs2 ( graph , root) ;
466
459
let stop = time:: precise_time_s ( ) ;
467
460
468
- io:: stdout ( ) . write_line ( #fmt ( "Validation completed in %? seconds." ,
469
- stop - start) ) ;
461
+ total_seq += stop - start;
462
+
463
+ io:: stdout ( ) . write_line (
464
+ #fmt ( "Alternate Sequential BFS completed in %? seconds." ,
465
+ stop - start) ) ;
466
+
467
+ if do_validate {
468
+ let start = time:: precise_time_s ( ) ;
469
+ assert ( validate ( edges, root, bfs_tree) ) ;
470
+ let stop = time:: precise_time_s ( ) ;
471
+
472
+ io:: stdout ( ) . write_line (
473
+ #fmt ( "Validation completed in %? seconds." ,
474
+ stop - start) ) ;
475
+ }
470
476
}
471
-
477
+
472
478
let start = time:: precise_time_s ( ) ;
473
479
let bfs_tree = pbfs ( graph, root) ;
474
480
let stop = time:: precise_time_s ( ) ;
@@ -502,49 +508,7 @@ import comm::port;
502
508
import comm:: chan;
503
509
import comm:: send;
504
510
import comm:: recv;
505
- import task:: spawn;
506
-
507
- iface future<T : send> {
508
- fn get ( ) -> T ;
509
- }
510
-
511
- type future_ < T : send > = {
512
- mut slot : option < T > ,
513
- port : port < T > ,
514
- } ;
515
-
516
- impl < T : send > of future < T > for future_ < T > {
517
- fn get ( ) -> T {
518
- get ( self )
519
- }
520
- }
521
-
522
- fn get < T : send > ( f : future_ < T > ) -> T {
523
- alt ( f. slot ) {
524
- some ( x) { x }
525
- none {
526
- let x = recv ( f. port ) ;
527
- f. slot = some ( x) ;
528
- x
529
- }
530
- }
531
- }
532
-
533
-
534
- #[ doc="Executes a bit of code asynchronously.
535
-
536
- Returns a handle that can be used to retrieve the result at your
537
- leisure." ]
538
- fn future < T : send > ( thunk : fn ~( ) -> T ) -> future < T > {
539
- let p = port ( ) ;
540
- let c = chan ( p) ;
541
-
542
- spawn ( ) { ||
543
- send ( c, thunk ( ) ) ;
544
- }
545
-
546
- { mut slot: none :: < T > , port : p} as future :: < T >
547
- }
511
+ import future:: future;
548
512
549
513
#[ doc="The maximum number of tasks this module will spawn for a single
550
514
operationg." ]
@@ -576,7 +540,7 @@ fn map_slices<A: send, B: send>(xs: [A], f: fn~(uint, [A]) -> B) -> [B] {
576
540
while base < len {
577
541
let slice = vec:: slice ( xs, base,
578
542
uint:: min ( len, base + items_per_task) ) ;
579
- futures += [ future ( ) { |copy base|
543
+ futures += [ future:: spawn ( ) { |copy base|
580
544
f ( base, slice)
581
545
} ] ;
582
546
base += items_per_task;
0 commit comments