开发java版本的并行程序
基于MPJ Express的入门程序Hello World
前期准备工作(包括相关工具或所使用的原料等)MPJ Expresseclipse 详细的操作方法或具体步骤
关于MPJ Express开发环境的极速搭建
请参考百度经验
《Windows下极速搭建java并行开发环境MPJ Express》

【创建并行工程】




【创建类,编写并行程序】
import java.net.InetAddress;
import mpi.*;
public class mpjHelloWorld {
public static void main(String[] args) throws Exception{
String [] tmps=MPI.Init(args);
int me=MPI.COMM_WORLD.Rank();
int size=MPI.COMM_WORLD.Size();
InetAddress strIP=InetAddress.getLocalHost();
System.out.println("线程号:" + me + ", ip: "+strIP);
if ( me==0 ){
System.out.println("参数个数:" + tmps.length);
for (int i=0;i System.out.println("args["+ i+ "]=" + tmps[i]); } MPI.Finalize(); } } 从第3步可看到,eclipse显示了一些错误 解决方法: 加入mpj.jar mpj.jar在mpj express的安装目录下的lib目录下 可以看到加入mpj.jar后 没有错误了 不过还需要设置: 在【run configuration/VM arguments】中加入如下 -jar ${MPJ_HOME}/lib/starter.jar -np 4 在VM中随便加些参数,如下图 在【Preferences/string substitution】加入一个变量【MPJ_HOME】 值是安装路径【F:\dy2003310\mpj\mpj-v0_43】 如下图: 测试运行,结果: MPJ Express (0.43) is started in the multicore configuration 线程号:1, ip: HydroLAB-PC41/192.168.1.13 线程号:0, ip: HydroLAB-PC41/192.168.1.13 参数个数:3 args[0]=111 args[1]=222 args[2]=333 线程号:3, ip: HydroLAB-PC41/192.168.1.13 线程号:2, ip: HydroLAB-PC41/192.168.1.13 









- 评论列表(网友评论仅供网友表达个人看法,并不表明本站同意其观点或证实其描述)
-
