我写了一些代码,将消息发送到一台机器,然后回复,我想知道我如何计时,将消息发送到另一台计算机然后返回所需的时间?
这是我到目前为止的代码:
import mpi.* ;
class Hello {
static public void main(String[] args) {
MPI.Init(args) ;
int myrank = MPI.COMM_WORLD.Rank();
if(myrank == 0) {
char[] mess = " Raptor" .toCharArray();
MPI.COMM_WORLD.Send(mess, 0, mess.length, MPI.CHAR, 1, 99);
} else {
char[] mess = new char [20];
MPI.COMM_WORLD.Recv(mess, 0, 20, MPI.CHAR, 0, 99);
System.out.println("received:"+new String(mess)+":");
}
MPI.Finalize();
}
}
对不起,如果这是一个简单的问题,第一次使用 mpi !
编辑:
现在的代码是:
import mpi.* ;
class Hello {
static public void main(String[] args) {
MPI.Init(args) ;
int myrank = MPI.COMM_WORLD.Rank();
if(myrank == 0) {
long startTime = System.nanoTime();
char[] mess = " Hello, there" .toCharArray();
MPI.COMM_WORLD.Send(mess, 0, mess.length, MPI.CHAR, 1, 99);
} else {
char[] mess = new char [20];
MPI.COMM_WORLD.Recv(mess, 0, 20, MPI.CHAR, 0, 99);
System.out.println("received:"+new String(mess)+":");
long endTime = System.nanoTime();
}
long duration = endTime - startTime;
system.out.println(duration);
MPI.Finalize();
}
}
但我现在在编译时遇到这些错误:
javac 你好.java
Hello.java:19: error: cannot find symbol
long duration = endTime - startTime;
^
symbol: variable endTime
location: class Hello
Hello.java:19: error: cannot find symbol
long duration = endTime - startTime;
^
symbol: variable startTime
location: class Hello
Hello.java:20: error: package system does not exist
system.out.println(duration);
^
3 errors