2002-02-12 17:38:38 +00:00
|
|
|
%% demo2.pl -- Stasinos Konstantopoulos
|
|
|
|
%% konstant@let.rug.nl, Tue Feb 12 2002
|
|
|
|
%%
|
|
|
|
|
2014-09-10 05:55:47 +01:00
|
|
|
:- use_module(library(mpi)).
|
|
|
|
|
2002-02-12 17:38:38 +00:00
|
|
|
%%
|
|
|
|
%% This the calculation that needs to be performed, in this case
|
|
|
|
%% the sum of [From..To]
|
|
|
|
%%
|
|
|
|
|
|
|
|
calc( From, From, Acc, Res ) :- !,
|
|
|
|
Res is Acc + From.
|
|
|
|
calc( From, To, Acc, Res ) :- !,
|
|
|
|
Acc1 is Acc + To,
|
|
|
|
To1 is To - 1,
|
|
|
|
calc( From, To1, Acc1, Res ).
|
|
|
|
|
|
|
|
|
|
|
|
%%
|
|
|
|
%% We'll pretend the preprocessing was more complicated, and have the
|
|
|
|
%% root broadcast how many numbers each processor should do.
|
|
|
|
%% Each processor must then figure out which ones to do and call calc/4.
|
|
|
|
%%
|
|
|
|
|
|
|
|
do(0, Num) :-
|
|
|
|
!,
|
2002-02-22 14:31:45 +00:00
|
|
|
mpe_create_event(Ev1),
|
|
|
|
mpe_create_event(Ev2),
|
|
|
|
format( "Ev1 == ~q, Ev2 == ~q~n", [Ev1,Ev2] ),
|
2002-02-27 13:41:24 +00:00
|
|
|
mpe_create_state(Ev1,Ev2,state1,red),
|
2002-02-22 14:31:45 +00:00
|
|
|
format( "1 AA~n", [] ),
|
2002-02-27 13:41:24 +00:00
|
|
|
mpe_log(Ev1,0,event1),
|
2002-02-22 14:31:45 +00:00
|
|
|
format( "2 AA~n", [] ),
|
2002-10-03 18:28:37 +01:00
|
|
|
mpi_bcast( Num, 0 ),
|
2002-02-22 14:31:45 +00:00
|
|
|
format( 'Proc 0: broadcast ~q.~n', [Num] ),
|
2002-02-27 13:41:24 +00:00
|
|
|
mpe_log(Ev2,0,event2).
|
2002-02-12 17:38:38 +00:00
|
|
|
do(Rank, _) :-
|
|
|
|
!,
|
2002-02-22 14:31:45 +00:00
|
|
|
mpe_create_event(Ev1),
|
|
|
|
mpe_create_event(Ev2),
|
|
|
|
format( "Ev1 == ~q, Ev2 == ~q~n", [Ev1,Ev2] ),
|
2002-02-27 13:41:24 +00:00
|
|
|
mpe_log(Ev1,0,event1),
|
2002-10-03 18:28:37 +01:00
|
|
|
mpi_bcast( Num, 0 ),
|
2002-02-22 14:31:45 +00:00
|
|
|
format( 'Proc ~q: had ~q broadcast from 0.~n', [Rank, Num] ),
|
2002-02-27 13:41:24 +00:00
|
|
|
mpe_log(Ev2,0,event2).
|
2002-02-12 17:38:38 +00:00
|
|
|
|
|
|
|
|
|
|
|
%%
|
|
|
|
%% This is the entry point
|
|
|
|
%%
|
|
|
|
|
2002-02-22 14:31:45 +00:00
|
|
|
start(Msg) :-
|
2002-02-12 17:38:38 +00:00
|
|
|
mpi_open( Rank, NumProc, ProcName ),
|
|
|
|
format( 'Rank: ~q NumProc: ~q, ProcName: ~q~n', [Rank,NumProc,ProcName] ),
|
2002-10-03 18:28:37 +01:00
|
|
|
(mpe_open -> true ;
|
|
|
|
assert_static(mpe_create_event(dummy)),
|
|
|
|
assert_static(mpe_create_state(_,_,_,_)),
|
|
|
|
assert_static(mpe_log(_,_,_)),
|
|
|
|
assert_static(mpe_close(_))
|
|
|
|
),
|
2002-02-22 14:31:45 +00:00
|
|
|
do(Rank, Msg),
|
|
|
|
format( 'Rank ~q finished!~n', [Rank] ),
|
2002-02-27 13:41:24 +00:00
|
|
|
mpe_close( demo2 ).
|
2002-10-03 18:28:37 +01:00
|
|
|
|