gajendra-iitm / starplat

0 stars 5 forks source link

Static PageRankDSLV3 compilation error #8

Open RohanK22 opened 3 months ago

RohanK22 commented 3 months ago

PageRankDSLV3 Code (Static):

function ComputePageRank(Graph g, float beta, float delta, int maxIter, propNode<float> pageRank) {
    float numNodes = g.num_nodes();
    propNode<float> pageRankNext;
    g.attachNodeProperty(pageRank = 1 / numNodes, pageRankNext = 0);
    int iterCount = 0;
    float diff = 0.0;
    do {
        forall(v in g.nodes()) {
            float sum = 0.0;
            for (nbr in g.nodes_to(v)) {
                sum = sum + nbr.pageRank / g.count_outNbrs(nbr);
            }
            float newPageRank = (1 - delta) / numNodes + delta * sum;
            if(newPageRank - v.pageRank >= 0) {
                diff += newPageRank - v.pageRank;
            } else {
                diff += v.pageRank - newPageRank;
            }
            v.pageRankNext = newPageRank;
        }
        pageRank = pageRankNext;
        iterCount++;
    } while ((diff > beta) && (iterCount < maxIter));
}

Generated MPI Code that contains duplicate declaration of variable (diff_temp):

#include"PageRankDSLV3.h"

void ComputePageRank(Graph& g, float beta, float delta, int maxIter, 
  NodeProperty<float>& pageRank, boost::mpi::communicator world )
{
  float numNodes = (float)g.num_nodes( );
  NodeProperty<float> pageRankNext;
  pageRank.attachToGraph(&g, (float)1 / numNodes);
  pageRankNext.attachToGraph(&g, (float)0);
  int iterCount = 0;
  float diff = 0.000000;
  do
  {
    world.barrier();
    for (int v = g.start_node(); v <= g.end_node(); v ++) 
    {
      float sum = 0.000000;
      for (int nbr : g.getInNeighbors(v)) 
      {
        sum = sum + pageRank.getValue(nbr) / g.num_out_nbrs(nbr);
      }

      float newPageRank = (1 - delta) / numNodes + delta * sum;
      if (newPageRank - pageRank.getValue(v) >= 0 )
      {
        diff = ( diff + newPageRank - pageRank.getValue(v)) ;
      }
      else
      {
        diff = ( diff + pageRank.getValue(v) - newPageRank) ;
      }
      pageRankNext.setValue(v,newPageRank);
    }
    world.barrier();

    float diff_temp = diff;
    MPI_Allreduce(&diff_temp,&diff,1,MPI_FLOAT,MPI_SUM,MPI_COMM_WORLD);
    float diff_temp = diff;
    MPI_Allreduce(&diff_temp,&diff,1,MPI_FLOAT,MPI_SUM,MPI_COMM_WORLD);

    pageRank = pageRankNext;
    iterCount++;
  }
  while((diff > beta) && (iterCount < maxIter));
}
durwasa-chakraborty commented 3 months ago

Logical Consistency

The following two DSL snippets are logically the same:

if(newPageRank - v.pageRank >= 0) {
    diff = newPageRank - v.pageRank + diff;
} else {
    diff = v.pageRank - newPageRank + diff;
}

and

if(newPageRank - v.pageRank >= 0) {
    diff += newPageRank - v.pageRank;
} else {
    diff += v.pageRank - newPageRank;
}

Both snippets update diff by adding the absolute difference between newPageRank and v.pageRank.

Current Workaround

To avoid this issue, we have been using the following workaround:

float newPageRank = (1 - delta) / numNodes + delta * sum;
if (newPageRank - v.pageRank >= 0) {
    diff_temp = newPageRank - v.pageRank + diff;
} else {
    diff_temp = v.pageRank - newPageRank + diff;
}
diff = diff_temp;

With this workaround, the double declaration does not occur.

Proposed Solution

To ensure correct behavior and eliminate redundant declarations, we need to address the root cause of the problem: the unary operator conversion in our DSL. The DSL should support language constructs that handle unary operations properly.