next up previous Return to CLIP Main Page
Next: Using the CIAO Concurrency Up: Document: distrib_imperial Previous: Some Concurrency & Parallelism

Using Parallelism: Examples

main :-
        read_input_list(L),
        collect_unloaded_hosts(Hosts),
        add_workers(Ids, Hosts),
        process_list(L),
        halt.

process_list([]).
process_list([H|T]) :-
        process(H) &
        process_list(T).

add_workers([Id|Ids],[Host|Hosts]) :-
        add_worker(Id,Host),
        add_workers(Ids,Hosts).
add_workers([],[]).

process_list([]).
process_list([H|T]) :-
    ( H < 5 -> 
        process_list(T), process(H) 
    ;   process(H) & process_list(T) ).

(CIAO parallelizing preprocessor: automatic parallelization and granularity control)

seq :-  move(red), move(green).
par :-  move(red) & move(green).
con :-  move(red) &, move(green).
thr :-  move(red) &&, move(green).
syn :-  sync_move(red, [ok|X]) &&, sync_move(green, X).

move(X) :-
        create(X,H),
        move(100, H),
        destroy(H).

move(0, _) :- !.
move(N, H) :- N > 0,
        move_step(H),
        N1 is N-1,
        move(N1, H).

sync_move(X, L) :-
        create(X,H),
        sync_move(100, H, L),
        destroy(H).

sync_move(0, _, _) :- !.
sync_move(N, H, L) :- N > 0,
        ask(L = [ok|R]),
        move_step(H),
        R = [ok|S],
        N1 is N-1,
        sync_move(N1, H, S).



<herme@fi.upm.es>-< webmaster@clip.dia.fi.upm.es>
Last updated on Mon Mar 31 21:20:55 MET DST 1997