I have this function, which basicly is creating a list of primes from 0-2^32-1, however im not sure it works correctly, so im testing it right now. However, as you might imagine, this is gonna take some time and then i thought: "hey, i have two cores! In theory i could double the speed!" The calculations allows it, but finding resources on the matter has proved more difficult than expected, so if someone could just give me a little tiny push in the right direction, i would be forever gratefull.
Regards
multi core programming (C++)
multi core programming (C++)
This was supposed to be a cool signature...
- AndrewAPrice
- Member
- Posts: 2299
- Joined: Mon Jun 05, 2006 11:00 pm
- Location: USA (and Australia)
You need to split the function into two and know which parts you want to run on either processor, which might be hard if you don't know how the function works.
On Windows you create a 2nd thread (http://www.codersource.net/win32_multithreading.html). Normally Windows will take care of distributing threads across processors. But you can manually chose which cores to use (Google "processor affinity").
On Unix, I'm not sure how multi-threading works, but you could try forking the process (simple with fork() ) and compare the old/new PID to see if you're in the new process or not, then set up a pipe between the two programs to share results. The Window's way seems easier (I'm sure Unix has threads but I don't know how they work, sorry).
On Windows you create a 2nd thread (http://www.codersource.net/win32_multithreading.html). Normally Windows will take care of distributing threads across processors. But you can manually chose which cores to use (Google "processor affinity").
On Unix, I'm not sure how multi-threading works, but you could try forking the process (simple with fork() ) and compare the old/new PID to see if you're in the new process or not, then set up a pipe between the two programs to share results. The Window's way seems easier (I'm sure Unix has threads but I don't know how they work, sorry).
My OS is Perception.
- Colonel Kernel
- Member
- Posts: 1437
- Joined: Tue Oct 17, 2006 6:06 pm
- Location: Vancouver, BC, Canada
- Contact:
Most modern *nixes support the pthreads (POSIX threads) library.
Top three reasons why my OS project died:
- Too much overtime at work
- Got married
- My brain got stuck in an infinite loop while trying to design the memory manager