Puzzling performance difference between ifort and gfortran

后端 未结 1 1936
遇见更好的自我
遇见更好的自我 2021-01-21 08:23

Recently, I read a post on Stack Overflow about finding integers that are perfect squares. As I wanted to play with this, I wrote the following small program:

P         


        
1条回答
  •  陌清茗
    陌清茗 (楼主)
    2021-01-21 09:22

    What compiler versions are you using? Interestingly, it looks like a case where there is a performance regression from 11.1 to 12.0 -- e.g. for me, 11.1 (ifort -fast square.f90) takes 3.96s, and 12.0 (same options) took 13.3s. gfortran (4.6.1) (-O3) is still faster (3.35s). I have seen this kind of a regression before, although not quite as dramatic. BTW, replacing the if statement with

    is_square = any(m == [0, 1, 4, 9])
    if(.not. is_square) return
    

    makes it run twice as fast with ifort 12.0, but slower in gfortran and ifort 11.1.

    It looks like part of the problem is that 12.0 is overly aggressive in trying to vectorize things: adding

    !DEC$ NOVECTOR
    

    right before the DO loop (without changing anything else in the code) cuts the run time down to 4.0 sec.

    Also, as a side benefit: if you have a multi-core CPU, try adding -parallel to the ifort command line :)

    0 讨论(0)
提交回复
热议问题