Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is Multi-Threaded algorithm required to make use of Multi-core processors?

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:

  • Muti-Threaded quick or merge sort in java
like image 856
Emil Avatar asked Oct 01 '10 06:10

Emil


3 Answers

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.)

like image 96
Jon Skeet Avatar answered Oct 26 '22 23:10

Jon Skeet


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.

like image 43
Babak Naffas Avatar answered Oct 27 '22 00:10

Babak Naffas


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.

like image 41
Statler Avatar answered Oct 26 '22 23:10

Statler