C++: Simple Code Parallelization, one thread per core.
$30-5000 USD
Concluído
Publicado há aproximadamente 14 anos
$30-5000 USD
Pago na entrega
I have a function: int MyFunc(void *Data, const int &DataNum) in C++.
I'd like to run the function many times, with DataNum ranging from 0...N-1.
I'd like to run one function on each core, presumably on its own thread. When one function finishes, I'd like the next one to start.
Typically, I have a multi-core processor with, say M cores, where M is typically about 4. Typically, I have N pieces of data, where N typically ranges from 2 to 12. (Sometimes I have more cores than data!)
I'm looking for a class with a static function. Something like this:
class SpawnFunctionOnProcessorCores() {
public:
static std::vector<int> SpawnAndWait(
int (*Command)(void *, const int &i),
void *Data,
const int &MinNum, const int &MaxNum,
const DWORD &TimeToWaitInMilliSeconds);
}
I'll be using Visual Studio 2008 on Windows. The return is the vector of results from the functions.
Also, please give me a simple test program to show the function is working.
## Deliverables
You can do this program pretty much any way you want.
My understanding is that there are some open-source multi-core commands support by Visual Studio. If you use them, great. If not, no problem.
Also, I have a class called SpawnThread, which currently spawns a bunch of threads at once. Presumably, all you need to do is figure out the number of processors on the computer, and add a thread affinity. (You might also need to know when a thread ends, so that you can spawn the next one.) If it will be helpful to you, I can share the class with you. But, I suspect you want to write your own thing.