Increasing double loop efficiency
Increasing double loop efficiency
(OP)
I have the following double loop;
Here, S is a 100x100 symmetric REAL array, ALPHA, b1, and b2 are REAL constants.
I am hoping to incorporate LAPACK dgemm or some other library function to increase the efficiency of this calculation. However, dgemm( TRANSA, TRANSB, M, N, K, ALPHA, A, LDA,B, LDB, BETA, C, LDC ) needs A and B arrays as input. I could define A as the first exponential using a DO loop and B as the second exponential using another DO loop but this approach may be less efficient.
What would be the most efficient way to calculate the above double loop in fortran?
Thanks,
Vahid
CODE -->
DO i=1,100 DO j=1,100 S(i,j)= S(i,j)+ALPHA*exp[(real(i)/b1)**2]*exp[(real(j)/b2)**2] ENDDO ENDDO
Here, S is a 100x100 symmetric REAL array, ALPHA, b1, and b2 are REAL constants.
I am hoping to incorporate LAPACK dgemm or some other library function to increase the efficiency of this calculation. However, dgemm( TRANSA, TRANSB, M, N, K, ALPHA, A, LDA,B, LDB, BETA, C, LDC ) needs A and B arrays as input. I could define A as the first exponential using a DO loop and B as the second exponential using another DO loop but this approach may be less efficient.
What would be the most efficient way to calculate the above double loop in fortran?
Thanks,
Vahid
RE: Increasing double loop efficiency
so the call
seems to be
where
S is your 100x100 matrix
A is 100x100 matrix of this form, which only has the first column non-zero, otherwise all columns are zeros:
B is 100x100 matrix of this form, which only has the first row non-zero, otherwise all rows are zeros:
RE: Increasing double loop efficiency
Vahid
RE: Increasing double loop efficiency
A is 100x1 matrix of this form:
B is 1x100 matrix of this form:
Then the call seems to be
RE: Increasing double loop efficiency
But now when I think about it again, I have doubt, that DGEMM is faster for your simple case, than your simple 2 loops.
Look at the source o DGEMM how many loops it has:
https://netlib.org/lapack/explore-html/d7/d2b/dgem...
Maybe DGEMM is efficient for more complicated cases ...
RE: Increasing double loop efficiency
Thanks,
Vahid
RE: Increasing double loop efficiency
RE: Increasing double loop efficiency
When using the double DO loop, the total run time is 7h19m. With DGEMM replacing the double loop, the runtime is 3h34m, a significant speed up.
Thanks mikrom for all your help.
Cheers,
Vahid
RE: Increasing double loop efficiency