Beispiel #1
0
int main (int argc,char **argv )
{
  Chroma::initialize(&argc,&argv);

  WilsonTypeFermActs4DEnv::registerAll(); 
  LinOpSysSolverArrayEnv::registerAll();

  bfmarg::Verbose(1);
  bfmarg::UseCGdiagonalMee(0);

  /********************************************************
   * Command line parsing
   ********************************************************
   */
#define COMMANDLINE
#ifdef COMMANDLINE
  if ( argc != 6 ) { 
   Printf("Usage: %s lx ly lz lt Ls\n All must be even\n",argv[0]);
   Printf("argc is %d\n",argc);
   for ( int i=0;i<argc;i++){
      Printf("%d %s\n",i,argv[i]);
   }
      exit(-1);
  }
#endif

  /********************************************************
   * Setup QDP
   ********************************************************
   */
  multi1d<int> nrow(Nd);
#ifdef COMMANDLINE
  nrow[0] = atoi(argv[1]);
  nrow[1] = atoi(argv[2]);
  nrow[2] = atoi(argv[3]);
  nrow[3] = atoi(argv[4]);
#else
  nrow[0] = 4;
  nrow[1] = 2;
  nrow[2] = 2;
  nrow[3] = 4;
#endif

  bfmarg::Threads(1);
  bfmarg::Verbose(0);
  Layout::setLattSize(nrow);
  Layout::create();


  LatticeFermion src;
  gaussian(src);

  for(int i=0;i<1;i++){
    test_solver(HmCayleyTanh,src);
  }
}
Beispiel #2
0
void interface() {
  cout << "Which map do you want to resolve (from the server) ?" << endl;
  cout << "1: solve a board from the server" << endl;
  cout << "2: launch a test" << endl;

  cout << "Choice ?";
  int choice;
  cin >> choice;
  if (choice == 1) {
    cout << "Number of the map ?" << endl;
    int numMap;
    cin >> numMap;
    test_solver(numMap, true);
  }
Beispiel #3
0
int main(int argc, char *argv[])
{
  MPI_Comm comm, dup_comm, sub_comm;
  int err = 0;
  double timeout = 2;


  MPI_Init(&argc, &argv);

  comm = MPI_COMM_WORLD;

  MPI_Comm_size(comm, &size);
  MPI_Comm_rank(comm, &rank);

  if (argc < 2) goto exit;

  if (argc > 2) timeout = atof(argv[2]);

  if (rank == 0)
  {
    printf("Communicator test with method: '%s', timeout: %f second(s)\n", argv[1], timeout);
  }

  MPI_Comm_dup(comm, &dup_comm);
  MPI_Comm_split(comm, rank % 2, -rank, &sub_comm);

  if (rank % 2) err = test_solver(argv[1], sub_comm);
  else MPI_Barrier(sub_comm);

/*  if (err) goto exit;*/
  
  int b = 0xdeadbeef;

  if (rank > 0) MPI_Send(&b, 1, MPI_INT, 0, 0, dup_comm);
  else
  {
    MPI_Request req = MPI_REQUEST_NULL;
    MPI_Status status;
    int flag;
    int r = size - 1;
    double t = MPI_Wtime() + timeout;

    while (r > 0)
    {
      if (req == MPI_REQUEST_NULL) MPI_Irecv(&b, 1, MPI_INT, MPI_ANY_SOURCE, 0, dup_comm, &req);

      MPI_Test(&req, &flag, &status);

      if (flag) --r;

      if (MPI_Wtime() > t) break;
    }
    
    if (r > 0) MPI_Abort(MPI_COMM_WORLD, 1);
  }

  MPI_Bcast(&err, 1, MPI_INT, 1, comm);

exit:
  MPI_Finalize();

  return err;
}
Beispiel #4
0
int main(int argc, char* argv[])
{
  // STATUS MESSAGE
  std::string usage("This application solve the problem of the ECMA ");
  usage += "project, using different solver. You can chose the solver that you want to ";
  usage += "use with the --solver flag. Usage is defined below. You also have to set a ";
  usage += "instance file with the flag --instance, and you can define an output file.\n";
  usage += "Simple usage : \n\t";
  usage += argv[0];
  usage += " --solver=frontal --instance=path_to_instance";
  gflags::SetUsageMessage(usage);
  
  // VERSION MESSAGE
  gflags::SetVersionString(ecma::helpers::to_string(ECMA_VERSION_MAJOR) + "." + ecma::helpers::to_string(ECMA_VERSION_MINOR) + "."
    + ecma::helpers::to_string(ECMA_VERSION_PATCH) + " -- Build type : " + CMAKE_BUILD_TYPE);

  // Parsing flags
  gflags::ParseCommandLineFlags(&argc, &argv, true); // NoHelp

  // Initialize Google's logging library.
  FLAGS_stderrthreshold = 0;
  FLAGS_log_dir = FLAGS_logFile;
  google::InitGoogleLogging(argv[0]);


  if (FLAGS_instance == "") {
    LOG(ERROR) << "You have to pass an instance through the --instance flag";
    LOG(FATAL) << "Wrong Parameters";
  }
  else {
    // Démarrage d'un chronomètre
    time_t start_time;
    time(&start_time);

    LOG(INFO) << "Reading Data from instance : " << FLAGS_instance;
    Data data;
    ecma::reader::read_instance(data, FLAGS_instance);
    Solution sol(data);

    double cost;
    bool is_admissible;
    std::string description;
    int borne = 10000;

    // Computation of the born in any cases.
    std::string tag = std::string(FLAGS_instance).substr(std::string(FLAGS_instance).find("projet"));
    ecma::constants::init();
    // Si la borne est dans la map de donnée, load it
    if (ecma::constants::bornes.find(tag) != ecma::constants::bornes.end()) {
      borne = ecma::constants::bornes[tag];
    }
    //  GreedySolverWithoutConnexity greedy_solver_without_connexity(data);
    //  description = greedy_solver_without_connexity.name() + " : " + greedy_solver_without_connexity.description(); 
    // // LOG(INFO) << description;
    //  greedy_solver_without_connexity.solve();
    //  borne = greedy_solver_without_connexity.sol().compute_cost();    
     LOG(INFO) << "Borne :\t" << borne;

    // Solving this instance using "Solver"
    if (FLAGS_solver == "stupid") {
      // Solve via Stupid Solver
      StupidSolver stupid_solver(data);
      description = stupid_solver.name() + " : " + stupid_solver.description(); 
      LOG(INFO) << description;
      stupid_solver.solve();
      sol.fill_sol(stupid_solver.sol());
    }
    else if (FLAGS_solver == "frontal") {
      // Solve via Frontal Solver
      FrontalSolver frontal_solver(data);
      description = frontal_solver.name() + " : " + frontal_solver.description(); 
      LOG(INFO) << description;
      frontal_solver.solve(borne);
      sol.fill_sol(frontal_solver.sol());
    }
    else if (FLAGS_solver == "frontalWconnexity") {
      // Solve via greedy Solver
      GreedySolverWithoutConnexity greedy_solver_without_connexity(data);
      if (not(greedy_solver_without_connexity.solve())) LOG(FATAL) << "Greedy solver failed !";
      
      // Solve via Frontal Solver
      FrontalSolverWithoutConnexity frontal_solver_without_connexity(data);
      description = frontal_solver_without_connexity.name() + " : " + frontal_solver_without_connexity.description(); 
      LOG(INFO) << description;
      frontal_solver_without_connexity.sol_ptr()->fill_sol(greedy_solver_without_connexity.sol());
      frontal_solver_without_connexity.solve(borne,true);
      sol.fill_sol(frontal_solver_without_connexity.sol());
    }
    else if (FLAGS_solver == "warmGreedyFrontal") {
      // Solve via greedy Solver
      GreedySolver greedy_solver(data);
      if (not(greedy_solver.solve())) LOG(FATAL) << "Greedy solver failed !";
      
      // Solve via Frontal Solver
      FrontalSolver frontal_solver(data);
      description = frontal_solver.name() + " : " + frontal_solver.description(); 
      LOG(INFO) << description;
      frontal_solver.sol_ptr()->fill_sol(greedy_solver.sol());
      frontal_solver.solve(borne,true);
      sol.fill_sol(frontal_solver.sol());
    }
    else if (FLAGS_solver == "warmAnnealingFrontal") {
      AnnealingSolver annealing_solver(data);
      if (not(annealing_solver.solve(FLAGS_tempInit))) LOG(FATAL) << "Greedy solver failed !";
      
      // Solve via Frontal Solver
      FrontalSolver frontal_solver(data);
      description = frontal_solver.name() + " : " + frontal_solver.description(); 
      LOG(INFO) << description;
      frontal_solver.sol_ptr()->fill_sol(annealing_solver.sol());
      frontal_solver.solve(borne,true);
      sol.fill_sol(frontal_solver.sol());
    }
    else if (FLAGS_solver == "greedy") {
      // Solve via Greedy Solver
      GreedySolver greedy_solver(data);
      description = greedy_solver.name() + " : " + greedy_solver.description(); 
      LOG(INFO) << description;
      greedy_solver.solve();
      sol.fill_sol(greedy_solver.sol());
    }
    else if (FLAGS_solver == "greedyWconnexity") {
      // Solve via Greedy Solver Without connexity
      GreedySolverWithoutConnexity greedy_solver_without_connexity(data);
      description = greedy_solver_without_connexity.name() + " : " + greedy_solver_without_connexity.description(); 
      LOG(INFO) << description;
      greedy_solver_without_connexity.solve();
      sol.fill_sol(greedy_solver_without_connexity.sol());
    }
    else if (FLAGS_solver == "constraint") {
      // Solve via Constraint Solver
      ConstraintSolver constaint_solver(data);
      description = constaint_solver.name() + " : " + constaint_solver.description(); 
      LOG(INFO) << description;
      constaint_solver.solve(borne);
      sol.fill_sol(constaint_solver.sol());
    }
    else if (FLAGS_solver == "annealing") {
      // Solve via Annealing Solver
      // GreedySolver greedy_solver(data);
      // if (not(greedy_solver.solve())) LOG(FATAL) << "Greedy solver failed !";
      AnnealingSolver annealing_solver(data);
      description = annealing_solver.name() + " : " + annealing_solver.description(); 
      LOG(INFO) << description;
      // annealing_solver.sol_ptr()->fill_sol(greedy_solver.sol());
      annealing_solver.solve(FLAGS_tempInit);
      sol.fill_sol(annealing_solver.sol());
    }
    else if (FLAGS_solver == "annealing1") {
      AnnealingSolver annealing_solver(data);
      description = annealing_solver.name() + " : " + annealing_solver.description(); 
      LOG(INFO) << description;
      Solution* sol_i = annealing_solver.sol_ptr();
      for (int i = 0; i < sol_i->x_.size(); ++i)
      for (int j = 0; j < sol_i->x_[i].size(); ++j)    
        sol_i->x_[i][j] = 1;
      annealing_solver.solve(FLAGS_tempInit,true);
      sol.fill_sol(annealing_solver.sol());
    }
    else if (FLAGS_solver == "ant") {
      // Solve via Ant Solver
      AntSolver ant_solver(data);
      description = ant_solver.name() + " : " + ant_solver.description(); 
      LOG(INFO) << description;
      ant_solver.solve();
      sol.fill_sol(ant_solver.sol());
    }
    else if (FLAGS_solver == "mix") {
      // Solve via Annealing Solver
      GreedySolver greedy_solver(data);
      if (not(greedy_solver.solve())) LOG(FATAL) << "Greedy solver failed !";
      AnnealingSolver annealing_solver(data);
      description = annealing_solver.name() + " : " + annealing_solver.description(); 
      LOG(INFO) << description;
      annealing_solver.sol_ptr()->fill_sol(greedy_solver.sol());
      annealing_solver.solve(FLAGS_tempInit,true);
      sol.fill_sol(annealing_solver.sol());
    }
    else if (FLAGS_solver == "test") {
      // Solve via Test Solver
      TestSolver test_solver(data);
      description = test_solver.name() + " : " + test_solver.description(); 
      LOG(INFO) << description;
      test_solver.solve();
      sol.fill_sol(test_solver.sol());
      AnnealingSolver annealing_solver(data);
      LOG(INFO) << description;
      annealing_solver.sol_ptr()->fill_sol(test_solver.sol());
      annealing_solver.solve(FLAGS_tempInit,true);
      sol.fill_sol(annealing_solver.sol());      
    }
    else {
      LOG(FATAL) << "Wrong solver id, use the --solver tag, with stupid, frontal, or constraint";
    }

    // Arrêt et exploitation du chronomètre
    time_t end_time;
    time(&end_time);
    double diff = difftime(end_time, start_time);

    // Data exportation
    data.print();
    cost = sol.compute_cost();
    is_admissible = sol.ratio() >= 2 && sol.is_connex();
    sol.print();
    LOG(INFO) << "Temps de calcul:\t" << diff << " seconds";
    LOG(INFO) << "Borne :\t" << borne;

    if (is_admissible || FLAGS_solver == "frontalWconnexity" ||
        FLAGS_solver == "greedyWconnexity") {
      ecma::writer::write_in_synthetic_res_file(
          cost, description, FLAGS_instance, diff, FLAGS_synRes);
      ecma::writer::export_solution(sol, FLAGS_solDir, diff);
    } else
      LOG(ERROR) << "The solution is not admissible";
  }
  return 0;

}