1

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!

Mat
  • 202,337
  • 40
  • 393
  • 406

1 Answers1

0

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.
Artem Oboturov
  • 4,344
  • 2
  • 30
  • 48
  • I can't distribute anything, because when I enter something in the console, there is no reaction at all! I added ad syso right after the br.readline, but it was never called. – user1447713 Jun 12 '12 at 12:40
  • so it's not an mpj problem at all. Are you sure you had attached to correct process to debug? – Artem Oboturov Jun 12 '12 at 13:43