public void enviroment(string[] args) { mpi = new MPI.Environment(ref args); worldcomm = Communicator.world; Size = worldcomm.Size; Rank = worldcomm.Rank; }
public IMPIDirectImpl() { string[] args = System.Environment.GetCommandLineArgs(); mpi = new MPI.Environment(ref args); Console.WriteLine("MPI.NET Init for process #" + Communicator.world.Rank); }
static void Main(string[] args) { MPI.Environment mpi = new MPI.Environment(ref args); MPI.Intracommunicator worldComm = Communicator.world; Console.WriteLine("OK\n"); mpi.Dispose(); }
//protected Thread master = null; private void setup_mpi() { int nc, color; string[] args = System.Environment.GetCommandLineArgs(); mpi = new MPI.Environment(ref args); worldcomm = Communicator.world; total_nodes = worldcomm.Size; node = worldcomm.Rank; //--------------------------------------------------------------------- // compute square root; add small number to allow for roundoff //--------------------------------------------------------------------- nc = Convert.ToInt32(Math.Sqrt(total_nodes) + 0.00001d); maxcells = Convert.ToInt32(Math.Sqrt(total_nodes)); //--------------------------------------------------------------------- // We handle a non-square number of nodes by making the excess nodes // inactive. However, we can never handle more cells than were compiled // in. //--------------------------------------------------------------------- if (nc > maxcells) { nc = maxcells; } if (node >= nc * nc) { active = false; color = 1; } else { active = true; color = 0; } comm_setup = (Intracommunicator)worldcomm.Split(color, node); if (!active) { return; } no_nodes = comm_setup.Size; comm_solve = (Intracommunicator)comm_setup.Clone(); comm_rhs = (Intracommunicator)comm_setup.Clone(); //--------------------------------------------------------------------- // let node 0 be the root for the group (there is only one) //--------------------------------------------------------------------- root = 0; }
static void Main(string[] args) { using (MPI.Environment environment = new MPI.Environment(ref args)) { if (args[4].Equals("*")) { args[4] = "0"; } SectorInfo sectorinfo = new SectorInfo() { RealMinimum = Convert.ToDouble(args[0]), ImgMinimum = Convert.ToDouble(args[1]), Delta = Convert.ToDouble(args[2]), FromX = Convert.ToInt32(args[3]), FromY = Convert.ToInt32(args[4]), Width = Convert.ToInt32(args[5]), Height = Convert.ToInt32(args[6]), MaxIterations = Convert.ToInt32(args[7]), MaxValue = Convert.ToInt32(args[8]) }; Intracommunicator comm = Communicator.world; if (comm.Rank == 0) { SectorInfo[] sectors = new SectorInfo[comm.Size]; for (int k = 0; k < sectors.Length; k++) { SectorInfo newsector = new SectorInfo() { RealMinimum = sectorinfo.RealMinimum, ImgMinimum = sectorinfo.ImgMinimum, Delta = sectorinfo.Delta, FromX = sectorinfo.FromX, FromY = sectorinfo.FromY + k * (sectorinfo.Height / comm.Size), Width = sectorinfo.Width, Height = sectorinfo.Height / comm.Size, MaxIterations = sectorinfo.MaxIterations, MaxValue = sectorinfo.MaxValue }; sectors[k] = newsector; } SectorInfo si = comm.Scatter(sectors); CalculateSector(args, si); } else { SectorInfo si = comm.Scatter <SectorInfo>(0); CalculateSector(args, si); } } }
static void Main(string[] args) { using (MPI.Environment environment = new MPI.Environment(ref args)) { Intracommunicator comm = Communicator.world; rank = Communicator.world.Rank; size = Communicator.world.Size; Communicator.world.Barrier(); found = false; if (comm.Rank == 0) { int[] numbers = new int[comm.Size]; for (int k = 0; k < numbers.Length; k++) { numbers[k] = k + 1; } int r = comm.Scatter(numbers); Console.WriteLine("Received {0} at {1}", r, comm.Rank); } else { int r = comm.Scatter <int>(0); Console.WriteLine("Received {0} at {1}", r, comm.Rank); } nvalues = 50 / size; i = rank * nvalues; inrange = ((i <= ((rank + 1) * nvalues - 1)) & (i >= rank * nvalues)); while (inrange) { int p = 0; if (numbers[i] == nrToSearch) { temp = 23; for (j = 0; j < size; ++j) { Communicator.world.Send <int>(temp, j, 1); } Console.WriteLine("Process: " + rank + "has found " + numbers[i] + " at global index " + i + "\n"); found = true; } ++i; inrange = (i <= ((rank + 1) * nvalues - 1) && i >= rank * nvalues); } if (!found) { Console.WriteLine("Process: " + rank + " stopped at global index " + (i - 1) + "\n"); } } }
public void StartMPI(string[] args) { Console.WriteLine("Starting MPI ... "); mpi = new MPI.Environment(ref args, Threading.Multiple); Trace.Write("ok !"); this.global_communicator = MPI.Communicator.world; number_of_workers = this.global_communicator.Size; my_rank = this.global_communicator.Rank; Console.WriteLine("Rank #" + my_rank + " at processor " + MPI.Environment.ProcessorName + " - threading is " + MPI.Environment.Threading); }
static void Main(string[] args) { using (MPI.Environment env = new MPI.Environment(ref args)) { for (int i = 0; i < Communicator.world.Size; ++i) { RunTests(i); } } }
static void Main(string[] args) { using (var env = new MPI.Environment(ref args)) { if (MPI.Communicator.world.Rank == 0) { Console.WriteLine("Исходный массив: "); int[,] mass = new int[6, 6]; Random rand = new Random(); for (int i = 0; i < 6; i++) { for (int j = 0; j < 6; j++) { mass[i, j] = rand.Next(0, 9); Console.Write(mass[i, j] + " "); } Console.WriteLine(); } List<int> current_array_string = new List<int>(); List<int> to_multiply = new List<int>(); for (int i = 0; i < 6; i++) { for (int j = 0; j < 6; j++) { current_array_string.Add(mass[i, j]); } MPI.Communicator.world.Send(current_array_string, Communicator.world.Rank + i + 1, 0); to_multiply.Add(MPI.Communicator.world.Receive<int>(Communicator.world.Rank + i + 1, 0)); } int multiplications_sum = 0; foreach (int j in to_multiply) { multiplications_sum += j; } Console.WriteLine("Сумма строк равна: " + multiplications_sum); } for (int i = 1; i < 7; i++) { if (MPI.Communicator.world.Rank == i) { Console.WriteLine(); int multiplication = 1; List<int> received_list = new List<int>(); received_list = MPI.Communicator.world.Receive<List<int>>(Communicator.world.Rank - i, 0); for(int k = 0; k<received_list.Count(); k++) { multiplication = multiplication*received_list[k]; } Communicator.world.Send(multiplication, 0, 0); } } } Console.ReadLine(); }
public static void RunTest(string[] args) { using (var env = new MPI.Environment(ref args, MPI.Threading.Serialized)) { var proc = Process.GetCurrentProcess(); var name = proc.ProcessName; Console.WriteLine(" name: " + name); System.Threading.Thread.Sleep(17000); var comm = Communicator.world; int sum = comm.Rank; var total = comm.Reduce(sum, (a, b) => a + b, 0); if (comm.Rank == 0) { Console.WriteLine("testing mpi"); Console.WriteLine(total); } } }
static void main(string[] args) { using (MPI.Environment env = new MPI.Environment(ref args)) { Intracommunicator comm = MPI.Communicator.world; if (comm.Size < 2) { // Our ring needs at least two processes System.Console.WriteLine("The Ring example must be run with at least two processes."); System.Console.WriteLine("Try: mpiexec -np 4 ring.exe"); } else if (comm.Rank == 0) { // Rank 0 initiates communication around the ring string data = "Hello, World!"; // Send "Hello, World!" to our right neighbor comm.Send(data, (comm.Rank + 1) % comm.Size, 0); // Receive data from our left neighbor comm.Receive((comm.Rank + comm.Size - 1) % comm.Size, 0, out data); // Add our own rank and write the results data += " 0"; System.Console.WriteLine(data); } else { // Receive data from our left neighbor String data; comm.Receive((comm.Rank + comm.Size - 1) % comm.Size, 0, out data); // Add our own rank to the data data = data + " " + comm.Rank.ToString() + ","; // Pass on the intermediate to our right neighbor comm.Send(data, (comm.Rank + 1) % comm.Size, 0); } } }
static void Main(string[] args) { using (MPI.Environment env = new MPI.Environment(ref args)) { Intracommunicator comm = MPI.Communicator.world; if (comm.Size < 2) { // Our ring needs at least two processes System.Console.WriteLine("The Ring example must be run with at least two processes."); System.Console.WriteLine("Try: mpiexec -np 4 ring.exe"); } else if (comm.Rank == 0) { // Rank 0 initiates communication around the ring string data = "Hello, World!"; // Send "Hello, World!" to our right neighbor comm.Send(data, (comm.Rank + 1) % comm.Size, 0); // Receive data from our left neighbor comm.Receive((comm.Rank + comm.Size - 1) % comm.Size, 0, out data); // Add our own rank and write the results data += " 0"; System.Console.WriteLine(data); } else { // Receive data from our left neighbor String data; comm.Receive((comm.Rank + comm.Size - 1) % comm.Size, 0, out data); // Add our own rank to the data data = data + " " + comm.Rank.ToString() + ","; // Pass on the intermediate to our right neighbor comm.Send(data, (comm.Rank + 1) % comm.Size, 0); } } }
public static void Main (string[] args){ MPI.Environment mpi = new MPI.Environment(ref args); MPI.Intracommunicator worldcomm = MPI.Communicator.world; int np = worldcomm.Size; int node = worldcomm.Rank; //Process P = System.Diagnostics.Process.Start ("/bin/hostname"); func_c(args.Length, args); worldcomm.Barrier (); if(node==0) System.Console.WriteLine ("*************************************"); worldcomm.Barrier (); int soma = worldcomm.Reduce<int>(node, Operation<int>.Add, 0); System.Console.WriteLine("RANK.NET: "+node+" SIZE: "+np+" soma: "+soma); mpi.Dispose(); }
public static void RunSimulated(string[] args) { using (var env = new MPI.Environment(ref args, MPI.Threading.Serialized)) { var proc = Process.GetCurrentProcess(); var name = proc.ProcessName; Console.WriteLine(" name: " + name); //System.Threading.Thread.Sleep(17000); var comm = Communicator.world; //READ DATA var folder = @"C:\dev\GitHub\p9-data\small\fits\simulation_point\"; var bla = @"C:\dev\GitHub\p9-data\small\fits\simulation_point"; var fullData = DistributedData.LoadSimulated(folder); var data = DistributedData.SplitDataAmongNodes(comm, fullData); var totalVisibilitiesCount = fullData.VisibilitiesCount; int gridSize = 256; int subgridsize = 16; int kernelSize = 8; int max_nr_timesteps = 512; double cellSize = 1.0 / 3600.0 * PI / 180.0; var c = new GriddingConstants(totalVisibilitiesCount, gridSize, subgridsize, kernelSize, max_nr_timesteps, (float)cellSize, 1, 0.0f); comm.Barrier(); if (comm.Rank == 0) { Console.WriteLine("Done Reading, Starting reconstruction"); } var reconstruction = MPIMajorCycle.Reconstruct(comm, data, c, 1, 0.5f, 0.8f, 1000); if (comm.Rank == 0) { FitsIO.Write(reconstruction, "simulatedReconstruction.fits"); } } }
static void Main(string[] args) { IDictionary<int, MPI.Intracommunicator> colors = new Dictionary<int, MPI.Intracommunicator>(); MPI.Environment mpi = new MPI.Environment(ref args); MPI.Intracommunicator worldComm = Communicator.world; int min = 8; int max=min; int rank = min; rank = worldComm.Rank; min = worldComm.Allreduce<int>(rank+1, MPI.Operation<int>.Min); max = worldComm.Reduce<int>(rank+1, MPI.Operation<int>.Max, 1); colors[rank] = (MPI.Intracommunicator)worldComm.Split(rank+100, rank); int rec = 8; if (rank == 0) { MPI.Request req = worldComm.ImmediateSend<int> (50, rank, 0); rec = worldComm.Receive<int> (rank, 0); req.Wait(); } Console.WriteLine("Node {0} of {1} - min={2} - max={3} - rec={4}\n", rank, worldComm.Size, min, max, rec); mpi.Dispose(); }
public static void Main(string[] args) { MPI.Environment mpi = new MPI.Environment(ref args); MPI.Intracommunicator worldcomm = MPI.Communicator.world; int np = worldcomm.Size; int node = worldcomm.Rank; //Process P = System.Diagnostics.Process.Start ("/bin/hostname"); func_c(args.Length, args); worldcomm.Barrier(); if (node == 0) { System.Console.WriteLine("*************************************"); } worldcomm.Barrier(); int soma = worldcomm.Reduce <int>(node, Operation <int> .Add, 0); System.Console.WriteLine("RANK.NET: " + node + " SIZE: " + np + " soma: " + soma); mpi.Dispose(); }
public static void RunTinyMeerKAT(string[] args) { using (var env = new MPI.Environment(ref args, MPI.Threading.Serialized)) { var proc = Process.GetCurrentProcess(); var name = proc.ProcessName; Console.WriteLine(" name: " + name); var comm = Communicator.world; var folder = @"C:\dev\GitHub\p9-data\large\fits\meerkat_tiny\"; var data = DistributedData.LoadTinyMeerKAT2(comm.Rank, comm.Size, folder); var totalVisCount = comm.Allreduce(data.VisibilitiesCount, (x, y) => x + y); int gridSize = 3072; int subgridsize = 32; int kernelSize = 16; int max_nr_timesteps = 1024; double cellSize = 1.5 / 3600.0 * PI / 180.0; var c = new GriddingConstants(totalVisCount, gridSize, subgridsize, kernelSize, max_nr_timesteps, (float)cellSize, 1, 0.0f); comm.Barrier(); if (comm.Rank == 0) { Console.WriteLine("Done Reading, Starting reconstruction"); } var lambda = 0.4f; var alpha = 0.1f; var reconstruction = MPIMajorCycle.Reconstruct(comm, data, c, 2, lambda, alpha, 10000); if (comm.Rank == 0) { FitsIO.Write(reconstruction, "tinyMeerKATReconstruction.fits"); } } }
static void Main(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); Debug.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); Debug.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++) { Debug.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++) { Debug.Assert(recvValues_s[j] == i.ToString()); } } if (comm.Rank == 0) { System.Console.WriteLine(" done."); } } }
static void Main(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() + " "); Debug.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); Debug.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); Debug.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); Debug.Assert(containsBool == new ContainsBool(17)); } } }
static void Main(string[] args) { using (var mppi = new MPI.Environment(ref args)) { if (Communicator.world.Rank == 0) { Random r = new Random(); double[,] mas = new double[5, 5]; for (int i = 0; i < 5; i++) { for (int j = 0; j < 5; j++) { mas[i, j] = r.Next(0, 10); } } Console.WriteLine("Исходный Массив:"); for (int i = 0; i < mas.GetLength(0); i++) { for (int j = 0; j < mas.GetLength(1); j++) { Console.Write(mas[i, j] + " "); } Console.WriteLine(); } Console.WriteLine(); double temp; for (int repeat = 0; repeat < 5; repeat++) { for (int i = 0; i < 4; i++) { if (mas[i, 0] > mas[i + 1, 0]) { for (int j = 0; j < 5; j++) { temp = mas[i, j]; mas[i, j] = mas[i + 1, j]; mas[i + 1, j] = temp; } } } } Communicator.world.Send(mas, 1, 0); } if (Communicator.world.Rank == 1) { double[,] msg = Communicator.world.Receive <double[, ]>(Communicator.world.Rank - 1, 0); Console.WriteLine("Итоговый Массив:"); for (int i = 0; i < msg.GetLength(0); i++) { for (int j = 0; j < msg.GetLength(1); j++) { Console.Write(msg[i, j] + " "); } Console.WriteLine(); } } } }
static void Main(string[] args) { using (var env = new MPI.Environment(ref args)) { if (MPI.Communicator.world.Rank == 0) { Console.WriteLine("Найти максимальный элемент матрицы."); Console.WriteLine("Исходный массив: "); int[,] matrix = new int[5, 5]; Random rand = new Random(); for (int i = 0; i < 5; i++) { for (int j = 0; j < 5; j++) { matrix[i, j] = rand.Next(1, 20); Console.Write(matrix[i, j] + " "); } Console.WriteLine(); } List <int> list = new List <int>(); int currentmax = 0; List <int> results = new List <int>(); for (int i = 0; i < 5; i++) { for (int j = 0; j < 5; j++) { list.Add(matrix[i, j]); } MPI.Communicator.world.Send(list, Communicator.world.Rank + i + 1, 0); Console.WriteLine("Передана " + (i + 1) + "-я часть матрицы"); results.Add(MPI.Communicator.world.Receive <int>(Communicator.world.Rank + i + 1, 0)); } foreach (int j in results) { if (j > currentmax) { currentmax = j; } } Console.WriteLine("Наибольший элемент: " + currentmax); } for (int i = 1; i < 6; i++) { if (MPI.Communicator.world.Rank == i) { Console.WriteLine(); int max = 0; List <int> multiplication = MPI.Communicator.world.Receive <List <int> >(Communicator.world.Rank - i, 0); foreach (int j in multiplication) { if (j > max) { max = j; } } multiplication.Clear(); Communicator.world.Send(max, 0, 0); } } } }
static void Main(string[] args) { //Инициализируем окружение MPI using (var env = new MPI.Environment(ref args)) { if (MPI.Communicator.world.Rank == 0) { Console.WriteLine("Определить сумму из произведений элементов каждой строки матрицы."); Console.WriteLine("Исходный массив: "); int[,] mass = new int[6, 6]; Random rand = new Random(); for (int i = 0; i < 6; i++) { for (int j = 0; j < 6; j++) { mass[i, j] = rand.Next(1, 20); Console.Write(mass[i, j] + " "); } Console.WriteLine(); } List <int> current_array_string = new List <int>(); List <int> to_multiply = new List <int>(); for (int i = 0; i < 6; i++) { for (int j = 0; j < 6; j++) { current_array_string.Add(mass[i, j]); } //метод отправки списка в другой поток (что передаём, куда передаём) MPI.Communicator.world.Send(current_array_string, Communicator.world.Rank + i + 1, 0); //метод отправки списка в другой поток (что получаем, откуда получаем) to_multiply.Add(MPI.Communicator.world.Receive <int>(Communicator.world.Rank + i + 1, 0)); } int multiplications_sum = 0; foreach (int j in to_multiply) { multiplications_sum += j; } if (multiplications_sum < 0) { multiplications_sum *= (-1); } Console.WriteLine("Сумма произведений строк равна: " + multiplications_sum); } for (int i = 1; i < 7; i++) { if (MPI.Communicator.world.Rank == i) { Console.WriteLine(); int multiplication = 1; List <int> received_list = new List <int>(); received_list = MPI.Communicator.world.Receive <List <int> >(Communicator.world.Rank - i, 0); for (int k = 0; k < received_list.Count(); k++) { multiplication = multiplication * received_list[k]; } Communicator.world.Send(multiplication, 0, 0); } } } }
static void Main(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); Debug.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); Debug.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++) Debug.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++) Debug.Assert(recvValues_s[j] == i.ToString()); } if (comm.Rank == 0) System.Console.WriteLine(" done."); } }
static void Main(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; Debug.Assert(sum == expected); if (world.Rank == 0) { System.Console.WriteLine("Sum of ranks = " + sum); } // Test addition of integers through the Operations class Debug.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); Debug.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); Debug.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); Debug.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); Debug.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); Debug.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); Debug.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; } Debug.Assert(expectedStr == strcat); if (world.Rank == 0) { System.Console.WriteLine("Concatenation of rank strings = " + strcat); } Debug.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); Debug.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"; } Debug.Assert(expectedStrs[0] == strArray[0]); Debug.Assert(expectedStrs[1] == strArray[1]); if (world.Rank == 0) { System.Console.WriteLine(" done."); } } }
//Install-Package MPI.NET -Version 1.3.0 // MPIEXEC -n 3 Mpi.NET1.exe "data3.txt" "50" static void Main(string[] args) { using (MPI.Environment environment = new MPI.Environment(ref args)) { if (args.Length < 2) { Console.WriteLine("At least two Arguments are needed"); return; } Intracommunicator comm = MPI.Communicator.world; if (comm.Size < 2) { Console.WriteLine("At least two processes are needed"); return; } float support = float.Parse(args[1]); if (comm.Rank == 0) // It's the root { // đọc dữ liệu đầu vào string inputFile = args[0]; string[] database = System.IO.File.ReadAllLines(inputFile); List <List <int> > db = new List <List <int> >(); List <int> items; foreach (string item in database) { items = new List <int>(); foreach (string it in item.Split(',')) { items.Add(int.Parse(it)); } db.Add(items); } for (int i = 1; i < comm.Size; i++) { comm.Send(db, i, 0);// gửi tới các tiến trình i, tag 0 } Dictionary <int, int> tongHop = new Dictionary <int, int>(); for (int i = 1; i < comm.Size; i++) { Dictionary <int, int> demItem; comm.Receive(i, 1, out demItem);// nhận từ i, tag 1 foreach (var item in demItem) { if (tongHop.ContainsKey(item.Key)) { tongHop[item.Key] += item.Value; } else { tongHop.Add(item.Key, item.Value); } } } int len = db.Count; //var ordered = tongHop.OrderByDescending(x => x.Value); List <int> keys = new List <int>(tongHop.Keys); foreach (var key in keys) { //Console.WriteLine("Item {0}", key); if (((float)tongHop[key] / (float)len * 100.0) < support) { tongHop.Remove(key); } } tongHop = tongHop.OrderByDescending(x => x.Value).ToDictionary(x => x.Key, y => y.Value); //foreach (var item in tongHop) //{ // Console.WriteLine("Item {0} count {1}", item.Key, item.Value); //} //tongHop.OrderByDescending(x => x.Value) // gửi 1-item phổ biến for (int i = 1; i < comm.Size; i++) { comm.Send(tongHop, i, 2);// gửi tới các tiến trình i, tag 2 } // Dictionary <int, Dictionary <int, Dictionary <int, int> > > Pall = new Dictionary <int, Dictionary <int, Dictionary <int, int> > >(); for (int i = 1; i < comm.Size; i++) { Dictionary <int, Dictionary <int, Dictionary <int, int> > > P; comm.Receive(i, 3, out P);// nhận từ i, tag 1 foreach (var itemset in P) { if (Pall.ContainsKey(itemset.Key)) { foreach (var item in itemset.Value) { Dictionary <int, Dictionary <int, int> > keyValues = Pall[itemset.Key]; if (keyValues.ContainsKey(item.Key)) { Dictionary <int, int> kv = keyValues[item.Key]; //keyValues[item.Key] += item.Value; foreach (var k in item.Value) { if (kv.ContainsKey(k.Key)) { kv[k.Key] += k.Value; } else { kv.Add(k.Key, k.Value); } } } else { keyValues.Add(item.Key, item.Value); } Pall[itemset.Key] = keyValues; } } else { Pall.Add(itemset.Key, itemset.Value); } } } List <int> itemkey = new List <int>(Pall.Keys); foreach (var itemset in itemkey) { Dictionary <int, Dictionary <int, int> > keyValues = Pall[itemset]; Dictionary <int, int> coutValue = CountValue(keyValues); //PrintDictionary(coutValue); List <int> kv = new List <int>(keyValues.Keys); foreach (var item in kv) { Dictionary <int, int> keyValue = keyValues[item]; List <int> ikey = new List <int>(keyValue.Keys); foreach (var k in ikey) { if ((float)coutValue[k] / len * 100.0 < support) { keyValue.Remove(k); } } keyValues[item] = keyValue; } //keyValues.Add(itemset, tongHop[itemset]); Pall[itemset] = keyValues; } //foreach (var itemset in Pall) //{ // Console.WriteLine("FPTree: {0}", itemset.Key); // foreach (var item in itemset.Value) // { // Console.WriteLine("Node: {0}", item.Key); // foreach (var key in item.Value) // Console.Write("Item {0} count {1} -> ", key.Key, key.Value); // Console.WriteLine(); // } // Console.WriteLine(); //} //foreach (var itemset in Pall) //{ // Console.WriteLine("Item {0}: ", itemset.Key); // foreach (var item in itemset.Value) // Console.WriteLine("Item {0} count {1}", item.Key, item.Value); //} Dictionary <List <int>, float> FPTreeCon = new Dictionary <List <int>, float>(); foreach (var itemset in Pall) { FPTreeCon.Add(new List <int> { itemset.Key }, (float)tongHop[itemset.Key] / len * 100f); foreach (var item in itemset.Value) { List <int> keyValues = new List <int>(item.Value.Keys); //Console.WriteLine("keyValues {0}", string.Join(",", keyValues.ToArray())); List <List <int> > subsets = Bit.FindSubsets(keyValues, 0); //get all subsets foreach (var itms in subsets) { if (itms.Count > 0) { //Console.WriteLine("subsets {0}", string.Join(",", itms.ToArray())); float itemsupport = FindSupport(len, Pall[itemset.Key], itms); itms.Add(itemset.Key); if (itemsupport >= support && !ContainsKey(new List <List <int> >(FPTreeCon.Keys), itms)) { FPTreeCon.Add(itms, itemsupport); } } } } } //foreach (var itemset in FPTreeCon) //{ // Console.WriteLine("Item {0} - support {1}", String.Join(", ", itemset.Key.ToArray()), itemset.Value); //} using (StreamWriter outputFile = new StreamWriter("OutputFPGrowth.txt")) { foreach (var itemset in FPTreeCon) { outputFile.WriteLine("{0}:{1}", string.Join(",", itemset.Key.ToArray()), itemset.Value); } } } else { List <List <int> > db; comm.Receive(0, 0, out db);// nhận từ 0, tag 0 Dictionary <int, int> demItem = new Dictionary <int, int>(); // tính chia db int size = comm.Size - 1; int len = db.Count; int n = len / size; int start = (comm.Rank - 1) * n; int end = comm.Rank * n; if (comm.Rank == size) { end = len; } // for (int i = start; i < end; i++) { foreach (int item in db[i]) { if (demItem.ContainsKey(item)) { demItem[item]++; } else { demItem.Add(item, 1); } } } // item cout cục bộ comm.Send(demItem, 0, 1);// gửi tới các tiến trình 0, tag 1 // nhận 1-itemset phổ biến Dictionary <int, int> Fre; comm.Receive(0, 2, out Fre);// nhận từ 0, tag 2 // T itemset cục bộ List <List <int> > Tcucbo = new List <List <int> >(); for (int i = start; i < end; i++) { List <int> itemset = new List <int>(); foreach (var item in Fre) { if (db[i].Contains(item.Key)) { itemset.Add(item.Key); } } if (itemset.Count > 0) { Tcucbo.Add(itemset); } } //if(comm.Rank == 2) //foreach (var items in Tcucbo) //{ // foreach (var item in items) // Console.Write(item + " "); // Console.WriteLine(); //} // xây dựng FP-Tree cục bộ FPTree tree = CreateTree(Tcucbo); // Conditional Patern Bases Dictionary <int, Dictionary <int, Dictionary <int, int> > > P = new Dictionary <int, Dictionary <int, Dictionary <int, int> > >(); foreach (var itemset in Fre) { Dictionary <int, Dictionary <int, int> > nodeParent = new Dictionary <int, Dictionary <int, int> >(); //List<int> itemsetCollectionKey = new List<int>(); //int itemsetCollectionValue = 0; //Console.WriteLine("Node: {0}", itemset.Key); for (int j = 0; j < tree.countNode; j++) { Dictionary <int, int> itemsetCollection = new Dictionary <int, int>(); var node = tree.arrayNode[j]; if (node.itemName == itemset.Key && !node.visited) { node.visited = true; var nodeparent = node.nodeParent; while (nodeparent.itemName > -1) { //bool index = itemsetCollection.Key.Contains(nodeparent.itemName); if (itemsetCollection.ContainsKey(nodeparent.itemName)) { itemsetCollection[nodeparent.itemName] += node.count; } else { itemsetCollection.Add(nodeparent.itemName, node.count); } //Console.Write("Item:{0}({1})->", nodeparent.itemName, node.count); nodeparent = nodeparent.nodeParent; } if (itemsetCollection.Count > 0) { if (nodeParent.ContainsKey(itemsetCollection.Keys.Last())) { Dictionary <int, int> keyValues = nodeParent[itemsetCollection.Keys.Last()]; foreach (var item in itemsetCollection) { if (keyValues.ContainsKey(item.Key)) { keyValues[item.Key] += item.Value; } else { keyValues.Add(item.Key, item.Value); } } nodeParent[itemsetCollection.Keys.Last()] = keyValues; } else { nodeParent.Add(itemsetCollection.Keys.Last(), itemsetCollection); } } } } P.Add(itemset.Key, nodeParent); } comm.Send(P, 0, 3);// gửi tới các tiến trình 0, tag 3 } } }
static void Main(string[] args) { // Whether we should use the unsafe, Direct interface to MPI. // When false, use the normal MPI.NET interface. bool useDirectInterface = false; using (MPI.Environment env = new MPI.Environment(ref args)) { if (args.Length > 0 && args[0] == "/direct") { useDirectInterface = true; System.Console.WriteLine("Using direct MPI interface."); System.Console.WriteLine("Bzzt. Can't do that here. Goodbye"); return; } else { System.Console.WriteLine("Using MPI.NET interface."); } comm = MPI.Communicator.world; if (comm.Size != 2) { if (comm.Rank == 0) { System.Console.WriteLine("Only two processes allowed. Rerun with -np 2"); } return; } else { self = comm.Rank; other = (comm.Rank + 1) % 2; } System.Console.WriteLine(comm.Rank + ": " + MPI.Environment.ProcessorName); bwdata = new Data[nSamp]; testLatency(); testSyncTime(); comm.Broadcast(ref latency, 0); if (self == 0) { System.Console.WriteLine("Latency: {0:F9}", latency); System.Console.WriteLine("Sync Time: {0:F9}", synctime); System.Console.WriteLine("Now starting main loop"); } int i, j, n, nq; int inc = 1, len; int start = 0, end = 1024 * 1024 * 1024; int bufflen = start, bufalign = 16 * 1024; double tlast = latency; for (n = nq = 0, len = start; tlast < stopTime && len <= end; len += inc, nq++) { if (nq > 2 && (nq % 2 != 0)) { inc *= 2; } int ipert, pert; for (ipert = 0, pert = (inc > PERT + 1) ? -PERT : 0; pert <= PERT; ipert++, n++, pert += (inc > PERT + 1) ? PERT : PERT + 1) { int nRepeat = bufflen == 0 ? latencyReps : (int)Math.Max((RUNTM / ((double)bufflen / (bufflen - inc + 1.0) * tlast)), TRIALS); comm.Broadcast(ref nRepeat, 0); bufflen = len + pert; Tortoise[] sendBuffer = new Tortoise[bufflen]; // Align the data? Some day. Maybe. Tortoise[] recvBuffer = new Tortoise[bufflen]; for (i = 0; i < bufflen; i++) { sendBuffer[i] = new Tortoise(); sendBuffer[i].contents = 0; } if (self == 0) { System.Console.Write("{0,3:D}: {1,9:D} bytes {2,7:D} times ---> ", n, bufflen, nRepeat); } bwdata[n].t = 1e99; double t1 = 0, t2 = 0; for (i = 0; i < TRIALS; i++) { sync(); double t0 = when(); if (useDirectInterface) { } else { for (j = 0; j < nRepeat; j++) { if (self == 0) { comm.Send(sendBuffer, other, 142); comm.Receive(ref recvBuffer, other, 242); } else { comm.Receive(ref recvBuffer, other, 142); comm.Send(sendBuffer, other, 242); } } } double t = (when() - t0) / (2.0 * nRepeat); t2 += t * t; t1 += t; bwdata[n].t = Math.Min(bwdata[n].t, t); bwdata[n].variance = t2 / TRIALS - t1 / TRIALS * t1 / TRIALS; tlast = bwdata[n].t; bwdata[n].bits = bufflen * sizeof(byte) * 8; bwdata[n].bps = bwdata[n].bits / (bwdata[n].t * 1024 * 1024); bwdata[n].repeat = nRepeat; } if (self == 0) { System.Console.WriteLine("{0,9:F2} Mbps in {1:F9} sec", bwdata[n].bps, tlast); } } } } }
static void Main(string[] args) { using (var mppi = new MPI.Environment(ref args)) { if (Communicator.world.Rank == 0) { int n = 5; int m = 5; Random r = new Random(); double[,] mas = new double[n, m]; for (int i = 0; i < n; i++) { for (int j = 0; j < m; j++) { mas[i, j] = r.Next(0, 10); } } Console.WriteLine("Исходный Массив:"); for (int i = 0; i < mas.GetLength(0); i++) { for (int j = 0; j < mas.GetLength(1); j++) { Console.Write(mas[i, j] + " "); } Console.WriteLine(); } double[] b = new double[n]; Console.WriteLine(); for (int i = 0; i < n; i++) { for (int j = 0; j < m; j++) { b[i] += mas[j, i]; } } double currentAmount = 0; double nextAmount = 0; for (int k = 0; k < n; k++) { for (int i = 0; i < n - 1; i++) { for (int j = 0; j < m; j++) { currentAmount += mas[j, i]; nextAmount += mas[j, i + 1]; } if (nextAmount < currentAmount) { for (int g = 0; g < m; g++) { var temp = mas[g, i]; mas[g, i] = mas[g, i + 1]; mas[g, i + 1] = temp; } } currentAmount = 0; nextAmount = 0; } } Communicator.world.Send(mas, 1, 0); } if (Communicator.world.Rank == 1) { double[,] msg = Communicator.world.Receive <double[, ]>(Communicator.world.Rank - 1, 0); Console.WriteLine("Итоговый Массив:"); for (int i = 0; i < msg.GetLength(0); i++) { for (int j = 0; j < msg.GetLength(1); j++) { Console.Write(msg[i, j] + " "); } Console.WriteLine(); } } } }
static void Main(string[] args) { // Whether we should use the unsafe, Direct interface to MPI. // When false, use the normal MPI.NET interface. bool useDirectInterface = false; using (MPI.Environment env = new MPI.Environment(ref args)) { if (args.Length > 0 && args[0] == "/direct") { useDirectInterface = true; System.Console.WriteLine("Using direct MPI interface."); } else System.Console.WriteLine("Using MPI.NET interface."); comm = MPI.Communicator.world; if (comm.Size != 2) { if (comm.Rank == 0) System.Console.WriteLine("Only two processes allowed. Rerun with -np 2"); return; } else { self = comm.Rank; other = (comm.Rank + 1) % 2; } System.Console.WriteLine(comm.Rank + ": " + MPI.Environment.ProcessorName); bwstats = new Stats[nSamp]; testLatency(); testSyncTime(); comm.Broadcast(ref latency, 0); if (self == 0) { System.Console.WriteLine("Latency: {0:F9}", latency); System.Console.WriteLine("Sync Time: {0:F9}", synctime); System.Console.WriteLine("Now starting main loop"); } int i, j, n, nq; int inc = 1, len; int start = 0, end = 1024 * 1024 * 1024; int bufflen = start; double tlast = latency; for (n = nq = 0, len = start; tlast < stopTime && len <= end; len += inc, nq++) { if (nq > 2 && (nq % 2 != 0)) inc *= 2; int ipert, pert; for (ipert = 0, pert = (inc > PERT + 1) ? -PERT : 0; pert <= PERT; ipert++, n++, pert += (inc > PERT + 1) ? PERT : PERT + 1) { int nRepeat = bufflen == 0 ? latencyReps : (int)Math.Max((RUNTM / ((double)bufflen / (bufflen - inc + 1.0) * tlast)), TRIALS); comm.Broadcast(ref nRepeat, 0); bufflen = len + pert; byte[] sendBuffer = new byte[bufflen]; // Align the data? Some day. Maybe. byte[] recvBuffer = new byte[bufflen]; if (self == 0) System.Console.Write("{0,3:D}: {1,9:D} bytes {2,7:D} times ---> ", n, bufflen, nRepeat); bwstats[n].t = 1e99; double t1 = 0, t2 = 0; for (i = 0; i < TRIALS; i++) { sync(); double t0 = when(); if (useDirectInterface) { // Use the unsafe, direct interface to MPI via P/Invoke unsafe { fixed (byte* sendPtr = sendBuffer, recvPtr = recvBuffer) { for (j = 0; j < nRepeat; j++) { if (self == 0) { Unsafe.MPI_Send(new IntPtr(sendPtr), bufflen, Unsafe.MPI_BYTE, other, 142, Unsafe.MPI_COMM_WORLD); Unsafe.MPI_Recv(new IntPtr(recvPtr), bufflen, Unsafe.MPI_BYTE, other, 242, Unsafe.MPI_COMM_WORLD, out *Unsafe.MPI_STATUS_IGNORE); } else { Unsafe.MPI_Recv(new IntPtr(recvPtr), bufflen, Unsafe.MPI_BYTE, other, 142, Unsafe.MPI_COMM_WORLD, out *Unsafe.MPI_STATUS_IGNORE); Unsafe.MPI_Send(new IntPtr(sendPtr), bufflen, Unsafe.MPI_BYTE, other, 242, Unsafe.MPI_COMM_WORLD); } } } } } else { for (j = 0; j < nRepeat; j++) { if (self == 0) { comm.Send(sendBuffer, other, 142); comm.Receive(other, 242, ref recvBuffer); } else { comm.Receive(other, 142, ref recvBuffer); comm.Send(sendBuffer, other, 242); } } } double t = (when() - t0) / (2.0 * nRepeat); t2 += t*t; t1 += t; bwstats[n].t = Math.Min(bwstats[n].t, t); bwstats[n].variance = t2 / TRIALS - t1 / TRIALS * t1 / TRIALS; tlast = bwstats[n].t; bwstats[n].bits = bufflen * sizeof(byte)*8; bwstats[n].bps = bwstats[n].bits / (bwstats[n].t * 1024 * 1024); bwstats[n].repeat = nRepeat; } if (self == 0) System.Console.WriteLine("{0,9:F2} Mbps in {1:F9} sec", bwstats[n].bps, tlast); } } } }
static void Main(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() + " "); Debug.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); Debug.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); Debug.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); Debug.Assert(containsBool == new ContainsBool(17)); } } }
static void Main(string[] args) { MPI.Environment mpi; mpi = new MPI.Environment(ref args); size = Communicator.world.Size - 1; // NUMBER OF WORKERS rank = Communicator.world.Rank; // Set the integrating function. f = NINTLIB.IntegratingFunctions.p33_f; // Set the number of dimensions getargs(args, ref dim_num, ref dim_partition_size, ref number_of_partitions); int num_jobs = (int)Math.Pow(dim_partition_size, dim_num); int num_local_jobs = num_jobs / size; if (rank == 0) // MANAGER (the manager only distribute jobs and collect results) { Console.WriteLine("dim_num = " + dim_num); Console.WriteLine("dim_partition_size = " + dim_partition_size); Console.WriteLine("number_of_partitions = " + number_of_partitions); Console.WriteLine("num_jobs = " + num_jobs); Console.WriteLine("num_local_jobs = " + num_local_jobs); DateTime startTime = DateTime.Now; // Set/Divide the interval double[][,] a = new double[size + 1][, ]; double[][,] b = new double[size + 1][, ]; a[0] = new double[0, 0]; b[0] = new double[0, 0]; for (int r = 1; r < size + 1; r++) { a[r] = new double[num_local_jobs, dim_num]; b[r] = new double[num_local_jobs, dim_num]; } int[] dims = new int[dim_num]; for (int job = 0; job < num_jobs; job++) { int r = job % size + 1; int j = job / size; for (int i = 0; i < dim_num; i++) { a[r][j, i] = dims[i] * (1.0D / dim_partition_size); b[r][j, i] = (dims[i] + 1) * (1.0D / dim_partition_size); } // NEXT JOB int ii = 0; while (ii < dim_num) { dims[ii] = (dims[ii] + 1) % dim_partition_size; if (dims[ii] == 0) { ii++; } else { break; } } } // Distribute jobs. Communicator.world.Scatter <double[, ]>(a); Communicator.world.Scatter <double[, ]>(b); // Collect/Combine results double result = 0.0D; double[] dummy_result = new double[num_local_jobs]; double[] local_result = Communicator.world.Reduce <double>(dummy_result, Operation <double> .Add, 0); foreach (double r in local_result) { result += r; } DateTime stopTime = DateTime.Now; TimeSpan time = stopTime - startTime; // Present result Console.WriteLine(" ROMBERG_ND: " + result + " in " + time.TotalMilliseconds + " milliseconds !"); } else // WORKER ! { // Receive jobs. double[,] a_local = Communicator.world.Scatter <double[, ]>(0); double[,] b_local = Communicator.world.Scatter <double[, ]>(0); // Perform work. sub_num = new int[dim_num]; for (int i = 0; i < dim_num; i++) { sub_num[i] = number_of_partitions / dim_partition_size; } result = new double[num_local_jobs]; double[] a; double[] b; System.Collections.Generic.IList <Thread> work_threads = new System.Collections.Generic.List <Thread>(); timeW = TimeSpan.FromSeconds(0); eval_num_total = 0; for (int j = 0; j < num_local_jobs; j++) { a = new double[dim_num]; b = new double[dim_num]; for (int i = 0; i < dim_num; i++) { a[i] = a_local[j, i]; b[i] = b_local[j, i]; } DoWork worker = new DoWork(j, a, b); worker.perform(); // Thread workThread = new Thread(worker.perform); // work_threads.Add(workThread); // workThread.Start(); } foreach (Thread wt in work_threads) { wt.Join(); } Communicator.world.Reduce <double>(result, Operation <double> .Add, 0); Console.WriteLine("ABSOLUTE WORKER TIME = " + timeW.TotalMilliseconds + "ms - eval_num = " + eval_num_total); } mpi.Dispose(); }