예제 #1
1
/*------------------------------------------*/
int main ( int argc , char ** argv )
{
	
  // display:
  NOMAD::Display out ( NOMAD::rout );     //zhenghua
  out.precision ( NOMAD::DISPLAY_PRECISION_STD );
	

  std::string error;
  {
    // NOMAD initializations:
    NOMAD::begin ( argc , argv );

    // usage:
    if ( argc < 2 ) {
      NOMAD::display_usage ( out); //zhenghua
      NOMAD::end();
      return EXIT_FAILURE;
    }

    // parameters file:
    std::string param_file_name = argv[1];
    std::string opt             = param_file_name;
    NOMAD::toupper ( opt );

	  // display version if option '-v' has been specified:
	  if ( opt == "-U" ) {
		  NOMAD::display_usage ( out );
		  NOMAD::end();
		  return EXIT_SUCCESS;
	  }
	  
	  
    // display version if option '-v' has been specified:
    if ( opt == "-V" || opt =="-VERSION") {
      NOMAD::display_version ( out );
      NOMAD::end();
      return EXIT_SUCCESS;
    }

    // display info if option '-i' has been specified:
    if ( opt == "-I" || opt == "-INFO" ) {
      NOMAD::display_info  ( out );
      NOMAD::display_usage ( out ); //zhenghua
      NOMAD::end();
      return EXIT_SUCCESS;
    }
  
    // parameters creation:
    NOMAD::Parameters p ( out );

    // display help on parameters if option '-h' has been specified:
    if ( opt == "-H" || opt == "-HELP" ) {
      p.help ( argc , argv );
      NOMAD::end();
      return EXIT_SUCCESS;
    }

	  // display developer help on parameters if option '-d' has been specified:
	  if ( opt == "-D" ) {
		  p.help ( argc , argv,true );
		  NOMAD::end();
		  return EXIT_SUCCESS;
	  }  
	  
	  
    // check the number of processess:
#ifdef USE_MPI
    if ( NOMAD::Slave::get_nb_processes() < 2 ) {
				NOMAD::rout << "ERROR: Incorrect command to run with MPI." << std::endl; //zhenghua
      NOMAD::display_usage ( out ); //zhenghua
      NOMAD::end();
      return EXIT_FAILURE;
    }
#endif
    
    try {

	
      // read parameters file:
      p.read ( param_file_name );

      // parameters check:
      p.check();

	  // display NOMAD info:
	  if ( p.get_display_degree() > NOMAD::MINIMAL_DISPLAY)
		NOMAD::display_info ( out );

      // parameters display:
      if ( NOMAD::Slave::is_master() &&
       	   p.get_display_degree() == NOMAD::FULL_DISPLAY ) 
	out << std::endl
	    << NOMAD::open_block ( "parameters" ) << std::endl
	    << p
	    << NOMAD::close_block();

      // algorithm creation and execution:
      NOMAD::Mads mads ( p , NULL );
      if ( p.get_nb_obj() == 1 )
	mads.run();
      else
	mads.multi_run();

#ifdef MODEL_STATS
      mads.display_model_stats ( out );
#endif

    }
    catch ( std::exception & e ) {
      if ( NOMAD::Slave::is_master() ) {
	error = std::string ( "NOMAD has been interrupted: " ) + e.what();
	NOMAD::rout << std::endl << error << std::endl << std::endl;  //zhenghua
      }
    }
    
    NOMAD::Slave::stop_slaves ( out );
    NOMAD::end();
  }

#ifdef MEMORY_DEBUG
  NOMAD::display_cardinalities ( out );
#endif

  return ( error.empty() ) ? EXIT_SUCCESS : EXIT_FAILURE;
}
예제 #2
0
파일: main.cpp 프로젝트: TheLoutre/nomad
/*-----------------------------------*/
int main ( int argc , char ** argv ) {

  // MPI initialization:
  MPI_Init ( &argc , &argv );
  int rank , np;
  MPI_Comm_rank ( MPI_COMM_WORLD, &rank );
  MPI_Comm_size ( MPI_COMM_WORLD, &np   );

  // check the arguments and the number of processes:
  if ( np <= 2 || argc != 4 ) {
    if ( rank == 0 )
      cerr << "usage: mpirun -np p " << argv[0]
	   << " param_file bbe ns, with p>2,"
	   << " bbe>1, and 1<=ns<=n."
	   << endl;
    MPI_Finalize();
    return 1;
  }

  // display:
  Display out ( cout );
  out.precision ( 16 );

  // parameters:
  NOMAD::Parameters p ( out );
  int bbe = atoi ( argv[2] );
  int ns  = atoi ( argv[3] );

  try {

    // read the parameters file:
    p.read ( argv[1] );

    // check the parameters:
    p.check();

    if ( ns < 1 || ns > p.get_dimension() )
      throw Exception ( __FILE__ , __LINE__ ,
      "Bad value for ns the number of free variables for each process" );

    if ( p.get_nb_obj() > 1 )
      throw Exception ( __FILE__ , __LINE__ ,
      "PSD-MADS is not designed for multi-objective optimization" );
  }
  catch ( exception & e ) {
    if ( rank == 0 )
      cerr << "error with parameters" << endl;
    MPI_Finalize();
    return 1;
  }

  // start the master:
  Master_Slaves master_slaves ( rank , np , bbe , ns , p , DEBUG );
  master_slaves.start();

  // cache server:
  Cache_Server cache ( out                  ,
		       rank                 ,
		       np                   ,
		       p.get_h_min()        ,
		       p.get_max_bb_eval()  ,
		       false                ,  // ALLOW_MULTIPLE_EVALS
		       DEBUG                  );

  // start the cache server:
  if ( rank == np-1 ) {
    if ( !DEBUG )
      out << endl << "TIME\tBBE\tOBJ" << endl << endl;
    cache.start();
  }

  // slaves: algorithm creation and execution:
  if ( rank != 0 && rank != np-1 ) {

    // MADS run:
    master_slaves.mads_run ( cache );

    // stop the master:
    master_slaves.stop();
  }

  // stop the cache server:
  cache.stop();

  // display the final solution:
  if ( !DEBUG && rank == np-1 )
    cache.display_best_points ( out );

  // MPI finalization:
  MPI_Finalize();
  return 0;
}