Skip to content

Commit 82081ba

Browse files
committed
examples: Report indexing overhead honestly in the benchmark
Add a ratio column and stop calling the serial overhead 'negligible'. It is a fixed per-call cost (the .data accessor and global-index translation): large relative to NumPy for a trivial index -- whose NumPy cost is almost nothing -- but, being fixed, amortising to ~2x at realistic operation sizes.
1 parent 872d6a4 commit 82081ba

1 file changed

Lines changed: 14 additions & 9 deletions

File tree

examples/mpi/benchmark_data_indexing.py

Lines changed: 14 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,12 @@
44
The script runs one of two studies, picked automatically from the MPI launch
55
size, each making a single point:
66
7-
* **Serial** (run without ``mpirun``) -- with MPI off, ``data[idx]`` is a thin
8-
wrapper over NumPy indexing. The benchmark shows the overhead is small: a
9-
fixed cost plus a low per-point cost (vectorised, with no per-element Python
10-
loop), so for realistic operation sizes it stays negligible. ::
7+
* **Serial** (run without ``mpirun``) -- with MPI off, ``data[idx]`` wraps
8+
NumPy indexing. The overhead is a fixed per-call cost (the ``.data`` accessor
9+
plus global-index translation), not a per-element one. It is large *relative*
10+
to NumPy for a trivial index -- whose NumPy cost is almost nothing -- but, being
11+
fixed, it amortises: only a few times NumPy at realistic sizes, and negligible
12+
against actual compute. ::
1113
1214
python examples/mpi/benchmark_data_indexing.py
1315
@@ -83,7 +85,8 @@ def serial_study(reps):
8385
print(f"\nSerial overhead of data[idx] = v over NumPy "
8486
f"(axis={AXIS}, reps={reps})\n")
8587
header = ('points'.rjust(10) + 'numpy [us]'.rjust(14)
86-
+ 'devito [us]'.rjust(14) + 'overhead [us]'.rjust(16))
88+
+ 'devito [us]'.rjust(14) + 'overhead [us]'.rjust(16)
89+
+ 'ratio'.rjust(9))
8790
print(header)
8891
print('-' * len(header))
8992
for npoint in POINTS:
@@ -95,10 +98,12 @@ def serial_study(reps):
9598
print(str(npoint).rjust(10)
9699
+ format(t_np * 1e6, '.1f').rjust(14)
97100
+ format(t_dv * 1e6, '.1f').rjust(14)
98-
+ format((t_dv - t_np) * 1e6, '.1f').rjust(16))
99-
print("\noverhead = devito - numpy; a small fixed cost plus a low per-point "
100-
"cost (no\nper-element Python loop) -- tens of microseconds at "
101-
"realistic sizes.")
101+
+ format((t_dv - t_np) * 1e6, '.1f').rjust(16)
102+
+ (format(t_dv / t_np, '.0f') + 'x').rjust(9))
103+
print("\noverhead = devito - numpy; a fixed per-call cost (the .data accessor "
104+
"and\nglobal-index translation). It is large relative to NumPy for a "
105+
"trivial\nindex but, being fixed, amortises to a few x at realistic "
106+
"sizes.")
102107

103108

104109
def mpi_study(comm, nprocs, reps):

0 commit comments

Comments
 (0)