Skip to content

Commit

Permalink
r.resamp.interp: implement parallelization with OpenMP (#1771)
Browse files Browse the repository at this point in the history
  • Loading branch information
aaronsms authored Dec 9, 2022
1 parent ba819c4 commit 352a038
Show file tree
Hide file tree
Showing 6 changed files with 496 additions and 189 deletions.
3 changes: 2 additions & 1 deletion raster/r.resamp.interp/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,9 @@ MODULE_TOPDIR = ../..

PGM = r.resamp.interp

LIBES = $(RASTERLIB) $(GISLIB) $(MATHLIB)
LIBES = $(RASTERLIB) $(GISLIB) $(MATHLIB) $(OMPLIB)
DEPENDENCIES = $(RASTERDEP) $(GISDEP)
EXTRA_CFLAGS = $(OMPCFLAGS)

include $(MODULE_TOPDIR)/include/Make/Module.make

Expand Down
57 changes: 57 additions & 0 deletions raster/r.resamp.interp/benchmark/benchmark_r_resamp_interp.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
"""Benchmarking of r.resamp.interp
@author Aaron Saw Min Sern
"""

from grass.exceptions import CalledModuleError
from grass.pygrass.modules import Module
from subprocess import DEVNULL

import grass.benchmark as bm


def main():
results = []

# Users can add more or modify existing reference maps
benchmark(7071, "r.resamp.interp_50M", results)
benchmark(14142, "r.resamp.interp_200M", results)
benchmark(10000, "r.resamp.interp_100M", results)
benchmark(20000, "r.resamp.interp_400M", results)

bm.nprocs_plot(results)


def benchmark(size, label, results):
reference = "r_resamp_interp_reference_map"
output = "benchmark_r_resamp_interp"

generate_map(rows=size, cols=size, fname=reference)
module = Module(
"r.resamp.interp",
input=reference,
output=output,
method="lanczos",
memory=500,
run_=False,
stdout_=DEVNULL,
overwrite=True,
)
results.append(bm.benchmark_nprocs(module, label=label, max_nprocs=16, repeat=3))
Module("g.remove", quiet=True, flags="f", type="raster", name=reference)
Module("g.remove", quiet=True, flags="f", type="raster", name=output)


def generate_map(rows, cols, fname):
Module("g.region", flags="p", s=0, n=rows, w=0, e=cols, res=1)
# Generate using r.random.surface if r.surf.fractal fails
try:
print("Generating reference map using r.surf.fractal...")
Module("r.surf.fractal", output=fname)
except CalledModuleError:
print("r.surf.fractal fails, using r.random.surface instead...")
Module("r.random.surface", output=fname)


if __name__ == "__main__":
main()
Loading

0 comments on commit 352a038

Please sign in to comment.