Onotate / IHPCSS_challenges

Self-attempt solutions to IHPCSS challenges of different years
1 stars 0 forks source link

OpenMP - Each loop in a parallel directive #4

Open pedramhaqiqi opened 2 months ago

pedramhaqiqi commented 2 months ago

By putting each loop of the iterations in a simple pragma omp for with no shared parallel region and performing reductions on diff and page_rank_total achieves a 2.5x speed up from baseline.

Precompute section (Gains about 50 iterations on avg)

#pragma omp parallel for
    for (int i = 0; i < GRAPH_ORDER; i++)
        for (int k = 0; k < GRAPH_ORDER; k++)
            if (adjacency_matrix[i][k] == 1) outdegrees[i]++;

Main page rank computation

#pragma omp parallel for
  for (int i = 0; i < GRAPH_ORDER; i++)
      for (int j = 0; j < GRAPH_ORDER; j++)
          if (adjacency_matrix[j][i] == 1)
              new_pagerank[i] += pagerank[j] / (double)outdegrees[j];    

Setting new page rank

#pragma omp parallel for
  for(int i = 0; i < GRAPH_ORDER; i++)
  {
      new_pagerank[i] = DAMPING_FACTOR * new_pagerank[i] + damping_value;
  }

Reduction for diff

diff = 0.0;
#pragma omp parallel for reduction(+:diff)
for(int i = 0; i < GRAPH_ORDER; i++)
{
    diff += fabs(new_pagerank[i] - pagerank[i]);
}

Reduction for page rank

double pagerank_total = 0.0;
  #pragma omp parallel for reduction(+:pagerank_total)
  for(int i = 0; i < GRAPH_ORDER; i++)
  {
      pagerank_total += pagerank[i];
  }
pedramhaqiqi commented 2 months ago

Removing the reductions, to be done serially, given that we are not in a parallel region: 3.0x

Onotate commented 2 months ago

We should specify the shared/private property of the used variables instead of letting OMP decide the default. Can you try adding that?