C#MPI 第三课 MPI 发送图像数据

来源:互联网 发布:mp3铃声制作软件 编辑:程序博客网 时间:2024/04/28 21:47
using System;using Emgu.CV;using Emgu.CV.Structure;using MPI;namespace MPIHello{    /// <summary>    /// 测试发送图像数据    /// </summary>    class TestSendImageProgram : IProgram    {        #region Implementation of IProgram        /// <summary>        /// 应用程序入口点        /// </summary>        /// <param name="args">入口参数</param>        public void Entrance(string[] args)        {            //初始化MPI运行环境            using (new MPI.Environment(ref args))            {                //获取Communicator                var comm = Communicator.world;                if (0 == comm.Rank)                {                    var obj = new YFrame                                  {                                      Image = new Image<Bgr, byte>("1.jpg")                                  };                    //令0进程发送数据然后接收数据                    comm.Send(obj, 1, 0);                    // receive the final message                     var msg = comm.Receive<YFrame>(Communicator.anySource, 0);                                        //输出收到的信息                    Console.WriteLine("Rank " + comm.Rank + " received message \"" + msg + "\".");                }                else                {                    //令n程序接收上一进程发送的数据然后发给下一进程                    var msg = comm.Receive<YFrame>(comm.Rank - 1, 0);                    if (msg.Image != null) msg.Image.Save("recv"+comm.Rank + ".jpg");                    //增加                    //输入收到的消息                    Console.WriteLine("Rank " + comm.Rank + " received message \"" + msg + "\".");                    //发送给下一个进程                    comm.Send(msg, (comm.Rank + 1) % comm.Size, 0);                }                Console.WriteLine(Communicator.world.Rank);            }        }        #endregion    }}

原创粉丝点击