javampj-express

Reading console input with mpj-express


I have to do an exercise for a parallel computing course. I used MPJ Express to distribute tasks to several processes (in my case 5 processes). I solved all the sub tasks, which are working fine. Now I want to implement a simple user dialog so that my professor can choose which subtask he wants to run, like "please enter '1' if you want to run assignment 1. I used following code to read input from the console:

 InputStreamReader isr = new InputStreamReader(System.in);
                BufferedReader br = new BufferedReader(isr);
                System.out.println("Enter a number between 1 and 4");
                String s = br.readLine();

Since I have to run the application using a .bat file which runs my application with 5 instances (for each process one instance), the console input can't be "mapped" to a specific process. So my application just keeps hanging when waiting for user input.

Does anyone has a solution how I could overcome this problem? Many thanks in advance!


Solution

  • Why don't you implement some kind of protocol over the Scatter operation to distribute your user's input: for example treat received message from parent process as a pair : (command code, command data). Handle at least two command codes in your child processes:

    1. for handling user input : check if current process ID is the same as requested execution by user - and if it is - execute operation;
    2. for receiving data distributed at start of your application.