I have the below file called demo2.py. Copied from: parallel write to different groups with h5py and http://docs.h5py.org/en/stable/mpi.html.
from mpi4py import MPI
import h5py
rank = MPI.COMM_WORLD.rank
size = MPI.COMM_WORLD.size
f = h5py.File('parallel_test.hdf5', 'w', driver='mpio', comm=MPI.COMM_WORLD)
dsets = []
for i in range(size):
dsets.append(f.create_dataset('test{0}'.format(i), (1,), dtype='i'))
dsets[rank][:] = rank
f.close()
I run it using: mpiexec -n 2 python3 demo2.py
in the command line. When I check the cores being used using htop
, I can clearly see that more than 2 cores are being used. I have three questions:
- Why and how is this happening?
- How can I strictly restrict the number of cores being used?
- How is a part of the code being executed only once and the rest being distributed? Or have I misunderstood this? Could you please explain the flow of the program along with the sharing of resources among processes?
Thanks a lot, any help is greatly appreciated!