Intel® Fortran Compiler
Build applications that can scale for the future with optimized code designed for Intel® Xeon® and compatible processors.
29413 Discussions

different run time despite few lines

diedro
Beginner
1,460 Views

hi everyone,

something stange is happening to me. Iuse intel fortran conpiler. This is my simple code:

IF(ASSOCIATED(LISTPART(ii,jj)%head)==.true.) THEN
    CALL dlist_begin(LISTPART(ii,jj))
    DO

    CORE

    IF(.NOT. dlist_move_next(LISTPART(ii,jj))) EXIT

ENDDO

however if I had only two lines, maybe 

IF(ASSOCIATED(LISTPART(ii,jj)%head)==.true.) THEN
    CALL dlist_begin(LISTPART(ii,jj))
    DO

    CORE

     WRITE(*,*) 'HELLO'

    IF(.NOT. dlist_move_next(LISTPART(ii,jj))) EXIT

ENDDO

the run time of my program change a lot

Does someone know why?

is it a problem accordind to compile option?

THANKS A LOT

0 Kudos
7 Replies
TimP
Honored Contributor III
1,460 Views
I think what you have put here is too cryptic for a definite answer. However, placing a WRITE is likely to act as a barrier against optimization or dead code deletion, not to mention that WRITE itself is slow.
0 Kudos
diedro
Beginner
1,460 Views
wow, very quick replay. thank you Actually I did non but write, I put 6 lines. They are only few lines of code. I put my code in the attachment. You can see the additional lines, compared to the original code, as comments. You can see that they are simple summation and multiplications. I do not understand why my code slows down without these lines, it should run faster without this calculations.
0 Kudos
Heinz_B_Intel
Employee
1,460 Views
I think this is the explanation: Your code computes "dCRy" in the loop but without using the value computed in the loop, you re-define this variable in one of the 6 lines you refer to. Thus it is a valid compiler optimization to remove the loop completely. This then accelerates your code of course. In case you remove the second definition of "dCRy", the loop is non-redundant and has to be executed.
0 Kudos
diedro
Beginner
1,460 Views
hi, it is this the strange thing. If i remove the second dCrys the code slow down. In this moment I compute the second dCry only to check the first dCry. I will remove the second dCry once I will have checked all the problem in mu code.
0 Kudos
diedro
Beginner
1,460 Views
hi, sorry. I get you. The code optimizes all the staff in the second case. It understands that i do not use the first dCRy so it does not use the do loop. do I have understood correctly?
0 Kudos
Heinz_B_Intel
Employee
1,460 Views
Yes - right. The compiler consider the loop as 'dead code' since all you compute here is never used. You will see the change in case you add e.g. a WRITE(*,*) dCRy after the loop: This would be a very simple test to verify the change in run time. Or compile once without optimization ( -O0): Then the compiler would not remove the loop either.
0 Kudos
diedro
Beginner
1,460 Views
hi, thanks a lot. I have also learn how to compile without optimization. really really thanks
0 Kudos
Reply