From 97e318ff5d90c165c3b2df2cb2c360d98b52b16a Mon Sep 17 00:00:00 2001 From: nebmit <76664673+nebmit@users.noreply.github.com> Date: Thu, 30 Nov 2023 15:09:39 +0100 Subject: [PATCH] perf: added threading [skip ci] --- julia/tug/Core/FTCS.jl | 23 ++++++++++------------- 1 file changed, 10 insertions(+), 13 deletions(-) diff --git a/julia/tug/Core/FTCS.jl b/julia/tug/Core/FTCS.jl index 8db17be..87d9fd5 100644 --- a/julia/tug/Core/FTCS.jl +++ b/julia/tug/Core/FTCS.jl @@ -157,10 +157,10 @@ end function FTCS_1D(grid::Grid{T}, bc::Boundary{T}, timestep::T) where {T} colMax = getCols(grid) - sx = timestep / getDeltaCol(grid) * getDeltaCol(grid) + sx = timestep / (getDeltaCol(grid)^2) - # matrix for concentrations at time t+1 - concentrations_t1 = zeros(1, colMax) + concentrations = getConcentrations(grid) + concentrations_t1 = copy(concentrations) # only one row in 1D case -> row constant at index 1 row = 1 @@ -168,17 +168,14 @@ function FTCS_1D(grid::Grid{T}, bc::Boundary{T}, timestep::T) where {T} # inner cells # independent of boundary condition type for col = 2:colMax-1 - concentrations_t1[row, col] = getConcentrations(grid)[row, col] + - sx * calcHorizontalChange(grid, row, col) + concentrations_t1[row, col] += sx * calcHorizontalChange(grid, row, col) end # left boundary; hold column constant at index 1 - concentrations_t1[row, 1] = getConcentrations(grid)[row, 1] + - sx * calcHorizontalChangeLeftBoundary(grid, bc, row, 1) + concentrations_t1[row, 1] += sx * calcHorizontalChangeLeftBoundary(grid, bc, row, 1) # right boundary; hold column constant at max index - concentrations_t1[row, colMax] = getConcentrations(grid)[row, colMax] + - sx * calcHorizontalChangeRightBoundary(grid, bc, row, colMax) + concentrations_t1[row, colMax] += sx * calcHorizontalChangeRightBoundary(grid, bc, row, colMax) # overwrite obsolete concentrations setConcentrations!(grid, concentrations_t1) @@ -193,9 +190,7 @@ function FTCS_2D(grid::Grid{T}, bc::Boundary{T}, timestep::T) where {T} concentrations = getConcentrations(grid) concentrations_t1 = copy(concentrations) - # inner cells - # these are independent of the boundary condition type - for row = 2:rowMax-1 + Threads.@threads for row = 2:rowMax-1 # inner cells for col = 2:colMax-1 concentrations_t1[row, col] += sy * calcVerticalChange(grid, row, col) + @@ -205,16 +200,18 @@ function FTCS_2D(grid::Grid{T}, bc::Boundary{T}, timestep::T) where {T} # left boundary without corners concentrations_t1[row, 1] += sx * calcHorizontalChangeLeftBoundary(grid, bc, row, 1) + sy * calcVerticalChange(grid, row, 1) + # right boundary without corners concentrations_t1[row, colMax] += sx * calcHorizontalChangeRightBoundary(grid, bc, row, colMax) + sy * calcVerticalChange(grid, row, colMax) end # top / bottom without corners / looping over columns - for col = 2:colMax-1 + Threads.@threads for col = 2:colMax-1 # top concentrations_t1[1, col] += sy * calcVerticalChangeTopBoundary(grid, bc, 1, col) + sx * calcHorizontalChange(grid, 1, col) + # bottom concentrations_t1[rowMax, col] += sy * calcVerticalChangeBottomBoundary(grid, bc, rowMax, col) + sx * calcHorizontalChange(grid, rowMax, col)