c++ - How to handle IO etc outide MPI portion -


writing sorting program mpi. best have code handles io outside mpi scope, e.g. reading in data file before sorting, writing out sorted data file after sorting.

so in main function did input before mpi_init , output after mpi_finalize. not seem work way wanted. because trying print out line of "*" before mpi_init , guess what, n_procs times instead of once. best way handle io in mpi code?

int main() {    read in data;    cout << "************************";    mpi_init();    mpi_comm_rank(mpi_comm_world, &my_rank);    mpi_comm_rank(mpi_comm_world, &nproc);    if(rank == 0)    {       mergesort_parallel; // recursively    }    else    {       mpi_recv subarray parent;       mergesort_parallel(subarray);       mpi_send subarray after sorting parent;       mpi_finalize();       return 0;    }    mpi_finalize();     output sorted data file; } 

the processes created mpiexec/mpirun , exist before mpi_init() called. therefore prints *** lines number of times equal process count. suggest go using standard i/o routines fopen(), fread() etc. inside code root process. i.e.

if(myrank == 0) {   read file buffer of root ; //master i/o. } else { other code ;  } mpi_finalize(); return 0;  } 

further, place mpi_finalize(), return 0 outside both if , else conditions. if want read portion of file individual buffers of process in parallel go mpi i/o i.e. use i/o functions provided mpi mpi_file_open(), mpi_file_set_view() etc.


Comments

Popular posts from this blog

PHPMotion implementation - URL based videos (Hosted on separate location) -

javascript - Using Windows Media Player as video fallback for video tag -

c# - Unity IoC Lifetime per HttpRequest for UserStore -