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

后端 未结 4 2136
长情又很酷
长情又很酷 2021-02-03 11:58

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 eve

4条回答
  •  無奈伤痛
    2021-02-03 12:37

    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.

提交回复
热议问题