1 /*-----------------------------------------------------*/
2 /*                      COOP-MADS                      */
3 /*  see user guide for a description of the algorithm  */
4 /*-----------------------------------------------------*/
5 #include "Cache_Server.hpp"
6 using namespace std;
7 using namespace NOMAD;
8 
9 // COOP-MADS parameters:
10 const bool USE_CACHE_SEARCH     = true;
11 const bool OPPORT_CACHE_SEARCH  = false;
12 const bool ALLOW_MULTIPLE_EVALS = false;
13 
14 /*-----------------------------------*/
15 /*           main function           */
16 /*-----------------------------------*/
main(int argc,char ** argv)17 int main ( int argc , char ** argv ) {
18 
19   // MPI initialization:
20   MPI_Init ( &argc , &argv );
21   int rank , np;
22   MPI_Comm_rank ( MPI_COMM_WORLD, &rank );
23   MPI_Comm_size ( MPI_COMM_WORLD, &np   );
24 
25   // check the arguments and the number of processes:
26   if ( np <= 1 || argc != 2 ) {
27     if ( rank==np-1 )
28       cerr << "usage: mpirun -np p " << argv[0]
29 	   << " param_file, with p>1" << endl;
30     MPI_Finalize();
31     return 1;
32   }
33 
34   // display:
35   Display out ( cout );
36   out.precision ( 16 );
37 
38   // parameters:
39   Parameters p ( out );
40 
41   try {
42 
43     // read the parameters file:
44     p.read ( argv[1] );
45 
46     // modify parameters:
47     p.set_DISPLAY_DEGREE ( NO_DISPLAY );
48     p.set_DISPLAY_STATS ( "process #" + itos(rank) + " BBE OBJ" );
49     p.set_SEED ( get_pid() );
50 
51     p.set_ANISOTROPIC_MESH(false);
52 
53     // cache search:
54     p.set_CACHE_SEARCH               ( USE_CACHE_SEARCH    );
55     p.set_OPPORTUNISTIC_CACHE_SEARCH ( OPPORT_CACHE_SEARCH );
56 
57     // check the parameters:
58     p.check();
59 
60     if ( p.get_nb_obj() > 1 )
61       throw Exception ( __FILE__ , __LINE__ ,
62       "COOP-MADS is not designed for multi-objective optimization" );
63   }
64   catch ( exception & e ) {
65     if ( rank==np-1 )
66       cerr << "error with parameters" << endl;
67     MPI_Finalize();
68     return 1;
69   }
70 
71   // cache server:
72   Cache_Server cache ( out                  ,
73 		       rank                 ,
74 		       np                   ,
75 		       p.get_h_min()        ,
76 		       p.get_max_bb_eval()  ,
77 		       ALLOW_MULTIPLE_EVALS   );
78 
79   if ( rank == np-1 )
80     out << endl << "TIME\tBBE\tOBJ" << endl << endl;
81 
82   // start the cache server:
83   cache.start();
84 
85   // clients: algorithm creation and execution:
86   if ( rank != np-1 ) {
87     Mads mads ( p , NULL , NULL , &cache , NULL );
88     mads.run();
89   }
90 
91   // stop the cache server:
92   cache.stop();
93 
94   // display the best solutions:
95   cache.display_current_solution();
96   if ( rank == np-1 )
97     out << endl;
98   cache.display_best_points();
99 
100   // MPI finalization:
101   MPI_Finalize();
102   return 0;
103 }
104