Example #1
0
void memory_release_loop() {
    memory_release_lock.lock();
    while (!stop_memory_release_thread) {
        memory_release_cond.timedwait(memory_release_lock, 15);
        MallocExtension::instance()->ReleaseFreeMemory();
    }
    memory_release_lock.unlock();
}
void thread_stuff() {
  std::pair<graphlab::vertex_id_type, bool> deq;
  while(1) {
    deq = locked_elements.dequeue();
    if (deq.second == false) break;
    else {
      locks->philosopher_stops_eating(deq.first);
      mt.lock();
      current_demand_set[deq.first] = 0;
      bool getnextlock = nlocks_to_acquire > 0;
      if (nlocks_to_acquire > 0) {
        nlocks_to_acquire--;
        if (nlocks_to_acquire % 100 == 0) {
          std::cout << "Remaining: " << nlocks_to_acquire << std::endl;
        }
      }
      if (nlocks_to_acquire == 0 &&
        nlocksacquired == INITIAL_NLOCKS_TO_ACQUIRE + lockable_vertices.size()) cond.signal();
      mt.unlock();

      if (getnextlock > 0) {
        graphlab::vertex_id_type toacquire = 0;
        while(1) {
          mt.lock();
           toacquire = lockable_vertices[graphlab::random::rand() %
                                         lockable_vertices.size()];
          if (current_demand_set[toacquire] == 0) {
            current_demand_set[toacquire] = 1;
            demand_set[toacquire]++;
            mt.unlock();
            break;
          }
          mt.unlock();
        }
        locks->make_philosopher_hungry(toacquire);
      }
    }
  }
}
Example #3
0
int main(int argc, char** argv) {
    size_t parent_pid = get_parent_pid();
    // Options
    std::string program_name = argv[0];
    std::string server_address;

    boost::program_options::variables_map vm;
    po::options_description desc("Allowed options");
    desc.add_options()
    ("help", "Print this help message.")
    ("server_address",
     po::value<std::string>(&server_address)->implicit_value(server_address),
     "This must be a valid ZeroMQ endpoint and "
     "is the address the server listens on");

    po::positional_options_description positional;
    positional.add("server_address", 1);

    // try to parse the command line options
    try {
        po::command_line_parser parser(argc, argv);
        parser.options(desc);
        parser.positional(positional);
        po::parsed_options parsed = parser.run();
        po::store(parsed, vm);
        po::notify(vm);
    } catch(std::exception& error) {
        std::cout << "Invalid syntax:\n"
                  << "\t" << error.what()
                  << "\n\n" << std::endl
                  << "Description:"
                  << std::endl;
        print_help(program_name, desc);
        return 1;
    }

    if(vm.count("help")) {
        print_help(program_name, desc);
        return 0;
    }

    // initialize a new R instance and pass to unity server
    RInside * R = new RInside(0, 0);

    cppipc::comm_server server(std::vector<std::string>(), "", server_address);

    // pass a R instance to unity server
    server.register_type<graphlab::lambda::lambda_evaluator_interface>([&]() {
        return new graphlab::lambda::rcpplambda_evaluator(R);
    });

    server.start();

#ifdef HAS_TCMALLOC
    graphlab::thread memory_release_thread;
    memory_release_thread.launch(memory_release_loop);
#endif

    wait_for_parent_exit(parent_pid);

#ifdef HAS_TCMALLOC
    stop_memory_release_thread = true;
    memory_release_cond.signal();
    memory_release_thread.join();
#endif


}
Example #4
0
int main(int argc, char** argv) {
  size_t parent_pid = getppid();
  // Options
  std::string program_name = argv[0];
  std::string server_address;

  // Handle server commandline options
  boost::program_options::variables_map vm;
  po::options_description desc("Allowed options");
  desc.add_options()
      ("help", "Print this help message.")
      ("server_address", 
       po::value<std::string>(&server_address)->implicit_value(server_address),
       "This must be a valid ZeroMQ endpoint and "
                         "is the address the server listens on");

  po::positional_options_description positional;
  positional.add("server_address", 1);

  // try to parse the command line options
  try {
    po::command_line_parser parser(argc, argv);
    parser.options(desc);
    parser.positional(positional);
    po::parsed_options parsed = parser.run();
    po::store(parsed, vm);
    po::notify(vm);
  } catch(std::exception& error) {
    std::cout << "Invalid syntax:\n"
              << "\t" << error.what()
              << "\n\n" << std::endl
              << "Description:"
              << std::endl;
    print_help(program_name, desc);
    return 1;
  }

  if(vm.count("help")) {
    print_help(program_name, desc);
    return 0;
  }

  try {
    graphlab::lambda::init_python(argc, argv);
  } catch (const std::string& error) {
    logstream(LOG_WARNING) << "Fail initializing python: " << error << std::endl;
    exit(-1);
  }

  // construct the server
  cppipc::comm_server server(std::vector<std::string>(), "", server_address);

  server.register_type<graphlab::lambda::lambda_evaluator_interface>([](){
                                            return new graphlab::lambda::pylambda_evaluator();
                                          });
  server.register_type<graphlab::lambda::graph_lambda_evaluator_interface>([](){
                                            return new graphlab::lambda::graph_pylambda_evaluator();
                                          });

  server.start();

#ifdef HAS_TCMALLOC
  graphlab::thread memory_release_thread;
  memory_release_thread.launch(memory_release_loop);
#endif

  while(1) {
    sleep(5);
    // has parent_pid and parent_pid 
    if (parent_pid != 0 && kill(parent_pid, 0) == -1) {
      break;
    }

  }

#ifdef HAS_TCMALLOC
  stop_memory_release_thread = true;
  memory_release_cond.signal();
  memory_release_thread.join();
#endif

}