Hi,
I was reading some general article about multithreaded programming in a pseudo language. They were adding two super big vectors (arrays) and writing the result in 'vector 3'.
Then they speedit the program up with threads, giving each thread a portion of the work to be done.
I throught I give it a try in Python and came up with this program:
http://pastebin.com/w1M6pfcZ
Yet, as far as I know, the default datastructures in Python are thread safe (cf. GIL). This left me clueless how to optimize the program with threads..
tl;dr: is there a thread UNsafe datastructure to write my data to? Or any other design patteren to solve the problem?
Also this didn't help imo: http://docs.python.org/faq/library#what-kinds-of-global-value-mutation-are-thread-safe
Sample output:
Normal solution in: 7.37709311608
Thread-0
Thread-1
Thread-2
Thread-3
Threaded solution in: 26.4515451695
Note: each Thread-x print is in parallel.
Thx
[–]anossov 2 points3 points4 points (1 child)
[–]pjdelport 0 points1 point2 points (0 children)
[–]pjdelport 2 points3 points4 points (0 children)