Replacing extrordinarily slow pow() function

前端 未结 4 1787
野性不改
野性不改 2020-12-09 03:01

We have a CFD solver and while running a simulation, it was found to run extraordinarily slow on some machines but not others. Using Intel VTune, it was found the following

相关标签:
4条回答
  • 2020-12-09 03:13

    Just write your own pow function, put the .o file in a static library archive libmypow.a somewhere in the linker's library path, and pass -lmypow when linking.

    0 讨论(0)
  • 2020-12-09 03:15

    pow(a,b) is the same as exp(b*ln(a)), maybe that substitution will work for you.

    0 讨论(0)
  • 2020-12-09 03:30

    I tested this myself, and indeed if I compile the test program from the page you link to it uses call pow in the assembly code. However, compiling with optimization -ffast-math there is no call to pow, but the result is slightly different.

    0 讨论(0)
  • 2020-12-09 03:39

    Well, hold on now. The library isn't calling __slowpow() just to toy with you; it's calling __slowpow() because it believes the extra precision is necessary to give an accurate result for the values you're giving it (in this case, base very near 1, exponent of order 1). If you care about the accuracy of this computation, you should understand why that is and if it matters before trying to work around it. It might be the case that for (say) large negative F0 this whole thing can be safely rounded to 1; or it might not, depending on what's done with this value later. If you ever need 1.d0 minus this result, you're going to want that extra precision.

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