c++真正的大浮点计算
我想做非常大的浮点计算。应该足够快。
如果有图形处理器,我该如何使用?如果没有可用的 GPU,那么我想使用主 CPU。
谢谢
I want to do really large floating point calculations. Should be fast enough.
How can I make use of Graphics processors if available? If not GPU available then I would like to use main CPU.
thanks
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
根据这些数字的“大小”,您可以尝试 MPFR,虽然它不是 GPU 解决方案,但它可以处理大数字并且应该相对较快,一些开源编译器(GCC 和 LLVM)使用它来进行静态常量折叠,因此它的设计是为了保持准确性。
要在 GPU(实际上是 GPGPU)上工作,您需要使用以下代码编写内核像 OpenCL 或 DirectCompute,并在其中进行数字运算。
您可能还对英特尔新的 AVX 扩展感兴趣。
Depending on the 'size' of these numbers, you can try MPFR, although its not a GPU solution, it can handle big numbers and should be relitively fast, its used by a few opensource compilers(GCC & LLVM) to do static constant folding, so its designed to preserve accuracy.
To do work on a GPU (really a GPGPU), you'd need to write a kernel using soemthing like OpenCL or DirectCompute, and do your number crunching in that.
You may also be interested in intels new AVX extensions as well.
浮点计算可以处理非常大的数字、非常小的数字以及介于两者之间的数字。问题是有效数字的数量是有限的,并且不完全符合基数 2 表示的数字(类似于 1/3 或 1/7 的数字)在转换为最接近的基数 2 时会遇到错误同行。
如果 GPU 可用(几乎所有带视频的计算机都有 GPU),那么像 GPGPU 这样的库应该可以帮助您访问它,而无需编写大量汇编语言。也就是说,在您确定您的计算将涉及与 GPU 已经执行的操作类似的操作之前,您最好避免使用 GPU,因为它们非常适合做它们已经做的事情,但不擅长适应其他任何事情。
Floating point calculations can handle very large numbers, very small numbers, and numbers somewhere in-between. The problem is that the number of significant digits is limited, and and number that doesn't perfectly fit in a base two representation (numbers similar to 1/3 or 1/7) will experience errors as they are translated into their closest base 2 counterparts.
If a GPU is available, as one is in nearly all computers with video, then a libarary like GPGPU should help you access it without writing tons of assembly language. That said, until you are sure your computations will involve operations that are similar to those already performed by a GPU, you would be better off avoiding the GPU as they are excellent for doing what they already do, and poor at being adaptable to anything else.