added MPI_Bcast
git-svn-id: https://yap.svn.sf.net/svnroot/yap/trunk@357 b08c6af1-5177-4d33-ba66-4b1c6b8b522a
This commit is contained in:
@@ -16,6 +16,7 @@ calc( From, To, Acc, Res ) :- !,
|
||||
|
||||
%%
|
||||
%% This spreads the work among the processors
|
||||
%% and collects the results.
|
||||
%%
|
||||
|
||||
do(0, Num) :-
|
||||
|
42
library/mpi/examples/demo2.pl
Normal file
42
library/mpi/examples/demo2.pl
Normal file
@@ -0,0 +1,42 @@
|
||||
%% 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] ).
|
Reference in New Issue
Block a user