Newsgroups: comp.parallel.mpi
From: atl@mathematik.uni-ulm.de (Andreas Leibl)
Subject: Re: Problems reading a file from each MPI process
Organization: University of Ulm, SAI, Germany
Date: 28 Sep 1995 08:29:08 GMT
Message-ID: <44dmck$ema@waage.rz.uni-ulm.de>

Hello Ben.

Ben Keeping (umeca60) wrote:
: First of all, is this really the best way to solve the problem? For example,
: for every line in the master program where you write to this file, you could
: use an MPI_Pack call instead, followed by a single MPI_Bcast at the end (with
: corresponding Bcast and an Unpack for each 'read' in the slave processes.)
This might be easy, but this would create a sequential bottleneck in the
program. If that file scales with the problem size this would be a real mess.
If every process reads its portion of the file, this could be done - in the
algorithm - in parallel, meaning that if a parallel file system comes your
way it would also be executed in parallel.

: If you must do it this way, it seems likely that your workers are trying to
: open the file before the file system knows it has been created. You could use
Yes, could be NFS, and you have to synchronize it. Possibly you are using an 
old mpirun script. Try the command sync (usually /usr/sbin/sync, see man pages)
to synchronize the NFS. That should do.

: MPI_Barrier to ensure they don't try before it HAS been created! And make sure
: the master closes the file before its call to MPI_Barrier. 
Would still not force the NFS to synchronize, and the other machines cannot
access the file.

: If there
: are still problems, you could try something like this in the slaves:

: int trys;
: FILE *fp;
: trys=0; fp=NULL;
: while (trys<5 && fp==NULL) {
:    if (!fp=fopen("thefile","r")) sleep(1);
:    trys++;
: }
: if (fp==NULL) {
:    fprintf(stderr,"Still not there after 5 seconds!\n");
:     exit(1);
      ^^^^^^^^
Bad! Don't forget to call MPI_Finalize() before terminating your process, this
would leave it looping and creating load. 
: }
: .. read from the file ...     

Greetings from Ulm
                      Andy

-- 
Andreas Leibl / grad. student / Dept. of Physics, University of Ulm, Germany
Theoretical Physics I / Room O25 - 406 / Phone 0731-502-2918
leibl@physik.uni-ulm.de             http://www.mathematik.uni-ulm.de/~atl/ 
atl@mathematik.uni-ulm.de           irc: croc (see you later, alligator :-))
-----------------------------------------------------------------------------
Windows '95 is a graphical interrupt parser.  Nothing more.

