【发布时间】:2013-04-06 05:57:21
【问题描述】:
我收到此运行时错误:
C:\Users\Richard\Dropbox\Year 3\DISPARP\Coursework>mpjrun -np 2 -dev niodev Ping
PongVariousLengths
MPJ Express (0.35) is started in the cluster configuration
Starting process <0> on <Tornado>
Starting process <1> on <Tornado>
Time for the ping to be sent and recived of 1 kb is 7 miliseconds
transferRate: 142.85714285714286KB per second
Speed of network in Mbps: 0
Time for the ping to be sent and recived of 2 kb is 0 miliseconds
transferRate: InfinityKB per second
java.lang.reflect.InvocationTargetException
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.
java:57)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAcces
sorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:601)
at runtime.daemon.Wrapper.execute(Wrapper.java:165)
at runtime.daemon.Wrapper.main(Wrapper.java:180)
Caused by: java.lang.ArithmeticException: / by zero
at PingPongVariousLengths.main(PingPongVariousLengths.java:32)
... 6 more
我认为是什么原因造成的,代码试图除以 0
Time for the ping to be sent and recived of 2 kb is 0 miliseconds
transferRate: InfinityKB per second
导致错误,我该如何解决这个错误,它仍然除以0但返回0而不是
如果您需要代码,请说:)
感谢您的帮助
编辑
代码:
if (myrank == 0) {
for (int len = minlen; len <= maxlen; len *= 2) { //len=*2 doubles the ping size each time
long startTime = System.currentTimeMillis();
MPI.COMM_WORLD.Send(sendbuff, 0, len, MPI.CHAR, 1, tag);
MPI.COMM_WORLD.Recv(recvbuff, 0, len, MPI.CHAR, 1, tag);
long endTime = System.currentTimeMillis();
long duration = endTime - startTime;
System.out.println("Time for the ping to be sent and recived of " + len + " kb is " + duration + " miliseconds");
double transferRate = (len * 1000.0)/ duration ; //amount of data in kilobytes transferred in 1 second
System.out.println("transferRate: " + transferRate + "KB per second");
speedKbps = (len / duration);
speedMbps = (speedKbps / 1024);
System.out.println("Speed of network in Mbps: " + speedMbps);
}
} else if (myrank == 1) {
for (int len = minlen; len <= maxlen; len *= 2) {
MPI.COMM_WORLD.Recv(recvbuff, 0, len, MPI.CHAR, 0, tag);
MPI.COMM_WORLD.Send(recvbuff, 0, len, MPI.CHAR, 0, tag);
}
}
【问题讨论】:
-
我想说你有两个选择:1)鉴于持续时间可以为零,在使用它来划分之前检查它。 2) 使用 'system.nanoTime()' 而不是 'currentTimeMillis()' 并相应地调整代码。