| ResidentBiscuit (2214) | |
| So I've got a programming assignment that just multiplies two matrices together, and stores the result in a third. Supposed to be done using threads, but I have no idea how to start. I understand what a thread is, but I guess I just don't know how to actually use threads when programming. I've hit this wall in my head where I can't even comprehend what's supposed to happen. Any tips? | |
|
|
|
| naraku9333 (919) | |
|
Maybe have a thread that does the calculations for each column or row of the product matrix. Edit: Links... This has pseudo code http://stackoverflow.com/questions/5290190/matrix-multiplication-using-threads These have code http://www.daniweb.com/software-development/cpp/threads/386246/c-matrix-multiplication-with-threads http://www.cplusplus.com/forum/general/28599/ http://stackoverflow.com/questions/5290190/matrix-multiplication-using-threads NOTE: I do not know if any of the code in those links will work but either way they should get you in the right direction. | |
|
Last edited on
|
|
| codewalker (159) | |||
|
you can use pthreads or if you have a C++11 capable compiler (clang 3.1 later, gcc 4.7.1 later, Visual Studio 2012 etc) then you can use the built in threads of C++11 std. Here is how threads in C++11 are created
You need to #include<thread>. More information here http://en.cppreference.com/w/cpp/thread/thread If you need thread synchronisation (who doesn't?) then look at http://en.cppreference.com/w/cpp/thread/mutex | |||
|
|
|||
| Grey Wolf (3172) | |
|
ResidentBiscuit, this may be of use: https://computing.llnl.gov/tutorials/pthreads/ | |
|
|
|
| ResidentBiscuit (2214) | |
| Ah thanks these links are great! I understand what the program needs to get done, I was just having trouble of actually using the threads. We covered threads in theory but not with how they work at all. Didn't know that you created a thread and passed it a function to perform. Not really sure what I was thinking for how threads worked -_- | |
|
|
|
| iHutch105 (947) | |
| I've used the link that Grey Wolf provided for threading before. Absolute gold. | |
|
|
|