forked from OSGeo/grass
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
r.neighbors: implement parallelization with OpenMP (OSGeo#1724)
- Loading branch information
Showing
16 changed files
with
508 additions
and
106 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
58 changes: 58 additions & 0 deletions
58
raster/r.neighbors/benchmark/benchmark_r_neighbors_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,58 @@ | ||
"""Benchmarking of r.neighbors | ||
@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 = [] | ||
|
||
reference = "r_neighbors_reference_map" | ||
generate_map(rows=10000, cols=10000, fname=reference) | ||
# Users can add more or modify existing reference maps | ||
benchmark(0, "r.neighbors_0MB", results, reference) | ||
benchmark(5, "r.neighbors_5MB", results, reference) | ||
benchmark(10, "r.neighbors_10MB", results, reference) | ||
benchmark(100, "r.neighbors_100MB", results, reference) | ||
benchmark(300, "r.neighbors_300MB", results, reference) | ||
|
||
Module("g.remove", quiet=True, flags="f", type="raster", name=reference) | ||
bm.nprocs_plot(results, filename="r_neighbors_benchmark_memory.svg") | ||
|
||
|
||
def benchmark(memory, label, results, reference): | ||
output = "benchmark_r_neighbors_nprocs" | ||
|
||
module = Module( | ||
"r.neighbors", | ||
input=reference, | ||
output=output, | ||
size=9, | ||
memory=memory, | ||
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=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() |
57 changes: 57 additions & 0 deletions
57
raster/r.neighbors/benchmark/benchmark_r_neighbors_nprocs.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,57 @@ | ||
"""Benchmarking of r.neighbors | ||
@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.neighbors_50M", results) | ||
benchmark(10000, "r.neighbors_100M", results) | ||
benchmark(14142, "r.neighbors_200M", results) | ||
benchmark(20000, "r.neighbors_400M", results) | ||
|
||
bm.nprocs_plot(results, filename="r_neighbors_benchmark_nprocs.svg") | ||
|
||
|
||
def benchmark(size, label, results): | ||
reference = "r_neighbors_reference_map" | ||
output = "benchmark_r_neighbors_nprocs" | ||
|
||
generate_map(rows=size, cols=size, fname=reference) | ||
module = Module( | ||
"r.neighbors", | ||
input=reference, | ||
output=output, | ||
size=9, | ||
memory=300, | ||
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() |
57 changes: 57 additions & 0 deletions
57
raster/r.neighbors/benchmark/benchmark_r_neighbors_size.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,57 @@ | ||
"""Benchmarking of r.neighbors | ||
@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_neighbors_reference_map" | ||
generate_map(rows=10000, cols=10000, fname=reference) | ||
# Users can add more or modify existing reference maps | ||
benchmark(3, "r.neighbors_3x3", results, reference) | ||
benchmark(9, "r.neighbors_9x9", results, reference) | ||
benchmark(15, "r.neighbors_15x15", results, reference) | ||
benchmark(31, "r.neighbors_31x31", results, reference) | ||
|
||
Module("g.remove", quiet=True, flags="f", type="raster", name=reference) | ||
bm.nprocs_plot(results, filename="r_neighbors_benchmark_size.svg") | ||
|
||
|
||
def benchmark(size, label, results, reference): | ||
output = "benchmark_r_neighbors_nprocs" | ||
|
||
module = Module( | ||
"r.neighbors", | ||
input=reference, | ||
output=output, | ||
size=size, | ||
memory=300, | ||
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=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() |
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
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
Oops, something went wrong.