If or function pointers in fortran

前端 未结 4 805
南旧
南旧 2021-01-21 01:39

as it is so common with Fortran, I\'m writing a massively parallel scientific code. In the beginning of my code I read my configuration file which tells me which type of solver

4条回答
  •  日久生厌
    2021-01-21 01:48

    After a brief search I couldn't find the answer to the question, so I ran a little benchmark myself (see this link for the Makefile & dependencies). The benchmark consists of:

    • Draw random number to select method a, b, or c, which all perform a simple addition to their single integer argument
    • Call the chosen method 100 million times, using either a procedure pointer or if-statements
    • Repeat the above 5 times

    The result with gfortran 4.8.5 on an CPU E5-2630 v3 @ 2.40GHz is:

    Time per call (proc. pointer):       1.89 ns
    Time per call (if statement):        1.89 ns
    

    In other words, there is not much of a performance difference!

提交回复
热议问题