navras
(NAVras)
August 23, 2024, 5:42am
1
Here is a minimal example:
#include <mpi.h>
#include <stdio.h>
int main(int argc, char *argv[])
{
MPI_Init(&argc, &argv);
int rank;
MPI_Comm_rank(MPI_COMM_WORLD, &rank);
if (rank == 1)
{
printf("rank %d\n", rank);
getchar();
}
MPI_Finalize();
return 0;
}
It does not terminate unless with “rank == 0” and “–stdin 0” below. It is stuck on getchar(). The issue can be reproduced on Live USB.
$ module load mpi
$ mpirun -V
mpirun (Open MPI) 5.0.2
$ mpicc -Wall -pedantic -o test test.c
$ mpirun -n 6 --stdin 1 ./test
rank 1
a
b
...
Is this a bug or am I doing something wrong?
EDIT: Nope does not happen on 4.1.6 (Ubuntu). I think it might either be the newer version or the package.
You have not changed the stdin mode.
It is in line mode, so getchar() will not return anything until you type return.
navras
(NAVras)
August 24, 2024, 3:32am
3
Hmm with --stream-buffering 0
it’s still the same.
p.s. I also tried typing just return.
navras
(NAVras)
August 24, 2024, 7:12am
4
Also happens on 5.0.5 on Arch. Guess this is upstream then…
That is not documented as a python option as far as I can see 1. Command line and environment — Python 3.12.5 documentation
You need to write code to put stdin into a mode that will work.
It is your code that is not using an API that does do what you want.
That is not a python issue.
navras
(NAVras)
August 24, 2024, 7:36am
6
Doh! My bad I have been switching between python and fedora forums.
The same issue is that C runtime STDIN FILE object is in line buffered mode and getchar() will not read on one key press.
You can use termios(3) - Linux manual page to set the germinsl into 1 char mode.
The MPI software changes the stdin mode? That is surprising.
1 Like
Once you have the terminal in one char mode then you can use read() on stdin FD to get 1 char. getchar() is not the right API to use.