示例#1
0
文件: phat_tool.cpp 项目: bnels/ctl
int main( int argc, char *argv[]){
  po::variables_map vm;
  process_args( argc, argv, vm);

  //setup some variables
  std::string full_complex_name = vm[ "input-file"].as< std::string>();
  std::string complex_name( full_complex_name);
  std::string binary_name( argv[ 0]);
  std::string base_name( full_complex_name);
  std::string output_name;
  size_t found = complex_name.rfind( '/');
  if ( found != std::string::npos){
        complex_name.replace( 0, found+1, "");
  }
  found = full_complex_name.rfind('.');
   if ( found != std::string::npos){
        base_name.replace(found,full_complex_name.length(), "");
  	output_name = base_name + ".phat";
  }
  std::ofstream out(output_name.c_str());
  
  Complex complex;

  // Read the cell_set in
  ctl::read_complex( full_complex_name, complex);
 
  Complex_filtration complex_filtration( complex);


  typedef ctl::Filtration_boundary< Complex_filtration> 
				   Filtration_boundary;
  typedef Filtration_boundary::Term Filtration_term;
  typedef ctl::Chain< Filtration_term> Chain;
  std::cout << "Writing PHAT ASCII file To: " << output_name << std::endl;
  Filtration_boundary bd( complex_filtration);
  for (Complex_filtration_iterator sigma = complex_filtration.begin(); 
				   sigma != complex_filtration.end(); ++sigma){
       Chain cascade_boundary;
       cascade_boundary.reserve( bd.length( sigma));
       for( auto i = bd.begin( sigma); i != bd.end( sigma); ++i){
                  cascade_boundary.emplace( i->cell(), i->coefficient());
       }
       cascade_boundary.sort();
       out << (*sigma)->first.dimension();
       for( auto term : cascade_boundary){
       	out << " " << term.cell(); 
       }
       out << std::endl;
  }
  return 0;
}
示例#2
0
int main( int argc, char *argv[]){
  #ifdef ZOOM_PROFILE
  std::cout << "Connect" <<  ZMConnect() << std::endl;
  #endif
 
  po::variables_map vm;
  process_args( argc, argv, vm);
  size_t num_parts = atoi( vm[ "num-parts"].as< std::string>().c_str());

  //setup some variables
  std::string full_complex_name = vm[ "input-file"].as< std::string>();
  std::string complex_name( full_complex_name);
  std::string binary_name( argv[ 0]);

  size_t found = complex_name.rfind( '/');
  if ( found != std::string::npos){
        complex_name.replace( 0, found+1, "");
  }
  tbb::task_scheduler_init init;
  
  Complex complex;
  Nerve nerve;
  tbb::concurrent_vector< Complex_iterator> nearly_pure;
  Stats stats;

  // Read the cell_set in
  //read_complex( full_complex_name, complex);
  stats.timer.start();
  Complex_filtration complex_filtration( complex);
  stats.timer.stop();
  double orig_filtration_time = stats.timer.elapsed();
  std::cout << "filtered complex " << orig_filtration_time << std::endl;
  stats.timer.start();
  ctl::parallel::init_cover_complex( nerve, num_parts);
  ctl::parallel::graph_partition_open_cover( complex_filtration, nerve, nearly_pure);
  stats.timer.stop();
  double cover_time = stats.timer.elapsed();
  std::cout << "built cover." << std::endl;
  #ifdef ZOOM_PROFILE
  std::cout << "Profiling Begin";
  ZMError start_error = ZMStartSession();
  std::cout << start_error << std::endl;
  #endif 
 
  ctl::parallel::compute_homology( complex, nerve, num_parts, stats);
  #ifdef ZOOM_PROFILE
  ZMError end_error = ZMStopSession();
  std::cout << "Profiling End" << end_error << std::endl;
  #endif
  #ifdef ZOOM_PROFILE
   std::cout << "Disconnect" <<  ZMDisconnect() << std::endl;
  #endif
  double total_time = cover_time + stats.filtration_time + stats.get_iterators +
         	     stats.parallel_persistence + stats.initialize_cascade_boundary;
                  
  std::cout << std::setprecision( 2) << std::fixed;
                                                                                
  std::cout << "build cover: " << cover_time 
            << " (" << (cover_time/total_time)*100 << "%)" << std::endl;
                                                                                
  std::cout << "re-filter complex: " << stats.filtration_time 
            << " (" << (stats.filtration_time/total_time)*100 << "%)" 
            << std::endl;
  std::cout << "compute parallel ranges: " << stats.get_iterators
            << " (" << (stats.get_iterators/total_time)*100 << "%)" 
	    << std::endl;
  std::cout << "initialize_cascade_boundary: " 
            << stats.initialize_cascade_boundary << " (" 
            << (stats.initialize_cascade_boundary/total_time)*100 << "%)" << std::endl;
  std::cout << "parallel_homology: " 
            << stats.parallel_persistence << " (" 
            << (stats.parallel_persistence/total_time)*100 << "%)" << std::endl;
  std::cout << "total time: " << total_time << " (100%)" << std::endl;

#ifdef TESTS_ON
  ctl::run_tests( complex, blowup_complex, nerve);
#endif
  init.terminate();
  return 0;
}