Changeset 4455 for trunk/examples

Show
Ignore:
Timestamp:
08/30/08 06:47:37 (4 months ago)
Author:
pmoura
Message:

Updated the "mtbatch" example to detect unexpected failures when running the multi-threading integration benchmarks.

Update the "integration2d" multi-threading example to make the recursive and the split/spawn/collect methods equivalent.

Location:
trunk/examples/threads
Files:
2 modified

Legend:

Unmodified
Added
Removed
  • trunk/examples/threads/integration2d/integration2d.lgt

    r4393 r4455  
    121121 
    122122    :- info([ 
    123         version is 1.0, 
     123        version is 1.1, 
    124124        author is 'Paul Crocker', 
    125         date is 2008/03/17, 
     125        date is 2008/08/30, 
    126126        comment is 'Multi-threading implementation of Recursive Gaussian Quadrature Methods for Numerical Integration for functions of two real variables.', 
    127127        parameters is ['Threads'- 'Number of threads to use.']]). 
     
    136136            start(Function, A, B, C, D, NP, Epsilon, Integral) 
    137137        ;   % Threads > 1 
     138            Threads2 is round(sqrt(Threads)), 
    138139            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), 
    141143            collect(Goals, 0.0, Integral) 
    142144        ). 
     
    155157 
    156158    % 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). 
    161168 
    162169    % wait for the threads to finish and then we will collect the results summing as we go 
    163170    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)),       
    166173        Acc2 is Acc + SubVolume, 
    167174        collect(Goals, Acc2, Integral). 
  • trunk/examples/threads/mtbatch/mtbatch.lgt

    r4454 r4455  
    33 
    44    :- info([ 
    5         version is 1.1, 
     5        version is 1.2, 
    66        author is 'Paulo Moura', 
    7         date is 2008/06/14, 
     7        date is 2008/08/30, 
    88        comment is 'Multi-threading benchmarks.', 
    99        parameters is ['Prolog'- 'Prolog backend compiler. Supported compilers are SWI-Prolog (swi), YAP (yap), and XSB (xsb).']]). 
     
    272272        write('Numerical integration of functions of two variables (average of '), write(N), write(' runs)'), nl, 
    273273        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, 
    276276                put_char('\t'), write(Threads) 
    277277            )), nl, 
     
    288288            ), 
    289289            (   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, 
    292292                        catch(run(quadsplit2d(Threads, Function, A, B, C, D, NP, Epsilon), N, Average), Error, write_error) -> 
    293293                        (   var(Error) -> 
     
    408408    do_benchmark(quadrec(Threads, Function, Inf, Sup, NP, Epsilon), N) :- 
    409409        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            ), 
    411414        fail. 
    412415    do_benchmark(quadrec(_, _, _, _, _, _), _). 
     
    414417    do_benchmark(quadsplit(Threads, Function, Inf, Sup, NP, Epsilon), N) :- 
    415418        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            ), 
    417423        fail. 
    418424    do_benchmark(quadsplit(_, _, _, _, _, _), _). 
     
    420426    do_benchmark(quadrec2d(Threads, Function, A, B, C, D, NP, Epsilon), N) :- 
    421427        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            ), 
    423432        fail. 
    424433    do_benchmark(quadrec2d(_, _, _, _, _, _, _, _), _). 
     
    426435    do_benchmark(quadsplit2d(Threads, Function, A, B, C, D, NP, Epsilon), N) :- 
    427436        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            ), 
    429441        fail. 
    430442    do_benchmark(quadsplit2d(_, _, _, _, _, _, _, _), _).