I'm attempting to use a java implenetation of MPI called MPJ-Express and ran into a bug where I am unable to read console input on a node from which I ran my application. To demonstrate the problem, I made the following simple program.
public class TestConsole {
/**
* @param args
*/
public static void main(String[] args) {
BufferedReader bufferRead = new BufferedReader(new InputStreamReader(System.in));
String aLine = "";
if (MPI.COMM_WORLD.Rank() == 0)
{
while(!aLine.equals("exit"))
{
System.out.println("please enter data: ");
try {
aLine = bufferRead.readLine();
System.out.println(aLine);
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
}
}
}
If I run that application with mpjrun I am presented with the prompt "please enter data:" and no matter what I type, I am unable to get any content echod back. When I run the application using plain old java -jar blah, the application works fine (after stripping the mpi stuff of course).
I am using 3 virtual machines that are running ubuntu. From what I've read, MPJ should accept console input on the rank 0 node, so I'm not sure what I'm doing wrong.
There was very similar question just yesterday: https://stackoverflow.com/a/26640877/491687
You shouldn't rely on using stdin
in MPI programs. The mechanisms needed to forward the input around are somewhat unreliable and very tricky. The usual way to get input in an MPI program is to read it from a file. That's much more reliable since files can easily be made available at all processes.