inference/dimmwitted/src/factor_graph.cc
// Construct index using multiple threads
// 6 sec instead of 30 sec for a 270M-factor graph
// std::vector<std::tuple<size_t, size_t, size_t, size_t>> params;
Construct index using multiple threads
6 sec instead of 30 sec for a 270M-factor graph
std::vector> params.
Construct index using multiple threads 6 sec instead of 30 sec for a 270M - factor graph std :: vector > params .
void FactorGraph::construct_index() {
  size_t total = size.num_variables;
  size_t cores = sysconf(_SC_NPROCESSORS_CONF);
  size_t increment = total / cores;
  if (total < 1000) {
    increment = total;
  }
  size_t milestone = 0;
  size_t num_values = 0, num_factors = 0;
  std::vector<std::function<void()>> tasks;
  for (size_t i = 0; i < size.num_variables; ++i) {
    if (i == milestone) {
      milestone += increment;
      if (milestone > total) {
        milestone = total;
      }
      tasks.push_back([this, i, milestone, num_values, num_factors]() {
        construct_index_part(i, milestone, num_values, num_factors);
      });
    }
    num_values += variables[i].internal_cardinality();
    if (variables[i].adjacent_factors) {
      num_factors += variables[i].adjacent_factors->size();
    }
  }
  size.num_values = capacity.num_values = num_values;
  values.reset(fast_alloc_no_init<VariableToFactor>(num_values));
  std::vector<std::thread> threads;
  for (const auto &task : tasks) {
    threads.push_back(std::thread(task));
  }
  for (auto &t : threads) t.join();
  threads.clear();
}
void FactorGraph :: construct_index ( ) { size_t total = size . num_variables ; size_t cores = sysconf ( _SC_NPROCESSORS_CONF ) ; size_t increment = total / cores ; if ( total < 1000 ) { increment = total ; } size_t milestone = 0 ; size_t num_values = 0 , num_factors = 0 ; std :: vector < std :: function < void ( ) > > tasks ; for ( size_t i = 0 ; i < size . num_variables ; ++ i ) { if ( i == milestone ) { milestone += increment ; if ( milestone > total ) { milestone = total ; } tasks . push_back ( [ this , i , milestone , num_values , num_factors ] ( ) { construct_index_part ( i , milestone , num_values , num_factors ) ; } ) ; } num_values += variables [ i ] . internal_cardinality ( ) ; if ( variables [ i ] . adjacent_factors ) { num_factors += variables [ i ] . adjacent_factors -> size ( ) ; } } size . num_values = capacity . num_values = num_values ; values . reset ( fast_alloc_no_init < VariableToFactor > ( num_values ) ) ; std :: vector < std :: thread > threads ; for ( const auto & task : tasks ) { threads . push_back ( std :: thread ( task ) ) ; } for ( auto & t : threads ) t . join ( ) ; threads . clear ( ) ; }
Construct index using multiple threads
6 sec instead of 30 sec for a 270M-factor graph
std::vector<std::tuple<size_t, size_t, size_t, size_t>> params;
Construct index using multiple threads 6 sec instead of 30 sec for a 270M - factor graph std :: vector<std :: tuple<size_t size_t size_t size_t >> params ;
// small graph, single thread