PlummersSoftwareLLC / Primes

Prime Number Projects in C#/C++/Python
https://plummerssoftwarellc.github.io/PrimeView/
2.43k stars 574 forks source link

Lisp solution 2: multithreading, sbcl 2.3.4 #927

Closed surabax closed 1 year ago

surabax commented 1 year ago

Description

Implement multithreading for the Lisp solution 2 by mayerrobert, upgrade the compiler.

Before adding multithreading, using sbcl 2.3.4 on Windows 11, WSL2, Ubuntu 22.04, 13th Gen Intel(R) Core(TM) i9-13900 @ 2.00 GHz (max turbo frequency 5.6 GHz) I get:

$ sh run.sh 2> /dev/null
mayerrobert-cl;17652;5.000019;1;algorithm=base,faithful=yes,bits=1
mayerrobert-cl-modulo;12615;5.000081;1;algorithm=base,faithful=yes,bits=1
mayerrobert-cl-modulo-functions;20403;5.000057;1;algorithm=base,faithful=yes,bits=1
mayerrobert-cl-wheel-bitvector;51692;5.009988;1;algorithm=wheel,faithful=yes,bits=1
mayerrobert-cl-wheel-opt;40565;5.000033;1;algorithm=wheel,faithful=yes,bits=1
mayerrobert-cl-dense;30667;5.000027;1;algorithm=base,faithful=yes,bits=1
mayerrobert-cl-words;23425;5.009996;1;algorithm=other,faithful=yes,bits=1

After adding multithreading, I get:

$ sh run.sh 2> /dev/null
mayerrobert-YaroslavKhnygin-cl;169347;5.00212;32;algorithm=base,faithful=yes,bits=1 (~9.6x speedup)
mayerrobert-YaroslavKhnygin-cl-modulo;144798;5.009999;32;algorithm=base,faithful=yes,bits=1 (~11.5x speedup)
mayerrobert-YaroslavKhnygin-cl-modulo-functions;166947;5.01;32;algorithm=base,faithful=yes,bits=1 (~8.2x speedup)
mayerrobert-YaroslavKhnygin-cl-wheel-bitvector;263743;5.000134;32;algorithm=wheel,faithful=yes,bits=1 (~5.1x speedup)
mayerrobert-YaroslavKhnygin-cl-wheel-opt;230758;5.001088;32;algorithm=wheel,faithful=yes,bits=1 (~5.7x speedup)
mayerrobert-YaroslavKhnygin-cl-dense;194721;5.009873;32;algorithm=base,faithful=yes,bits=1 (~6.3x speedup)
mayerrobert-YaroslavKhnygin-cl-words;171292;5.009966;32;algorithm=other,faithful=yes,bits=1 (~7.3x speedup)

On Windows natively:

mayerrobert-cl;16877;5.000088;1;algorithm=base,faithful=yes,bits=1
mayerrobert-YaroslavKhnygin-cl;187182;5.001492;32;algorithm=base,faithful=yes,bits=1 (~11.1x speedup)
mayerrobert-cl-dense;30444;5.00008;1;algorithm=base,faithful=yes,bits=1
mayerrobert-YaroslavKhnygin-cl-dense;289691;5.000001;32;algorithm=base,faithful=yes,bits=1 (~9.5x speedup)
mayerrobert-cl-modulo;12751;5.000211;1;algorithm=base,faithful=yes,bits=1
mayerrobert-YaroslavKhnygin-cl-modulo;165283;5.000001;32;algorithm=base,faithful=yes,bits=1 (~13x speedup)
mayerrobert-cl-modulo-functions;20686;5.000219;1;algorithm=base,faithful=yes,bits=1
mayerrobert-YaroslavKhnygin-cl-modulo-functions;218102;5.000001;32;algorithm=base,faithful=yes,bits=1 (~10.5x speedup)
mayerrobert-cl-wheel-bitvector;49864;5.000063;1;algorithm=wheel,faithful=yes,bits=1
mayerrobert-YaroslavKhnygin-cl-wheel-bitvector;366041;5.000001;32;algorithm=wheel,faithful=yes,bits=1 (~7.3x speedup)
mayerrobert-cl-wheel-opt;37852;5.000091;1;algorithm=wheel,faithful=yes,bits=1
mayerrobert-YaroslavKhnygin-cl-wheel-opt;329089;5.000001;32;algorithm=wheel,faithful=yes,bits=1 (~8.7x speedup)
mayerrobert-cl-words;22622;5.000061;1;algorithm=other,faithful=yes,bits=1
mayerrobert-YaroslavKhnygin-cl-words;227452;5.003467;32;algorithm=other,faithful=yes,bits=1 (~10x speedup)

