<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<meta http-equiv="content-type" content="text/html; charset=ISO-8859-15">
</head>
<body bgcolor="#ffffff" text="#000000">
Hi,<br>
as I did not receive any reply to my email from 31.7.2012 I post it
again and really hope that somebody can help me.<br>
<br>
I want to have a communication on the root process (rank=0) in such a
way that single characters are read from the terminal.<br>
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.<br>
<br>
I translated the program with mpicc without any problems and started it
directly from the command line: it worked well.<br>
Then I started it with<br>
<big><tt> mpiexec -f nodes -n 2 tioTestMPI <br>
</tt></big>and received the following:<br>
<br>
<big><tt>Waiting for input ...<br>
error with cbreak<br>
Waiting for input ...<br>
error with cbreak<br>
</tt></big><br>
A more detailed analysis shows that the call to "tcgetattr" yields the
error "Invalid argument". This was obtained by a subsequent call to
perror.<br>
<br>
A version including prior calls to <br>
<big><tt> MPI_Init(&argc, &argv);<br>
MPI_Comm_rank(MPI_COMM_WORLD, &rank);<br>
MPI_Comm_size(MPI_COMM_WORLD, &size);<br>
</tt></big>is given by the second program. It yields the same results:<br>
<big><tt>Waiting for input ...<br>
error with cbreak<br>
lazy slave<br>
</tt></big><br>
Thanks in advance<br>
Wilfried Jakob<br>
<br>
<br>
Here is the source code of the test program 1:<br>
=================================================<br>
#include <stdio.h><br>
#include <stdlib.h><br>
#include <termios.h><br>
#include <unistd.h><br>
<br>
static struct termios new_io;<br>
static struct termios old_io;<br>
<br>
int cbreak(int fd) {<br>
/* save old terminal settings */<br>
if((tcgetattr(fd, &old_io)) == -1)<br>
return -1;<br>
new_io = old_io;<br>
/* change terminal settings */<br>
new_io.c_lflag = new_io.c_lflag & ~(ECHO|ICANON);<br>
new_io.c_cc[VMIN] = 1;<br>
new_io.c_cc[VTIME]= 0;<br>
<br>
/* set new settings */<br>
if((tcsetattr(fd, TCSAFLUSH, &new_io)) == -1)<br>
return -1;<br>
return 1;<br>
}<br>
<br>
<br>
int getch(void) {<br>
int c;<br>
<br>
if(cbreak(STDIN_FILENO) == -1) {<br>
printf(" error with cbreak \n");<br>
exit(EXIT_FAILURE);<br>
}<br>
c = getchar();<br>
/* restore old terminal settings */<br>
tcsetattr(STDIN_FILENO, TCSANOW, &old_io);<br>
return c;<br>
}<br>
<br>
<br>
int main (int argc, char** argv)<br>
{<br>
int ii;<br>
<br>
printf ("Waiting for input ...\n");<br>
ii = getch ();<br>
printf (" read: \"%c\" = %d\n", (char)ii, ii);<br>
<br>
printf ("Waiting for input ...\n");<br>
ii = getch ();<br>
printf (" read: \"%c\" = %d\n", (char)ii, ii);<br>
<br>
printf ("\nfinished!\n");<br>
return 0;<br>
}<br>
=================================================<br>
<br>
Here is the source code of the test program 2:<br>
=================================================<br>
#include <stdio.h><br>
#include <stdlib.h><br>
#include <termios.h><br>
#include <unistd.h><br>
<br>
#include "mpi.h"<br>
<br>
static struct termios new_io;<br>
static struct termios old_io;<br>
<br>
<br>
int cbreak(int fd) {<br>
/* save old terminal settings */<br>
if((tcgetattr(fd, &old_io)) == -1)<br>
return -1;<br>
new_io = old_io;<br>
/* change terminal settings */<br>
new_io.c_lflag = new_io.c_lflag & ~(ECHO|ICANON);<br>
new_io.c_cc[VMIN] = 1;<br>
new_io.c_cc[VTIME]= 0;<br>
<br>
/* set new settings */<br>
if((tcsetattr(fd, TCSAFLUSH, &new_io)) == -1)<br>
return -1;<br>
return 1;<br>
}<br>
<br>
<br>
int getch(void) {<br>
int c;<br>
<br>
if(cbreak(STDIN_FILENO) == -1) {<br>
printf(" error with cbreak\n");<br>
exit(EXIT_FAILURE);<br>
}<br>
c = getchar();<br>
/* restore old terminal settings */<br>
tcsetattr(STDIN_FILENO, TCSANOW, &old_io);<br>
return c;<br>
}<br>
<br>
<br>
int main (int argc, char** argv)<br>
{<br>
int ii, rank, size;<br>
<br>
MPI_Init(&argc, &argv);<br>
MPI_Comm_rank(MPI_COMM_WORLD, &rank);<br>
MPI_Comm_size(MPI_COMM_WORLD, &size);<br>
<br>
if (rank == 0) { /* master */<br>
printf ("Waiting for input ...\n");<br>
ii = getch ();<br>
printf (" read: \"%c\" = %d\n", (char)ii, ii);<br>
<br>
printf ("Waiting for input ...\n");<br>
ii = getch ();<br>
printf (" read: \"%c\" = %d\n", (char)ii, ii);<br>
<br>
printf ("\nfinished!\n");<br>
} /* master */<br>
else<br>
printf ("lazy slave\n");<br>
<br>
MPI_Finalize();<br>
return 0;<br>
}<br>
=================================================<br>
<br>
</body>
</html>