PTL logo

From: Sérgio Clemente Filho (sergioclemente_at_[hidden])
Date: 2010-05-18 01:14:34


Hi Folks,

Not sure if this is the right alias to post. But I found a very
interesting behavior. In the following code it doesn't work when I enable
the red line. It just works when I enable the green line.

*using System;*
*using System.Collections.Generic;*
*using System.Linq;*
*using MPI;*
*using System.Text;*
*
*
*namespace TestMPI*
*{*
* class Program*
* {*
* static int[][] s_ranks = { new int[] { 0, 1 }, new int[] { 0, 1 },
new int[] { 2, 3 }, new int[] { 2, 3 } };*
*
*
* // The following code always assumes it's ran with 4 processors *
* static void Main(string[] args)*
* {*
* using (new MPI.Environment(ref args))*
* {*
* int myRank = MPI.Communicator.world.Rank;*
*
*
* int val = myRank;*
* int rootRank = myRank == 0 || myRank == 1 ? 1 : 3;*
*
*
* //RealBroadcast(myRank, ref val, rootRank);*
* SimulatedBroadcast(myRank, ref val, rootRank); *
* Console.WriteLine("Rank{0}, received={1}", myRank, val);*
* }*
* }*
*
*
* static void SimulatedBroadcast(int myRank, ref int val, int
rootRank)*
* {*
* if (rootRank == myRank)*
* {*
* int[] ranks = s_ranks[myRank];*
*
*
* // If I'm sending*
* foreach (int rank in ranks)*
* {*
* // I don't need to send to myself (doh!)*
* if (rank != myRank)*
* {*
* MPI.Communicator.world.Send<int>(val, rank, 0);*
* }*
* }*
*
*
* } else {*
* // If I'm receiving*
* val = MPI.Communicator.world.Receive<int>(rootRank, 0);*
* }*
* }*
*
*
* static void RealBroadcast(int myRank, ref int val, int rootRank)*
* {*
* Group group =
MPI.Communicator.world.Group.IncludeOnly(s_ranks[myRank]);*
* Intracommunicator communicator =
(Intracommunicator)MPI.Communicator.world.Create(group);*
*
*
* communicator.Broadcast<int>(ref val, rootRank);*
* }*
* }*
*}*
*
*
*
Can anyone tell what I'm doing wrong here? I get the following error:

Thanks in advance,
Sergio

MPI_Bcast(791): MPI_Bcast(buf=0x001FEFFC, count=1, MPI_INT, root=3,
comm=0x84000002) failed
MPI_Bcast(732): Invalid root (value given was 3)
Parameter name: root
   at MPI.Communicator.Broadcast_impl[T](Boolean isRoot, T& value, Int32
root)
   at TestMPI.Program.RealBroadcast(Int32 myRank, Int32& val, Int32
rootRank) in C:\Users\sergiocf.REDMOND\documents\vis
ual studio 2010\Projects\ConsoleApplication2\TestMPI\Program.cs:line 55
   at TestMPI.Program.Main(String[] args) in
C:\Users\sergiocf.REDMOND\documents\visual studio 2010\Projects\ConsoleAppl
ication2\TestMPI\Program.cs:line 22
System.ArgumentException: Invalid root, error stack:
MPI_Bcast(791): MPI_Bcast(buf=0x0036F00C, count=1, MPI_INT, root=3,
comm=0x84000002) failed
MPI_Bcast(732): Invalid root (value given was 3)
Parameter name: root
   at MPI.Communicator.Broadcast_impl[T](Boolean isRoot, T& value, Int32
root)
   at TestMPI.Program.RealBroadcast(Int32 myRank, Int32& val, Int32
rootRank) in C:\Users\sergiocf.REDMOND\documents\vis
ual studio 2010\Projects\ConsoleApplication2\TestMPI\Program.cs:line 55
   at TestMPI.Program.Main(String[] args) in
C:\Users\sergiocf.REDMOND\documents\visual studio 2010\Projects\ConsoleAppl
ication2\TestMPI\Program.cs:line 22

*