calculation parallelization

L

Leonid

Hello,

Please help me with calculation parallelization. I have 2
processors DELL PRECISION 530 computer and I'd like
parallelize cycles like
for(int i = 0; i < last; ++i)
{
a = b + c;
}

I've read about '#pragma omp parallel for' instruction for
the future version of VC++(Visual C++ "Whidbey": Advanced
Code Generation ). What can I do with VC++6 and VC++ .NET
2003?

Regards

Leonid
 
M

Mihajlo Cvetanovic

Leonid said:
Please help me with calculation parallelization. I have 2
processors DELL PRECISION 530 computer and I'd like
parallelize cycles like
for(int i = 0; i < last; ++i)
{
a = b + c;
}


Just make two worker threads which would work on one half of your
data. One (and only) parameter of a worker thread should be pointer to
a struct embodying your input and output parameters, like:

class ThreadParams
{
public:
ThreadParams(int* o, int* i1, int* i2, size_t l) : output(o),
input1(i1), input2(i2), length(l) {}

int* output;
int* input1;
int* input2;
size_t length;
}

Worker thread function should look like this:

unsigned int __stdcall ThreadProc(void* pParam)
{
ThreadParams* pParams = reinterpret_cast<ThreadParams*>(pParam);
size_t i;

for (i = 0; i < pParams->length; ++i)
pParams->output = pParams->input1 + pParams->input2;

return 0;
}

You create non-MFC threads with _beginthreadex and MFC threads with
AfxBeginThread. ThreadParams class should be created on heap like this:

ThreadParams* pTp = new ThreadParams(a+last/2, b+last/2, c+last/2,
last/2);

Also consider the situation where <last> is odd number.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top