Note that there are some explanatory texts on larger screens.

plurals
  1. POHow to loop a piece of code x times and take the average
    text
    copied!<p>i am looking to loop the main section of the code below, and then calculates the average of the results collected from the loop</p> <p>here is the code :</p> <pre><code>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 &lt;= 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 &lt;= 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(); } } </code></pre> <p>i am trying to loop it say 10 or 20 times,the code from </p> <pre><code> for (int len = minlen; len &lt;= maxlen; len *= 2) { //len=*2 doubles the ping size each time </code></pre> <p>to </p> <pre><code> long durationseconds = (duration * 10-9); // Converts nanoseconds to seconds </code></pre> <p>i want to run 20 times and then the results for <code>duration</code> to be average over the 10 or 20 </p> <p>how can i best and most efficiently go about this </p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload