Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
31 commits
Select commit Hold shift + click to select a range
6af4ca5
expand buffer and cache to multiple rows for multithreading
cyliang368 Jun 21, 2024
72a0970
fix the segmentfault problems
cyliang368 Jun 22, 2024
420cf19
add tests for parallelization
cyliang368 Jun 22, 2024
b665ca7
Merge branch 'OSGeo:main' into parallel_rmapcalc
cyliang368 Jun 22, 2024
95afb43
merge main to the branch
cyliang368 May 20, 2025
e7fd542
Update raster/r.mapcalc/testsuite/test_r_mapcalc_parallel.py
cyliang368 May 20, 2025
5a70b45
Update raster/r.mapcalc/testsuite/test_r_mapcalc_parallel.py
cyliang368 May 20, 2025
c2e55ca
Merge remote-tracking branch 'upstream/main' into parallel_rmapcalc
cyliang368 May 20, 2025
8c497d0
remove redundant parts
cyliang368 May 21, 2025
14ca376
fix malloc errors related threading
cyliang368 May 21, 2025
d0ca65e
use multiple file descriptors instead of locks
cyliang368 May 22, 2025
5b3184d
disable parallelization for not implemented functions
cyliang368 May 22, 2025
c06c345
Merge remote-tracking branch 'upstream/main' into parallel_rmapcalc
cyliang368 May 22, 2025
76ae210
Update benchmark_rmapcalc.py
cyliang368 May 22, 2025
224e7f3
remove unused variables
cyliang368 May 22, 2025
851d67c
remove unuse variable
cyliang368 May 22, 2025
96329eb
add more benchmarking
petrasovaa Jun 6, 2025
c315726
Merge branch 'main' into parallel_rmapcalc
petrasovaa Jun 6, 2025
f960c32
add performance to manual
petrasovaa Jun 13, 2025
45f7763
add openmp to cmake
petrasovaa Jun 13, 2025
59dcd3f
Merge branch 'main' into parallel_rmapcalc
petrasovaa Jun 13, 2025
b2ba22f
use new functions for setting openmp threads
petrasovaa Jun 13, 2025
42b3f97
correct the location and the condition to free nprocs->answer
cyliang368 Jun 14, 2025
8746bbb
Ensure r3 is detected and ensure correct #threads is assigned
cyliang368 Jun 15, 2025
bed8011
Handle Windows path separators
cyliang368 Jun 15, 2025
dfe3a1b
remove redundant empty line
cyliang368 Jun 15, 2025
895a7d9
remove space
cyliang368 Jun 15, 2025
8ab77d2
test1
petrasovaa Jun 24, 2025
a4862b2
fix
petrasovaa Jun 24, 2025
cbb864e
test nmedian with nprocs=1
petrasovaa Jun 24, 2025
dd0468d
remove static variable
petrasovaa Jun 25, 2025
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 2 additions & 6 deletions lib/calc/xnmedian.c
Original file line number Diff line number Diff line change
Expand Up @@ -44,8 +44,7 @@ static int dcmp(const void *aa, const void *bb)

int f_nmedian(int argc, const int *argt, void **args)
{
static void *array;
static int alloc;
void *array;
int size = argc * Rast_cell_size(argt[0]);
int i, j;

Expand All @@ -56,10 +55,7 @@ int f_nmedian(int argc, const int *argt, void **args)
if (argt[i] != argt[0])
return E_ARG_TYPE;

if (size > alloc) {
alloc = size;
array = G_realloc(array, size);
}
array = G_malloc(size);

switch (argt[0]) {
case CELL_TYPE: {
Expand Down
3 changes: 2 additions & 1 deletion raster/r.mapcalc/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,8 @@ build_program(
OPTIONAL_DEPENDS
Readline::Readline
Readline::History
Threads::Threads)
Threads::Threads
OPENMP)

build_program(
NAME
Expand Down
6 changes: 4 additions & 2 deletions raster/r.mapcalc/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,10 @@ r3_mapcalc_OBJS := $(filter-out map.o xcoor.o xres.o, $(AUTO_OBJS))
include $(MODULE_TOPDIR)/include/Make/Multi.make

EXTRA_CFLAGS = $(READLINEINCPATH) $(PTHREADINCPATH)
LIBES2 = $(CALCLIB) $(GISLIB) $(RASTERLIB) $(BTREELIB) $(READLINELIBPATH) $(READLINELIB) $(HISTORYLIB) $(PTHREADLIBPATH) $(PTHREADLIB)
LIBES3 = $(CALCLIB) $(RASTER3DLIB) $(GISLIB) $(RASTERLIB) $(BTREELIB) $(READLINELIBPATH) $(READLINELIB) $(HISTORYLIB) $(PTHREADLIBPATH) $(PTHREADLIB)
LIBES2 = $(CALCLIB) $(GISLIB) $(RASTERLIB) $(BTREELIB) $(READLINELIBPATH) $(READLINELIB) $(HISTORYLIB) $(PTHREADLIBPATH) $(PTHREADLIB) $(OPENMP_LIBPATH) $(OPENMP_LIB)
LIBES3 = $(CALCLIB) $(RASTER3DLIB) $(GISLIB) $(RASTERLIB) $(BTREELIB) $(READLINELIBPATH) $(READLINELIB) $(HISTORYLIB) $(PTHREADLIBPATH) $(PTHREADLIB) $(OPENMP_LIBPATH) $(OPENMP_LIB)
EXTRA_CFLAGS = $(OPENMP_CFLAGS)
EXTRA_INC = $(OPENMP_INCPATH)

default: multi

Expand Down
104 changes: 104 additions & 0 deletions raster/r.mapcalc/benchmark/benchmark_rmapcalc.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,104 @@
"""Benchmarking of r.mapcalc
raster (2D)

@author Chung-Yuan Liang, 2025
"""

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

import grass.benchmark as bm


def main():
results = []
metrics = ["time", "speedup", "efficiency"]
mapsizes = [10e6, 50e6, 100e6]

# run benchmarks

for mapsize in mapsizes:
benchmark(
size=int(mapsize**0.5),
step=0,
results=results,
)

# plot results

for metric in metrics:
bm.nprocs_plot(
results,
filename=f"r_mapcalc_{metric}.svg",
title=f"r.mapcalc {metric}",
metric=metric,
)


def benchmark(size, step, results):
map1 = "benchmark_r_mapcalc_map1"
map2 = "benchmark_r_mapcalc_map2"
output = "benchmark_r_mapcalc"

generate_map(rows=size, cols=size, fname=map1)
generate_map(rows=size, cols=size, fname=map2)
module = Module(
"r.mapcalc",
expression=f"{output}=({map1} + {map2})",
overwrite=True,
)

results.append(
bm.benchmark_nprocs(
module,
label=f"r.mapcalc_simple_{int((size * size) / 1e6)}M",
max_nprocs=12,
repeat=5,
)
)

module = Module(
"r.mapcalc",
expression=f"{output}=({map1} + {map2} - 2*{map2} + {map1}*{map2} - {map1}/{map2})/2",
overwrite=True,
)
results.append(
bm.benchmark_nprocs(
module,
label=f"r.mapcalc_complex_{int((size * size) / 1e6)}M",
max_nprocs=12,
repeat=5,
)
)

module = Module(
"r.mapcalc",
expression=f"{output}= if (({map1}[5, 5] + {map2}[-5, -5]) > 0, 1.6, 0.1)",
overwrite=True,
)
results.append(
bm.benchmark_nprocs(
module,
label=f"r.mapcalc_neighbor_{int((size * size) / 1e6)}M",
max_nprocs=12,
repeat=5,
)
)
Module(
"g.remove", quiet=True, flags="f", type="raster", pattern="benchmark_r_mapcalc*"
)


def generate_map(rows, cols, fname):
Module("g.region", flags="p", rows=rows, cols=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, overwrite=True)
except CalledModuleError:
print("r.surf.fractal fails, using r.random.surface instead...")
Module("r.random.surface", output=fname, overwrite=True)


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