The processes are created by mpiexec/mpirun and exist before MPI_Init()
is called. Therefore it prints the *** lines the number of times equal to the process count. I suggest go for using standard I/O routines like fopen(), fread()
etc. inside the code for the root process. i.e.
If(myrank == 0)
{
read file into buffer of root ; //Master I/O.
}
else
{
other code ;
}
MPI_Finalize();
return 0;
}
Further, place MPI_Finalize()
, return 0
outside both If
and else
conditions. If you want to read a portion of the file into individual buffers of a process in parallel then go for MPI I/O i.e. use I/O functions provided by MPI like MPI_File_open(), MPI_File_set_view()
etc.