[mpich-discuss] In MPI for multiple process scanf taking input only once

Pavan Balaji balaji at mcs.anl.gov
Sun Sep 15 09:00:19 CDT 2013


stdin is only forwarded to rank 0.  In any case, reading from stdin is a bad idea with a capital VERY, and is not supported by the standard.  We only support that for legacy applications.

 -- Pavan

On Sep 15, 2013, at 4:48 AM, Mahesh Doijade wrote:

> I am trying to write MPI code with scanf which will take input for all process individually, but only one process taking the input from user and others assign garbage value to that variable. The program is as below
> 
> #include <stdlib.h>
> #include <stdio.h>
> #include "mpi.h"
> #include<string.h>
> 
> 
> 
> int main(int argc, char* argv[])
>  
> 
> {
> int i, size, rank;
> int arr;
> 
> MPI_Init
> (&argc, &argv);
> 
> MPI_Comm_size
> (MPI_COMM_WORLD, &size);
> 
> MPI_Comm_rank
> (MPI_COMM_WORLD, &rank);
> 
> printf
> ("Enter the number\n");
> 
> scanf
> ("%d",&i);
> 
> 
> printf
> ("%d\n",i);
> 
> MPI_Finalize
> ();
> 
> exit
> (0);
> }
> 
> 
> -- 
> 
> Regards,
> -- Mahesh Doijade
> 
> 
> 
>                                                                            
> _______________________________________________
> discuss mailing list     discuss at mpich.org
> To manage subscription options or unsubscribe:
> https://lists.mpich.org/mailman/listinfo/discuss

--
Pavan Balaji
http://www.mcs.anl.gov/~balaji




More information about the discuss mailing list