简体   繁体   中英

Efficiency of sequential algorithm executed on machine with 60Gb RAM

Will sequential algorithm written in Java execute faster (in Eclipse) on a machine with 60Gb RAM and 16 cores, if compared to a dual-core machine with 16Gb RAM? I expected that the algorithm would really run faster, but experiments on a Google Compute Engine and my laptop showed that it's not a truth. I appreciate if someone could explain why this happens.

Java doesn't parallize the code automatically for you, you need to do it yourself.

There are some abstractions that like parallel streams that give you concise parallelism, but still, the performance of your program is governed by Amdahl's law . Having more memory will help in launching more threads and applying parallel algorithms for leveraging more cores.

Example:

  • Arrays.sort is a sequential Dual-Pivot Quicksort that runs in O(nlgn) time, its overall performance governed by the clock rate.

  • Arrays.parallelSort is parallel merge-sort, it uses more space ( so here memory is important ), it divided the array into pieces and sort each piece and merge them.

But, someone had to write this parallel sort in order to benefit from multicores machines.

What could be done automatically for you, is a highly concurrent and parallel GC that effects the overall performance of your program.

You are asking for sequential algorithm , which clearly means there are no multiple threads, no parallelism or multi-processing involved in the execution of the code. Lets say, the code is:

a = 5;
b = a + 5;
c = b + 5;
...
and so on...

We cannot execute any of the latter lines because of their dependency on the former values.

A simple loop,

for i from 1 to 100 increment 1
    a = a + i

will have to be executed 100 times, in order, as that would create a difference in result, and hence cannot be parallelized.

Also, since you are not using threads in your code, java has no support for parallelism inbuilt, so there go your chances even if the code was a bit parallelizable.

If it's a single threaded piece of code, the system it will run on has some influence on the execution time. This is measured by the IPC

https://en.wikipedia.org/wiki/Instructions_per_cycle

You code will definitely run faster on a newer system than a 10 year old, but maybe the difference between the two machines you mentioned for 1 thread are not significant enough.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM