Java并行编程

发布于 2024-10-12 02:55:50 字数 168 浏览 4 评论 0原文

我需要在多核桌面上并行化 CPU 密集型 Java 应用程序,但我对线程编程不太熟悉。我研究了 Scala,但这意味着学习一门新语言,这确实很耗时。我还研究了 Ateji PX Java 并行扩展,它看起来很容易使用,但还没有机会评估它。有人会推荐吗?欢迎其他建议。

预先感谢您的帮助

比尔

I need to parallelize a CPU intensive Java application on my multicore desktop but I am not so comfortable with threads programming. I looked at Scala but this would imply learning a new language which is really time consuming. I also looked at Ateji PX Java parallel extensions which seem very easy to use but did not have a chance yet to evaluate it. Would anyone recommend it? Other suggestions welcome.

Thanks in advance for your help

Bill

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(5

奈何桥上唱咆哮 2024-10-19 02:55:50

我建议您尝试使用内置的 ExecutorService 在多个线程/核心之间分配多个任务。您是否有任何这可能不适合您的要求?

I would suggest you try the built-in ExecutorService for distributing multiple tasks across multiple threads/cores. Do you have any requirements which this might not do for you?

魂ガ小子 2024-10-19 02:55:50

Java 并发实用程序:

http://download.oracle。 com/javase/1.5.0/docs/guide/concurrency/overview.html

使 Java 上的并行编程变得比以前更加容易。我建议从这里开始 - 如果您对使用线程的这种级别感到不舒服,我会三思而后行。并行化任何东西都需要一定程度的技术能力,了解并发计算的完成和协调方式。在我看来,没有比这个框架更容易的了——这就是为什么你看到的替代方案如此之少的部分原因。

其次,您应该考虑的主要问题是并行化的工作单元是什么。如果您的工作单元是独立的(即每个并行任务不影响其他任务),那么这通常要容易得多,因为您根本不需要担心太多(或任何)同步。努力思考如何对问题进行建模,以便计算尽可能独立。如果你建模得好,你几乎肯定会减少代码行数(从而减少错误等)。

诚然,为您自动并行化的框架不太容易出错,但如果您的模型工作单元不符合其并行化方案,则可能不是最佳的。

The Java concurrency utilites:

http://download.oracle.com/javase/1.5.0/docs/guide/concurrency/overview.html

make parallel programming on Java even easier than it already was. I would suggest starting there - if you are uncomfortable with that level of working with threads, I would think twice about proceeding further. Parallelizing anything requires some level of technical comfort with how concurrent computation is done and coordinated. In my opinion, it can't get much easier than that framework - which is part of the reason why you see so few alternatives.

Second, the main thing you should think about is what the unit of work is for parallelization. If your unit of work is independent (i.e., each parallel task does not impact the others), this is generally far easier because you don't need to worry about much (or any) synchronization at all. Put effort into thinking how to model the problem so that computation is as independent as possible. If you model it well, you will almost certainly reduce the lines of code (which reduces the error, etc).

Admittedly, frameworks that automatically parallelize for you are less error prone, but can be suboptimal if your model unit of work doesn't play to their parallelization scheme.

澜川若宁 2024-10-19 02:55:50

我是 Ateji PX 的首席开发人员。正如您提到的,保证线程安全是一个重要的话题。这也是一个非常困难的问题,除了手写和手工检查的 @ThreadSafe 注释之外,没有太多帮助。请参见“线程问题”。

我们目前正在为 Ateji PX 开发并行验证器。这之所以成为可能,是因为 Ateji PX 中的并行性是组合性的(与线程不同),并且基于可靠的数学基础,即 pi 演算。即使没有工具,经验表明,以直观和组合的方式表达并行性使得“并行思考”和更早发现错误变得更加容易。

I am the lead developer of Ateji PX. As you mention, guaranteeing thread safety is an important topic. It is also a very difficult one, and there's not much help out there beside hand-written and hand-checked @ThreadSafe annotations. See e.g. "The problem with threads".

We are currently working on a parallel verifier for Ateji PX. This has become possible because parallelism in Ateji PX is compositional (unlike threads) and based on a sound mathematical foundation, namely pi-calculus. Even without a tool, experience shows that expressing parallelism in an intuitive and compositional way makes it much easier to "think parallel" and catch errors earlier.

云裳 2024-10-19 02:55:50

我快速浏览了 Ateji PX 网站。似乎是一个不错的产品,但我担心您在某些时候会感到失望,因为 Ateji PX 只为您提供了一种执行高级并行操作(例如将工作负载分配给多个工作人员)的直观简单方法、在并行任务之间创建集合点等。但是,正如您可以在常见问题解答部分中阅读的如何检测和防止数据依赖? Ateji PX 不确保底层代码是线程安全的。因此无论如何,您仍然需要 Java 线程编程技能。

编辑:

还要考虑到,当维护时间到来而您无法执行维护时,找到具有标准 Java 多线程编程技能的承包商、员工或实习生会比找到具有标准 Java 多线程编程技能的承包商、员工或实习生更容易。阿特吉 PX。

最后一句话,有 30 天免费评估,试试吧。

I browsed quickly through the Ateji PX web site. Seems to be a nice product but I'm afraid you will be disappointed at some point since Ateji PX only provides you an intuitive simple way of performing high level parallel operations such as distributing the work load on several workers, creating rendez-vous points between parallel tasks, etc. However as you can read in the FAQ in the section How do you detect and prevent data dependencies? Ateji PX does not ensure that the underlying code is thread safe. So at any rate you'll still be needing skills in Java thread programming.

Edit:

Also consider that when maintenance time will come and you won't be available to perform it, it'll be easier to find a contractor, employee or trainee with skills in standard Java multithread programming than in Ateji PX.

Last word, there's a free 30 days evaluation, try it.

妥活 2024-10-19 02:55:50

别担心,java 7 即将推出 Doug lea 的 Fork Join 来进行分布式处理。

Dont worry java 7 is coming up with Fork Join by Doug lea for Distributed Processing.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文