S
S
smite1072015-05-11 11:19:11
C++ / C#
smite107, 2015-05-11 11:19:11

How to parallelize a nested loop?

There is a code:

for (j = 1; j <= p; j++) {
  //Для всех индексов j = 1..p
  for (k = -q; k <= q; k++) {
    //и k = -q..q вычисляем значение свертки
    double sum = 0;
    for (i = -q; i <= q; i++) {
      //сумма по i = -q..q
      sum += (filterWb(k, i) * G[j - 1][i + q]);
    }
    V[j - 1][k + q] = h * sum;
  }
}

It needs to be parallelized using MPI. The idea itself is of interest - what and how to parallelize in this code. Help me please)

Answer the question

In order to leave comments, you need to log in

1 answer(s)
S
Stanislav Silin, 2015-05-11
@smite107

Poidei can parallelize the calculation of the sum. We divide the interval i...q into n parts and calculate n sums for these sections in different flows (optionally in n). Then we sum them up and continue the calculations further.
You can try to parallelize something else, but this part will be simpler, I think.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question