how can i transfer file from one proccess to all o

2019-06-01 00:32发布

问题:

I have a text file that is available on one computer only and I need the other computers to be able to read that file too. How can I send a file using mpich2 (c++)?

I tried using MPI_File_open() but it seems that all the computers need that file locally to work.

回答1:

OK, this is the secret ninja answer to your question. haraldkl's answer is the most straightforward, but there's another way: ROMIO (the MPI-IO implementation in MPICH2) has a little-documented feature called deferred open: if you tell ROMIO that you will do no independent I/O, and you only make collective calls, then only the "i/o aggregator" will open the file, and the two-phase collective i/o optimization will send that data to all processors.

MPI_Info_set(info, "romio_no_indep_rw" "true"); MPI_File_open(comm, filename, mode, info, &fh); MPI_File_read_all(fh, buf, count, MPI_CHAR, &status);

Read-and-broadcast is probably the way to go, as every process is reading the same data. Just thought I'd mention this if you find yourself in another situation where not every process has access to the file.

I have a more detailed writeup on the ROMIO blog: http://press3.mcs.anl.gov/romio/2003/08/05/deferred-open/



回答2:

so i end up read the file a broadcast it to the rest of the of the proccesses as a char array.
thanks @haraldkl



标签: c++ mpi