I have a simple problem comparing all elements with each other. The comparison itself is symmetrical, so it does not need to be done twice.
The following code example shows what I'm looking for, showing the indices of the available elements:
int n = 5; for (int i = 0; i < n; i++) { for (int j = i + 1; j < n; j++) { printf("%d %d\n", i,j); } }
Output:
0 1 0 2 0 3 0 4 1 2 1 3 1 4 2 3 2 4 3 4
So, each element is compared with each other once. When I want to parallelize this code, I have a problem that first of all I have to stick to dynamic planning, because the calculation time of each iteration varies greatly. And I cannot use collapse due to the fact that nested iterations are indices, dependent on the outer loop.
Using #pragma omp parallel for schedule(dynamic, 3) for the outer loop can lead to single-core executions at the end, while using this for the inner loop can lead to such execution in every iteration of the outer loop.
Is there a more complicated way to do this / parallelize it?
source share