<div dir="ltr"><div class="">

        <p>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</p>

<pre style class=""><code><span class="">#include</span><span class=""> </span><span class=""><stdlib.h></span><span class="">
</span><span class="">#include</span><span class=""> </span><span class=""><stdio.h></span><span class="">
</span><span class="">#include</span><span class=""> </span><span class="">"mpi.h"</span><span class="">
</span><span class="">#include</span><span class=""><string.h></span><span class="">

</span><span class="">int</span><span class=""> main</span><span class="">(</span><span class="">int</span><span class=""> argc</span><span class="">,</span><span class=""> </span><span class="">char</span><span class="">*</span><span class=""> argv</span><span class="">[])</span><span class=""> 
</span><span class="">{</span><span class="">
</span><span class="">int</span><span class=""> i</span><span class="">,</span><span class=""> size</span><span class="">,</span><span class=""> rank</span><span class="">;</span><span class="">
</span><span class="">int</span><span class=""> arr</span><span class="">;</span><span class="">
MPI_Init</span><span class="">(&</span><span class="">argc</span><span class="">,</span><span class=""> </span><span class="">&</span><span class="">argv</span><span class="">);</span><span class="">
MPI_Comm_size</span><span class="">(</span><span class="">MPI_COMM_WORLD</span><span class="">,</span><span class=""> </span><span class="">&</span><span class="">size</span><span class="">);</span><span class="">
MPI_Comm_rank</span><span class="">(</span><span class="">MPI_COMM_WORLD</span><span class="">,</span><span class=""> </span><span class="">&</span><span class="">rank</span><span class="">);</span><span class="">
printf</span><span class="">(</span><span class="">"Enter the number\n"</span><span class="">);</span><span class="">
scanf</span><span class="">(</span><span class="">"%d"</span><span class="">,&</span><span class="">i</span><span class="">);</span><span class="">

printf</span><span class="">(</span><span class="">"%d\n"</span><span class="">,</span><span class="">i</span><span class="">);</span><span class="">
MPI_Finalize</span><span class="">();</span><span class="">
exit</span><span class="">(</span><span class="">0</span><span class="">);</span><span class="">
</span><span class="">}</span></code></pre>

    </div><br clear="all"><br>-- <br><br>Regards,<br>-- Mahesh Doijade<br><br><br><br>
                                                                           <br>
</div>