Contributing requirements

rbergen commented 1 year ago

@mayerrobert As this is an update to the solution you originally wrote, I was wondering if you'd like to lend your view on the proposed changes?

rbergen commented 1 year ago

@surabax I've compared the current and new version of the solution locally, and it seems the single-threaded implementations are slower after the update than they were before. The difference is not massive, but does seem to be consistent.

These are the results for the current solution (I've only included the drag-race format lines of output):

mayerrobert-cl;9598;5.000001;1;algorithm=base,faithful=yes,bits=1
mayerrobert-cl-hashdot;433692667;5.000002;1;algorithm=base,faithful=no,bits=1
mayerrobert-cl-modulo;4248;5.000004;1;algorithm=base,faithful=yes,bits=1
mayerrobert-cl-modulo-functions;5078;5.000014;1;algorithm=base,faithful=yes,bits=1
mayerrobert-cl-wheel-bitvector;15447;5.01;1;algorithm=wheel,faithful=yes,bits=1
mayerrobert-cl-wheel-opt;12120;5.01;1;algorithm=wheel,faithful=yes,bits=1
mayerrobert-cl-dense;17429;5.01;1;algorithm=base,faithful=yes,bits=1
mayerrobert-cl-words;11032;5.01;1;algorithm=other,faithful=yes,bits=1

The updated solution yields this output (again, drag-race output lines only):

mayerrobert-cl;9497;5.009999;1;algorithm=base,faithful=yes,bits=1
mayerrobert-cl-hashdot;397541690;5.01;1;algorithm=base,faithful=no,bits=1
mayerrobert-YaroslavKhnygin-cl;29822;5.019999;32;algorithm=base,faithful=yes,bits=1
mayerrobert-cl-modulo;4117;5.01;1;algorithm=base,faithful=yes,bits=1
mayerrobert-cl-modulo-functions;5024;5.01;1;algorithm=base,faithful=yes,bits=1
mayerrobert-YaroslavKhnygin-cl-modulo-functions;22662;5.04;32;algorithm=base,faithful=yes,bits=1
mayerrobert-YaroslavKhnygin-cl-modulo;19756;5.02;32;algorithm=base,faithful=yes,bits=1
mayerrobert-cl-wheel-bitvector;15214;5.01;1;algorithm=wheel,faithful=yes,bits=1
mayerrobert-YaroslavKhnygin-cl-wheel-bitvector;48912;5.02;32;algorithm=wheel,faithful=yes,bits=1
mayerrobert-cl-wheel-opt;11878;5.009999;1;algorithm=wheel,faithful=yes,bits=1
mayerrobert-YaroslavKhnygin-cl-wheel-opt;41823;5.039999;32;algorithm=wheel,faithful=yes,bits=1
mayerrobert-cl-dense;17375;5.01;1;algorithm=base,faithful=yes,bits=1
mayerrobert-YaroslavKhnygin-cl-dense;41511;5.03;32;algorithm=base,faithful=yes,bits=1
mayerrobert-cl-words;10525;5.01;1;algorithm=other,faithful=yes,bits=1
mayerrobert-YaroslavKhnygin-cl-words;35269;5.01;32;algorithm=other,faithful=yes,bits=1

I'm inclined to attribute this to the different base Docker image, which is the only change for the single-threaded solutions as far as I can tell. This being a drag-race, this represents a reason to not apply the base image change/compiler upgrade at this time.

What is your view on this?

surabax commented 1 year ago

@rbergen This makes sense, I'll remove the compiler upgrade as it was completely optional anyway.

rbergen commented 1 year ago

@surabax Thank you. With the only change that affects the existing implementations now reverted, I will proceed with merging.

Thank you for your contribution!

surabax commented 1 year ago

@rbergen Awesome, thank you!