calculation parallelization

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Leonid

    #1

    calculation parallelization

    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[i] = b[i] + c[i];
    }

    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

  • Mihajlo Cvetanovic

    #2
    Re: calculation parallelization

    Leonid wrote:[color=blue]
    > 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[i] = b[i] + c[i];
    > }[/color]

    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(in t* 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_cas t<ThreadParams* >(pParam);
    size_t i;

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

    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.

    Comment

    Working...