我期待環路下面的代碼的主要部分,然後計算從環一段代碼x次,以及如何循環取平均值
這裏收集的結果的平均值是代碼:
class PingPongVariousLengths {
static public void main(String[] args) {
MPI.Init(args);
int myrank = MPI.COMM_WORLD.Rank();
int tag = 99;
int maxlen = 104857600; //200 megabytes 104857600 characters * 2 bytes per character = 209715200 bytes total, or 200 megabytes
int minlen = 1; // 2 bytes
char [] sendbuff = new char [maxlen];
char [] recvbuff = new char [maxlen];
long speedKbps;
long speedMbps;
if (myrank == 0) {
for (int len = minlen; len <= maxlen; len *= 2) { //len=*2 doubles the ping size each time
long startTime = System.nanoTime();
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.nanoTime();
long duration = endTime - startTime;
long durationseconds = (duration * 10-9); // Converts nanoseconds to seconds
System.out.println("Time for the ping to be sent and recived of " + (len*2) + " bytes is " + durationseconds + " seconds"); // multiples by 2 becuase 1 character is 2 bytes
//double transferRate = ((len*2.0)/durationseconds) ; //amount of data in bytes transferred in 1 second. Currently returning 0 for every result
//System.out.println("transferRate: " + transferRate + " bytes per second");
double transferRateMb = ((len*524288.0)/durationseconds) ; //amount of data in megabytes transferred in 1 second.
System.out.println("transferRate (megabytes) : " + transferRateMb + " megabytes per second");
}
} 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);
}
}
MPI.Finalize();
}
}
我試圖循環它說10或20倍,將代碼從
for (int len = minlen; len <= maxlen; len *= 2) { //len=*2 doubles the ping size each time
到
long durationseconds = (duration * 10-9); // Converts nanoseconds to seconds
我要運行20次,然後將結果duration
是平均超過10或20
我怎樣才能最好的和最有效地去了解這個
不知道,如果你實際上是在問這個...在一般平均可以通過添加所有時長來計算,然後通過循環次數劃分的?... 1/N *總和(持續時間) – gausss
「和然後計算平均值「你在說什麼? –
上面編輯,希望它更有意義,對第一個令人困惑的問題抱歉 – user2065929