from mpi4py import MPI
comm = MPI.COMM_SELF
mode = MPI.MODE_RDWR | MPI.MODE_CREATE
info = MPI.INFO_NULL
fh = MPI.File.Open(comm, "/tmp/datafile", mode, info)
fh.Set_size(0)
assert fh.Get_size() == 0
fh.Preallocate(1)
assert fh.Get_size() == 1
fh.Preallocate(100)
assert fh.Get_size() == 100
$ python test-ompi-4.py
Traceback (most recent call last):
File "test-ompi-4.py", line 11, in <module>
assert fh.Get_size() == 100
AssertionError