I am coding in the analytic expression for a determinant a follows:
detW = &
(one+be*(u11+u22+u33)-&
be2*(u12sq+u13sq-u11*u22+u23sq-u11*u33-u22*u33)-&
al2*(-(u11*u22)+u13sq*(one+three*be*u22)-six*be*u12*u13*u23+u23sq+three*be*u11*u23sq-&
u11*u33-u22*u33-three*be*u11*u22*u33+u12sq*(one+three*be*u33))-&
al3*(u13sq*u22-two*u12*u13*u23+u12sq*u33+u11*(u23sq-u22*u33))-&
be3*(u13sq*u22-two*u12*u13*u23+u12sq*u33+u11*(u23sq-u22*u33))+&
al*(u22+u33-three*be2*(u13sq*u22-two*u12*u13*u23+u12sq*u33)-&
two*be*(u12sq+u13sq+u23sq-u22*u33)+&
u11*(one+two*be*(u22+u33)-three*be2*(u23sq-u22*u33))))
print*, 'detW = ', detW
print*, 'ga3 = ', ga3
detW = ga3/detW
Ng = (det1*detW)**pt5
The true value of the determinant is the first large portion as the denominator and ga3 as the numerator. I have found that when I do not calculate this determinant my code (~176,000 lines of code total) takes around 0.07 seconds whereas calculating this determinant makes the entire program take about 2.5 seconds. Furthermore, I have found that the culprit is the line detW = ga3/detW
. When I comment this line out, the runtime drops back down to 0.07.
It only takes this long when the value of detW
on the detW = ga3/detW
line is exactly 1.0. Why would this occur? Why does division by 1.0 cause the program to take 3571% times as long to run?
I have found that the source of the slowdown was, in fact, in the Ng = (det1*detW)**pt5
line - using sqrt
reduces the time considerably.