Geekzone: technology news, blogs, forums
Guest
Welcome Guest.
You haven't logged in yet. If you don't have an account you can register now.


JaseNZ

2576 posts

Uber Geek
+1 received by user: 1489

ID Verified
Lifetime subscriber

#281236 6-Feb-2021 19:38
Send private message

So was mucking around today so thought I would try this out as came across it.

 

If you are able and know how to run this python script and see what the outcome is.

 

Its currently set to getting prime numbers within the first 200k

 

Here is my result on my unraid server AMD 3900X

 

root@6cd0543b9bc2:/# python3 prime2.py
Find all primes up to: 200000 using 96 processes.
Time elapsed: 72.67 seconds
Number of primes found 17984

 

import multiprocessing as mp
import time

 

#max number to look up to
max_number = 200000
#four processes per cpu
num_processes = mp.cpu_count() * 4

 

def chunks(seq, chunks):
        size = len(seq)
        start = 0
        for i in range(1, chunks + 1):
            stop = i * size // chunks
            yield seq[start:stop]
            start = stop

 

def calc_primes(numbers):
    num_primes = 0
    primes = []

 

    #Loop through each number, then through the factors to identify prime numbers
    for candidate_number in numbers:
        found_prime = True
        for div_number in range(2, candidate_number):
            if candidate_number % div_number == 0:
                found_prime = False
                break
        if found_prime:
            primes.append(candidate_number)
            num_primes += 1
    return  num_primes

 

def main():
    #Record the test start time
    start = time.time()
    pool = mp.Pool(num_processes)
    #0 and 1 are not primes
    parts = chunks(range(2, max_number, 1), num_processes)
    #run the calculation
    results = pool.map(calc_primes, parts)
    total_primes = sum(results)
    pool.close()
    #Once all numbers have been searched, stop the timer
    end = round(time.time() - start, 2)
    #Display the results, uncomment the last to list the prime numbers found
    print('Find all primes up to: ' + str(max_number) + ' using ' + str(num_processes) + ' processes.')
    print('Time elapsed: ' + str(end) + ' seconds')
    print('Number of primes found ' + str(total_primes))
if __name__ == "__main__":
    main()





Ding Ding Ding Ding Ding : Ice cream man , Ice cream man


View this topic in a long page with up to 500 replies per page Create new topic
 1 | 2 | 3
Rust
110 posts

Master Geek
+1 received by user: 105

ID Verified

  #2648818 6-Feb-2021 21:00
Send private message

Find all primes up to: 200000 using 32 processes.
Time elapsed: 83.59 seconds
Number of primes found 17984

 

 

 

4 year old laptop. A full 11 seconds longer than your results.

 

Note that this is a VERY inefficient algorithm for finding primes.

 

 




JaseNZ

2576 posts

Uber Geek
+1 received by user: 1489

ID Verified
Lifetime subscriber

  #2648823 6-Feb-2021 21:34
Send private message

Rust:

 

Find all primes up to: 200000 using 32 processes.
Time elapsed: 83.59 seconds
Number of primes found 17984

 

 

 

4 year old laptop. A full 11 seconds longer than your results.

 

Note that this is a VERY inefficient algorithm for finding primes.

 

 

 

 

Yup very very true but its not about being efficient its about taxing the system :-) 





Ding Ding Ding Ding Ding : Ice cream man , Ice cream man


timmmay
20859 posts

Uber Geek
+1 received by user: 5350

Trusted
Lifetime subscriber

  #2648825 6-Feb-2021 21:37
Send private message

Ryzen 5600X, Python 3.9. Program only used 16% of CPU but my fan worked at full speed and CPU got up to 75 degrees - which is pretty warm for this cooler (dark rock pro 4 with two towers and 2 fans)

 

> python test.py
Find all primes up to: 200000 using 48 processes.
Time elapsed: 45.35 seconds
Number of primes found 17984

 

Look like the 5600X is a fair bit faster than the 3900X.




JaseNZ

2576 posts

Uber Geek
+1 received by user: 1489

ID Verified
Lifetime subscriber

  #2648831 6-Feb-2021 21:45
Send private message

timmmay:

 

Ryzen 5600X, Python 3.9. Program only used 16% of CPU but my fan worked at full speed and CPU got up to 75 degrees - which is pretty warm for this cooler (dark rock pro 4 with two towers and 2 fans)

 

> python test.py
Find all primes up to: 200000 using 48 processes.
Time elapsed: 45.35 seconds
Number of primes found 17984

 

Look like the 5600X is a fair bit faster than the 3900X.

 

 

Nice yeah that is interesting , Gotta love the future of cpu's as they progress. 

 

Coming from the 286 days I am always amazed at how things have progressed over the past 35 years.

 

I still want my hover car though wheres my hover car.





Ding Ding Ding Ding Ding : Ice cream man , Ice cream man


timmmay
20859 posts

Uber Geek
+1 received by user: 5350

Trusted
Lifetime subscriber

  #2648832 6-Feb-2021 21:49
Send private message

JaseNZ:

 

Nice yeah that is interesting , Gotta love the future of cpu's as they progress. 

 

Coming from the 286 days I am always amazed at how things have progressed over the past 35 years.

 

I still want my hover car though wheres my hover car.

 

 

Yeah, my first computer at uni (other than the Amstrad at school) was a 486, the Pentiums played Doom much better.


DimasikTurbo
93 posts

Master Geek
+1 received by user: 28

ID Verified

  #2648837 6-Feb-2021 22:00
Send private message

There is a bug in the posted code. This line in main:

 

parts = chunks(range(2, max_number, 1), 1)

 

