Skip to content

Update mpi_numpi.py #27

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: gh-pages
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 1 addition & 4 deletions _episodes/code/02_parallel_jobs/mpi_numpi.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,12 @@
from mpi4py import MPI
import numpy as np

np.random.seed(2017)

comm = MPI.COMM_WORLD
size = comm.Get_size()
rank = comm.Get_rank()


def inside_circle(total_count):

np.random.seed(2022*rank)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Aren't you now resetting the seed here every time the function is called? A rank specific seed is indeed necessary...perhaps this deserves an explanatory comment?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The function is only called once. Would it be clearer if the seed is set once the rank has been determined, for example on line 9?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think that would be the right thing to do, there are two subtle things going on that should be clarified in a comment (or in the lesson?): you only set the seed once in your application, and the seed of each rank should be different.

hname = MPI.Get_processor_name()

x = np.float32(np.random.uniform(size=total_count))
Expand Down