void run_pagerank(const char* filename, int nthreads) {

  Graph<PR> G;
  PageRank pr;
  Degree<PR> dg;

 
  G.ReadMTX(filename, nthreads*4); //nthread pieces of matrix

  auto dg_tmp = graph_program_init(dg, G);

  #ifdef PROFILE
  std::ofstream outputFile;
  outputFile.open("./.ready");
  outputFile.close();
  printf("continue? \n");
  int i = getchar();
  #endif

  struct timeval start, end;
  gettimeofday(&start, 0);

  G.setAllActive();
  run_graph_program(&dg, G, 1, &dg_tmp);

  gettimeofday(&end, 0);
  double time = (end.tv_sec-start.tv_sec)*1e3+(end.tv_usec-start.tv_usec)*1e-3;
  printf("Degree Time = %.3f ms \n", time);

  graph_program_clear(dg_tmp);
  
  auto pr_tmp = graph_program_init(pr, G);

  gettimeofday(&start, 0);

  G.setAllActive();
  //run_graph_program(&pr, G, -1, &pr_tmp);
  run_graph_program(&pr, G, maxIter, &pr_tmp);  

  gettimeofday(&end, 0);
  time = (end.tv_sec-start.tv_sec)*1e3+(end.tv_usec-start.tv_usec)*1e-3;
  printf("PR Time = %.3f ms \n", time);

  graph_program_clear(pr_tmp);

  for (int i = 0; i < std::min((unsigned long long int)25, (unsigned long long int)G.getNumberOfVertices()); i++) { 
    printf("%d : %d %f\n", i, G.getVertexproperty(i).degree, G.getVertexproperty(i).pagerank);
  }

  double pr_sum = 0;
  for (int i = 0; i < (unsigned long long int)G.getNumberOfVertices(); i++) { 
    pr_sum += G.getVertexproperty(i).pagerank;
  }
  //printf("sum of ranks: %f\n", pr_sum );
  std::cout << "sum of ranks: " << pr_sum << std::endl;
  printf("sum = %.6lf\n", pr_sum);

}
示例#2
0
void run_triangle_counting(char* filename, int nthreads) {
  Graph<TC> G;
  G.ReadMTX(filename, nthreads*16); //nthread pieces of matrix
  
  int numberOfVertices = G.getNumberOfVertices();
  GetNeighbors gn(numberOfVertices);
  CountTriangles ct(numberOfVertices);

  auto gn_tmp = graph_program_init(gn, G);
  auto ct_tmp = graph_program_init(ct, G);
  
  struct timeval start, end;

  for (int i = 1; i <= numberOfVertices; i++) {
	TC vp = G.getVertexproperty(i);
	vp.id = i;
    G.setVertexproperty(i, vp);
  }
  gettimeofday(&start, 0);


  G.setAllActive();
  run_graph_program(&gn, G, 1, &gn_tmp);

  G.setAllActive();
  run_graph_program(&ct, G, 1, &ct_tmp);
  
  gettimeofday(&end, 0);
  printf("Time = %.3f ms \n", (end.tv_sec-start.tv_sec)*1e3+(end.tv_usec-start.tv_usec)*1e-3);

  graph_program_clear(gn_tmp);
  graph_program_clear(ct_tmp);  

  unsigned long int ntriangles = 0;
  for (int i = 1; i <= numberOfVertices; i++) ntriangles += G.getVertexproperty(i).triangles;
  printf("Total triangles = %lu \n", ntriangles);
  
  for (int i = 1; i <= std::min(10, numberOfVertices); i++) {
    G.getVertexproperty(i).print();
  }

}
示例#3
0
void run_pagerank(const char* filename, int nthreads) {

  Graph<PR, edge> G;
  PageRank<edge> pr;
  Degree<PR, edge> dg;

 
  G.ReadMTX(filename, nthreads*4); //nthread pieces of matrix

  auto dg_tmp = graph_program_init(dg, G);

  struct timeval start, end;
  gettimeofday(&start, 0);

  G.setAllActive();
  run_graph_program(&dg, G, 1, &dg_tmp);

  gettimeofday(&end, 0);
  double time = (end.tv_sec-start.tv_sec)*1e3+(end.tv_usec-start.tv_usec)*1e-3;
  printf("Degree Time = %.3f ms \n", time);

  graph_program_clear(dg_tmp);
  
  auto pr_tmp = graph_program_init(pr, G);

  gettimeofday(&start, 0);

  G.setAllActive();
  run_graph_program(&pr, G, -1, &pr_tmp);
  
  gettimeofday(&end, 0);
  time = (end.tv_sec-start.tv_sec)*1e3+(end.tv_usec-start.tv_usec)*1e-3;
  printf("PR Time = %.3f ms \n", time);

  graph_program_clear(pr_tmp);

  for (int i = 1; i <= std::min((unsigned long long int)25, (unsigned long long int)G.getNumberOfVertices()); i++) { 
    printf("%d : %d %f\n", i, G.getVertexproperty(i).degree, G.getVertexproperty(i).pagerank);
  }
}
示例#4
0
文件: SSSP.cpp 项目: btbytes/GraphMat
void run_sssp(const char* filename, int nthreads, int v) {
  //__itt_pause();

  Graph<BFSD2> G;
  //Graph<SSSPD> G;
  //G.ReadMTX_sort(filename, nthreads*8); //8 nthread pieces of matrix
  G.ReadMTX(filename, nthreads*8); //8 nthread pieces of matrix
  //G.ReadMTX(filename, 240*8); //8 nthread pieces of matrix

  //BFS b;
  //BFS2 b;
  SSSP b;
  //SSSPwithParent b;
  auto tmp_ds = graph_program_init(b, G);

  //for (int v = 0; v < 25; v++) { 
  //G.reset(); 

  //for (int i = 0; i <= G.nvertices; i++) 
  //  G.vertexproperty[i].id = i;

  BFSD2 init; 
  init.distance = 0; 

  BFSD2 inf; 
  //int v = 10;
  //for (int v = 0; v < 25; v++) {
  G.setAllVertexproperty(inf);
  G.setAllInactive();
  //int v = 1758293;
  //G.vertexproperty[v].distance = 0;
  //G.active[v] = true;

  G.setVertexproperty(v, init);
  G.setActive(v);

  struct timeval start, end;
  gettimeofday(&start, 0);

  //__itt_resume();

  run_graph_program(&b, G, -1, &tmp_ds);
  //run_dense_graph_program(b, G, -1);

  //__itt_pause();

  gettimeofday(&end, 0);
  printf("Time = %.3f ms \n", (end.tv_sec-start.tv_sec)*1e3+(end.tv_usec-start.tv_usec)*1e-3);
  
 
  int reachable_vertices = 0;

  for (int i = 0; i < G.nvertices; i++) {
    if (G.getVertexproperty(i).distance < MAX_DIST) {
      reachable_vertices++;
    }
  }

  printf("Reachable vertices = %d \n", reachable_vertices);

  for (int i = 0; i <= std::min((unsigned long long int)25, (unsigned long long int)G.nvertices); i++) {
  //for (int i = 1; i <= G.nvertices; i++) {
    printf("%d : ", i);
    //G.vertexproperty[i].print();
    G.getVertexproperty(i).print();
    /*if (G.vertexproperty[i].distance < MAX_DIST) {
      printf("PATH: ");
      int par = i;
      //while(par != -1) {
      //  printf(" %d ", par);
      //  par = G.vertexproperty[par].parent;
      //}
      printf("\n");
    }*/
    //if (G.vertexproperty[i].depth < MAX_DIST) {
    //  printf("Depth %d : %d \n", i, G.vertexproperty[i].depth);
    //}
    //else {
    //  printf("Depth %d : INF \n", i);
    //}
  }
  //}
  
  graph_program_clear(tmp_ds);
  //}
  //}

  /*FILE* f;
  f = fopen("out", "w");
  for (int i = 1; i <= G.nvertices; i++) {
      fprintf(f, "Depth %d : %d \n", i, G.vertexproperty[i].depth);
  }
  fclose(f);*/

}
示例#5
0
文件: SGD.cpp 项目: btbytes/GraphMat
void run_sgd(char* filename, int nthreads) {
  const int k = 20;
  Graph< LatentVector<k> > G;
  G.ReadMTX(filename, nthreads*8); //nthread pieces of matrix

  srand(0);
  for (int i = 0; i < nthreads; i++) {
    rseed[16*i] = rand();
  }
  double err = 0.0;

  SGDProgram<k> sgdp(0.001, 0.00000035);
  SGDInitProgram<k> sgdip;
  RMSEProgram<k> rmsep;

  auto sgdp_tmp = graph_program_init(sgdp, G);
  auto rmsep_tmp = graph_program_init(rmsep, G);

  G.setAllActive();
  run_graph_program(&sgdip, G);
  
  G.setAllActive();
  run_graph_program(&rmsep, G, 1, &rmsep_tmp);

  for (int i = 0; i < G.nvertices; i++) err += G.getVertexproperty(i).sqerr;
  printf("RMSE error = %lf per edge \n", sqrt(err/(G.nnz)));

  printf("SGD Init over\n");
  
  struct timeval start, end;

  gettimeofday(&start, 0);

  G.setAllActive();
  run_graph_program(&sgdp, G, 10, &sgdp_tmp);

  /*
  for (int it = 0; it < 10; it ++) {

  G.setAllActive();
  run_graph_program(sgdp, G, 1, &sgdp_tmp);
  
  //G.setAllActive();
  //run_graph_program(rmsep, G, 1, &rmsep_tmp);

  //err = 0.0;
  //for (int i = 1; i <= G.nvertices; i++) err += G.vertexproperty[i].sqerr;
  //printf("RMSE error = %lf per edge \n", sqrt(err/(G.nnz)));
  }
  */

  gettimeofday(&end, 0);
  
  double time = (end.tv_sec-start.tv_sec)*1e3+(end.tv_usec-start.tv_usec)*1e-3;
  printf("Time = %.3f ms \n", time);

  G.setAllActive();
  run_graph_program(&rmsep, G, 1, &rmsep_tmp);

  graph_program_clear(sgdp_tmp);
  graph_program_clear(rmsep_tmp);

  err = 0.0;
  for (int i = 0; i < G.nvertices; i++) err += G.getVertexproperty(i).sqerr;
  printf("RMSE error = %lf per edge \n", sqrt(err/(G.nnz)));

  for (int i = 0; i <= std::min(10, G.nvertices); i++) { 
    printf("%d : ", i) ;
    G.getVertexproperty(i).print();
    printf("\n");
  }
}