Пример #1
0
int
main(int argc, char *argv[]) 
{
  double vel_keep = 0.333;
  double accel_keep = 0.333;

  /* ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ *
   * Setup and register algorithm with the server
   * ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ */
  stinger_registered_alg * alg = 
    stinger_register_alg(
      .name="rate_monitor",
      .data_per_vertex=sizeof(double)*2,
      .data_description="dd wgtd_edge_vel wgtd_edge_accel",
      .host="localhost",
    );

  if(!alg) {
    LOG_E("Registering algorithm failed.  Exiting");
    return -1;
  }

  bzero(alg->alg_data, sizeof(double) * 2 * alg->stinger->max_nv);
  double * vel	  = (double *)alg->alg_data;
  double * accel  = vel + alg->stinger->max_nv;

  
  /* ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ *
   * Initial static computation
   * ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ */
  stinger_alg_begin_init(alg); {
  } stinger_alg_end_init(alg);

  /* ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ *
   * Streaming Phase
   * ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ */
  while(alg->enabled) {
    /* Pre processing */
    if(stinger_alg_begin_pre(alg)) {
      /* nothing to do */
      stinger_alg_end_pre(alg);
    }

    /* Post processing */
    if(stinger_alg_begin_post(alg)) {
      update_rates(alg, stinger_max_active_vertex(alg->stinger)+1, vel, accel, vel_keep, accel_keep);
      stinger_alg_end_post(alg);
    }
  }

  LOG_I("Algorithm complete... shutting down");
}
Пример #2
0
int
main(int argc, char *argv[])
{
  if (getenv ("COMPUTE"))
    initial_compute = 1;
  if (argc > 1) {
    if (0 == strcmp(argv[1], "--compute"))
      initial_compute = 1;
    else if (0 == strcmp(argv[1], "--help") || 0 == strcmp(argv[1], "-h")) {
      fprintf (stderr, "Pass --compute or set COMPUTE env. var to compute\n"
              "an initial community map.");
    }
  }

  /* ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ *
   * Setup and register algorithm with the server
   * ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ */
  stinger_registered_alg * alg =
    stinger_register_alg(
      .name="simple_communities",
      .data_per_vertex=sizeof(int64_t),
      .data_description="l community_label",
      .host="localhost",
    );

  if(!alg) {
    LOG_E("Registering algorithm failed.  Exiting");
    return -1;
  }

  nv = stinger_max_active_vertex(alg->stinger)+1;
  cmap = (int64_t *)alg->alg_data;

  /* ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ *
   * Initial static computation
   * ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ */
  stinger_alg_begin_init(alg); {
    const struct stinger * S = alg->stinger;
    init_empty_community_state (&cstate, nv, 2*nv);
    free (cstate.cmap);
    cstate.cmap = cmap;
    if (initial_compute)
      init_cstate_from_stinger (&cstate, S);
    else
      init_empty_community_state (&cstate, nv, (1+stinger_total_edges(S))/2);
  } stinger_alg_end_init(alg);

  /* ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ *
   * Streaming Phase
   * ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ */
  while(alg->enabled) {
    /* Pre processing */
    if(stinger_alg_begin_pre(alg)) {
      /* Must be here to find the removal weights. */
      cstate_preproc_alg (&cstate, alg);
      stinger_alg_end_pre(alg);
    }

    /* Post processing */
    if(stinger_alg_begin_post(alg)) {
      cstate_update (&cstate, alg->stinger);
      stinger_alg_end_post(alg);
    }
  }

  LOG_I("Algorithm complete... shutting down");
  finalize_community_state (&cstate);
}
Пример #3
0
int
main(int argc, char *argv[])
{
  if(argc < 4) {
    printf("too few args");
    return -1;
  }

  /* ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ *
   * Setup and register algorithm with the server
   * ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ */
  stinger_register_alg_params register_params;
  memset(&register_params, 0, sizeof(stinger_register_alg_params));

  register_params.name=argv[1];
  register_params.data_per_vertex=atol(argv[2]);
  register_params.data_description=argv[3];
  register_params.host="localhost";

  if(argc > 4) {
    register_params.num_dependencies = argc - 4;
    register_params.dependencies = argv + 4;
  }

  stinger_registered_alg * alg = stinger_register_alg_impl(register_params);

  if(!alg) {
    LOG_E("Registering algorithm failed.  Exiting");
    return -1;
  }


  /* Print dependency storage information */
  for(int a = 0; a < argc - 4; a++) {
    printf("Alg %s\nLoc %s\nDesc %s\nPtr %p\nData Per %ld\n",
      alg->dep_name[a], alg->dep_location[a], alg->dep_description[a], 
      alg->dep_data[a], alg->dep_data_per_vertex[a]);
  }

  /* ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ *
   * Initial static computation
   * ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ */
  stinger_alg_begin_init(alg); {

    LOG_I_A("Initializing algorithm... consistency check: %ld",
      (long) stinger_consistency_check(alg->stinger, alg->stinger->max_nv));

  } stinger_alg_end_init(alg);

  /* ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ *
   * Streaming Phase
   * ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ */
  while(alg->enabled) {

    /* Preprocessing */
    if(stinger_alg_begin_pre(alg)) {

      LOG_I_A("Preprocessing algorithm... consistency check: %ld",
	(long) stinger_consistency_check(alg->stinger, alg->stinger->max_nv));

      LOG_I_A("Preprocessing algorithm... num_insertions: %ld",
	alg->num_insertions);
      for(int64_t i = 0; i < alg->num_insertions; i++) {
	LOG_I_A("\tINS: TYPE %s %ld FROM %s %ld TO %s %ld WEIGHT %ld TIME %ld", 
	  alg->insertions[i].type_str,
	  alg->insertions[i].type,
	  alg->insertions[i].source_str,
	  alg->insertions[i].source,
	  alg->insertions[i].destination_str,
	  alg->insertions[i].destination,
	  alg->insertions[i].weight,
	  alg->insertions[i].time);
      }

      LOG_I_A("Preprocessing algorithm... num_deletions: %ld",
	alg->num_deletions);
      for(int64_t i = 0; i < alg->num_deletions; i++) {
	LOG_I_A("\tDEL: TYPE %s %ld FROM %s %ld TO %s %ld",
	  alg->deletions[i].type_str,
	  alg->deletions[i].type,
	  alg->deletions[i].source_str,
	  alg->deletions[i].source,
	  alg->deletions[i].destination_str,
	  alg->deletions[i].destination);
      }

      stinger_alg_end_pre(alg);
    }

    /* Post processing */
    if(stinger_alg_begin_post(alg)) {

      LOG_I_A("Postprocessing algorithm... consistency check: %ld",
	(long) stinger_consistency_check(alg->stinger, alg->stinger->max_nv));

      LOG_I_A("Postprocessing algorithm... num_insertions: %ld",
	alg->num_insertions);
      for(int64_t i = 0; i < alg->num_insertions; i++) {
	LOG_I_A("\tINS: TYPE %s %ld FROM %s %ld TO %s %ld WEIGHT %ld TIME %ld", 
	  alg->insertions[i].type_str,
	  alg->insertions[i].type,
	  alg->insertions[i].source_str,
	  alg->insertions[i].source,
	  alg->insertions[i].destination_str,
	  alg->insertions[i].destination,
	  alg->insertions[i].weight,
	  alg->insertions[i].time);
      }

      LOG_I_A("Postprocessing algorithm... num_deletions: %ld",
	alg->num_deletions);
      for(int64_t i = 0; i < alg->num_deletions; i++) {
	LOG_I_A("\tDEL: TYPE %s %ld FROM %s %ld TO %s %ld",
	  alg->deletions[i].type_str,
	  alg->deletions[i].type,
	  alg->deletions[i].source_str,
	  alg->deletions[i].source,
	  alg->deletions[i].destination_str,
	  alg->deletions[i].destination);
      }

      stinger_alg_end_post(alg);
    }
  }

  LOG_I("Algorithm complete... shutting down");
}
Пример #4
0
int
main(int argc, char *argv[])
{
  /* ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ *
   * Setup and register algorithm with the server
   * ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ */
  char name[1024];
  char type_str[1024];

  int type_specified = 0;
  int directed = 0;

  double epsilon = EPSILON_DEFAULT;
  double dampingfactor = DAMPINGFACTOR_DEFAULT;
  int64_t maxiter = MAXITER_DEFAULT;
  
  int opt = 0;
  while(-1 != (opt = getopt(argc, argv, "t:e:f:i:d?h"))) {
    switch(opt) {
      case 't': {
        sprintf(name, "pagerank_%s", optarg);
        strcpy(type_str,optarg);
        type_specified = 1;
      } break;   
      case 'd': {
        directed = 1;
      } break;
      case 'e': {
        epsilon = atof(optarg);
      } break;
      case 'f': {
        dampingfactor = atof(optarg);
      } break;
      case 'i': {
        maxiter = atol(optarg);
      } break;
      default: 
        printf("Unknown option '%c'\n", opt);
      case '?':
      case 'h': {
        printf(
          "PageRank\n"
          "==================================\n"
          "\n"
          "  -t <str>  Specify an edge type to run page rank over\n"
          "  -d        Use a PageRank that is safe on directed graphs\n"
          "  -e        Set PageRank Epsilon (default: %0.1e)\n"
          "  -f        Set PageRank Damping Factor (default: %lf)\n"
          "  -i        Set PageRank Max Iterations (default: %ld)\n"
          "\n",EPSILON_DEFAULT,DAMPINGFACTOR_DEFAULT,MAXITER_DEFAULT);
        return(opt);
      }
    }
  }

  stinger_registered_alg * alg = 
    stinger_register_alg(
      .name=type_specified ? name : "pagerank",
      .data_per_vertex=sizeof(double),
      .data_description="d pagerank",
      .host="localhost",
    );

  if(!alg) {
    LOG_E("Registering algorithm failed.  Exiting");
    return -1;
  }

  double * pr = (double *)alg->alg_data;
  OMP("omp parallel for")
  for(uint64_t v = 0; v < alg->stinger->max_nv; v++) {
    pr[v] = 1 / ((double)alg->stinger->max_nv);
  }

  double * tmp_pr = (double *)xcalloc(alg->stinger->max_nv, sizeof(double));

  double time;
  init_timer();
  
  /* ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ *
   * Initial static computation
   * ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ */
  stinger_alg_begin_init(alg); {
    int64_t type = -1;
    if(type_specified) {
      type = stinger_etype_names_lookup_type(alg->stinger, type_str);
    }
    if(type_specified && type > -1) {
      if (directed) {
        page_rank_type_directed(alg->stinger, stinger_mapping_nv(alg->stinger), pr, tmp_pr, epsilon, dampingfactor, maxiter, type);
      } else {
        page_rank_type(alg->stinger, stinger_mapping_nv(alg->stinger), pr, tmp_pr, epsilon, dampingfactor, maxiter, type);
      }
    } else if (!type_specified) {
      if (directed) {
        page_rank_directed(alg->stinger, stinger_mapping_nv(alg->stinger), pr, tmp_pr, epsilon, dampingfactor, maxiter);
      } else {
        page_rank(alg->stinger, stinger_mapping_nv(alg->stinger), pr, tmp_pr, epsilon, dampingfactor, maxiter);
      }
    }
  } stinger_alg_end_init(alg);

  /* ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ *
   * Streaming Phase
   * ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ */
  while(alg->enabled) {
    /* Pre processing */
    if(stinger_alg_begin_pre(alg)) {
      /* nothing to do */
      time = timer();
      stinger_alg_end_pre(alg);
      time = timer() - time;
      LOG_I_A("Pre time : %20.15e", time);
    }

    /* Post processing */
      time = timer();
    if(stinger_alg_begin_post(alg)) {
      int64_t type = -1;
      if(type_specified) {
      	type = stinger_etype_names_lookup_type(alg->stinger, type_str);
      	if(type > -1) {
          if (directed) {
            page_rank_type_directed(alg->stinger, stinger_mapping_nv(alg->stinger), pr, tmp_pr, epsilon, dampingfactor, maxiter, type);
          } else {
            page_rank_type(alg->stinger, stinger_mapping_nv(alg->stinger), pr, tmp_pr, epsilon, dampingfactor, maxiter, type);
          }
      	} else {
      	  LOG_W_A("TYPE DOES NOT EXIST %s", type_str);
      	  LOG_W("Existing types:");
          // TODO: Don't go through the loop if LOG_W isn't enabled
      	  for(int64_t t = 0; t < stinger_etype_names_count(alg->stinger); t++) {
      	    LOG_W_A("  > %ld %s", (long) t, stinger_etype_names_lookup_name(alg->stinger, t));
      	  }
      	}
      } else {
        if (directed) {
          page_rank_directed(alg->stinger, stinger_mapping_nv(alg->stinger), pr, tmp_pr, epsilon, dampingfactor, maxiter);
        } else {
          page_rank(alg->stinger, stinger_mapping_nv(alg->stinger), pr, tmp_pr, epsilon, dampingfactor, maxiter);
        }
      }
      stinger_alg_end_post(alg);
    }
    time = timer() - time;
    LOG_I_A("Post time : %20.15e", time);
  }

  LOG_I("Algorithm complete... shutting down");

  free(tmp_pr);
}
Пример #5
0
int
main(int argc, char *argv[])
{
    /* ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ *
    * Options and arg parsing
    * ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ */
    int64_t max_iter = 5;
    char * alg_name = "community_detection";

    int opt = 0;
    while(-1 != (opt = getopt(argc, argv, "i:n:x?h"))) {
        switch(opt) {
            case 'i': {
                max_iter = atol(optarg);
                if(max_iter < 1) {
                    max_iter = 5;
                }
            } break;

            case 'n': {
                alg_name = optarg;
            } break;

            default:
                printf("Unknown option '%c'\n", opt);
            case '?':
            case 'h': {
                printf(
                        "Louvain Community detection\n"
                                "==================================\n"
                                "\n"
                                "This approach returns the first level of Louvain's Community detection\n"
                                "\n"
                                "  -i <num>  Set the max number of iterations (%ld by default)\n"
                                "  -n <str>  Set the algorithm name (%s by default)\n"
                                "\n", max_iter,alg_name
                );
                return(opt);
            }
        }
    }


    /* ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ *
    * Setup and register algorithm with the server
    * ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ */
    stinger_registered_alg * alg =
    stinger_register_alg(
            .name=alg_name,
    .data_per_vertex=sizeof(int64_t),
    .data_description="l partitions",
    .host="localhost",
    );

    if(!alg) {
        LOG_E("Registering algorithm failed.  Exiting");
        return -1;
    }

    int64_t * partitions = (int64_t *)alg->alg_data;


    /* ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ *
    * Initial static computation
    * ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ */
    stinger_alg_begin_init(alg); {
        if (stinger_max_active_vertex(alg->stinger) > 0)
            community_detection(alg->stinger, stinger_max_active_vertex(alg->stinger) + 1, partitions, max_iter);
    } stinger_alg_end_init(alg);

    /* ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ *
    * Streaming Phase
    * ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ */
    while(alg->enabled) {
        /* Pre processing */
        if(stinger_alg_begin_pre(alg)) {
            /* nothing to do */
            stinger_alg_end_pre(alg);
        }

        /* Post processing */
        if(stinger_alg_begin_post(alg)) {
            int64_t nv = (stinger_mapping_nv(alg->stinger))?stinger_mapping_nv(alg->stinger)+1:0;
            if (nv > 0) {
                community_detection(alg->stinger, nv, partitions, max_iter);
            }

            stinger_alg_end_post(alg);
        }
    }

    LOG_I("Algorithm complete... shutting down");
}