public static void DoTest(string[] args) { Intracommunicator comm = Communicator.world; if (comm.Rank == 0) { Console.WriteLine("Rank 0 is alive and running on " + MPI.Environment.ProcessorName); for (int dest = 1; dest < comm.Size; ++dest) { Console.Write("Pinging process with rank " + dest + "..."); comm.Send("Ping!", dest, 0); string destHostname = comm.Receive <string>(dest, 1); Console.WriteLine(" Pong!"); Console.WriteLine(" Rank " + dest + " is alive and running on " + destHostname); } } else { var brk = System.Environment.GetEnvironmentVariable("BreakUnitTestOutcomeTest"); if (!string.IsNullOrEmpty(brk)) { int rankToBreak = int.Parse(brk); if (rankToBreak == comm.Rank) { MPIDebug.Assert(false, "Force failure of an assertion in BreakUnitTestOutcomeTest"); } } comm.Receive <string>(0, 0); comm.Send(MPI.Environment.ProcessorName, 0, 1); } }
public static void DoTest(string[] args) { using (new MPI.Environment(ref args)) { Intracommunicator world = Communicator.world; world.Barrier(); // Test addition of integers if (world.Rank == 0) { System.Console.Write("Testing exclusive scan of strings..."); } int partial_sum = world.ExclusiveScan(world.Rank, addInts); int expected = world.Rank * (world.Rank - 1) / 2; MPIDebug.Assert(partial_sum == expected); if (world.Rank == 0) { System.Console.WriteLine(" done."); } // Test addition of integer points if (world.Rank == 0) { System.Console.Write("Testing exclusive scan of strings..."); } Point point_sum = world.ExclusiveScan(new Point(world.Rank, 1), Point.Plus); MPIDebug.Assert(point_sum.x == partial_sum && point_sum.y == world.Rank); if (world.Rank == 0) { System.Console.WriteLine(" done."); } // Test addition of integer arrays if (world.Rank == 0) { System.Console.Write("Testing exclusive scan of integer arrays..."); } int[] arraySum = world.ExclusiveScan(new int[] { world.Rank, 1 }, Operation <int> .Add); MPIDebug.Assert((world.Rank == 0 && arraySum == null) || (world.Rank != 0 && arraySum[0] == partial_sum && arraySum[1] == world.Rank)); if (world.Rank == 0) { System.Console.WriteLine(" done."); } // Test concatenation of strings if (world.Rank == 0) { System.Console.Write("Testing exclusive scan of strings..."); } string str = world.ExclusiveScan(world.Rank.ToString(), Operation <string> .Add); string expectedStr = null; if (world.Rank != 0) { expectedStr = ""; for (int p = 0; p < world.Rank; ++p) { expectedStr += p.ToString(); } } MPIDebug.Assert(expectedStr == str); if (world.Rank == 0) { System.Console.WriteLine(" done."); } // Test concatenation of string arrays if (world.Rank == 0) { System.Console.Write("Testing exclusive scan of string arrays..."); } string[] strArray = world.ExclusiveScan(new string[] { world.Rank.ToString(), "World" }, Operation <string> .Add); string[] expectedStrs = null; if (world.Rank != 0) { expectedStrs = new string[2] { "", "" }; for (int p = 0; p < world.Rank; ++p) { expectedStrs[0] += p.ToString(); expectedStrs[1] += "World"; } MPIDebug.Assert(expectedStrs[0] == strArray[0]); MPIDebug.Assert(expectedStrs[1] == strArray[1]); } else { MPIDebug.Assert(expectedStrs == null); } if (world.Rank == 0) { System.Console.WriteLine(" done."); } } }
public static void DoTest(string[] args) { //using (MPI.Environment env = new MPI.Environment(ref args)) { Intracommunicator comm = MPI.Communicator.world; int recvValue_i; string recvValue_s; int[] recvValues_i; int[] sendValues_i; string[] recvValues_s; string[] sendValues_s; if (comm.Rank == 0) { System.Console.Write("Testing SendReceive of integer..."); } for (int i = 0; i < comm.Size; i++) { comm.SendReceive(comm.Rank, i, 0, out recvValue_i); MPIDebug.Assert(recvValue_i == i); } if (comm.Rank == 0) { System.Console.WriteLine(" done."); } if (comm.Rank == 0) { System.Console.Write("Testing SendReceive of string..."); } for (int i = 0; i < comm.Size; i++) { comm.SendReceive(comm.Rank.ToString(), i, 0, out recvValue_s); MPIDebug.Assert(recvValue_s == i.ToString()); } if (comm.Rank == 0) { System.Console.WriteLine(" done."); } if (comm.Rank == 0) { System.Console.Write("Testing SendReceive of integers..."); } sendValues_i = new int[comm.Rank]; for (int i = 0; i < comm.Rank; i++) { sendValues_i[i] = comm.Rank; } for (int i = 0; i < comm.Size; i++) { recvValues_i = new int[i]; comm.SendReceive(sendValues_i, i, 0, ref recvValues_i); for (int j = 0; j < i; j++) { MPIDebug.Assert(recvValues_i[j] == i); } } if (comm.Rank == 0) { System.Console.WriteLine(" done."); } if (comm.Rank == 0) { System.Console.Write("Testing SendReceive of strings..."); } sendValues_s = new string[comm.Rank]; for (int i = 0; i < comm.Rank; i++) { sendValues_s[i] = comm.Rank.ToString(); } for (int i = 0; i < comm.Size; i++) { recvValues_s = new string[i]; comm.SendReceive(sendValues_s, i, 0, ref recvValues_s); for (int j = 0; j < i; j++) { MPIDebug.Assert(recvValues_s[j] == i.ToString()); } } if (comm.Rank == 0) { System.Console.WriteLine(" done."); } } }
public static void DoTest(string[] args) { using (new MPI.Environment(ref args)) { bool isRoot = (Communicator.world.Rank == 0); // Construct graph if (isRoot) { System.Console.WriteLine("Testing constructor..."); } int nprocesses = MPI.Communicator.world.Size; int[][] edges = new int[nprocesses][]; int nneighbors = nprocesses - 1; for (int i = 0; i < nprocesses; i++) { edges[i] = new int[3]; edges[i][0] = (i + 1) % nprocesses; edges[i][1] = (i + 2) % nprocesses; edges[i][2] = (i + 3) % nprocesses; } MPI.GraphCommunicator gc = new MPI.GraphCommunicator(MPI.Communicator.world, edges, false); if (isRoot) { System.Console.WriteLine(" done."); } // Test Edges if (isRoot) { System.Console.WriteLine("Testing Edges..."); } int[][] edges2; edges2 = gc.Edges; for (int j = 0; j < edges.Length; j++) { for (int k = 0; k < edges[j].Length; k++) { MPIDebug.Assert(edges[j][k] == edges2[j][k]); } } if (isRoot) { System.Console.WriteLine(" done."); } // Test Edges if (isRoot) { System.Console.WriteLine("Testing NumEdges..."); } MPIDebug.Assert(gc.NumEdges == 3 * nprocesses); if (isRoot) { System.Console.WriteLine(" done."); } // Test Neighbors if (isRoot) { System.Console.WriteLine("Testing Neighbors..."); } MPIDebug.Assert(gc.Neighbors[0] == edges[gc.Rank][0]); MPIDebug.Assert(gc.Neighbors[1] == edges[gc.Rank][1]); MPIDebug.Assert(gc.Neighbors[2] == edges[gc.Rank][2]); if (isRoot) { System.Console.WriteLine(" done."); } // Test NeighborsOf() if (isRoot) { System.Console.WriteLine("Testing NeighborsOf()..."); } MPIDebug.Assert(gc.NeighborsOf((gc.Rank + 1) % gc.Size)[0] == edges[(gc.Rank + 1) % gc.Size][0]); MPIDebug.Assert(gc.NeighborsOf((gc.Rank + 1) % gc.Size)[1] == edges[(gc.Rank + 1) % gc.Size][1]); MPIDebug.Assert(gc.NeighborsOf((gc.Rank + 1) % gc.Size)[2] == edges[(gc.Rank + 1) % gc.Size][2]); if (isRoot) { System.Console.WriteLine(" done."); } } }
public static void DoTest(string[] args) { int rank = Communicator.world.Rank; Intracommunicator sub_comm = (Intracommunicator)Communicator.world.Split(rank % 2, rank); Intercommunicator inter_comm; if (rank % 2 == 0) { inter_comm = new Intercommunicator(sub_comm, 0, Communicator.world, 1, 0); } else { inter_comm = new Intercommunicator(sub_comm, 0, Communicator.world, 0, 0); } int j; int p; int size; int outValue_i; string outValue_s; int[] inValues_i; int[] outValues_i; string[] inValues_s; string[] outValues_s; int checkValue_i; int[] checkValues_i; string checkValue_s; string[] checkValues_s; bool success = true; int[] remoteSuccess = null; // Gather with ints if (rank == 0) { outValues_i = inter_comm.Gather(inter_comm.Rank, Intercommunicator.Root); inter_comm.Gather(inter_comm.Rank, 0); } else if (rank == 1) { outValues_i = inter_comm.Gather(inter_comm.Rank, 0); outValues_i = inter_comm.Gather(inter_comm.Rank, Intercommunicator.Root); } else if (rank % 2 == 1) { outValues_i = inter_comm.Gather(inter_comm.Rank, 0); outValues_i = inter_comm.Gather(inter_comm.Rank, Intercommunicator.Null); } else { outValues_i = inter_comm.Gather(inter_comm.Rank, Intercommunicator.Null); outValues_i = inter_comm.Gather(inter_comm.Rank, 0); } if (rank == 0 || rank == 1) { Array.Sort(outValues_i); for (int i = 0; i < inter_comm.RemoteSize; i++) { if (i != outValues_i[i]) { success = false; } } System.Console.WriteLine("Rank " + rank + ": Gather<int> Passed == " + success); MPIDebug.Assert(success); } success = true; // Gather with strings if (rank == 0) { outValues_s = inter_comm.Gather(inter_comm.Rank.ToString(), Intercommunicator.Root); inter_comm.Gather(inter_comm.Rank.ToString(), 0); } else if (rank == 1) { outValues_s = inter_comm.Gather(inter_comm.Rank.ToString(), 0); outValues_s = inter_comm.Gather(inter_comm.Rank.ToString(), Intercommunicator.Root); } else if (rank % 2 == 1) { outValues_s = inter_comm.Gather(inter_comm.Rank.ToString(), 0); outValues_s = inter_comm.Gather(inter_comm.Rank.ToString(), Intercommunicator.Null); } else { outValues_s = inter_comm.Gather(inter_comm.Rank.ToString(), Intercommunicator.Null); outValues_s = inter_comm.Gather(inter_comm.Rank.ToString(), 0); } if (rank == 0 || rank == 1) { Array.Sort(outValues_s, CompareNumberStrings); for (int i = 0; i < inter_comm.RemoteSize; i++) { if (i.ToString() != outValues_s[i]) { success = false; } } System.Console.WriteLine("Rank " + rank + ": Gather<string> Passed == " + success); } MPIDebug.Assert(success); success = true; // Scatter with ints inValues_i = new int[inter_comm.RemoteSize]; if (rank == 0 || rank == 1) { for (int i = 0; i < inter_comm.RemoteSize; i++) { inValues_i[i] = i; } } if (rank == 0) { inter_comm.Scatter <int>(inValues_i); remoteSuccess = inter_comm.Gather <int>(1, Intercommunicator.Root); foreach (int b in remoteSuccess) { if (b == 0) { success = false; } } System.Console.WriteLine("Rank " + rank + ": Scatter<int> Passed == " + success); MPIDebug.Assert(success); success = true; outValue_i = inter_comm.Scatter <int>(0); inter_comm.Gather <int>((inter_comm.Rank == outValue_i ? 1 : 0), 0); } else if (rank == 1) { outValue_i = inter_comm.Scatter <int>(0); inter_comm.Gather <int>((inter_comm.Rank == outValue_i ? 1 : 0), 0); inter_comm.Scatter <int>(inValues_i); remoteSuccess = inter_comm.Gather <int>(1, Intercommunicator.Root); System.Console.WriteLine(); foreach (int b in remoteSuccess) { if (b == 0) { success = false; } } System.Console.WriteLine("Rank " + rank + ": Scatter<int> Passed == " + success); MPIDebug.Assert(success); success = true; } else if (rank % 2 == 1) { outValue_i = inter_comm.Scatter <int>(0); inter_comm.Gather <int>((inter_comm.Rank == outValue_i ? 1 : 0), 0); inter_comm.Scatter <int>(); inter_comm.Gather <int>(1, Intercommunicator.Null); } else { inter_comm.Scatter <int>(); inter_comm.Gather <int>(1, Intercommunicator.Null); outValue_i = inter_comm.Scatter <int>(0); inter_comm.Gather <int>((inter_comm.Rank == outValue_i ? 1 : 0), 0); } // Scatter with strings (MPI_DATATYPE_NULL) inValues_s = new string[inter_comm.RemoteSize]; if (rank == 0 || rank == 1) { for (int i = 0; i < inter_comm.RemoteSize; i++) { inValues_s[i] = i.ToString(); } } if (rank == 0) { inter_comm.Scatter(inValues_s); remoteSuccess = inter_comm.Gather <int>(1, Intercommunicator.Root); foreach (int b in remoteSuccess) { if (b == 0) { success = false; } } System.Console.WriteLine("Rank " + rank + ": Scatter<string> Passed == " + success); MPIDebug.Assert(success); success = true; outValue_s = inter_comm.Scatter <string>(0); inter_comm.Gather <int>((inter_comm.Rank.ToString() == outValue_s ? 1 : 0), 0); } else if (rank == 1) { outValue_s = inter_comm.Scatter <string>(0); inter_comm.Gather <int>((inter_comm.Rank.ToString() == outValue_s ? 1 : 0), 0); inter_comm.Scatter(inValues_s); remoteSuccess = inter_comm.Gather <int>(1, Intercommunicator.Root); foreach (int b in remoteSuccess) { if (b == 0) { success = false; } } System.Console.WriteLine("Rank " + rank + ": Scatter<string> Passed == " + success); MPIDebug.Assert(success); success = true; } else if (rank % 2 == 1) { outValue_s = inter_comm.Scatter <string>(0); inter_comm.Gather <int>((inter_comm.Rank.ToString() == outValue_s ? 1 : 0), 0); inter_comm.Scatter <string>(); inter_comm.Gather <int>(1, Intercommunicator.Null); } else { inter_comm.Scatter <string>(); inter_comm.Gather <int>(1, Intercommunicator.Null); outValue_s = inter_comm.Scatter <string>(0); inter_comm.Gather <int>((inter_comm.Rank.ToString() == outValue_s ? 1 : 0), 0); } // Broadcast with int int data = 0; if (rank == 0) { data = 5; inter_comm.Broadcast(ref data, Intercommunicator.Root); remoteSuccess = inter_comm.Gather <int>(1, Intercommunicator.Root); foreach (int b in remoteSuccess) { if (b != 1) { success = false; } } System.Console.WriteLine("Rank " + rank + ": Broadcast<int>(int) Passed == " + success); MPIDebug.Assert(success); } else if (rank % 2 == 1) { inter_comm.Broadcast(ref data, 0); remoteSuccess = inter_comm.Gather <int>((data == 5 ? 1 : 0), 0); } else { inter_comm.Broadcast(ref data, Intercommunicator.Null); remoteSuccess = inter_comm.Gather <int>(1, Intercommunicator.Null); } // System.Console.WriteLine("Broadcast Test: Process " + rank + " has data == " + data); success = true; // Broadcast with string string data_s = ""; if (rank == 0) { data_s = "x"; inter_comm.Broadcast(ref data_s, Intercommunicator.Root); remoteSuccess = inter_comm.Gather <int>(1, Intercommunicator.Root); foreach (int b in remoteSuccess) { if (b != 1) { success = false; } } System.Console.WriteLine("Rank " + rank + ": Broadcast<string>(string) Passed == " + success); MPIDebug.Assert(success); } else if (rank % 2 == 1) { inter_comm.Broadcast(ref data_s, 0); remoteSuccess = inter_comm.Gather <int>((data_s == "x" ? 1 : 0), 0); } else { inter_comm.Broadcast(ref data_s, Intercommunicator.Null); remoteSuccess = inter_comm.Gather <int>(1, Intercommunicator.Null); } success = true; // Broadcast with int[] success = true; inValues_i = new int[] { 0, 1 }; outValues_i = null; if (rank == 0) { outValues_i = new int[inValues_i.Length]; inValues_i.CopyTo(outValues_i, 0); inter_comm.Broadcast(ref outValues_i, Intercommunicator.Root); remoteSuccess = inter_comm.Gather <int>(1, Intercommunicator.Root); foreach (int b in remoteSuccess) { if (b == 0) { success = false; } } System.Console.WriteLine("Broadcast<int>(int[]) Passed == " + success); MPIDebug.Assert(success); success = true; } else if (rank % 2 == 0) { inter_comm.Broadcast(ref outValues_i, Intercommunicator.Null); inter_comm.Gather <int>(1, Intercommunicator.Null); } else { outValues_i = new int[inValues_i.Length]; inter_comm.Broadcast(ref outValues_i, 0); for (int i = 0; i < outValues_i.Length; i++) { if (inValues_i[i] != outValues_i[i]) { success = false; } } inter_comm.Gather <int>((success ? 1 : 0), 0); } // Broadcast with string[] success = true; inValues_s = new string[] { "0", "1" }; outValues_s = null; if (rank == 0) { outValues_s = new string[inValues_s.Length]; inValues_s.CopyTo(outValues_s, 0); inter_comm.Broadcast(ref outValues_s, Intercommunicator.Root); remoteSuccess = inter_comm.Gather <int>(1, Intercommunicator.Root); foreach (int b in remoteSuccess) { if (b == 0) { success = false; } } System.Console.WriteLine("Broadcast<string>(string[]) Passed == " + success); MPIDebug.Assert(success); success = true; } else if (rank % 2 == 0) { inter_comm.Broadcast(ref outValues_s, Intercommunicator.Null); inter_comm.Gather <int>(1, Intercommunicator.Null); } else { outValues_s = new string[inValues_s.Length]; inter_comm.Broadcast(ref outValues_s, 0); for (int i = 0; i < outValues_s.Length; i++) { if (inValues_s[i] != outValues_s[i]) { success = false; } } inter_comm.Gather <int>((success ? 1 : 0), 0); } // Barrier test if (rank == 0) { System.Console.WriteLine("Barrier Test..."); } inter_comm.Barrier(); //System.Console.WriteLine("Process " + rank + " has exited Barrier..."); if (rank == 0) { System.Console.WriteLine("Barrier Test Passed == True"); } // Allgather test with strings checkValues_s = new string[inter_comm.RemoteSize]; j = 1 - rank % 2; for (int i = 0; i < inter_comm.RemoteSize; i++) { checkValues_s[i] += j.ToString(); j += 2; } success = true; outValues_s = inter_comm.Allgather(rank.ToString()); for (int i = 0; i < inter_comm.RemoteSize; i++) { if (outValues_s[i] != checkValues_s[i]) { success = false; } } if (rank == 0) { remoteSuccess = inter_comm.Gather <int>(1, Intercommunicator.Root); foreach (int b in remoteSuccess) { if (b == 0) { success = false; } } System.Console.WriteLine("Allgather<string>() Passed == " + success); MPIDebug.Assert(success); success = true; } else if (rank % 2 == 0) { inter_comm.Gather <int>(1, Intercommunicator.Null); } else { inter_comm.Gather <int>((success ? 1 : 0), 0); } // Allgather test with ints checkValues_i = new int[inter_comm.RemoteSize]; j = 1 - rank % 2; for (int i = 0; i < inter_comm.RemoteSize; i++) { checkValues_i[i] += j; j += 2; } success = true; outValues_i = inter_comm.Allgather(rank); for (int i = 0; i < inter_comm.RemoteSize; i++) { if (outValues_i[i] != checkValues_i[i]) { success = false; } } if (rank == 0) { remoteSuccess = inter_comm.Gather <int>(1, Intercommunicator.Root); foreach (int b in remoteSuccess) { if (b == 0) { success = false; } } System.Console.WriteLine("Allgather<int>() Passed == " + success); MPIDebug.Assert(success); success = true; } else if (rank % 2 == 0) { inter_comm.Gather <int>(1, Intercommunicator.Null); } else { inter_comm.Gather <int>((success ? 1 : 0), 0); } // Alltoall with ints success = true; inValues_i = new int[inter_comm.RemoteSize]; for (int dest = 0; dest < inter_comm.RemoteSize; ++dest) { inValues_i[dest] = inter_comm.Rank; } outValues_i = inter_comm.Alltoall(inValues_i); for (int source = 0; source < inter_comm.RemoteSize; ++source) { if (source != outValues_i[source]) { success = false; } } remoteSuccess = Communicator.world.Gather <int>((success ? 1 : 0), 0); if (rank == 0) { foreach (int b in remoteSuccess) { if (b == 0) { success = false; } } System.Console.WriteLine("Alltoall<int>(int[]) Passed == " + success); MPIDebug.Assert(success); success = true; } // Alltoall with strings success = true; inValues_s = new string[inter_comm.RemoteSize]; for (int dest = 0; dest < inter_comm.RemoteSize; ++dest) { inValues_s[dest] = inter_comm.Rank.ToString(); } outValues_s = inter_comm.Alltoall(inValues_s); for (int source = 0; source < inter_comm.RemoteSize; ++source) { // if (inter_comm.Rank.ToString() != alltoalled_data[source]) if (source.ToString() != outValues_s[source]) { success = false; } } remoteSuccess = Communicator.world.Gather <int>((success ? 1 : 0), 0); if (rank == 0) { foreach (int b in remoteSuccess) { if (b == 0) { success = false; } } System.Console.WriteLine("Alltoall<string>(string[]) Passed == " + success); MPIDebug.Assert(success); success = true; } // Reduce with int if (rank == 0) { outValue_i = inter_comm.Reduce(0, Operation <int> .Add, Intercommunicator.Root); //System.Console.WriteLine("Received " + y + " from Reduce()"); checkValue_i = inter_comm.RemoteSize * inter_comm.RemoteSize; System.Console.WriteLine("Reduce<int>(int) Passed == " + (checkValue_i == outValue_i)); MPIDebug.Assert(checkValue_i == outValue_i); } else if (rank % 2 == 0) { outValue_i = inter_comm.Reduce(0, Operation <int> .Add, Intercommunicator.Null); } else { outValue_i = inter_comm.Reduce(rank, Operation <int> .Add, 0); } // Reduce with string checkValue_s = ""; if (rank == 0) { outValue_s = inter_comm.Reduce(rank.ToString(), Operation <string> .Add, Intercommunicator.Root); j = 1 - rank % 2; for (int i = 0; i < inter_comm.RemoteSize; i++) { checkValue_s += j.ToString(); j += 2; } System.Console.WriteLine("Reduce<string>(string) (Passed == " + (outValue_s == checkValue_s) + ")"); } else if (rank % 2 == 1) { inter_comm.Reduce(rank.ToString(), Operation <string> .Add, 0); } else { inter_comm.Reduce(rank.ToString(), Operation <string> .Add, Intercommunicator.Null); } // Reduce(int[]) success = true; outValues_i = null; inValues_i = null; if (rank == 0) { outValues_i = new int[inter_comm.RemoteSize]; inter_comm.Reduce <int>(null, Operation <int> .Add, Intercommunicator.Root, ref outValues_i); j = 1 - rank % 2; for (int i = 0; i < inter_comm.RemoteSize; i++) { //System.Console.WriteLine(sums[i] + " " + inter_comm.RemoteSize*inter_comm.RemoteSize); if (outValues_i[i] != inter_comm.RemoteSize * inter_comm.RemoteSize) { success = false; } j += 2; } System.Console.WriteLine("Reduce<int>(int[]) Passed == " + success); MPIDebug.Assert(success); success = true; } else if (rank % 2 == 1) { inValues_i = new int[inter_comm.Size]; for (int i = 0; i < inter_comm.Size; i++) { inValues_i[i] = rank; } inter_comm.Reduce <int>(inValues_i, Operation <int> .Add, 0, ref outValues_i); } else { inValues_i = new int[0]; inter_comm.Reduce <int>(null, Operation <int> .Add, Intercommunicator.Null, ref outValues_i); } // Reduce(string[]) success = true; outValues_s = null; checkValue_s = ""; if (rank == 0) { outValues_s = new string[inter_comm.RemoteSize]; inter_comm.Reduce <string>(null, Operation <string> .Add, Intercommunicator.Root, ref outValues_s); j = 1 - rank % 2; for (int i = 0; i < inter_comm.RemoteSize; i++) { checkValue_s += j.ToString(); j += 2; } j = 1 - rank % 2; for (int i = 0; i < inter_comm.RemoteSize; i++) { //System.Console.WriteLine(sums[i] + " " + inter_comm.RemoteSize*inter_comm.RemoteSize); if (outValues_s[i] != checkValue_s) { success = false; } j += 2; } System.Console.WriteLine("Reduce<string>(string[]) Passed == " + success); MPIDebug.Assert(success); success = true; } else if (rank % 2 == 1) { inValues_s = new string[inter_comm.Size]; for (int i = 0; i < inter_comm.Size; i++) { inValues_s[i] = rank.ToString(); } inter_comm.Reduce <string>(inValues_s, Operation <string> .Add, 0, ref outValues_s); } else { inter_comm.Reduce <string>(null, Operation <string> .Add, Intercommunicator.Null, ref outValues_s); } // Allreduce with ints outValue_i = inter_comm.Allreduce(rank, Operation <int> .Add); success = (outValue_i == (inter_comm.RemoteSize - (rank % 2)) * inter_comm.RemoteSize); if (rank == 0) { remoteSuccess = inter_comm.Gather <int>(1, Intercommunicator.Root); foreach (int b in remoteSuccess) { if (b == 0) { success = false; } } System.Console.WriteLine("Allreduce<int> Passed == " + success); MPIDebug.Assert(success); success = true; } else if (rank % 2 == 0) { inter_comm.Gather <int>(1, Intercommunicator.Null); } else { inter_comm.Gather <int>((success ? 1 : 0), 0); } success = true; // Allreduce with strings outValue_s = inter_comm.Allreduce(rank.ToString(), Operation <string> .Add); checkValue_s = ""; j = 1 - rank % 2; for (int i = 0; i < inter_comm.RemoteSize; i++) { checkValue_s += j.ToString(); j += 2; } success = (outValue_s == checkValue_s); if (rank == 0) { remoteSuccess = inter_comm.Gather <int>(1, Intercommunicator.Root); foreach (int b in remoteSuccess) { if (b == 0) { success = false; } } System.Console.WriteLine("Allreduce<string> Passed == " + success); MPIDebug.Assert(success); success = true; } else if (rank % 2 == 0) { inter_comm.Gather <int>(1, Intercommunicator.Null); } else { inter_comm.Gather <int>((success ? 1 : 0), 0); } success = true; // Allreduce<int>(int[]) // If we have an odd size, simply calling Allreduce won't work, since the data provided // by both groups has to be the same size int larger_group_size = (inter_comm.Size > inter_comm.RemoteSize ? inter_comm.Size : inter_comm.RemoteSize); outValues_i = new int[larger_group_size]; inValues_i = new int[larger_group_size]; for (int i = 0; i < inter_comm.Size; i++) { inValues_i[i] = rank; } if (larger_group_size > inter_comm.Size) { inValues_i[larger_group_size - 1] = 0; } inter_comm.Allreduce <int>(inValues_i, Operation <int> .Add, ref outValues_i); if (rank % 2 == 0) { checkValue_i = inter_comm.RemoteSize * inter_comm.RemoteSize; j = 1 - rank % 2; for (int i = 0; i < inter_comm.RemoteSize; i++) { if (outValues_i[i] != checkValue_i) { success = false; } j += 2; } if (larger_group_size > inter_comm.RemoteSize) { if (outValues_i[larger_group_size - 1] != 0) { success = false; } } } else if (rank % 2 == 1) { checkValue_i = (inter_comm.RemoteSize - 1) * inter_comm.RemoteSize; j = 1 - rank % 2; for (int i = 0; i < inter_comm.RemoteSize; i++) { if (outValues_i[i] != checkValue_i) { success = false; } j += 2; } } remoteSuccess = Communicator.world.Gather <int>((success ? 1 : 0), 0); if (rank == 0) { foreach (int b in remoteSuccess) { if (b == 0) { success = false; } } System.Console.WriteLine("Allreduce<int>(int[]) Passed == " + success); MPIDebug.Assert(success); } success = true; // Allreduce<string>(string[]) outValues_s = new string[larger_group_size]; inValues_s = new string[larger_group_size]; for (int i = 0; i < larger_group_size; i++) { inValues_s[i] = rank.ToString(); } inter_comm.Allreduce <string>(inValues_s, Operation <string> .Add, ref outValues_s); checkValue_s = ""; j = 1 - rank % 2; for (int i = 0; i < inter_comm.RemoteSize; i++) { checkValue_s += j.ToString(); j += 2; } if (rank % 2 == 0) { j = 1 - rank % 2; for (int i = 0; i < larger_group_size; i++) { if (outValues_s[i] != checkValue_s) { success = false; } j += 2; } } else if (rank % 2 == 1) { j = 1 - rank % 2; for (int i = 0; i < larger_group_size; i++) { if (outValues_s[i] != checkValue_s) { success = false; } j += 2; } } remoteSuccess = Communicator.world.Gather <int>((success ? 1 : 0), 0); if (rank == 0) { foreach (int b in remoteSuccess) { if (b == 0) { success = false; } } System.Console.WriteLine("Allreduce<string>(string[]) Passed == " + success); MPIDebug.Assert(success); } success = true; // ReduceScatter<int> // This test is just going to repeat the Allreduce test, for lack of a better test int smaller_group_size = (inter_comm.Size < inter_comm.RemoteSize ? inter_comm.Size : inter_comm.RemoteSize); inValues_i = new int[larger_group_size * smaller_group_size]; // same problem as with Allreduce outValues_i = new int[rank % 2 == 1 ? larger_group_size : smaller_group_size]; for (int i = 0; i < larger_group_size * smaller_group_size; i++) { inValues_i[i] = rank; } int[] counts = new int[rank % 2 == 0 ? larger_group_size : smaller_group_size]; for (int i = 0; i < (rank % 2 == 0 ? larger_group_size : smaller_group_size); i++) { counts[i] = rank % 2 == 1 ? larger_group_size : smaller_group_size; } inter_comm.ReduceScatter <int>(inValues_i, Operation <int> .Add, counts, ref outValues_i); if (rank % 2 == 0) { checkValue_i = inter_comm.RemoteSize * inter_comm.RemoteSize; j = 1 - rank % 2; for (int i = 0; i < inter_comm.RemoteSize; i++) { if (outValues_i[i] != checkValue_i) { success = false; } j += 2; } } else if (rank % 2 == 1) { checkValue_i = (inter_comm.RemoteSize - 1) * inter_comm.RemoteSize; j = 1 - rank % 2; for (int i = 0; i < inter_comm.RemoteSize; i++) { if (outValues_i[i] != checkValue_i) { success = false; } j += 2; } } remoteSuccess = Communicator.world.Gather <int>((success ? 1 : 0), 0); if (rank == 0) { foreach (int b in remoteSuccess) { if (b == 0) { success = false; } } System.Console.WriteLine("ReduceScatter<int> Passed == " + success); MPIDebug.Assert(success); } success = true; // ReduceScatter<string> // This test is just going to repeat the Allreduce test, for lack of a better test inValues_s = new string[larger_group_size * smaller_group_size]; // same problem as with Allreduce outValues_s = new string[rank % 2 == 1 ? larger_group_size : smaller_group_size]; for (int i = 0; i < larger_group_size * smaller_group_size; i++) { inValues_s[i] = rank.ToString(); } counts = new int[rank % 2 == 0 ? larger_group_size : smaller_group_size]; for (int i = 0; i < (rank % 2 == 0 ? larger_group_size : smaller_group_size); i++) { counts[i] = rank % 2 == 1 ? larger_group_size : smaller_group_size; } inter_comm.ReduceScatter <string>(inValues_s, Operation <string> .Add, counts, ref outValues_s); checkValue_s = ""; if (rank % 2 == 0) { j = 1 - rank % 2; for (int i = 0; i < inter_comm.RemoteSize; i++) { checkValue_s += j.ToString(); j += 2; } } else { j = 1 - rank % 2; for (int i = 0; i < inter_comm.RemoteSize; i++) { checkValue_s += j.ToString(); j += 2; } } if (rank % 2 == 0) { j = 1 - rank % 2; for (int i = 0; i < inter_comm.RemoteSize; i++) { if (outValues_s[i] != checkValue_s) { success = false; } j += 2; } } else if (rank % 2 == 1) { j = 1 - rank % 2; for (int i = 0; i < inter_comm.RemoteSize; i++) { if (outValues_s[i] != checkValue_s) { success = false; } j += 2; } } remoteSuccess = Communicator.world.Gather <int>((success ? 1 : 0), 0); if (rank == 0) { foreach (int b in remoteSuccess) { if (b == 0) { success = false; } } System.Console.WriteLine("ReduceScatter<string> Passed == " + success); MPIDebug.Assert(success); } success = true; // GatherFlattened with ints if (rank == 0) { success = true; System.Console.Write("GatherFlattened<int> Passed == "); size = inter_comm.RemoteSize; outValues_i = new int[(size * size + size) / 2]; counts = new int[size]; for (int i = 0; i < size; i++) { counts[i] = i; } inter_comm.GatherFlattened(counts, ref outValues_i); p = 0; for (int i = 0; i < size; ++i) { if (counts[i] > 0) { for (j = 0; j < i; j++) { MPIDebug.Assert(outValues_i[p] == i); if (outValues_i[p] != i) { success = false; } } } p += counts[i]; } System.Console.WriteLine(success); } else if (rank % 2 == 1) { counts = null; inValues_i = new int[inter_comm.Rank]; for (int i = 0; i < inter_comm.Rank; i++) { inValues_i[i] = inter_comm.Rank; } inter_comm.GatherFlattened(inValues_i, 0); } else { inter_comm.GatherFlattened <int>(); } // GatherFlattened with strings if (rank == 0) { success = true; System.Console.Write("GatherFlattened<string> Passed == "); size = inter_comm.RemoteSize; outValues_s = new string[(size * size + size) / 2]; counts = new int[size]; for (int i = 0; i < size; i++) { counts[i] = i; } inter_comm.GatherFlattened(counts, ref outValues_s); p = 0; for (int i = 0; i < size; ++i) { if (counts[i] > 0) { for (j = 0; j < i; j++) { if (outValues_s[p] != i.ToString()) { success = false; } } } p += counts[i]; } System.Console.WriteLine(success); } else if (rank % 2 == 1) { counts = null; inValues_s = new string[inter_comm.Rank]; for (int i = 0; i < inter_comm.Rank; i++) { inValues_s[i] = inter_comm.Rank.ToString(); } inter_comm.GatherFlattened(inValues_s, 0); } else { inter_comm.GatherFlattened <string>(); } // ScatterFromFlattened with ints success = true; if (rank == 0) { size = inter_comm.RemoteSize; inValues_i = new int[(size * size - size) / 2]; counts = new int[size]; p = 0; for (int i = 0; i < size; ++i) { counts[i] = i; for (j = 0; j < i; j++) { inValues_i[p + j] = i; } p += i; } inter_comm.ScatterFromFlattened(inValues_i, counts); } else if (rank % 2 == 1) { outValues_i = null; counts = new int[inter_comm.Size]; for (int i = 0; i < inter_comm.Size; ++i) { counts[i] = i; } inter_comm.ScatterFromFlattened(counts, 0, ref outValues_i); for (int i = 0; i < inter_comm.Rank; i++) { MPIDebug.Assert(outValues_i[i] == inter_comm.Rank); if (outValues_i[i] != inter_comm.Rank) { success = false; } } } else { inter_comm.ScatterFromFlattened <int>(); } remoteSuccess = Communicator.world.Gather <int>((success ? 1 : 0), 0); if (rank == 0) { foreach (int b in remoteSuccess) { if (b == 0) { success = false; } } System.Console.WriteLine("ScatterFromFlattened<int> Passed == " + success); MPIDebug.Assert(success); } success = true; // ScatterFromFlattened with strings success = true; if (rank == 0) { size = inter_comm.RemoteSize; inValues_s = new string[(size * size - size) / 2]; counts = new int[size]; p = 0; for (int i = 0; i < size; ++i) { counts[i] = i; for (j = 0; j < i; j++) { inValues_s[p + j] = i.ToString(); } p += i; } inter_comm.ScatterFromFlattened(inValues_s, counts); } else if (rank % 2 == 1) { outValues_s = null; counts = new int[inter_comm.Size]; for (int i = 0; i < inter_comm.Size; ++i) { counts[i] = i; } inter_comm.ScatterFromFlattened(counts, 0, ref outValues_s); for (int i = 0; i < inter_comm.Rank; i++) { MPIDebug.Assert(outValues_i[i] == inter_comm.Rank); if (outValues_s[i] != inter_comm.Rank.ToString()) { success = false; } } } else { inter_comm.ScatterFromFlattened <string>(); } remoteSuccess = Communicator.world.Gather <int>((success ? 1 : 0), 0); if (rank == 0) { foreach (int b in remoteSuccess) { if (b == 0) { success = false; } } System.Console.WriteLine("ScatterFromFlattened<string> Passed == " + success); MPIDebug.Assert(success); } success = true; // AllgatherFlattened with ints size = inter_comm.RemoteSize; outValues_i = new int[(size * size - size) / 2]; inValues_i = new int[inter_comm.Rank]; counts = new int[size]; for (int i = 0; i < inter_comm.Rank; i++) { inValues_i[i] = inter_comm.Rank; } for (int i = 0; i < size; i++) { counts[i] = i; } inter_comm.AllgatherFlattened(inValues_i, counts, ref outValues_i); p = 0; for (int i = 0; i < size; ++i) { if (counts[i] > 0) { for (j = 0; j < i; j++) { MPIDebug.Assert(outValues_i[p] == i); if (outValues_i[p] != i) { success = false; } } } p += counts[i]; } remoteSuccess = Communicator.world.Gather <int>((success ? 1 : 0), 0); if (rank == 0) { foreach (int b in remoteSuccess) { if (b == 0) { success = false; } } System.Console.WriteLine("AllgatherFlattened<int> Passed == " + success); MPIDebug.Assert(success); } success = true; // AllgatherFlattened with strings size = inter_comm.RemoteSize; outValues_s = new string[(size * size - size) / 2]; inValues_s = new string[inter_comm.Rank]; counts = new int[size]; for (int i = 0; i < inter_comm.Rank; i++) { inValues_s[i] = inter_comm.Rank.ToString(); } for (int i = 0; i < size; i++) { counts[i] = i; } inter_comm.AllgatherFlattened(inValues_s, counts, ref outValues_s); p = 0; for (int i = 0; i < size; ++i) { if (counts[i] > 0) { for (j = 0; j < i; j++) { MPIDebug.Assert(outValues_s[p] == i.ToString()); if (outValues_s[p] != i.ToString()) { success = false; } } } p += counts[i]; } remoteSuccess = Communicator.world.Gather <int>((success ? 1 : 0), 0); if (rank == 0) { foreach (int b in remoteSuccess) { if (b == 0) { success = false; } } System.Console.WriteLine("AllgatherFlattened<string> Passed == " + success); MPIDebug.Assert(success); } success = true; // AlltoallFlattened with ints size = inter_comm.Size; int rsize = inter_comm.RemoteSize; int irank = inter_comm.Rank; outValues_i = new int[(rsize * rsize - rsize) / 2]; inValues_i = new int[irank * rsize]; int[] sendCounts = new int[rsize]; int[] recvCounts = new int[rsize]; for (int i = 0; i < irank * rsize; i++) { inValues_i[i] = irank; } for (int i = 0; i < rsize; i++) { sendCounts[i] = irank; } for (int i = 0; i < rsize; i++) { recvCounts[i] = i; } inter_comm.AlltoallFlattened(inValues_i, sendCounts, recvCounts, ref outValues_i); p = 0; for (int i = 0; i < rsize; ++i) { if (recvCounts[i] > 0) { for (j = 0; j < i; j++) { if (outValues_i[p] != i) { success = false; } MPIDebug.Assert(outValues_i[p] == i); } } p += recvCounts[i]; } remoteSuccess = Communicator.world.Gather <int>((success ? 1 : 0), 0); if (rank == 0) { foreach (int b in remoteSuccess) { if (b == 0) { success = false; } } System.Console.WriteLine("Alltoall<int> Passed == " + success); } success = true; // AlltoallFlattened with strings outValues_s = new string[(rsize * rsize - rsize) / 2]; inValues_s = new string[irank * rsize]; for (int i = 0; i < irank * rsize; i++) { inValues_s[i] = irank.ToString(); } inter_comm.AlltoallFlattened(inValues_s, sendCounts, recvCounts, ref outValues_s); p = 0; for (int i = 0; i < rsize; ++i) { if (recvCounts[i] > 0) { for (j = 0; j < i; j++) { if (outValues_s[p] != i.ToString()) { success = false; } MPIDebug.Assert(outValues_s[p] == i.ToString()); } } p += recvCounts[i]; } remoteSuccess = Communicator.world.Gather <int>((success ? 1 : 0), 0); if (rank == 0) { foreach (int b in remoteSuccess) { if (b == 0) { success = false; } } System.Console.WriteLine("Alltoall<string> Passed == " + success); } success = true; }
public static void DoTest(string[] args) { using (new MPI.Environment(ref args)) { bool isRoot = (Communicator.world.Rank == 0); if (isRoot) { System.Console.Write("Testing Allgather with integers..."); } int[] ranks = Communicator.world.Allgather(Communicator.world.Rank); MPIDebug.Assert(ranks.Length == Communicator.world.Size); for (int i = 0; i < ranks.Length; ++i) { MPIDebug.Assert(ranks[i] == i); } if (isRoot) { System.Console.WriteLine(" done."); } if (isRoot) { System.Console.Write("Testing Allgather with strings..."); } string[] rankStrings = Communicator.world.Allgather(Communicator.world.Rank.ToString()); MPIDebug.Assert(rankStrings.Length == Communicator.world.Size); for (int i = 0; i < rankStrings.Length; ++i) { MPIDebug.Assert(rankStrings[i] == i.ToString()); } if (isRoot) { System.Console.WriteLine(" done."); } if (isRoot) { System.Console.Write("Testing AllgatherFlattened with integers..."); } int size = Communicator.world.Size; int[] outData = new int[(size * size - size) / 2]; int[] inData = new int[Communicator.world.Rank]; int[] counts = new int[size]; for (int i = 0; i < Communicator.world.Rank; i++) { inData[i] = Communicator.world.Rank; } for (int i = 0; i < size; i++) { counts[i] = i; } Communicator.world.AllgatherFlattened(inData, counts, ref outData); int p = 0; for (int i = 0; i < size; ++i) { if (counts[i] > 0) { for (int j = 0; j < i; j++) { MPIDebug.Assert(outData[p] == i); } } p += counts[i]; } if (isRoot) { System.Console.WriteLine(" done."); } if (isRoot) { System.Console.Write("Testing AllgatherFlattened with string..."); } string[] outData_s = null; string[] inData_s = new string[Communicator.world.Rank]; for (int i = 0; i < Communicator.world.Rank; i++) { inData_s[i] = Communicator.world.Rank.ToString(); } Communicator.world.AllgatherFlattened(inData_s, counts, ref outData_s); p = 0; for (int i = 0; i < size; ++i) { if (counts[i] > 0) { for (int j = 0; j < i; j++) { MPIDebug.Assert(outData_s[p] == i.ToString()); } } p += counts[i]; } if (isRoot) { System.Console.WriteLine(" done."); } } }
public static void DoTest(string[] args) { using (new MPI.Environment(ref args)) { Intracommunicator world = Communicator.world; if (world.Rank == 0) { System.Console.Write("Testing all-to-all on integers..."); } int[] sendInts = new int[world.Size]; for (int dest = 0; dest < world.Size; ++dest) { sendInts[dest] = world.Size * world.Rank + dest; } int[] recvInts = world.Alltoall(sendInts); for (int source = 0; source < world.Size; ++source) { MPIDebug.Assert(recvInts[source] == world.Size * source + world.Rank); } if (world.Rank == 0) { System.Console.WriteLine(" done."); } if (world.Rank == 0) { System.Console.Write("Testing all-to-all on strings..."); } string[] sendStrings = new string[world.Size]; for (int dest = 0; dest < world.Size; ++dest) { sendStrings[dest] = sendInts[dest].ToString(); } string[] recvStrings = world.Alltoall(sendStrings); for (int source = 0; source < world.Size; ++source) { MPIDebug.Assert(recvStrings[source] == recvInts[source].ToString()); } if (world.Rank == 0) { System.Console.WriteLine(" done."); } if (world.Rank == 0) { System.Console.Write("Testing AlltoallFlattened with integers..."); } int size = Communicator.world.Size; int rank = Communicator.world.Rank; int[] outData = new int[(size * size - size) / 2]; int[] inData = new int[rank * size]; int[] sendCounts = new int[size]; int[] recvCounts = new int[size]; for (int i = 0; i < rank * size; i++) { inData[i] = rank; } for (int i = 0; i < size; i++) { sendCounts[i] = rank; } for (int i = 0; i < size; i++) { recvCounts[i] = i; } Communicator.world.AlltoallFlattened(inData, sendCounts, recvCounts, ref outData); int p = 0; for (int i = 0; i < size; ++i) { if (recvCounts[i] > 0) { for (int j = 0; j < i; j++) { MPIDebug.Assert(outData[p] == i); } } p += recvCounts[i]; } if (world.Rank == 0) { System.Console.WriteLine(" done."); } if (world.Rank == 0) { System.Console.Write("Testing AlltoallFlattened with strings..."); } string[] outData_s = new string[(size * size - size) / 2]; string[] inData_s = new string[rank * size]; for (int i = 0; i < rank * size; i++) { inData_s[i] = rank.ToString(); } Communicator.world.AlltoallFlattened(inData_s, sendCounts, recvCounts, ref outData_s); p = 0; for (int i = 0; i < size; ++i) { if (recvCounts[i] > 0) { for (int j = 0; j < i; j++) { MPIDebug.Assert(outData_s[p] == i.ToString()); } } p += recvCounts[i]; } if (world.Rank == 0) { System.Console.WriteLine(" done."); } } }
public static void DoTest(string[] args) { using (new MPI.Environment(ref args)) { bool isRoot = (Communicator.world.Rank == 0); if (isRoot) { System.Console.Write("Testing Gather with integers..."); int[] ranks = new int[Communicator.world.Size]; Communicator.world.Gather(Communicator.world.Rank, 0, ref ranks); MPIDebug.Assert(ranks.Length == Communicator.world.Size); for (int i = 0; i < ranks.Length; ++i) { MPIDebug.Assert(ranks[i] == i); } System.Console.WriteLine(" done."); } else { Communicator.world.Gather(Communicator.world.Rank, 0); } if (isRoot) { System.Console.Write("Testing Gather with strings..."); string[] rankStrings = new string[Communicator.world.Size]; Communicator.world.Gather(Communicator.world.Rank.ToString(), 0, ref rankStrings); MPIDebug.Assert(rankStrings.Length == Communicator.world.Size); for (int i = 0; i < rankStrings.Length; ++i) { MPIDebug.Assert(rankStrings[i] == i.ToString()); } System.Console.WriteLine(" done."); } else { Communicator.world.Gather(Communicator.world.Rank.ToString(), 0); } if (isRoot) { System.Console.Write("Testing uniform Gather with integers..."); int[] outData = new int[Communicator.world.Size * Communicator.world.Size]; int[] inData = new int[Communicator.world.Size]; for (int i = 0; i < Communicator.world.Size; i++) { inData[i] = i; } Communicator.world.GatherFlattened(inData, 0, ref outData); MPIDebug.Assert(outData.Length == Communicator.world.Size * Communicator.world.Size); for (int i = 0; i < Communicator.world.Size; ++i) { for (int j = 0; j < Communicator.world.Size; j++) { MPIDebug.Assert(outData[i * Communicator.world.Size + j] == j); } } System.Console.WriteLine(" done."); } else { int[] outData = null; int[] inData = new int[Communicator.world.Size]; for (int i = 0; i < Communicator.world.Size; i++) { inData[i] = i; } Communicator.world.GatherFlattened(inData, 0, ref outData); } if (isRoot) { System.Console.Write("Testing uniform GatherFlattened with strings..."); string[] outData = new string[Communicator.world.Size * Communicator.world.Size]; string[] inData = new string[Communicator.world.Size]; for (int i = 0; i < Communicator.world.Size; i++) { inData[i] = i.ToString(); } Communicator.world.GatherFlattened(inData, 0, ref outData); MPIDebug.Assert(outData.Length == Communicator.world.Size * Communicator.world.Size); for (int i = 0; i < Communicator.world.Size; ++i) { for (int j = 0; j < Communicator.world.Size; j++) { MPIDebug.Assert(outData[i * Communicator.world.Size + j] == j.ToString()); } } System.Console.WriteLine(" done."); } else { string[] outData = null; string[] inData = new string[Communicator.world.Size]; for (int i = 0; i < Communicator.world.Size; i++) { inData[i] = i.ToString(); } Communicator.world.GatherFlattened(inData, 0, ref outData); } if (isRoot) { System.Console.Write("Testing GatherFlattened with integers..."); int size = Communicator.world.Size; int[] outData = new int[(size * size + size) / 2]; int[] inData = new int[Communicator.world.Rank]; int[] counts = new int[size]; for (int i = 0; i < Communicator.world.Rank; i++) { inData[i] = Communicator.world.Rank; } for (int i = 0; i < size; i++) { counts[i] = i; } Communicator.world.GatherFlattened(inData, counts, 0, ref outData); int p = 0; for (int i = 0; i < size; ++i) { if (counts[i] > 0) { for (int j = 0; j < i; j++) { MPIDebug.Assert(outData[p] == i); } } p += counts[i]; } System.Console.WriteLine(" done."); } else { int[] counts = null; int[] outData = null; int[] inData = new int[Communicator.world.Rank]; for (int i = 0; i < Communicator.world.Rank; i++) { inData[i] = Communicator.world.Rank; } Communicator.world.GatherFlattened(inData, counts, 0, ref outData); } if (isRoot) { System.Console.Write("Testing GatherFlattened with strings..."); int size = Communicator.world.Size; string[] outData = new string[(size * size + size) / 2]; string[] inData = new string[Communicator.world.Rank]; int[] counts = new int[size]; for (int i = 0; i < Communicator.world.Rank; i++) { inData[i] = Communicator.world.Rank.ToString(); } for (int i = 0; i < size; i++) { counts[i] = i; } Communicator.world.GatherFlattened(inData, counts, 0, ref outData); int p = 0; for (int i = 0; i < size; ++i) { if (counts[i] > 0) { for (int j = 0; j < i; j++) { MPIDebug.Assert(outData[p] == i.ToString()); } } //System.Console.WriteLine(p + " " + outData[p]); p += counts[i]; } System.Console.WriteLine(" done."); } else { int[] counts = null; string[] outData = null; string[] inData = new string[Communicator.world.Rank]; for (int i = 0; i < Communicator.world.Rank; i++) { inData[i] = Communicator.world.Rank.ToString(); } Communicator.world.GatherFlattened(inData, counts, 0, ref outData); } } }
private static void Test(int root) { Intracommunicator world = Communicator.world; // Broadcast an integer int intValue = default(int); if (world.Rank == root) { intValue = 17; System.Console.Write("Broadcasting integer from root " + root + "..."); } world.Broadcast(ref intValue, root); MPIDebug.Assert(intValue == 17); if (world.Rank == root) { System.Console.WriteLine(" done."); } // Broadcast a string string strValue = ""; if (world.Rank == root) { strValue = "Hello, World!"; System.Console.Write("Broadcasting string from root " + root + "..."); } world.Broadcast(ref strValue, root); MPIDebug.Assert(strValue == "Hello, World!"); if (world.Rank == root) { System.Console.WriteLine(" done."); } // Broadcast an array of integers int[] intArray = new int[7]; if (world.Rank == root) { intArray = new int[] { 1, 1, 2, 3, 5, 8, 13 }; System.Console.Write("Broadcasting integer array from root " + root + "..."); } world.Broadcast(ref intArray, root); MPIDebug.Assert(intArray[3] == 3); if (world.Rank == root) { System.Console.WriteLine(" done."); } // Broadcast an array of strings string[] strArray = new string[2]; if (world.Rank == root) { strArray = new string[] { "Hello", "World" }; System.Console.Write("Broadcasting string array from root " + root + "..."); } world.Broadcast(ref strArray, root); MPIDebug.Assert(strArray[0] == "Hello" && strArray[1] == "World"); if (world.Rank == root) { System.Console.WriteLine(" done."); } }
public static void DoTest(string[] args) { using (new MPI.Environment(ref args)) { Intracommunicator world = Communicator.world; if (world.Rank == 0) { System.Console.Write("Testing scatter of integers..."); int[] ranks = new int[world.Size]; for (int i = 0; i < world.Size; ++i) { ranks[i] = i; } int myRank = world.Scatter(ranks, 0); MPIDebug.Assert(myRank == 0); System.Console.WriteLine(" done."); System.Console.Write("Testing scatter of strings..."); string[] rankStrings = new string[world.Size]; for (int i = 0; i < world.Size; ++i) { rankStrings[i] = i.ToString(); } string myRankString = world.Scatter(rankStrings, 0); MPIDebug.Assert(myRankString == world.Rank.ToString()); System.Console.WriteLine(" done."); } else { int myRank = world.Scatter <int>(null, 0); MPIDebug.Assert(myRank == world.Rank); string myRankString = world.Scatter <string>(null, 0); MPIDebug.Assert(myRankString == world.Rank.ToString()); } if (world.Rank == 0) { System.Console.Write("Testing Scatter of bools..."); bool[] odds = new bool[world.Size]; for (int i = 0; i < world.Size; ++i) { odds[i] = i % 2 == 1; } bool amIOdd = world.Scatter(odds, 0); MPIDebug.Assert(!amIOdd); System.Console.WriteLine(" done."); } else { bool amIOdd = world.Scatter <bool>(null, 0); MPIDebug.Assert(amIOdd == (world.Rank % 2 == 1)); } world.Barrier(); if (world.Rank == 0) { int size = world.Size; System.Console.Write("Testing ScatterFromFlattened of integers..."); int[] inRanks = new int[(size * size - size) / 2]; int[] outRanks = null; int[] counts = new int[size]; int p = 0; for (int i = 0; i < world.Size; ++i) { counts[i] = i; for (int j = 0; j < i; j++) { inRanks[p + j] = i; } p += i; } world.ScatterFromFlattened(inRanks, counts, 0, ref outRanks); MPIDebug.Assert(outRanks.Length == 0); System.Console.WriteLine(" done."); } else { int[] outRanks = null; int[] counts = new int[world.Size]; for (int i = 0; i < world.Size; ++i) { counts[i] = i; } world.ScatterFromFlattened(null, counts, 0, ref outRanks); for (int i = 0; i < world.Rank; i++) { MPIDebug.Assert(outRanks[i] == world.Rank); } } if (world.Rank == 0) { int size = world.Size; System.Console.Write("Testing ScatterFromFlattened of strings..."); string[] inRanks = new string[(size * size - size) / 2]; string[] outRanks = null; int[] counts = new int[size]; int p = 0; for (int i = 0; i < world.Size; ++i) { counts[i] = i; for (int j = 0; j < i; j++) { inRanks[p + j] = i.ToString(); } p += i; } world.ScatterFromFlattened(inRanks, counts, 0, ref outRanks); MPIDebug.Assert(outRanks.Length == 0); System.Console.WriteLine(" done."); } else { string[] outRanks = null; int[] counts = new int[world.Size]; for (int i = 0; i < world.Size; ++i) { counts[i] = i; } world.ScatterFromFlattened(null, counts, 0, ref outRanks); for (int i = 0; i < world.Rank; i++) { MPIDebug.Assert(outRanks[i] == world.Rank.ToString()); } } } }
static void RunTests(int root) { Intracommunicator world = Communicator.world; world.Barrier(); if (world.Rank == root) { System.Console.WriteLine("Testing from root " + root); } // Test addition of integers int sum = world.Reduce(world.Rank, addInts, root); int expected = world.Size * (world.Size - 1) / 2; if (world.Rank == root) { MPIDebug.Assert(sum == expected); } else { MPIDebug.Assert(sum == default(int)); } if (world.Rank == root) { System.Console.WriteLine("Sum of ranks = " + sum); } // Test addition of integer points if (world.Rank == root) { Point point_sum = world.Reduce(new Point(world.Rank, world.Size - world.Rank), Point.Plus, root); MPIDebug.Assert(point_sum.x == sum && point_sum.y == (world.Size + 1) * world.Size / 2); System.Console.WriteLine("Sum of points = (" + point_sum.x + ", " + point_sum.y + ")"); } else { world.Reduce(new Point(world.Rank, world.Size - world.Rank), Point.Plus, root); } // Test addition of integer arrays if (world.Rank == root) { System.Console.Write("Testing reduction of integer arrays..."); int[] arraySum = null; world.Reduce(new int[] { world.Rank, world.Size - world.Rank }, Operation <int> .Add, root, ref arraySum); MPIDebug.Assert(arraySum[0] == sum && arraySum[1] == (world.Size + 1) * world.Size / 2); System.Console.WriteLine(" done."); } else { world.Reduce(new int[] { world.Rank, world.Size - world.Rank }, Operation <int> .Add, root); } // Test concatenation of string arrays if (world.Rank == root) { System.Console.Write("Testing reduction of string arrays..."); string[] strArray = null; world.Reduce(new string[] { world.Rank.ToString(), "World" }, Operation <string> .Add, root, ref strArray); string[] expectedStrs = new string[2] { "", "" }; for (int p = 0; p < world.Size; ++p) { expectedStrs[0] += p.ToString(); expectedStrs[1] += "World"; } MPIDebug.Assert(expectedStrs[0] == strArray[0]); MPIDebug.Assert(expectedStrs[1] == strArray[1]); System.Console.WriteLine(" done."); } else { world.Reduce(new string[] { world.Rank.ToString(), "World" }, Operation <string> .Add, root); } // Test reduction on boolean values if (world.Rank == root) { System.Console.Write("Testing reduction of bools..."); bool result = world.Reduce(true, Operation <bool> .LogicalAnd, root); MPIDebug.Assert(result == true); System.Console.WriteLine(" done."); } else { world.Reduce(true, Operation <bool> .LogicalAnd, root); } // Test reduction on boolean arrays if (world.Rank == root) { System.Console.Write("Testing reduction of bool arrays..."); bool[] boolArray = null; world.Reduce(new bool[] { false, world.Rank % 2 != 0, true }, Operation <bool> .LogicalOr, root, ref boolArray); MPIDebug.Assert(boolArray[0] == false); MPIDebug.Assert(boolArray[1] == (world.Size > 1)); MPIDebug.Assert(boolArray[2] == true); System.Console.WriteLine(" done."); } else { world.Reduce(new bool[] { false, world.Rank % 2 != 0, false }, Operation <bool> .LogicalOr, root); } }
public static void DoTest(string[] args) { using (new MPI.Environment(ref args)) { Intracommunicator parentComm = (Intracommunicator)Communicator.world.Clone(); // Create a bunch of attributes of different kinds Console.Error.WriteLine("Creating attributes..."); MPI.Attribute nocopyIntAttr = MPI.Attribute.Create <int>(AttributeDuplication.None); Console.Error.WriteLine("Creating second attribute..."); MPI.Attribute shallowIntAttr = MPI.Attribute.Create <int>(AttributeDuplication.Shallow); MPI.Attribute deepIntAttr = MPI.Attribute.Create <int>(AttributeDuplication.Deep); MPI.Attribute nocopyPointAttr = MPI.Attribute.Create <Point>(AttributeDuplication.None); MPI.Attribute shallowPointAttr = MPI.Attribute.Create <Point>(AttributeDuplication.Shallow); MPI.Attribute deepPointAttr = MPI.Attribute.Create <Point>(AttributeDuplication.Deep); MPI.Attribute nocopyStringAttr = MPI.Attribute.Create <StringHolder>(AttributeDuplication.None); MPI.Attribute shallowStringAttr = MPI.Attribute.Create <StringHolder>(AttributeDuplication.Shallow); MPI.Attribute deepStringAttr = MPI.Attribute.Create <StringHolder>(AttributeDuplication.Deep); // Place initial values for these attributes into the parent communicator Console.Error.WriteLine("Initial values..."); parentComm.Attributes[nocopyIntAttr] = 17; parentComm.Attributes[shallowIntAttr] = 25; parentComm.Attributes[deepIntAttr] = 42; parentComm.Attributes[nocopyPointAttr] = new Point(1.1, 1.2, 1.3); parentComm.Attributes[shallowPointAttr] = new Point(2.1, 2.2, 2.3); parentComm.Attributes[deepPointAttr] = new Point(3.1, 3.2, 3.3); parentComm.Attributes[nocopyStringAttr] = new StringHolder("Hello"); parentComm.Attributes[shallowStringAttr] = new StringHolder("MPI"); parentComm.Attributes[deepStringAttr] = new StringHolder("Attributes"); // Check initial values in the parent communicator Console.Error.WriteLine("Checking initial values..."); MPIDebug.Assert((int)parentComm.Attributes[nocopyIntAttr] == 17); MPIDebug.Assert((int)parentComm.Attributes[shallowIntAttr] == 25); MPIDebug.Assert((int)parentComm.Attributes[deepIntAttr] == 42); MPIDebug.Assert((Point)parentComm.Attributes[nocopyPointAttr] == new Point(1.1, 1.2, 1.3)); MPIDebug.Assert((Point)parentComm.Attributes[shallowPointAttr] == new Point(2.1, 2.2, 2.3)); MPIDebug.Assert((Point)parentComm.Attributes[deepPointAttr] == new Point(3.1, 3.2, 3.3)); MPIDebug.Assert(((StringHolder)parentComm.Attributes[nocopyStringAttr]).str == "Hello"); MPIDebug.Assert(((StringHolder)parentComm.Attributes[shallowStringAttr]).str == "MPI"); MPIDebug.Assert(((StringHolder)parentComm.Attributes[deepStringAttr]).str == "Attributes"); // Duplicate the communicator Communicator childComm = (Communicator)parentComm.Clone(); // Check values in the parent communicator (again) MPIDebug.Assert((int)parentComm.Attributes[nocopyIntAttr] == 17); MPIDebug.Assert((int)parentComm.Attributes[shallowIntAttr] == 25); MPIDebug.Assert((int)parentComm.Attributes[deepIntAttr] == 42); MPIDebug.Assert((Point)parentComm.Attributes[nocopyPointAttr] == new Point(1.1, 1.2, 1.3)); MPIDebug.Assert((Point)parentComm.Attributes[shallowPointAttr] == new Point(2.1, 2.2, 2.3)); MPIDebug.Assert((Point)parentComm.Attributes[deepPointAttr] == new Point(3.1, 3.2, 3.3)); MPIDebug.Assert(((StringHolder)parentComm.Attributes[nocopyStringAttr]).str == "Hello"); MPIDebug.Assert(((StringHolder)parentComm.Attributes[shallowStringAttr]).str == "MPI"); MPIDebug.Assert(((StringHolder)parentComm.Attributes[deepStringAttr]).str == "Attributes"); // Check values in the child communicator MPIDebug.Assert(childComm.Attributes[nocopyIntAttr] == null); MPIDebug.Assert((int)childComm.Attributes[shallowIntAttr] == 25); MPIDebug.Assert((int)childComm.Attributes[deepIntAttr] == 42); MPIDebug.Assert(childComm.Attributes[nocopyPointAttr] == null); MPIDebug.Assert((Point)childComm.Attributes[shallowPointAttr] == new Point(2.1, 2.2, 2.3)); MPIDebug.Assert((Point)childComm.Attributes[deepPointAttr] == new Point(3.1, 3.2, 3.3)); MPIDebug.Assert(childComm.Attributes[nocopyStringAttr] == null); MPIDebug.Assert(((StringHolder)childComm.Attributes[shallowStringAttr]).str == "MPI"); MPIDebug.Assert(((StringHolder)childComm.Attributes[deepStringAttr]).str == "Attributes"); // Check modification of shallow-copy attributes parentComm.Attributes[shallowIntAttr] = 99; MPIDebug.Assert((int)parentComm.Attributes[shallowIntAttr] == 99); MPIDebug.Assert((int)childComm.Attributes[shallowIntAttr] == 25); parentComm.Attributes[shallowPointAttr] = new Point(4.1, 4.2, 4.3); MPIDebug.Assert((Point)parentComm.Attributes[shallowPointAttr] == new Point(4.1, 4.2, 4.3)); MPIDebug.Assert((Point)childComm.Attributes[shallowPointAttr] == new Point(4.1, 4.2, 4.3)); ((StringHolder)parentComm.Attributes[shallowStringAttr]).str = "Cached"; MPIDebug.Assert(((StringHolder)parentComm.Attributes[shallowStringAttr]).str == "Cached"); MPIDebug.Assert(((StringHolder)childComm.Attributes[shallowStringAttr]).str == "Cached"); // Check modification of deep-copy attributes parentComm.Attributes[deepIntAttr] = 99; MPIDebug.Assert((int)parentComm.Attributes[deepIntAttr] == 99); MPIDebug.Assert((int)childComm.Attributes[deepIntAttr] == 42); parentComm.Attributes[deepPointAttr] = new Point(4.1, 4.2, 4.3); MPIDebug.Assert((Point)parentComm.Attributes[deepPointAttr] == new Point(4.1, 4.2, 4.3)); MPIDebug.Assert((Point)childComm.Attributes[deepPointAttr] == new Point(3.1, 3.2, 3.3)); ((StringHolder)parentComm.Attributes[deepStringAttr]).str = "Cached"; MPIDebug.Assert(((StringHolder)parentComm.Attributes[deepStringAttr]).str == "Cached"); MPIDebug.Assert(((StringHolder)childComm.Attributes[deepStringAttr]).str == "Attributes"); // Check attribute deletion parentComm.Attributes.Remove(shallowIntAttr); MPIDebug.Assert(parentComm.Attributes[shallowIntAttr] == null); MPIDebug.Assert((int)childComm.Attributes[shallowIntAttr] == 25); parentComm.Attributes.Remove(shallowIntAttr); parentComm.Attributes.Remove(shallowPointAttr); MPIDebug.Assert(parentComm.Attributes[shallowPointAttr] == null); MPIDebug.Assert((Point)childComm.Attributes[shallowPointAttr] == new Point(4.1, 4.2, 4.3)); parentComm.Attributes.Remove(shallowPointAttr); parentComm.Attributes.Remove(shallowStringAttr); MPIDebug.Assert(parentComm.Attributes[shallowStringAttr] == null); MPIDebug.Assert(((StringHolder)childComm.Attributes[shallowStringAttr]).str == "Cached"); parentComm.Attributes.Remove(shallowStringAttr); } }
public static void DoTest(string[] args) { using (new MPI.Environment(ref args)) { Intracommunicator world = MPI.Communicator.world; // Each process will receive Rank values int[] counts = new int[world.Size]; int sum = 0; for (int i = 0; i < world.Size; ++i) { counts[i] = i; sum += i; } if (world.Rank == 0) { System.Console.Write("Testing reduce-scatter on integers..."); } int[] intValues = new int[sum]; for (int rank = 0, index = 0; rank < world.Size; ++rank) { for (int i = 0; i < rank; ++i, ++index) { intValues[index] = i + world.Rank; } } int[] intResults = world.ReduceScatter(intValues, Operation <int> .Add, counts); MPIDebug.Assert(intResults.Length == world.Rank); for (int i = 0; i < world.Rank; ++i) { MPIDebug.Assert(intResults[i] == world.Size * i + world.Size * (world.Size - 1) / 2); } if (world.Rank == 0) { System.Console.WriteLine(" done."); } if (world.Rank == 0) { System.Console.Write("Testing reduce-scatter on strings..."); } string[] stringValues = new string[sum]; for (int i = 0; i < sum; ++i) { stringValues[i] = intValues[i].ToString(); } string[] stringResults = world.ReduceScatter(stringValues, Operation <string> .Add, counts); MPIDebug.Assert(stringResults.Length == world.Rank); for (int i = 0; i < world.Rank; ++i) { string expected = ""; for (int p = 0; p < world.Size; ++p) { expected += (i + p).ToString(); } MPIDebug.Assert(stringResults[i] == expected); } if (world.Rank == 0) { System.Console.WriteLine(" done."); } } }
public static void DoTest(string[] args) { using (new MPI.Environment(ref args)) { bool isRoot = (Communicator.world.Rank == 0); // Test helper function ComputeDimensions() if (isRoot) { System.Console.WriteLine("Testing ComputeDimensions()..."); } int nprocesses = MPI.Communicator.world.Size; int[] dims = { 0, 0 }; CartesianCommunicator.ComputeDimensions(nprocesses, 2, ref dims); if (isRoot) { System.Console.WriteLine("Dims = " + dims[0] + ", " + dims[1]); } if (isRoot) { System.Console.WriteLine(" done."); } // Test constructor if (isRoot) { System.Console.WriteLine("Testing constructor..."); } bool[] periods = { true, true }; MPI.Intracommunicator ic = (MPI.Intracommunicator)MPI.Communicator.world; MPI.CartesianCommunicator cc = new CartesianCommunicator(ic, 2, dims, periods, false); MPIDebug.Assert(cc != null); if (isRoot) { System.Console.WriteLine(" done."); } // Test accessors if (isRoot) { System.Console.WriteLine("Testing accessors..."); } int ndims = cc.Dimensions.Length; int[] coords = new int[ndims]; coords = cc.Coordinates; int[] temp_dims = { 0, 0 }; bool[] temp_periods = { false, false }; int[] temp_coords = { 0, 0 }; temp_dims = cc.Dimensions; temp_periods = cc.Periodic; MPIDebug.Assert(temp_dims[0] == dims[0] && temp_dims[1] == dims[1]); MPIDebug.Assert(temp_periods[0] == periods[0] && temp_periods[1] == periods[1]); temp_coords[0] = 0; temp_coords[1] = 0; temp_coords = cc.GetCartesianCoordinates(cc.Rank); int temp_rank = cc.GetCartesianRank(temp_coords); MPIDebug.Assert(temp_rank == cc.Rank); MPIDebug.Assert(temp_coords[0] == coords[0] && temp_coords[1] == coords[1]); //System.Console.WriteLine(temp_rank + " ?= " + cc.Rank + " for coords = " + temp_coords[0] + ", " + temp_coords[1]); // Test NumEdges int nedges = 0; nedges = dims[0] - 1; if (periods[0] == true) { nedges++; } int nedges_slice; int nodes_so_far = dims[0]; for (int i = 1; i < ndims; i++) { nedges_slice = dims[i] - 1; if (periods[i] == true) { nedges_slice++; } nedges_slice *= nodes_so_far; nodes_so_far *= dims[i]; nedges = nedges * dims[i] + nedges_slice; } MPIDebug.Assert(nedges == cc.NumEdges); if (isRoot) { System.Console.WriteLine(" done."); } // Test Shift() and communications if (isRoot) { System.Console.WriteLine("Testing Shift() and send/recv..."); } int source = 0; int dest = 0; cc.Shift(0, 1, out source, out dest); cc.Send(coords, dest, 0); //System.Console.WriteLine("Process at " + coords[0] + ", " + coords[1] + " (rank " + cc.Rank + ") will receive from " + source + " and send to " + dest); int[] recvcoords = new int[ndims]; cc.Receive(source, 0, ref recvcoords); //System.Console.WriteLine("Coords = " + coords[0] + ", " + coords[1] + "; Received message from coords = " + recvcoords[0] + ", " + recvcoords[1]); MPIDebug.Assert(coords[0] == (recvcoords[0] + 1) % dims[0] && coords[1] == recvcoords[1]); if (isRoot) { System.Console.WriteLine(" done."); } // Test Sub() if (isRoot) { System.Console.WriteLine("Testing Sub()..."); } int[] remain_dims = { 1, 0 }; CartesianCommunicator subgrid = cc.Subgrid(remain_dims); int subgrid_ndims = subgrid.Dimensions.Length; MPIDebug.Assert(subgrid_ndims == 1); if (isRoot) { System.Console.WriteLine(" done."); } // Test Neighbors if (isRoot) { System.Console.WriteLine("Testing Neighbors..."); } int[] neighbors = cc.Neighbors; /* * if (isRoot) * { * System.Console.Write("Neighbors: "); * foreach (int n in neighbors) * System.Console.Write(n + " "); * System.Console.WriteLine(); * } */ List <int> local_neighbors = new List <int>(); int[] neighbor_coords; for (int i = 0; i < ndims; i++) { neighbor_coords = cc.Coordinates; if (neighbor_coords[i] > 0) { neighbor_coords[i] = cc.Coordinates[i] - 1; local_neighbors.Add(cc.GetCartesianRank(neighbor_coords)); } else if (cc.Periodic[i] == true && cc.Dimensions[i] > 2) { neighbor_coords[i] = cc.Dimensions[i] - 1; local_neighbors.Add(cc.GetCartesianRank(neighbor_coords)); } neighbor_coords = cc.Coordinates; if (neighbor_coords[i] < dims[i] - 1) { neighbor_coords[i] = cc.Coordinates[i] + 1; local_neighbors.Add(cc.GetCartesianRank(neighbor_coords)); } else if (cc.Periodic[i] == true && cc.Dimensions[i] > 2) { neighbor_coords[i] = 0; local_neighbors.Add(cc.GetCartesianRank(neighbor_coords)); } } local_neighbors.Sort(); Array.Sort(neighbors); MPIDebug.Assert(neighbors.Length == local_neighbors.Count); for (int i = 0; i < neighbors.Length; i++) { MPIDebug.Assert(neighbors[i] == local_neighbors[i]); } //System.Console.WriteLine(neighbors.Length + " " + local_neighbors.Count); if (isRoot) { System.Console.WriteLine(" done."); } // Now test for 3d case ndims = 3; if (isRoot) { System.Console.WriteLine("Testing ComputeDimensions() with 3d..."); } nprocesses = MPI.Communicator.world.Size; dims = new int[3]; dims[0] = 0; dims[1] = 0; dims[2] = 2; CartesianCommunicator.ComputeDimensions(nprocesses, 3, ref dims); if (isRoot) { System.Console.WriteLine("Dims = " + dims[0] + ", " + dims[1] + ", " + dims[2]); } if (isRoot) { System.Console.WriteLine(" done."); } // Test constructor if (isRoot) { System.Console.WriteLine("Testing constructor with 3d..."); } periods = new bool[3]; periods[0] = true; periods[1] = true; periods[2] = true; ic = (MPI.Intracommunicator)MPI.Communicator.world; cc = new CartesianCommunicator(ic, 3, dims, periods, false); MPIDebug.Assert(cc != null); if (isRoot) { System.Console.WriteLine(" done."); } // Test NumEdges if (isRoot) { System.Console.WriteLine("Testing NumEdges with 3d..."); } nedges = 0; nedges = dims[0] - 1; if (periods[0] == true) { nedges++; } nodes_so_far = dims[0]; for (int i = 1; i < ndims; i++) { nedges_slice = dims[i] - 1; if (periods[i] == true) { nedges_slice++; } nedges_slice *= nodes_so_far; nodes_so_far *= dims[i]; nedges = nedges * dims[i] + nedges_slice; } MPIDebug.Assert(nedges == cc.NumEdges); if (isRoot) { System.Console.WriteLine(" done."); } // Test Neighbors if (isRoot) { System.Console.WriteLine("Testing Neighbors with 3d..."); } neighbors = cc.Neighbors; /* * if (isRoot) * { * System.Console.Write("Neighbors: "); * foreach (int n in neighbors) * System.Console.Write(n + " "); * System.Console.WriteLine(); * } */ local_neighbors = new List <int>(); for (int i = 0; i < ndims; i++) { neighbor_coords = cc.Coordinates; if (neighbor_coords[i] > 0) { neighbor_coords[i] = cc.Coordinates[i] - 1; local_neighbors.Add(cc.GetCartesianRank(neighbor_coords)); } else if (cc.Periodic[i] == true && cc.Dimensions[i] > 2) { neighbor_coords[i] = cc.Dimensions[i] - 1; local_neighbors.Add(cc.GetCartesianRank(neighbor_coords)); } neighbor_coords = cc.Coordinates; if (neighbor_coords[i] < dims[i] - 1) { neighbor_coords[i] = cc.Coordinates[i] + 1; local_neighbors.Add(cc.GetCartesianRank(neighbor_coords)); } else if (cc.Periodic[i] == true && cc.Dimensions[i] > 2) { neighbor_coords[i] = 0; local_neighbors.Add(cc.GetCartesianRank(neighbor_coords)); } } local_neighbors.Sort(); Array.Sort(neighbors); MPIDebug.Assert(neighbors.Length == local_neighbors.Count); for (int i = 0; i < neighbors.Length; i++) { MPIDebug.Assert(neighbors[i] == local_neighbors[i]); } // System.Console.WriteLine(cc.Rank + ": " + cc.Coordinates[0] + ", " + cc.Coordinates[1] + ", " + cc.Coordinates[2]); if (isRoot) { System.Console.WriteLine(" done."); } } }
static int Main(string[] args) { return(MPIDebug.Execute(DoTest, args)); }
public static void DoTest(string[] args) { //using (MPI.Environment env = new MPI.Environment(ref args)) { Intracommunicator world = Communicator.world; // Test addition of integers int sum = world.Allreduce(world.Rank, addInts); int expected = world.Size * (world.Size - 1) / 2; MPIDebug.Assert(sum == expected); if (world.Rank == 0) { System.Console.WriteLine("Sum of ranks = " + sum); } // Test addition of integers through the Operations class MPIDebug.Assert(world.Allreduce(world.Rank, Operation <int> .Add) == expected); // Test addition of integer points Point pointSum = world.Allreduce(new Point(world.Rank, world.Size - world.Rank), Point.Plus); MPIDebug.Assert(pointSum.x == sum && pointSum.y == (world.Size + 1) * world.Size / 2); if (world.Rank == 0) { System.Console.WriteLine("Sum of points = (" + pointSum.x + ", " + pointSum.y + ")"); } // Compute the minimum rank int minRank = world.Allreduce(world.Rank, Operation <int> .Min); MPIDebug.Assert(minRank == 0); if (world.Rank == 0) { System.Console.WriteLine("Minimum of ranks = " + minRank); } // Compute the minimum point Point minPoint = world.Allreduce(new Point(world.Rank, world.Size - world.Rank), Operation <Point> .Min); MPIDebug.Assert(minPoint.x == 0 && minPoint.y == world.Size); if (world.Rank == 0) { System.Console.WriteLine("Minimum point = (" + minPoint.x + ", " + minPoint.y + ")"); } // Compute the maximum rank int maxRank = world.Allreduce(world.Rank, Operation <int> .Max); MPIDebug.Assert(maxRank == world.Size - 1); if (world.Rank == 0) { System.Console.WriteLine("Maximum of ranks = " + maxRank); } // Compute the maximum point Point maxPoint = world.Allreduce(new Point(world.Rank, world.Size - world.Rank), Operation <Point> .Max); MPIDebug.Assert(maxPoint.x == world.Size - 1 && maxPoint.y == 1); if (world.Rank == 0) { System.Console.WriteLine("Maximum point = (" + maxPoint.x + ", " + maxPoint.y + ")"); } // Test addition of integer points via the Operations class Point pointSum2 = world.Allreduce(new Point(world.Rank, world.Size - world.Rank), Operation <Point> .Add); MPIDebug.Assert(pointSum2.x == sum && pointSum2.y == (world.Size + 1) * world.Size / 2); // Test concatenation of strings string strcat = world.Allreduce(world.Rank.ToString(), concat); string expectedStr = ""; for (int i = 0; i < world.Size; ++i) { expectedStr += i; } MPIDebug.Assert(expectedStr == strcat); if (world.Rank == 0) { System.Console.WriteLine("Concatenation of rank strings = " + strcat); } MPIDebug.Assert(world.Allreduce(world.Rank.ToString(), Operation <string> .Add) == expectedStr); // Test addition of integer arrays if (world.Rank == 0) { System.Console.Write("Testing reduction of integer arrays..."); } int[] arraySum = null; world.Allreduce(new int[] { world.Rank, world.Size - world.Rank }, Operation <int> .Add, ref arraySum); MPIDebug.Assert(arraySum[0] == sum && arraySum[1] == (world.Size + 1) * world.Size / 2); if (world.Rank == 0) { System.Console.WriteLine(" done."); } // Test concatenation of string arrays if (world.Rank == 0) { System.Console.Write("Testing reduction of string arrays..."); } string[] strArray = null; world.Allreduce(new string[] { world.Rank.ToString(), "World" }, Operation <string> .Add, ref strArray); string[] expectedStrs = new string[2] { "", "" }; for (int p = 0; p < world.Size; ++p) { expectedStrs[0] += p.ToString(); expectedStrs[1] += "World"; } MPIDebug.Assert(expectedStrs[0] == strArray[0]); MPIDebug.Assert(expectedStrs[1] == strArray[1]); if (world.Rank == 0) { System.Console.WriteLine(" done."); } } }
public static void DoTest(string[] args) { using (new MPI.Environment(ref args)) { Intracommunicator world = Communicator.world; world.Barrier(); // Test addition of integers int partial_sum = world.Scan(world.Rank, addInts); int expected = (world.Rank + 1) * world.Rank / 2; MPIDebug.Assert(partial_sum == expected); if (world.Rank == world.Size - 1) { System.Console.WriteLine("Sum of ranks = " + partial_sum); } // Test addition of integer points Point point_sum = world.Scan(new Point(world.Rank, 1), Point.Plus); MPIDebug.Assert(point_sum.x == partial_sum && point_sum.y == world.Rank + 1); if (world.Rank == world.Size - 1) { System.Console.WriteLine("Sum of points = (" + point_sum.x + ", " + point_sum.y + ")"); } // Test addition of integer arrays if (world.Rank == world.Size - 1) { System.Console.Write("Testing scan of integer arrays..."); } int[] arraySum = world.Scan(new int[] { world.Rank, 1 }, Operation <int> .Add); MPIDebug.Assert(arraySum[0] == partial_sum && arraySum[1] == world.Rank + 1); if (world.Rank == world.Size - 1) { System.Console.WriteLine(" done."); } // Test concatenation of strings if (world.Rank == world.Size - 1) { System.Console.Write("Testing scan of strings..."); } string str = world.Scan(world.Rank.ToString(), Operation <string> .Add); string expectedStr = ""; for (int p = 0; p <= world.Rank; ++p) { expectedStr += p.ToString(); } MPIDebug.Assert(expectedStr == str); if (world.Rank == world.Size - 1) { System.Console.WriteLine(" done."); } // Test concatenation of string arrays if (world.Rank == world.Size - 1) { System.Console.Write("Testing scan of string arrays..."); } string[] strArray = world.Scan(new string[] { world.Rank.ToString(), "World" }, Operation <string> .Add); string[] expectedStrs = new string[2] { "", "" }; for (int p = 0; p <= world.Rank; ++p) { expectedStrs[0] += p.ToString(); expectedStrs[1] += "World"; } MPIDebug.Assert(expectedStrs[0] == strArray[0]); MPIDebug.Assert(expectedStrs[1] == strArray[1]); if (world.Rank == world.Size - 1) { System.Console.WriteLine(" done."); } } }
public static void DoTest(string[] args) { int dataSize = 10000000; //using (MPI.Environment env = new MPI.Environment(ref args)) { if (Communicator.world.Size != 2) { System.Console.WriteLine("The Datatypes test must be run with two processes."); System.Console.WriteLine("Try: mpiexec -np 2 datatypes.exe"); } else if (Communicator.world.Rank == 0) { // Send an object that contains a "fixed" field Dimensions dims; unsafe { for (int i = 0; i < 11; ++i) { dims.values[i] = (float)i; } } Communicator.world.Send(dims, 1, 0); // Send an object that contains non-public fields Secretive secret = new Secretive(17, 25); Communicator.world.Send(secret, 1, 1); // Send an object with complex data AggregateData aggregate = new AggregateData(dataSize); Communicator.world.Send(aggregate, 1, 2); // Send an object with a private type Hidden hidden = new Hidden(17, 25); Communicator.world.Send(hidden, 1, 3); // Send a struct that requires serialization. ContainsBool containsBool = new ContainsBool(17); Communicator.world.Send(containsBool, 1, 4); } else { // Receive and check an object that contains a "fixed" field Dimensions dims; Communicator.world.Receive(0, 0, out dims); unsafe { for (int i = 0; i < 11; ++i) { System.Console.WriteLine(dims.values[i].ToString() + " "); MPIDebug.Assert(dims.values[i] == (float)i); } } // Receive and check an object that contains non-public fields Secretive secret; Communicator.world.Receive(0, 1, out secret); System.Console.WriteLine(secret); MPIDebug.Assert(secret == new Secretive(17, 25)); // Receive and check the "complex data" AggregateData aggregate = Communicator.world.Receive <AggregateData>(0, 2); if (!aggregate.Check(dataSize)) { System.Console.Error.WriteLine("Error: complex data not properly transmitted"); MPI.Environment.Abort(1); } // Receive and check an object with a private type Hidden hidden; Communicator.world.Receive(0, 3, out hidden); System.Console.WriteLine(hidden); MPIDebug.Assert(hidden == new Hidden(17, 25)); // Receive and check a struct that requires serialization ContainsBool containsBool; Communicator.world.Receive(0, 4, out containsBool); System.Console.WriteLine(containsBool); MPIDebug.Assert(containsBool == new ContainsBool(17)); } } }