Skip to content

Commit 3e386bb

Browse files
committed
Address comments.
1 parent 702cebf commit 3e386bb

File tree

2 files changed

+9
-8
lines changed

2 files changed

+9
-8
lines changed

src/sage/parallel/decorate.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -308,7 +308,7 @@ def parallel(p_iter='fork', ncpus=None, **kwds):
308308
- ``ncpus`` -- integer; maximal number of subprocesses to use at the same time
309309
- ``timeout`` -- number of seconds until each subprocess is killed (only supported
310310
by ``'fork'``; zero means not at all)
311-
- ``reseed_rng``: reseed the rng in each subprocess
311+
- ``reseed_rng``: reseed the rng (random number generator) in each subprocess
312312
313313
.. warning::
314314
@@ -402,10 +402,10 @@ def parallel(p_iter='fork', ncpus=None, **kwds):
402402
By default, all subprocesses use the same random seed and therefore the same deterministic randomness.
403403
For functions that should be randomized, we can reseed the random seed in each subprocess::
404404
405-
sage: @parallel(reseed_rng = True)
406-
....: def unif(n): return ZZ.random_element(x = 0, y = n)
405+
sage: @parallel(reseed_rng=True)
406+
....: def unif(n): return ZZ.random_element(x=0, y=n)
407407
sage: set_random_seed(42)
408-
sage: sorted(unif([1000]*3))
408+
sage: sorted(unif([1000]*3)) # random
409409
[(((1000,), {}), 444), (((1000,), {}), 597), (((1000,), {}), 640)]
410410
411411
.. warning::

src/sage/parallel/use_fork.py

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,7 @@ class p_iter_fork:
7070
about what the iterator does (e.g., killing subprocesses)
7171
- ``reset_interfaces`` -- boolean (default: ``True``); whether to reset all
7272
pexpect interfaces
73-
- ``reseed_rng`` -- booolean (default: ``False``); whether or not to reseed the rng in the subprocesses
73+
- ``reseed_rng`` -- boolean (default: ``False``); whether or not to reseed the rng in the subprocesses
7474
7575
EXAMPLES::
7676
@@ -164,7 +164,7 @@ def __call__(self, f, inputs):
164164
n = self.ncpus
165165
inputs = list(inputs)
166166
if self.reseed_rng:
167-
seeds = [getrandbits(512) for _ in range(0, len(inputs))]
167+
seeds = [getrandbits(512) for _ in range(len(inputs))]
168168
vs = list(zip(inputs, seeds))
169169
else:
170170
vs = list(zip(inputs, [None]*len(inputs)))
@@ -173,15 +173,16 @@ def __call__(self, f, inputs):
173173
while vs or workers:
174174
# Spawn up to n subprocesses
175175
while vs and len(workers) < n:
176-
(v0, seed0) = vs.pop(0) # Input value and seed for the next subprocess
176+
v0, seed0 = vs.pop(0) # Input value and seed for the next subprocess
177177
with ContainChildren():
178178
pid = os.fork()
179179
# The way fork works is that pid returns the
180180
# nonzero pid of the subprocess for the master
181181
# process and returns 0 for the subprocess.
182182
if not pid:
183183
# This is the subprocess.
184-
self.worker_seed = seed0 if self.reseed_rng else None
184+
if self.reseed_rng:
185+
self.worker_seed = seed0
185186
self._subprocess(f, dir, *v0)
186187
workers[pid] = WorkerData(v0)
187188

0 commit comments

Comments
 (0)