This repository has been archived on 2023-08-20. You can view files and clone it, but cannot push or open issues or pull requests.
yap-6.3/library/mpi/examples/demo2.pl
stasinos 39964380f1 added MPI_Bcast
git-svn-id: https://yap.svn.sf.net/svnroot/yap/trunk@357 b08c6af1-5177-4d33-ba66-4b1c6b8b522a
2002-02-12 17:38:38 +00:00

43 lines
961 B
Prolog

%% demo2.pl -- Stasinos Konstantopoulos
%% konstant@let.rug.nl, Tue Feb 12 2002
%%
%%
%% 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) :-
!,
mpi_bcast( Num, 0 ),
format( 'Proc 0: broadcast ~q.~n', [Num] ).
do(Rank, _) :-
!,
mpi_bcast( Num, 0 ),
format( 'Proc ~q: had ~q broadcast from 0.~n', [Rank, Num] ).
%%
%% This is the entry point
%%
start(Num) :-
mpi_open( Rank, NumProc, ProcName ),
format( 'Rank: ~q NumProc: ~q, ProcName: ~q~n', [Rank,NumProc,ProcName] ),
do( Rank, Num ),
format( 'Rank ~q finished!~n', [Rank] ).