对于长时间绘制密集粒子系统来说,什么是良好且安全的语言?
今天又问了一个比较模糊的问题,抱歉。
目前,我已经编写了一些还算不错的软件,它有一个“自己开发”的 RESTful 客户端,可以从 Twitter 中提取数据。然后使用 Open FrameWorks(与 C++ 配合使用的框架)通过多个粒子系统将这些数据可视化。
我的计划是在我的 VPS 上无限期地运行该软件,并构建某种前端 GUI,允许用户探索漂亮的粒子等等。在我使用的 JSON 库、C/C++、OpenFrameworks 和该死的 Xcode4 之间,我产生了太多需要处理的 SIGBIRT 和 GDB 错误。我已经走到虚拟世界的尽头来修复它们,并一遍又一遍地重写所有内容。我什至成功地对 openframeworks 画圆方法进行了 SIGBIRT,哈哈!
(TL;DR 从这里开始)好吧,无论如何,我从头开始,寻找一种强大的语言,可以处理数学并爆炸一组好的粒子,并且在最长的时间内运行得很好。现在我正在考虑 haskell,有什么想法吗?
预先感谢大家!
Another one of my rather ambiguous question today, sorry.
Currently I have written some half decent software that has a 'roll your own' RESTful client, which pulls data from twitter. This data is then visualized with a number of particle systems using Open FrameWorks (a framework that works with c++).
My plans for this were to run the software indefinitely on my VPS, and build some kind of front end GUI allowing users to explore the pretty particles and so on. Between the JSON library I am using, C/C++, OpenFrameworks, and freaking Xcode4 I have produced way too many SIGBIRT and GDB errors to care for. I have go to the ends of the virtual world to fix them, and re wrote everything over and over. I even managed to SIGBIRT the openframeworks draw circle method, HAH!
(TL;DR starts here) Ok so anyway I am starting from scratch, looking for a powerful language that can crunch maths and blast through a good set of particles, and run quite well over the longest periods of time. Right now I am thinking about haskell, any ideas?
Thanks in advance all!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
Haskell(或者更具体地说 GHC)的数字处理速度接近 C++,但稍微落后一些。不过,这当然并不可怕,Haskell 在并行性方面的优势可能会变得很重要。也就是说,如果您首先直接用 Haskell 编写它,那么很有可能很容易将其重构为现在或将来并行运行。但对于 C++ 来说却并非如此。
对于适合数字运算的数组来说,“向量”包(Hackage 上)将是一个不错的选择。它支持可变数组,以防需要这种方法。但是,如果您准备更深入地研究前沿并且您的算法可以并行化,您可能需要查看“repa”包,并且要在 GPU 上实现极致性能,请查看“Accelerate”(其中有效,但仍被归类为实验性)。
您提到的崩溃听起来可能表明您的问题有点复杂。 Haskell 擅长的地方在于管理……嗯,任何事物的复杂性。所以,如果问题很复杂,那么 Haskell 会很好地为你服务。
Haskell 中的外部函数接口设计得很好,尽管您需要在 Haskell 和 C++ 之间编写 C 胶水。所以,这是你处理数字的另一种选择。
对于 Web 界面,请查看“yesod”,它的开发非常活跃,并宣传自己采用 RESTful。
Haskell's (or more specifically GHC's) number crunching speed is approaching that of C++ but it's a little way behind. However, it's certainly not terrible, and Haskell's advantages in parallelism may become important. That is, if you write it in straight Haskell first, there's a good chance that it'll be easy to refactor it to run in parallel now or in the future. That isn't so true of C++.
The 'vector' package (on Hackage) would be a good choice for arrays suitable for number crunching. It supports mutable arrays in case that sort of approach is needed. However, if you're prepared to go more on the bleeding edge and your algorithm can be parallelized, you might want to look at the 'repa' package, and for extreme performance on a GPU, take a look at 'Accelerate' (which works but is still categorized as experimental).
The crashes you mention sound like they could be an indication of a bit of complexity in your problem. Where Haskell does well is in managing the complexity of... well, anything. So, if the problem is complex, then Haskell will serve you very well.
The foreign function interface in Haskell is well designed, though you will need to write C glue between Haskell and C++. So, that's another option for your number crunching.
For the web interface, take a look at 'yesod' which is seeing very active development and advertises itself as doing RESTful.
AFAIK,数字处理速度并不是 Haskell 的最强点——它是一种高度抽象的语言,远离“金属”;它在数字处理环境中的优势在于其语义的“数学性”——Haskell 代码通常读起来很像数学证明,并且它的许多概念都是从数学的各个领域借用的。
对于普通的旧式数字运算,C++ 可能仍然是您的最佳选择,因为它允许您靠近硬件并在机器级别优化紧密循环,同时提供更高级别的编程结构来管理复杂性。
OTOH,如果您有一个用于繁重工作的库,并且您只需要编写胶水即可使各个部分协同工作,那么请使用您最熟悉的任何内容 - python、C#、java、haskell、C++ ,... - 只要它们具有您所有库的绑定,就可以了。如果你没有库,那么你也可以考虑用 C 编写性能关键部分,然后将它们引入你最喜欢的高级语言 - 这在 C++ 中很简单,在 python 或 haskell 中稍微困难一些,而且非常糟糕java 不方便。
AFAIK, number crunching speed is not Haskell's strongest point - it's a highly abstract language, far from the 'metal'; its strength in a numeric processing context lies in the "mathiness" of its semantics - Haskell code often reads much like a Mathematical proof, and many of its concepts are borrowed from various fields of Mathematics.
For plain old number crunching, C++ is probably still your best choice, as it allows you to stay close to the hardware and optimize tight loops at the machine level, while offering higher-level programming constructs to manage complexity.
OTOH, if you have a library in place for the heavy lifting, and you merely need to write the glue to make the various parts work together, then go with whatever you're most comfortable with - python, C#, java, haskell, C++, ... - as long as they have bindings for all your libraries, you're good. If you don't have a library, then you might also consider writing the performance critical parts in C, and then pull them into your favorite high-level language - this is trivial in C++, slightly harder in python or haskell, and pretty damn inconvenient in java.