Changeset 4455 for trunk/examples
- Timestamp:
- 08/30/08 06:47:37 (4 months ago)
- Location:
- trunk/examples/threads
- Files:
-
- 2 modified
-
integration2d/integration2d.lgt (modified) (3 diffs)
-
mtbatch/mtbatch.lgt (modified) (7 diffs)
Legend:
- Unmodified
- Added
- Removed
-
trunk/examples/threads/integration2d/integration2d.lgt
r4393 r4455 121 121 122 122 :- info([ 123 version is 1. 0,123 version is 1.1, 124 124 author is 'Paul Crocker', 125 date is 2008/0 3/17,125 date is 2008/08/30, 126 126 comment is 'Multi-threading implementation of Recursive Gaussian Quadrature Methods for Numerical Integration for functions of two real variables.', 127 127 parameters is ['Threads'- 'Number of threads to use.']]). … … 136 136 start(Function, A, B, C, D, NP, Epsilon, Integral) 137 137 ; % Threads > 1 138 Threads2 is round(sqrt(Threads)), 138 139 Epsilon2 is Epsilon/Threads, 139 split(A, B, Threads, Intervals), 140 spawn(Intervals, Function, C, D, NP, Epsilon2, Goals), 140 split(A, B, Threads2, ABIntervals), 141 split(C, D, Threads2, CDIntervals), 142 spawn(ABIntervals, CDIntervals, Function, NP, Epsilon2, [], Goals), 141 143 collect(Goals, 0.0, Integral) 142 144 ). … … 155 157 156 158 % initiate the thread calls 157 spawn([], _, _, _,_, _, []). 158 spawn([Left-Right| Intervals], Function, C, D, NP, Epsilon, [start(Function,Left,Right,C,D,NP,Epsilon,SubVolume)| Goals]) :- 159 threaded_once(start(Function,Left,Right,C,D,NP,Epsilon,SubVolume)), 160 spawn(Intervals, Function, C,D, NP, Epsilon, Goals). 159 spawn([], _, _, _, _, Goals, Goals). 160 spawn([Left-Right| ABIntervals], CDIntervals, Function, NP, Epsilon, Acc, Goals) :- 161 spawn(CDIntervals, Left, Right, Function, NP, Epsilon, Acc, Acc2), 162 spawn(ABIntervals, CDIntervals, Function, NP, Epsilon, Acc2, Goals). 163 164 spawn([], _, _, _, _, _, Goals, Goals). 165 spawn([Bottom-Top| CDIntervals], Left, Right, Function, NP, Epsilon, Acc, Goals) :- 166 threaded_once(start(Function,Left,Right,Bottom,Top,NP,Epsilon,SubVolume)), 167 spawn(CDIntervals, Left, Right, Function, NP, Epsilon, [start(Function,Left,Right,Bottom,Top,NP,Epsilon,SubVolume)| Acc], Goals). 161 168 162 169 % wait for the threads to finish and then we will collect the results summing as we go 163 170 collect([], Integral, Integral). 164 collect([start(Function,Left,Right, C,D,NP,Epsilon,SubVolume)| Goals], Acc, Integral) :-165 threaded_exit(start(Function,Left,Right, C,D,NP,Epsilon,SubVolume)),171 collect([start(Function,Left,Right,Bottom,Top,NP,Epsilon,SubVolume)| Goals], Acc, Integral) :- 172 threaded_exit(start(Function,Left,Right,Bottom,Top,NP,Epsilon,SubVolume)), 166 173 Acc2 is Acc + SubVolume, 167 174 collect(Goals, Acc2, Integral). -
trunk/examples/threads/mtbatch/mtbatch.lgt
r4454 r4455 3 3 4 4 :- info([ 5 version is 1. 1,5 version is 1.2, 6 6 author is 'Paulo Moura', 7 date is 2008/0 6/14,7 date is 2008/08/30, 8 8 comment is 'Multi-threading benchmarks.', 9 9 parameters is ['Prolog'- 'Prolog backend compiler. Supported compilers are SWI-Prolog (swi), YAP (yap), and XSB (xsb).']]). … … 272 272 write('Numerical integration of functions of two variables (average of '), write(N), write(' runs)'), nl, 273 273 write('using a split/spawn/collect quadrature method with '), write(NP), write(' points'), nl, 274 loop::forto(T, 0, 4,275 ( Threads is truncate(2**T),274 loop::forto(T, 1, 4, 275 ( Threads is T*T, 276 276 put_char('\t'), write(Threads) 277 277 )), nl, … … 288 288 ), 289 289 ( write(Function), 290 loop::forto(T, 0, 4,291 ( Threads is truncate(2**T),290 loop::forto(T, 1, 4, 291 ( Threads is T*T, 292 292 catch(run(quadsplit2d(Threads, Function, A, B, C, D, NP, Epsilon), N, Average), Error, write_error) -> 293 293 ( var(Error) -> … … 408 408 do_benchmark(quadrec(Threads, Function, Inf, Sup, NP, Epsilon), N) :- 409 409 repeat(N), 410 quadrec(Threads)::integrate(Function, Inf, Sup, NP, Epsilon, _), 410 ( quadrec(Threads)::integrate(Function, Inf, Sup, NP, Epsilon, _) -> 411 true 412 ; throw(error(failure)) 413 ), 411 414 fail. 412 415 do_benchmark(quadrec(_, _, _, _, _, _), _). … … 414 417 do_benchmark(quadsplit(Threads, Function, Inf, Sup, NP, Epsilon), N) :- 415 418 repeat(N), 416 quadsplit(Threads)::integrate(Function, Inf, Sup, NP, Epsilon, _), 419 ( quadsplit(Threads)::integrate(Function, Inf, Sup, NP, Epsilon, _) -> 420 true 421 ; throw(error(failure)) 422 ), 417 423 fail. 418 424 do_benchmark(quadsplit(_, _, _, _, _, _), _). … … 420 426 do_benchmark(quadrec2d(Threads, Function, A, B, C, D, NP, Epsilon), N) :- 421 427 repeat(N), 422 quadrec2d(Threads)::integrate(Function, A, B, C, D, NP, Epsilon, _), 428 ( quadrec2d(Threads)::integrate(Function, A, B, C, D, NP, Epsilon, _) -> 429 true 430 ; throw(error(failure)) 431 ), 423 432 fail. 424 433 do_benchmark(quadrec2d(_, _, _, _, _, _, _, _), _). … … 426 435 do_benchmark(quadsplit2d(Threads, Function, A, B, C, D, NP, Epsilon), N) :- 427 436 repeat(N), 428 quadsplit2d(Threads)::integrate(Function,A, B, C, D, NP, Epsilon, _), 437 ( quadsplit2d(Threads)::integrate(Function,A, B, C, D, NP, Epsilon, _) -> 438 true 439 ; throw(error(failure)) 440 ), 429 441 fail. 430 442 do_benchmark(quadsplit2d(_, _, _, _, _, _, _, _), _).
