Skip to content

Commit 6246b07

Browse files
mmckyclaude
andcommitted
[numba.md] numba_ex3: release the 1e8 arrays after the timings
The `u_big`/`v_big` pair added for numba_ex3 stayed alive for the rest of the notebook. Because `numba_ex_draw_speed` rebinds `u_draws`/`v_draws` to a second pair of 1e8-element arrays, peak memory reached ~3.2 GB rather than ~1.6 GB. That is comfortable on the g4dn.2xlarge CI runner but not on the smaller machines the accompanying memory note is written for. Delete the arrays after their last use, and fix "Lets" -> "Let's" plus the trailing whitespace introduced alongside it. Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
1 parent b9b9c87 commit 6246b07

1 file changed

Lines changed: 10 additions & 3 deletions

File tree

lectures/numba.md

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -723,10 +723,10 @@ def calculate_pi_parallel(u_draws, v_draws):
723723
return area_estimate * 4 # dividing by radius**2
724724
```
725725

726-
Parallelization pays off when each thread has enough work to overcome the overhead costs while
727-
breaking the problem into parts for work to happen simultaneously.
726+
Parallelization pays off when each thread has enough work to overcome the overhead costs while
727+
breaking the problem into parts for work to happen simultaneously.
728728

729-
Lets draw a fresh, much larger set of points rather than reusing the arrays from above.
729+
Let's draw a fresh, much larger set of points rather than reusing the arrays from above.
730730

731731
```{note}
732732
The two arrays below occupy about 1.6 GB of memory — reduce `n` if your
@@ -769,6 +769,13 @@ on the number of CPUs on your machine — and at small sample sizes the
769769
parallel version can even be slower, because the gains cannot cover the cost of
770770
distributing work across threads.)
771771

772+
These two arrays are large and we are finished with them, so we release the
773+
memory before moving on.
774+
775+
```{code-cell} ipython3
776+
del u_big, v_big
777+
```
778+
772779
Notice that we drew all of the random points *before* the loop and passed them in
773780
as arrays, so the parallel loop only *reads* from memory.
774781

0 commit comments

Comments
 (0)