使用多核处理器是否需要多线程算法?
I was just wondering whether we actually need the algorithm to be muti-threaded if it must make use of the multi-core processors or will the jvm make use of multiple core's even-though our algorithm is sequential ?
UPDATE:
Related Question:
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
我不相信任何当前的生产 JVM 实现都可以执行自动多线程。他们可能会使用其他核心进行垃圾收集和其他一些内务处理,但如果您的代码是按顺序表达的,则很难自动并行化它并仍然保持精确的语义。
可能有一些实验/研究 JVM 尝试并行化 JIT 可能发现的令人尴尬的并行代码区域,但我还没有听说过生产系统有类似的情况。即使 JIT确实发现了这种情况,它也可能不如设计代码的并行性那么有效。 (按顺序编写代码,您很容易最终做出会无意中妨碍自动并行性的设计决策。)
I don't believe any current, production JVM implementations perform automatic multi-threading. They may use other cores for garbage collection and some other housekeeping, but if your code is expressed sequentially it's difficult to automatically parallelize it and still keep the precise semantics.
There may be some experimental/research JVMs which try to parallelize areas of code which the JIT can spot as being embarrassingly parallel, but I haven't heard of anything like that for production systems. Even if the JIT did spot this sort of thing, it would probably be less effective than designing your code for parallelism in the first place. (Writing the code sequentially, you could easily end up making design decisions which would hamper automatic parallelism unintentionally.)
您的实现需要是多线程的,以便利用您可以使用的多个核心。
您的系统作为一个整体可以为每个正在运行的应用程序或服务使用一个核心。不过,除非以其他方式实现,否则每个正在运行的应用程序都将在单个线程/核心上工作。
Your implementation needs to be multi-threaded in order to take advantage of the multiple cores at your disposal.
Your system as a whole can use a single core per running application or service. Each running application, though, will work off a single thread/core unless implemented otherwise.
Java 不会自动将你的程序分割成线程。目前,如果您希望代码能够同时在多个核心上运行,您需要通过线程或其他机制告诉计算机如何将代码拆分为任务以及程序中任务之间的依赖关系。但是,其他任务可以在其他内核上同时运行,因此如果您同时运行其他任务,您的程序在多核处理器上仍然可能运行得更快。
使当前代码可并行化的一个简单方法是使用 JOMP 并行化 for 循环和处理能力,增强代码中易于并行化的部分。
Java will not automatically split your program into threads. Currently, if you want you code to be able to run on multiple cores at once, you need to tell the computer through threads, or some other mechanism, how to split up the code into tasks and the dependencies between tasks in your program. However, other tasks can run concurrently on the other cores, so your program may still run faster on a multicore processor if you are running other things concurrently.
An easy way to make you current code parallizable is to use JOMP to parallelize for loops and processing power intensize, easily parellized parts of your code.
我认为使用多线程算法不会有效地利用多核处理器,除非为了有效性而进行编码。这是一篇不错的文章,讨论了开发人员如何使用多核处理器 -
http://java.dzone.com/news/building-multi-core-ready-java
I dont think using multi-threaded algorithm will make use of multi-core processors effectively unless coded for effectiveness. Here is a nice article which talks about making use of multi-core processors for developers -
http://java.dzone.com/news/building-multi-core-ready-java