Ejemplo n.º 1
0
int main(int argc, char ** argv) {
	if (argc<2) {
		fprintf(stderr, "usage: wcc [path] [memory budget in GB]\n");
		exit(-1);
	}
	std::string path = argv[1];
	long memory_bytes = (argc>=3)?atol(argv[2])*1024l*1024l*1024l:8l*1024l*1024l*1024l;

	Graph graph(path,atoi(argv[3]));
	graph.set_memory_bytes(memory_bytes);
	Bitmap * active_in = graph.alloc_bitmap();
	Bitmap * active_out = graph.alloc_bitmap();
	BigVector<VertexId> label(graph.path+"/label", graph.vertices);
	graph.set_vertex_data_bytes( graph.vertices * sizeof(VertexId) );

	active_out->fill();
	VertexId active_vertices = graph.stream_vertices<VertexId>([&](VertexId i){
		label[i] = i;
		return 1;
	});

	double start_time = get_time();
	int iteration = 0;
	while (active_vertices!=0) {
		iteration++;
		printf("%7d: %d\n", iteration, active_vertices);
		std::swap(active_in, active_out);
		active_out->clear();
		graph.hint(label);
		active_vertices = graph.stream_edges<VertexId>([&](Edge & e){
			if (label[e.source]<label[e.target]) {
				if (write_min(&label[e.target], label[e.source])) {
					active_out->set_bit(e.target);
					return 1;
				}
			}
			return 0;
		}, active_in);
	}
	double end_time = get_time();

	BigVector<VertexId> label_stat(graph.path+"/label_stat", graph.vertices);
	label_stat.fill(0);
	graph.stream_vertices<VertexId>([&](VertexId i){
		write_add(&label_stat[label[i]], 1);
		return 1;
	});
	VertexId components = graph.stream_vertices<VertexId>([&](VertexId i){
		return label_stat[i]!=0;
	});
	printf("%d components found in %.2f seconds\n", components, end_time - start_time);

	return 0;
}
Ejemplo n.º 2
0
static int merge_cont(int degree) {
  /* Get the minimum of the top element of each buffer
     Write it into ioBufs[degree], which is the buffer of output file
     Refill with the next element of this buffer block
     Until all the buffer block is empty. */
  int ret = 0;

  topElem = (GIT_T *)malloc(sizeof(GIT_T) * (degree + 1));
  if (topElem == NULL) {
    printf("Malloc memory for topElem failed.\n");
    return -1;
  }
  memset(topElem, 0, sizeof(GIT_T) * (degree + 1));

  // Initiate topElem[i] with the first record of each input file.
  int i;
  for (i = 0; i < degree ; i++) {
    get_next_word(i);
  }
 
  int min = 0;

  // If all files are done, min = -1.
  while (min >= 0) {
    // Get the order of buffer with minimum word_id
    min = sort_curr(degree);
    // Copy minimum to output buffer
    ret = write_min(min, degree);
    if (ret != 0) {
      return -1;
    }
    // Update record of that buffer
    get_next_word(min);
  } 

  free(topElem);
  return 0;
}