[mpich-discuss] Problems with terminal-IO and mpiexec

Dr. Wilfried Jakob (IAI) wilfried.jakob at kit.edu
Fri Aug 31 02:57:56 CDT 2012


Thanks a loot for the first reaction on my question.

I do not perform any terminal input on slaves. Terminal input is 
restricted to the root process without any exception. The basic idea is 
to use two threads for the root-process: one for user-I/O and one for 
handling the slaves.
I hoped that this is possible ... ?

Cheers
Wilfried


Am 31.08.2012 09:23, schrieb Titianingrum -:
> mpi program run hiden on slave side, so how to input there?
> that's I know that mpi program not run well while need input.
>
>
> On Mon, Aug 27, 2012 at 3:07 PM, Dr. Wilfried Jakob (IAI) 
> <wilfried.jakob at kit.edu <mailto:wilfried.jakob at kit.edu>> wrote:
>
>     Hi,
>     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.
>
>     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 worked 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 mpich-discuss at mcs.anl.gov
>     <mailto:mpich-discuss at mcs.anl.gov>
>     To manage subscription options or unsubscribe:
>     https://lists.mcs.anl.gov/mailman/listinfo/mpich-discuss
>
>
>
>
> -- 
> titia
>
>
> _______________________________________________
> mpich-discuss mailing list     mpich-discuss at mcs.anl.gov
> To manage subscription options or unsubscribe:
> https://lists.mcs.anl.gov/mailman/listinfo/mpich-discuss
>    
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.mcs.anl.gov/pipermail/mpich-discuss/attachments/20120831/f12fe66b/attachment.html>


More information about the mpich-discuss mailing list