should be

 

parts = chunks(range(2, max_number, 1), num_processes)

 

Current code does not split anything into chunks and it tests performance of single core. Fixed version of the code executed on i9-9900K:

 

[dadoc@dadoc-desktop:~/tmp] $python prime2.py
Find all primes up to: 200000 using 64 processes.
Time elapsed: 8.9 seconds
Number of primes found 17984


HP

 
 
 
 

Shop now for HP laptops and other devices (affiliate link).
JaseNZ

2576 posts

Uber Geek
+1 received by user: 1489

ID Verified
Lifetime subscriber

  #2648839 6-Feb-2021 22:07
Send private message

DimasikTurbo:

 

There is a bug in the posted code. This line in main:

 

parts = chunks(range(2, max_number, 1), 1)

 

should be

 

parts = chunks(range(2, max_number, 1), num_processes)

 

Current code does not split anything into chunks and it tests performance of single core. Fixed version of the code executed on i9-9900K:

 

[dadoc@dadoc-desktop:~/tmp] $python prime2.py
Find all primes up to: 200000 using 64 processes.
Time elapsed: 8.9 seconds
Number of primes found 17984

 

 

Good spotting I did not debug it when grabbing it. Results indeed on all theads make a difference.

 

Find all primes up to: 200000 using 96 processes.
Time elasped: 5.71 seconds
Number of primes found 17984

 

@timmmay what is your result now.

 

Edit: If a mod sees this could you please change the code in the original post to include the fix.





Ding Ding Ding Ding Ding : Ice cream man , Ice cream man


MaxineN
Max
2056 posts

Uber Geek
+1 received by user: 1675

ID Verified
Trusted
Subscriber

  #2648849 6-Feb-2021 22:47
Send private message

[tohru@tohru ~]$ python3 pythonscript.py

 

Find all primes up to: 200000 using 32 processes.

 

Time elapsed: 21.32 seconds.

 

Number of primes found 17984

 

 

 

On an i7 6700.





Ramblings from a mysterious lady who's into tech. Warning I may often create zingers.


Talkiet
4819 posts

Uber Geek
+1 received by user: 3934

Trusted

  #2648855 6-Feb-2021 23:05
Send private message

Find all primes up to: 200000 using 96 processes.
Time elapsed: 6.06 seconds
Number of primes found 17984

 

on my 7 year old Dell.

 

Cheers - N

 

 





Please note all comments are from my own brain and don't necessarily represent the position or opinions of my employer, previous employers, colleagues, friends or pets.


michaelmurfy
meow
13581 posts

Uber Geek
+1 received by user: 10914

Moderator
ID Verified
Trusted
Lifetime subscriber

  #2648861 7-Feb-2021 02:39
Send private message

Just fixed the OP.

 

Find all primes up to: 200000 using 64 processes.
Time elapsed: 5.76 seconds
Number of primes found 17984

 

This is on my (overclocked) Ryzen 7 3800X.





Michael Murphy | https://murfy.nz
Referral Links: Quic Broadband (use R122101E7CV7Q for free setup)

Are you happy with what you get from Geekzone? Please consider supporting us by subscribing.
Opinions are my own and not the views of my employer.


timmmay
20859 posts

Uber Geek
+1 received by user: 5350

Trusted
Lifetime subscriber

  #2648863 7-Feb-2021 07:05
Send private message

Updated script. Looks like the number of cores is the determining factor now, the 5600X is fast per core but has fewer cores than some processors. I got this one because I don't need too many cores, but fast cores :)

 

python test.py
Find all primes up to: 200000 using 48 processes.
Time elapsed: 8.89 seconds
Number of primes found 17984


 
 
 
 

Shop now for Dell laptops and other devices (affiliate link).
zenourn
281 posts

Ultimate Geek
+1 received by user: 168

ID Verified
Trusted
DR

  #2648877 7-Feb-2021 09:24
Send private message

Stock Ryzen 5900x:

 

Find all primes up to: 200000 using 96 processes.
Time elapsed: 4.81 seconds
Number of primes found 17984


KiwiSurfer
1725 posts

Uber Geek
+1 received by user: 994

ID Verified
Lifetime subscriber

  #2648879 7-Feb-2021 09:27
Send private message

Find all primes up to: 200000 using 16 processes.
Time elapsed: 136.66 seconds
Number of primes found 17984

 

On my Lenovo Carbon X1 5th gen.


zenourn
281 posts

Ultimate Geek
+1 received by user: 168

ID Verified
Trusted
DR

  #2648882 7-Feb-2021 09:36
Send private message

Dual EPYC 7452 CPU (64 cores total)

 

Find all primes up to: 200000 using 64 processes.
Time elapsed: 4.57 seconds
Number of primes found 17984

 

Find all primes up to: 200000 using 128 processes.
Time elapsed: 3.13 seconds
Number of primes found 17984

 

I suspect this isn't the best of benchmarks. 


SirHumphreyAppleby
2942 posts

Uber Geek
+1 received by user: 1863


  #2648898 7-Feb-2021 10:57
Send private message

Find all primes up to: 200000 using 16 processes.
Time elapsed: 21.59 seconds
Number of primes found 17984

 

i7 7700k.

 

EDIT: Removed comparison with i7 6700 as that was probably done using the buggy version.


 1 | 2 | 3
View this topic in a long page with up to 500 replies per page Create new topic








Geekzone Live »

Try automatic live updates from Geekzone directly in your browser, without refreshing the page, with Geekzone Live now.



Are you subscribed to our RSS feed? You can download the latest headlines and summaries from our stories directly to your computer or smartphone by using a feed reader.