different run time despite few lines

different run time despite few lines

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

8 Beiträge / 0 neu
Letzter Beitrag
Nähere Informationen zur Compiler-Optimierung finden Sie in unserem Optimierungshinweis.

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.

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.

Anlagen: 

AnhangGröße
Herunterladen test.txt5.09 KB

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.

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.

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?

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.

hi,
thanks a lot.
I have also learn how to compile without optimization.
really really thanks

Kommentar hinterlassen

Bitte anmelden, um einen Kommentar hinzuzufügen. Sie sind noch nicht Mitglied? Jetzt teilnehmen