更换extrordinarily慢POW()函数 [英] Replacing extrordinarily slow pow() function

查看:348
本文介绍了更换extrordinarily慢POW()函数的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我们有一个CFD求解器,并同时运行模拟,发现运行在某些机器上而不是其他异常缓慢。使用英特尔VTune,发现下面一行是问题(Fortran语言):

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 line was the problem (in Fortran):

RHOV= RHO_INF*((1.0_wp - COEFF*EXP(F0)))**(1.0_wp/(GAMM - 1.0_wp))

在VTune™可视化钻井,问题被曝呼叫POW 装配生产线和跟踪堆栈时,这表明它使用 __ slowpow( )。某些搜索,后此页面出现了抱怨同样的事情。

Drilling in with VTune, the problem was traced to the call pow assembly line and when tracing the stack, it showed it was using __slowpow(). After some searching, this page showed up complaining about the same thing.

在用的libc版本2.12的机器,仿真花了18秒。与libc的版本2.14计算机,模拟了0秒。

On the machine with libc version 2.12, the simulation took 18 seconds. On the machine with libc version 2.14, the simulation took 0 seconds.

根据上述页面上的信息,当基地 POW()已接近1.0的问题出现了。因此,我们做了另一种简单的测试,我们通过任意数量的 POW之前缩放所述基部()然后由<$ C $℃后升高到指数数除以> POW()电话。这种下降的运行时从18秒0秒用libc 2.12也。

Based on the information on the aforementioned page, the problem arises when the base to pow() is close to 1.0. So we did another simple test where we scaled the base by an arbitrary number before the pow() and then divided by the number raised to the exponent after the pow() call. This dropped the runtime from 18 seconds to 0 seconds with the libc 2.12 also.

然而,这是不切实际的,把这一切都在code其中我们做的 A ** b 。如何将一个去替换libc中的 POW()功能?举例来说,我想由Fortran编译器生成的流水线呼叫POW 来调用自定义的 POW()功能我们写,做缩放,调用的libc POW(),然后通过缩放分。怎样才能建立透明的编译器的中间层?

However, it's impractical to put this all over the code where we do a**b. How would one go about replacing the pow() function in libc? For instance, I would like the assembly line call pow generated by the Fortran compiler to call a custom pow() function we write that does the scaling, calls the libc pow() and then divides by the scaling. How does one create an intermediate layer transparent to the compiler?

修改

要澄清一下,我们正在寻找类似(伪code):

To clarify, we're looking for something like (pseudo-code):

double pow(a,b) {
   a *= 5.0
   tmp = pow_from_libc(a,b)
   return tmp/pow_from_libc(5.0, b)
}

是否有可能从libc中加载 POW ,它在我们的自定义函数重命名为避免命名冲突?如果 customPow.o 文件可能来自libc中重命名 POW ,如果仍然需要其他的东西libc中会发生什么?那会导致 customPow.o 之间的 POW 命名冲突和 POW 在libc中?

Is it possible to load the pow from libc and rename it in our custom function to avoid the naming conflicts? If the customPow.o file could rename pow from libc, what happens if libc is still needed for other things? Would that cause a naming conflict between pow in customPow.o and pow in libc?

推荐答案

只是写自己的 POW 功能,把的.o 静态库存档文件 libmypow.a 在链接的库路径的某处,并通过 -lmypow 链接时。

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.

这篇关于更换extrordinarily慢POW()函数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