How to send a 1kb size message java
<p>how can i send a 1kb message in java, i am trying to send a message from one machine to another, of a fixed size 1kb, how can this be achieved ?</p>

<p>currently i am able to send messages such as "test" between the machines, but ideally i want to be able to send a fixed size message of 1kb</p>

<p>this is how i am currently sending test</p>

<pre><code>   if (myrank == 0) {
    char[] mess = " test ".toCharArray();
    MPI.COMM_WORLD.Send(mess, 0, mess.length, MPI.CHAR, 1, 99);
} 
</code></pre>

<p>Currently this is how am i sending messages between machines :</p>

<pre><code>import mpi.* ;

class Hello {

  static public void main(String[] args) {
    MPI.Init(args);
int myrank = MPI.COMM_WORLD.Rank();
long startTime = System.currentTimeMillis();
if (myrank == 0) {
    char[] mess = " test ".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.currentTimeMillis();
long duration = endTime - startTime;
System.out.println(duration);
    MPI.Finalize();
  }
}   
</code></pre>

<p>would a byte array be a good solution ?</p>

<p>need fixed size messages, to help benchmark results for example i am looking to compare the increase in time taken to send a 1kb message, 1mb, 20mb ........ 1gb etc</p>

<p>EDIT :</p>

<p>would this work ? would this send 8 bits ?</p>

<pre><code>int i = 10;  

String text = String.format("%08d", i);  
// text now contains "00000010"  
// 8 bits
</code></pre>
