示例#1
0
void Test(const std::wstring& path, const std::string& search_text) {
  std::unique_ptr<TaskQueue> task_queue(new TaskQueueImpl());
  std::unique_ptr<TaskQueue> io_task_queue(new IOTaskQueue());
  std::thread io_thread([&io_task_queue] { io_task_queue->Run(); });
  Report report;
  RegexSearchFactoryImpl factory(search_text, &report);
  ProcessingManager consumer(
      std::thread::hardware_concurrency(), std::thread::hardware_concurrency(),
      std::thread::hardware_concurrency(), task_queue.get(),
      io_task_queue.get(), &factory, path);
  consumer.Start();
  task_queue->Run();
  io_task_queue->PostQuitTask();
  io_thread.join();
}
示例#2
0
int main(int argc, char** argv)
{
    struct options options;
    if (process_options(argc, argv, true, &options) != 0)
        return 0;

    if (options.rmat.a + options.rmat.b + options.rmat.c >= 1) {
        printf("Error: The sum of probabilities must equal 1\n");
        return 0;
    }
    double d = 1 - (options.rmat.a + options.rmat.b + options.rmat.c);
    xscale_node     = options.rmat.xscale_node;
    xscale_interval = options.rmat.xscale_interval;
    uint_fast32_t seed[5];
    make_mrg_seed(options.rng.userseed1, options.rng.userseed2, seed);
    mrg_state state;
    mrg_seed(&state, seed);
    //mrg_skip(&new_state, 50, 7, 0); // Do an initial skip?

    edge_t total_edges = options.rmat.edges;
    if((total_edges % options.rmat.xscale_interval) > options.rmat.xscale_node) {
        total_edges /= options.rmat.xscale_interval;
        total_edges++;
    }
    else {
        total_edges /= options.rmat.xscale_interval;
    }

    if (options.global.symmetric) {
        total_edges *= 2;
    }

    printf("Generator type: R-MAT\n");
    printf("Scale: %d (%" PRIu64 " vertices)\n", options.rmat.scale, ((uint64_t)1 << options.rmat.scale));
    printf("Edges: %" PRIet "\n", total_edges);
    printf("Probabilities: A=%4.2f, B=%4.2f, C=%4.2f, D=%4.2f\n", options.rmat.a, options.rmat.b, options.rmat.c, d);

    double start = get_time();

    // io thread
    size_t buffer_size = calculate_buffer_size(options.global.buffer_size);
    buffer_queue flushq;
    buffer_manager manager(&flushq, options.global.buffers_per_thread, buffer_size);
    io_thread_func io_func(options.global.graphname.c_str(), total_edges, &flushq, &manager, buffer_size);
    boost::thread io_thread(boost::ref(io_func));

    // worker threads
    int nthreads = options.global.nthreads;
    edge_t edges_per_thread = options.rmat.edges / nthreads;
    threadid_t* workers[nthreads];
    boost::thread* worker_threads[nthreads];
    for (int i = 0; i < nthreads; i++) {
        workers[i] = new threadid_t(i);
        thread_buffer* buffer = manager.register_thread(*workers[i]);
        // last thread gets the remainder (if any)
        edge_t start = i * edges_per_thread;
        edge_t end = (i == nthreads-1) ? (options.rmat.edges) : ((i+1) * edges_per_thread);
        worker_threads[i] = new boost::thread(generate, buffer,
                                              state, options.rmat.scale, start, end,
                                              options.rmat.a, options.rmat.b, options.rmat.c, /*d,*/
                                              options.global.symmetric);
    }

    // Wait until work completes
    for (int i = 0; i < nthreads; i++) {
        worker_threads[i]->join();
    }
    io_func.stop();
    io_thread.join();

    // cleanup
    for (int i = 0; i < nthreads; i++) {
        manager.unregister_thread(*workers[i]);
        delete worker_threads[i];
        delete workers[i];
    }

    double elapsed = get_time() - start;
    printf("Generation time: %fs\n", elapsed);

    make_ini_file(options.global.graphname.c_str(), (uint64_t)1 << options.rmat.scale, total_edges);

    return 0;
}