I wrote a solution code for the following simple task via MPI. Here it's statement:
- In processes of even rank (including the main one) enter an integer number.
- In processes of odd rank enter an integer, in processes of odd rank enter a real number.
- In each process, output the double value of the entered number.
I've compiled my program via (MPI-setted VS 2022) and ran via mpiexec -n 4 MPI_3 cmd command, it gave me the following output:
Enter an integer number:
Enter a float number:
Enter an integer number:
Enter a float number:
My programm doesn't wait for input and proceeds execution 4 times. I've already tried replacing couts and cins with printfs and scanfs, but this isn't helping.
I'm barely new to MPI and C++ at all, so I need you help in fixing my code very much.
P.S. Also sometimes when I'm trying to run my code via command line, it gives me no output at all. Only a blinking cursor that waiting for input without any response.
Reading the standard input stream by multiple MPI processes does not make much sense. For example, OpenMPI says:
So with OpenMPI, your non-root processes are trying to read the number from
/dev/null, which doesn't work.I cannot find anything about this problem in the MPI Stadnard; however, it seems that it does not define how a program should behave regarding reading from the standard input.
Here is some relevant discussion on MPI-Forum: MPI I/O interface for stdout/stderr/stdin.
In my experience, stdin usually works as in OpenMPI, that is, on the root process. The best you can do is thus using stdin by the root process only and send data to other processes then.