I am trying to speedup my code for Laplace Equation Solver. Based on code profiling, most of the time goes in the function given below. I have tried to optimise the functions as much as possible but the performance still isnβt near an available FORTRAN code (which runs 33% faster). Can anyone tell me how can I improve my code beyond this?
function calcNext!(Anew,A,m,n)
error = 0.0::Float64;
@inbounds for j=2:(m-1) , i = 2:(n-1)
@fastmath Anew[i,j] = 0.25*( A[i+1, j ]
+ A[i-1, j ]
+ A[ i ,j-1]
+ A[ i ,j+1] );
error = max(error, abs( Anew[i,j] - A[i,j] ) );
end
return(error);
end
The following is the time taken by each part of the code, as per TimerOutputs
.
ββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
Time Allocations
ββββββββββββββββββββββ βββββββββββββββββββββββ
Tot / % measured: 9.90s / 100% 12.4KiB / 86.2%
Section ncalls time %tot avg alloc %tot avg
ββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
Loop 1 9.90s 100% 9.90s 10.7KiB 100% 10.7KiB
calcNext! 1.00k 6.92s 69.9% 6.92ms 0.00B 0.00% 0.00B
Copy 1.00k 2.96s 29.9% 2.96ms 0.00B 0.00% 0.00B
Print 1.00k 13.9ms 0.14% 13.9ΞΌs 8.19KiB 76.7% 8.38B
ββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