我正在实施卡汉求和 http://en.wikipedia.org/wiki/Kahan_summation_algorithm,在支持 gcc47、gcc48、clang33、icc13 和 icc14 编译的项目中。
作为该算法的一部分,我想禁用利用实数加法的关联性的优化。 (浮点运算不具有关联性。)
我想禁用这些优化仅在相关功能中。我已经弄清楚如何在 gcc 下执行此操作,使用''无联想数学'' https://gcc.gnu.org/onlinedocs/gcc/Optimize-Options.html#Optimize-Options属性。我怎样才能在 icc 或 clang 中做到这一点?我搜索过但没有运气。
class KahanSummation
{
// GCC declaration
void operator()(float observation) __attribute__((__optimize__("no-associative-math")))
{
// Kahan summation implementation
}
};
其他 GCC 属性意味着no-associative-math
are no-unsafe-math-optimizations
or no-fast-math
.
看着一个英特尔演示文稿(PDF,幻灯片 8) https://software.intel.com/sites/default/files/article/326703/fp-control-2012-08.pdf或其他或其他(PDF,幻灯片 11) http://www.nccs.nasa.gov/images/FloatingPoint_consistency.pdf,我想在ICC中设置“fp-model precision”,仅用于此功能。我关心的编译器是 ICC 13 和 ICC 14。
class KahanSummation
{
// ICC or clang declaration
void operator()(float observation) __attribute__((????))
{
// Kahan summation implementation
}
};
__attribute__
is a GCC extension. Clang also supports that syntax to maintain some GCC compatibility, but the only optimization-related attribute it seems to support is optnone http://clang.llvm.org/docs/AttributeReference.html#optnone-clang-optnone, which turns off all optimizations. ICC has a few optimization pragmas https://software.intel.com/sites/products/documentation/doclib/iss/2013/compiler/cpp-lin/GUID-346BAAA5-CF2D-4A26-9194-CA840BFB34E5.htm, but nothing that does what you want to do, from what I can tell. appears to support https://software.intel.com/sites/products/documentation/doclib/iss/2013/compiler/cpp-lin/GUID-0B88D6DE-D06F-4C57-A313-11291B202C39.htm #pragma float_control
for VC++ compatibility, although I can't find anything on exactly how that pragma is supposed to be used in ICC's documentation, so you'll have to use VC++ http://msdn.microsoft.com/en-us/library/45ec64h6.aspx's.
不过,您可以做的是在单独的翻译单元(即 cpp 文件)中定义所需的函数:
// Your header
class KahanSummation
{
// Declaration
void operator()(float observation);
};
// Separate cpp file - implements only this function
void KahanSummation::operator()(float observation)
{
// Kahan summation implementation
}
然后,您可以使用需要使用的任何编译器选项来编译单独的文件,并将生成的目标文件链接到程序的其余部分。
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)