我对 MPJ 完全陌生,它是一个用于在 Java 中开发基于 MPI 的程序的 API。我写了一个简单的代码如下:
import mpi.MPI;
import mpi.Status;
public class Send {
public static void main(String[] args) throws Exception
{
MPI.Init(args);
int rank = MPI.COMM_WORLD.Rank();
int size = MPI.COMM_WORLD.Size();
int peer;
int buffer[] = new int[10];
int len = 1;
int dataToBeSent = 99;
int tag = 100;
if(rank == 0)
{
buffer[0] = dataToBeSent;
peer = 1;
MPI.COMM_WORLD.Send(buffer, 0, len, MPI.INT, peer, tag);
System.out.println("process <"+rank+"> sent a msg to process <"+peer+">");
}
else if(rank == 1)
{
peer = 0 ;
Status status = MPI.COMM_WORLD.Recv(buffer, 0, buffer.length, MPI.INT, peer, tag);
System.out.println("process <"+rank+"> recv'ed a msg\n"+ "\tdata <"+buffer[0]+"> \n"+"\tsource <"+status.source+"> \n"+"\ttag<"+status.tag+"> \n"+"\tcount <"+status.count +">");
}
MPI.Finalize();
}
}
当我编译时,我收到以下错误:
Exception in thread "main" java.lang.UnsupportedClassVersionError: mpi/MPI : Unsupported major.minor version 51.0
at java.lang.ClassLoader.defineClass1(Native Method)
at java.lang.ClassLoader.defineClass(ClassLoader.java:620)
at java.security.SecureClassLoader.defineClass(SecureClassLoader.java:124)
at java.net.URLClassLoader.defineClass(URLClassLoader.java:260)
at java.net.URLClassLoader.access$000(URLClassLoader.java:56)
at java.net.URLClassLoader$1.run(URLClassLoader.java:195)
at java.security.AccessController.doPrivileged(Native Method)
at java.net.URLClassLoader.findClass(URLClassLoader.java:188)
at java.lang.ClassLoader.loadClass(ClassLoader.java:306)
at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:276)
at java.lang.ClassLoader.loadClass(ClassLoader.java:251)
at java.lang.ClassLoader.loadClassInternal(ClassLoader.java:319)
at Send.main(Send.java:7)
Java Result: 1
为了解决这个问题,我知道我的 JDK 和 JRE 版本必须相同。执行以下命令后,我发现它们是相同的,没有不同:
C:\Users\Dev>javac -version
javac 1.6.0
C:\Users\Dev>java -version
java version "1.6.0"
Java(TM) SE Runtime Environment (build 1.6.0-b105)
Java HotSpot(TM) Client VM (build 1.6.0-b105, mixed mode, sharing)
在 Ubuntu Java 8 中,我得到以下异常:
Exception in thread "main" mpi.MPIException: Usage: java MPI <myrank> <conf_file> <device_name> conf_file can be, ../conf/xdev.conf <Local>OR http://holly.dsg.port.ac.uk:15000/xdev.conf <Remote>
at mpi.MPI.Init(MPI.java:233)
at mpi.MPI.Init(MPI.java:233) at mpi.MPI.Init(MPI.java:233)
at Send.main(Send.java:7)
Java Result: 1
如何解决此问题并让 MPI 在我的 Java 系统上运行?