/// <summary> /// Initialize the MPI environment, execute action with the world communicator, and finalize the MPI environment. /// If any exception is thrown by action, all processes will be terminated. /// This is preferable to creating an Environment in a "using" block, since that may hang if an exception is thrown. /// </summary> /// <param name="args"> /// Arguments passed to the <c>Main</c> function in your program. MPI /// may use some of these arguments for its initialization, and will remove /// them from this argument before returning. /// </param> /// <param name="threading"> /// The level of threading support requested of the MPI implementation. The /// implementation will attempt to provide this level of threading support. /// However, the actual level of threading support provided will be published /// via the <see cref="MPI.Environment.Threading"/> property. /// </param> /// <param name="action">Receives the world communicator and performs MPI actions.</param> /// <param name="cleanupEnvironment">If true, the MPi environment will be disposed of on completion /// and any thrown exceptions will result in Abort being called</param> public static void Run(ref string[] args, Threading threading, Action <Intracommunicator> action, bool cleanupEnvironment = true) { var env = new Environment(ref args); if (cleanupEnvironment) { try { action(Communicator.world); env.Dispose(); } catch (Exception exception) { try { Console.Error.WriteLine(exception); } catch { // exception.ToString() can sometimes throw an exception. Console.Error.WriteLine($"{exception.GetType().Name}: {exception.Message}"); } Abort(1); } } else { action(Communicator.world); } }
static void Main(string[] args) { MPI.Environment mpi = new MPI.Environment(ref args); MPI.Intracommunicator worldComm = Communicator.world; Console.WriteLine("OK\n"); 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 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(); }
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(); }
override public void destroySlice() { Console.Write("Finalizing MPI ..."); mpi.Dispose(); Console.WriteLine(" finished"); }
public void close_enviroment() { worldcomm.Barrier(); mpi.Dispose(); }
protected override void OnStop() { mpi.Dispose(); this.stopWorkerServer(); }
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(); }