-
-
Notifications
You must be signed in to change notification settings - Fork 285
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
r.slope.aspect: implement parallelization with OpenMP (#1767)
- Loading branch information
Showing
9 changed files
with
1,125 additions
and
416 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
64 changes: 64 additions & 0 deletions
64
raster/r.slope.aspect/benchmark/benchmark_r_slope_aspect.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,64 @@ | ||
"""Benchmarking of r.slope aspect | ||
@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.slope.aspect_50M", results) | ||
benchmark(10000, "r.slope.aspect_100M", results) | ||
benchmark(14142, "r.slope.aspect_200M", results) | ||
benchmark(20000, "r.slope.aspect_400M", results) | ||
|
||
bm.nprocs_plot(results, filename="r_slope_aspect_benchmark_size.svg") | ||
|
||
|
||
def benchmark(size, label, results): | ||
reference = "r_slope_aspect_reference_map" | ||
slope = "benchmark_slope" | ||
aspect = "benchmark_aspect" | ||
pcurv = "benchmark_pcurv" | ||
tcurv = "benchmark_tcurv" | ||
|
||
generate_map(rows=size, cols=size, fname=reference) | ||
module = Module( | ||
"r.slope.aspect", | ||
elevation=reference, | ||
slope=slope, | ||
aspect=aspect, | ||
pcurvature=pcurv, | ||
tcurvature=tcurv, | ||
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=slope) | ||
Module("g.remove", quiet=True, flags="f", type="raster", name=aspect) | ||
Module("g.remove", quiet=True, flags="f", type="raster", name=pcurv) | ||
Module("g.remove", quiet=True, flags="f", type="raster", name=tcurv) | ||
|
||
|
||
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() |
68 changes: 68 additions & 0 deletions
68
raster/r.slope.aspect/benchmark/benchmark_r_slope_aspect_memory.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,68 @@ | ||
"""Benchmarking of r.slope aspect | ||
@author Aaron Saw Min Sern | ||
@author Anna Petrasova | ||
""" | ||
|
||
from grass.exceptions import CalledModuleError | ||
from grass.pygrass.modules import Module | ||
from subprocess import DEVNULL | ||
|
||
import grass.benchmark as bm | ||
|
||
|
||
def main(): | ||
results = [] | ||
|
||
reference = "r_slope_aspect_reference_map" | ||
generate_map(rows=10000, cols=10000, fname=reference) | ||
# Users can add more or modify existing reference maps | ||
benchmark(0, "r.slope.aspect_0MB", results, reference) | ||
benchmark(5, "r.slope.aspect_5MB", results, reference) | ||
benchmark(10, "r.slope.aspect_10MB", results, reference) | ||
benchmark(100, "r.slope.aspect_100MB", results, reference) | ||
benchmark(300, "r.slope.aspect_300MB", results, reference) | ||
|
||
Module("g.remove", quiet=True, flags="f", type="raster", name=reference) | ||
bm.nprocs_plot(results, filename="r_slope_aspect_benchmark_memory.svg") | ||
|
||
|
||
def benchmark(memory, label, results, reference): | ||
|
||
slope = "benchmark_slope" | ||
aspect = "benchmark_aspect" | ||
pcurv = "benchmark_pcurv" | ||
tcurv = "benchmark_tcurv" | ||
|
||
module = Module( | ||
"r.slope.aspect", | ||
elevation=reference, | ||
slope=slope, | ||
aspect=aspect, | ||
pcurvature=pcurv, | ||
tcurvature=tcurv, | ||
run_=False, | ||
stdout_=DEVNULL, | ||
overwrite=True, | ||
) | ||
results.append(bm.benchmark_nprocs(module, label=label, max_nprocs=20, repeat=10)) | ||
|
||
Module("g.remove", quiet=True, flags="f", type="raster", name=slope) | ||
Module("g.remove", quiet=True, flags="f", type="raster", name=aspect) | ||
Module("g.remove", quiet=True, flags="f", type="raster", name=pcurv) | ||
Module("g.remove", quiet=True, flags="f", type="raster", name=tcurv) | ||
|
||
|
||
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() |
Oops, something went wrong.