I would like to optimize for speed the following block of code:
DO i=1, dim1
DO j=1, dim2
DO k=1, dim3
IF (A(k,j,i)>0) &
B(k,j,i) = exp(C(k))/A(k,j,i)
ENDDO
ENDDO
ENDDO
Very importantly, A is an INTEGER and B and C are COMPLEX!
There are two issues: 1) How to replace this by a BLAS/LAPACK call? The issue is the condition. 2) Calculation of the exp is slow. How to speed that up?
expis slower than simpler arithmetics, I see no way around it. Also, you can use thewhere-end whereconstruct to express the conditional.exp(c(k))at mostdim3times, you could look at not doing itdim1*dim2*dim3times.C(k)is independent of the necessary things of course.]