On 12 July 2017 at 18:18, <
ashu...@gmail.com> wrote:
>
> def main():
> global loop
> txt_write = 'buhahaha'
>
> with open('test', 'w') as f1:
> if rank == 0:
> f1.write(txt_write)
>
> # f1.flush()
> # os.fsync(f1.fileno())
>
This code smells bad, you should open/write/flush/sync in rank 0, you
are opening in all, then write in 0, then flushing and syncing in all.
This is a race condition. Using files with MPI is not different than
using files with threads or multiple processes.
>
> On Tuesday, 8 May 2012 20:59:23 UTC+2, Lisandro Dalcin wrote:
>>
>>
>> You SHOULD NOT rely on any ordering for "standard" I/O stream or
>> files. This is not a Python or mpi4py related issue, but for any
>> MPI-based program, even if written in C/C++/Fortran.
>>
>
> Am I to understand that it is nearly impossible for MPI barrier to wait
> until (not only "standard" I/O stream but also)
> "file" I/O streams have been flushed?
>
I did not say that. However, let me clarify something: when you use
MPI_barrier(), you are guaranteed that no process will leave the
barrier until all processes have entered it. Just writing to a file in
one of these processes is usually not enough, because of buffering. If
you do flushing/syncing explicitly, then I would say yes, an MPI
barrier is equivalent to "waiting" for I/O in all processes, but you
have to do it the right way:
if comm.rank == 0:
with open(..., 'w') as f:
f.write(...)
f.flush()
comm.Barrier()
# now all processes should be able to
# open the file and read same contents
> Will use of MPI file write fix this problem?
>
If you need to perform multiple writes from multiple processes to a
single file in a coordinated manner, then yes, MPI.File is the "right"
way of doing it. But of course, you have to learn the semantics of MPI
I/O, and understand how the many, many different read/write methods
work.
--
Lisandro Dalcin
============
Research Scientist
Computer, Electrical and Mathematical Sciences & Engineering (CEMSE)
Extreme Computing Research Center (ECRC)
King Abdullah University of Science and Technology (KAUST)
http://ecrc.kaust.edu.sa/
4700 King Abdullah University of Science and Technology
al-Khawarizmi Bldg (Bldg 1), Office # 0109
Thuwal 23955-6900, Kingdom of Saudi Arabia
http://www.kaust.edu.sa
Office Phone:
+966 12 808-0459