From 6e2166360f1253315cc646ae5ede0ff49bb720af Mon Sep 17 00:00:00 2001 From: Alex Gough Date: Fri, 19 Aug 2011 19:48:24 +1200 Subject: [PATCH] add ANY_SOURCE --- Simple.pm | 2 +- Simple.xs | 8 ++++++++ ic.pl | 16 ++++++++++++++++ test.pl | 4 ++-- 4 files changed, 27 insertions(+), 3 deletions(-) diff --git a/Simple.pm b/Simple.pm index 614921a..9e9b132 100644 --- a/Simple.pm +++ b/Simple.pm @@ -15,7 +15,7 @@ sub import { my $call = (caller())[0]; no strict 'refs'; # subs (MPI_ function calls) - foreach (qw(Init Finalize COMM_WORLD Comm_rank Comm_size + foreach (qw(Init Finalize COMM_WORLD ANY_SOURCE Comm_rank Comm_size Recv Send Barrier Bcast Gather Scatter Allgather Alltoall Reduce Comm_compare Comm_dup Comm_free Comm_split diff --git a/Simple.xs b/Simple.xs index 0291144..288ad59 100644 --- a/Simple.xs +++ b/Simple.xs @@ -100,6 +100,11 @@ SV* COMM_WORLD () { return newSViv((IV)MPI_COMM_WORLD); } +/* returns SV whose IV slot is a cast pointer to the MPI_ANY_SOURCE value */ +SV* ANY_SOURCE () { + return newSViv((IV)MPI_ANY_SOURCE); +} + /* calls MPI_Barrier for comm */ int Barrier (SV*comm) { MPI_Barrier((MPI_Comm)SvIVX(comm)); @@ -249,6 +254,9 @@ _Comm_size (comm) SV * COMM_WORLD () +SV * +ANY_SOURCE () + int Barrier (comm) SV * comm diff --git a/ic.pl b/ic.pl index 1ec1029..baef203 100755 --- a/ic.pl +++ b/ic.pl @@ -157,6 +157,22 @@ MPI_Barrier(MPI_COMM_WORLD); } } +MPI_Barrier(MPI_COMM_WORLD); +if ($rank == 0) { + my $msg = "Sending from ANY"; + MPI_Send($msg,1,0,MPI_COMM_WORLD); + print "ok 25 # sent from ANY\n"; +} +else { + my $msg = MPI_Recv(MPI_ANY_SOURCE,0,MPI_COMM_WORLD); + if ($msg =~ /Sending from ANY/) { + print "ok 26 # receive from ANY_SOURCE"; + } + else { + print "not ok 26 # receive from ANY_SOURCE"; + } +} + MPI_Finalize(); exit(0); diff --git a/test.pl b/test.pl index a55463e..4eb8eb8 100644 --- a/test.pl +++ b/test.pl @@ -10,8 +10,8 @@ $incs .= " -I$_" foreach @INC; my @newout = sort { (($a =~ /(\d+)/g)[0] <=> ($b =~ /(\d+)/g)[0]) } `$mpirun -np 2 $^X $incs ic.pl`; -print "1..24\n"; -if (@newout < 24) { +print "1..26\n"; +if (@newout < 25) { print "not ok 1 # mpirun failed. Do you need to start mpd?\n"; } print @newout; -- 2.39.5