Re: [mpich-discuss] Problems with terminal-IO and mpiexec
Using stdin in MPI is a terrible idea. Please don't do that. There are some improvements in mpich-3.0.1 to stdin management. See if that helps. If it doesn't, we'll look into it, but the priority to solve this will be really really low. Don't use stdin. Bad idea. -- Pavan On 07/31/2012 09:26 AM US Central Time, Dr. Wilfried Jakob (IAI) wrote:
Hi,
I would appreciate if someone can help me with the following problem:
I want to have a communication on the root process (rank=0) in such a way that single characters are read from the terminal. This is achieved in plain C by using termios.h and the functions tcgetattr() and tcsetattr() as shown in the attached test program. With gcc and Debian Linux this works fine.
I translated the program with mpicc without any problems and started it directly from the command line: it works well. Then I started it with mpiexec -f nodes -n 2 tioTestMPI and received the following:
Waiting for input ... error with cbreak Waiting for input ... error with cbreak
A more detailed analysis shows that the call to "tcgetattr" yields the error "Invalid argument". This was obtained by a subsequent call to perror.
A version including prior calls to MPI_Init(&argc, &argv); MPI_Comm_rank(MPI_COMM_WORLD, &rank); MPI_Comm_size(MPI_COMM_WORLD, &size); is given by the second program. It yields the same results: Waiting for input ... error with cbreak lazy slave
Thanks in advance Wilfried Jakob
Here is the source code of the test program 1: ================================================= #include <stdio.h> #include <stdlib.h> #include <termios.h> #include <unistd.h>
static struct termios new_io; static struct termios old_io;
int cbreak(int fd) { /* save old terminal settings */ if((tcgetattr(fd, &old_io)) == -1) return -1; new_io = old_io; /* change terminal settings */ new_io.c_lflag = new_io.c_lflag & ~(ECHO|ICANON); new_io.c_cc[VMIN] = 1; new_io.c_cc[VTIME]= 0;
/* set new settings */ if((tcsetattr(fd, TCSAFLUSH, &new_io)) == -1) return -1; return 1; }
int getch(void) { int c;
if(cbreak(STDIN_FILENO) == -1) { printf(" error with cbreak \n"); exit(EXIT_FAILURE); } c = getchar(); /* restore old terminal settings */ tcsetattr(STDIN_FILENO, TCSANOW, &old_io); return c; }
int main (int argc, char** argv) { int ii;
printf ("Waiting for input ...\n"); ii = getch (); printf (" read: \"%c\" = %d\n", (char)ii, ii);
printf ("Waiting for input ...\n"); ii = getch (); printf (" read: \"%c\" = %d\n", (char)ii, ii);
printf ("\nfinished!\n"); return 0; } =================================================
Here is the source code of the test program 2: ================================================= #include <stdio.h> #include <stdlib.h> #include <termios.h> #include <unistd.h>
#include "mpi.h"
static struct termios new_io; static struct termios old_io;
int cbreak(int fd) { /* save old terminal settings */ if((tcgetattr(fd, &old_io)) == -1) return -1; new_io = old_io; /* change terminal settings */ new_io.c_lflag = new_io.c_lflag & ~(ECHO|ICANON); new_io.c_cc[VMIN] = 1; new_io.c_cc[VTIME]= 0;
/* set new settings */ if((tcsetattr(fd, TCSAFLUSH, &new_io)) == -1) return -1; return 1; }
int getch(void) { int c;
if(cbreak(STDIN_FILENO) == -1) { printf(" error with cbreak\n"); exit(EXIT_FAILURE); } c = getchar(); /* restore old terminal settings */ tcsetattr(STDIN_FILENO, TCSANOW, &old_io); return c; }
int main (int argc, char** argv) { int ii, rank, size;
MPI_Init(&argc, &argv); MPI_Comm_rank(MPI_COMM_WORLD, &rank); MPI_Comm_size(MPI_COMM_WORLD, &size);
if (rank == 0) { /* master */ printf ("Waiting for input ...\n"); ii = getch (); printf (" read: \"%c\" = %d\n", (char)ii, ii);
printf ("Waiting for input ...\n"); ii = getch (); printf (" read: \"%c\" = %d\n", (char)ii, ii);
printf ("\nfinished!\n"); } /* master */ else printf ("lazy slave\n");
MPI_Finalize(); return 0; } =================================================
_______________________________________________ mpich-discuss mailing list [email protected] To manage subscription options or unsubscribe: https://lists.mcs.anl.gov/mailman/listinfo/mpich-discuss
-- Pavan Balaji http://www.mcs.anl.gov/~balaji
participants (1)
-
Pavan Balaji