4
5
6:- use_module(library(lam_mpi)). 7
8
9
10main :-
11 mpi_init,
13 mpi_comm_rank(Rank),
14 do_comm(Rank),
15 mpi_finalize.
16
17do_comm(0) :-
18 between(1,10,I),
19 NI is I*1000,
20 gen_list(NI,List),
21 mpi_send(List, 1, I),
22 T =.. [f|List],
23 mpi_send(T, 1, I),
24 writeln(sent:I),
25 fail.
26do_comm(0) :-
27 between(1,10,I),
28 NI is 2.3*I,
29 mpi_send(NI, 1, I),
30 fail.
31do_comm(0).
32do_comm(1) :-
33 between(1,10,I),
34 mpi_recv(0, I, List),
35 writeln(I:List),
36 mpi_recv(0, I, T),
37 writeln(I:T),
38 writeln(received:I),
39 fail.
40do_comm(1) :-
41 between(1,10,I),
42 mpi_recv(0, I, T),
43 writeln(I:T),
44 fail.
45do_comm(1).
46
47gen_list(0,[]) :- !.
48gen_list(I,[I|List]) :-
49 I1 is I-1,
50 gen_list(I1,List).
51
52:- main,halt.