阿里云搭建基于MatlabMPI的集群(九):一个基本的MatlabMPI程序
来源:互联网 发布:js 数组 split 编辑:程序博客网 时间:2024/06/04 18:52
一个最基本的MatlabMPI程序应当有以下结构:
% 初始化MPIMPI_Init;% 创建通信域comm = MPI_COMM_WORLD;%获取线程个数和自己的线程号comm_size = MPI_Comm_size(comm);my_rank = MPI_Comm_rank(comm);%线程号是从0开始的整数rank1=0;rank2=1;%定义消息传递标志tag=1;%线程1运行部分代码if(my_rank==rank1) 定义要发送的消息 SendMsg=1:10; 向rank2发送消息 MPI_Send(rank2,tag,com,SendMsg);end%rank2运行部分代码if(my_rank==rank2) 接收rank1发来的消息 RevMsg=MPI_Rev(rank1,tag,com);end% 结束MatlabMPIMPI_Finalize;
再附一个官网的基本MatlabMPI程序
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% Basic Matlab MPI script that% sends a matrix to another processor.%% To run, start Matlab and type:%% eval( MPI_Run('basic',2,{}) );%% Or, to run a different machine type:%% eval( MPI_Run('basic',2,{'machine1' 'machine2'}) );%% Output will be piped into two files:%% MatMPI/basic.0.out% MatMPI/basic.1.out%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% MatlabMPI% Dr. Jeremy Kepner% MIT Lincoln Laboratory% kepner@ll.mit.edu%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% Initialize MPI.MPI_Init;% Create communicator.comm = MPI_COMM_WORLD;% Modify common directory from default for better performance.% comm = MatMPI_Comm_dir(comm,'/tmp');% Uncomment if you want to save the messages that were sent.% comm = MatMPI_Save_messages(comm,1);% Get size and rank.comm_size = MPI_Comm_size(comm);my_rank = MPI_Comm_rank(comm);% Print rank.disp(['my_rank: ',num2str(my_rank)]);% Set who is source and who is destination.source = 1;dest = 0;% Create a unique tag id for this message (very important in Matlab MPI!).tag = 1;% Check to make sure that we have exactly two processors.if(comm_size == 2) % Source. if (my_rank == source) % Create data. data = 1:10; % Send it. MPI_Send( dest, tag, comm, data, data ); end % Destination. if (my_rank == dest) % Receive data. [data data1] = MPI_Recv( source, tag, comm ); % Check data. if(any((data - (1:10)) ~= 0)) disp('ERROR: incorrect data sent.'); exit; end endend% Finalize Matlab MPI.MPI_Finalize;disp('SUCCESS');if (my_rank ~= MatMPI_Host_rank(comm)) exit;end%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% Copyright 2002 Massachusetts Institute of Technology% % Permission is herby granted, without payment, to copy, modify, display% and distribute this software and its documentation, if any, for any% purpose, provided that the above copyright notices and the following% three paragraphs appear in all copies of this software. Use of this% software constitutes acceptance of these terms and conditions.%% IN NO EVENT SHALL MIT BE LIABLE TO ANY PARTY FOR DIRECT, INDIRECT,% SPECIAL, INCIDENTAL, OR CONSEQUENTIAL DAMAGES ARISING OUT OF THE USE OF% THIS SOFTWARE AND ITS DOCUMENTATION, EVEN IF MIT HAS BEEN ADVISED OF THE% POSSIBILITY OF SUCH DAMAGE.% % MIT SPECIFICALLY DISCLAIMS ANY EXPRESS OR IMPLIED WARRANTIES INCLUDING,% BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY, FITNESS% FOR A PARTICULAR PURPOSE, AND NON-INFRINGEMENT.%% THIS SOFTWARE IS PROVIDED "AS IS," MIT HAS NO OBLIGATION TO PROVIDE% MAINTENANCE, SUPPORT, UPDATE, ENHANCEMENTS, OR MODIFICATIONS.
阅读全文
0 0
- 阿里云搭建基于MatlabMPI的集群(九):一个基本的MatlabMPI程序
- 阿里云搭建基于MatlabMPI的集群(七):MatlabMPI安装
- 阿里云搭建基于MatlabMPI的集群(一):阿里云连接基本操作
- 阿里云搭建基于MatlabMPI的集群(四):阿里云实例之间内网互通
- 阿里云搭建基于MatlabMPI的集群(二):Ubuntu16.04基于VNC的图形界面安装
- 阿里云搭建基于MatlabMPI的集群(三):Ubuntu16.04安装MATLAB2014a
- 阿里云搭建基于MatlabMPI的集群(五):ssh免密码访问
- 阿里云搭建基于MatlabMPI的集群(六):NFS文件共享系统安装与配置
- 阿里云搭建基于MatlabMPI的集群(八):NFS性能调优
- 搭建一个简单的git服务器(基于阿里云)
- 阿里云搭建集群的过程记录(一)
- 基于阿里云的WordPress博客搭建
- 手把手做一个JSP入门程序(九):购物车的基本实现(Servlet)
- 阿里云搭建集群环境
- 阿里云搭建Hadoop集群
- HzhJava框架搭建三:一个基于配置的spring程序
- HzhJava框架搭建四:一个基于注解的spring程序
- 阿里云搭建基于PPTP的VPN(Windows Server 2008)
- NodeJs框架
- 11 个重要的数据库设计规则
- 七大 阻塞队列
- Android DEX安全攻防战
- 蓝桥杯java第五届决赛第二题--六角幻方
- 阿里云搭建基于MatlabMPI的集群(九):一个基本的MatlabMPI程序
- Mybatis框架通用Dao中getSqlSession().selectOne()的应用
- C#调用Python脚本并使用Python的第三方模块
- 21.七-测试两个整数相加
- 有依赖的背包问题——金明的预算方案
- 在CentOS7.0上安装Chrome浏览器
- hbase性能调优
- Android--下载zip压缩文件并解压
- 机器学习笔记4-朴素贝叶斯