Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
Change the way we specify the sizes of bandwidth tests to be able to send really...
[simgrid.git] / examples / amok / saturate / saturate.c
index 108e595..355c2ab 100644 (file)
@@ -31,15 +31,15 @@ int sensor (int argc,char *argv[]) {
 
   gras_init(&argc, argv);
   amok_bw_init();
-  amok_hm_init();
+  amok_pm_init();
  
   mysock = gras_socket_server_range(3000,9999,0,0);
   INFO1("Sensor starting (on port %d)",gras_os_myport());
   gras_os_sleep(2); /* let the master get ready */
   master = gras_socket_client_from_string(argv[1]);
                                              
-  amok_hm_group_join(master,"saturate");
-  amok_hm_mainloop(600);
+  amok_pm_group_join(master,"saturate");
+  amok_pm_mainloop(600);
 
   gras_socket_close(mysock);
   gras_socket_close(master);
@@ -56,8 +56,8 @@ int maestro (int argc,char *argv[]);
 
 /* XP setups */
 const int buf_size = 0;
-const int exp_size = 100 * 1024;
 const int msg_size = 50 * 1024;
+const int msg_amount = 2;
 const int sat_size = 1024 * 1024 * 10;
 const double min_duration = 1;
 
@@ -69,7 +69,7 @@ static double XP(const char *bw1, const char *bw2,
   gras_os_sleep(5.0); /* wait for the sensors to show up */
   /* Test BW without saturation */
   amok_bw_request(bw1,4000,bw2,4000,
-                 buf_size,exp_size,msg_size,min_duration,&sec,&bw);
+                 buf_size,msg_size,msg_amount,min_duration,&sec,&bw);
   INFO4("BW(%s,%s) => %f sec, achieving %f Mb/s",
        bw1, bw2, sec, (bw/1024.0/1024.0));
 
@@ -79,7 +79,7 @@ static double XP(const char *bw1, const char *bw2,
   gras_os_sleep(1.0); /* let it start */
 
   amok_bw_request(bw1,4000,bw2,4000,
-                 buf_size,exp_size,msg_size,min_duration,&sec_sat,&bw_sat);
+                 buf_size,msg_size,msg_amount,min_duration,&sec_sat,&bw_sat);
   INFO6("BW(%s,%s//%s,%s) => %f sec, achieving %f Mb/s",
        bw1,bw2,sat1,sat2,sec,bw/1024.0/1024.0);
   
@@ -113,26 +113,42 @@ static void free_peer(void *d){
 static void simple_saturation(int argc, char*argv[]) {
   xbt_ex_t e;
 
-  kill_buddy(argv[5],atoi(argv[6]));
-  kill_buddy(argv[7],atoi(argv[8]));
+  /* where are the sensors */
+  xbt_dynar_t peers;
+  xbt_peer_t h1,h2;
+  /* results */
+  double duration,bw;
 
-  amok_bw_saturate_start(argv[1],atoi(argv[2]),argv[3],atoi(argv[4]),
-                        sat_size,5);
-  gras_os_sleep(3);
+  /* Init the group */
+  peers=amok_pm_group_new("saturate");
+  /* wait for dudes */
+  gras_msg_handleall(5);
+
+  /* get 2 friends */
+  xbt_dynar_get_cpy(peers,0,&h1);
+  xbt_dynar_get_cpy(peers,1,&h2);
+   
+  /* Start saturation */
+  amok_bw_saturate_start(h1->name,h1->port,
+                        h2->name,h2->port,
+                        0, /* Be a nice boy, compute msg_size yourself */
+                        30  /* 5 sec timeout */);  
+
+  /* Stop it after a while */
+  gras_os_sleep(1);
   TRY {
-    amok_bw_saturate_stop(argv[1],atoi(argv[2]),NULL,NULL);
+    amok_bw_saturate_stop(h1->name,h1->port, &duration,&bw);
   } CATCH(e) {
     xbt_ex_free(e);
   }
-
-  kill_buddy(argv[1],atoi(argv[2]));
-  kill_buddy(argv[3],atoi(argv[4]));
+  INFO2("Saturation took %.2fsec, achieving %fb/s",duration,bw);
+   
+  /* Game is over, friends */
+  amok_pm_group_shutdown ("saturate");
 }
 /********************************************************************************************/
 static void full_fledged_saturation(int argc, char*argv[]) {
   xbt_ex_t e;
-//unsigned int time1=5,bw1=5;
   double time1=5.0,bw1=5.0; // 0.5 for test
   /* timers */
   double begin_simulated; 
@@ -151,7 +167,7 @@ static void full_fledged_saturation(int argc, char*argv[]) {
   xbt_peer_t h1,h2,h3,h4;
 
   /* Init the group */
-  peers=amok_hm_group_new("saturate");
+  peers=amok_pm_group_new("saturate");
   /* wait 4 dudes */
   gras_msg_handle(60);
   gras_msg_handle(60);
@@ -165,7 +181,7 @@ static void full_fledged_saturation(int argc, char*argv[]) {
   begin=time(NULL);
   begin_simulated=gras_os_time();
 
-  bw=amok_bw_matrix(peers,buf_size,exp_size,msg_size,min_duration);
+  bw=amok_bw_matrix(peers,buf_size,msg_size,msg_amount,min_duration);
 
   INFO2("Did all BW tests in %ld sec (%.2f simulated(?) sec)",
          time(NULL)-begin,gras_os_time()-begin_simulated);
@@ -198,7 +214,7 @@ static void full_fledged_saturation(int argc, char*argv[]) {
          VERB4("TEST %s %s // %s %s",
                h1->name,h2->name,h3->name,h4->name);
          amok_bw_request(h3->name,h3->port, h4->name,h4->port,
-                         buf_size,exp_size,msg_size,min_duration,
+                         buf_size,msg_size,msg_amount,min_duration,
                          NULL,&(bw_sat[k*nb_peers + l]));
 
          ratio=bw_sat[k*nb_peers + l] / bw[k*nb_peers + l];
@@ -209,7 +225,7 @@ static void full_fledged_saturation(int argc, char*argv[]) {
                ratio < 0.7 ? " THERE IS SOME INTERFERENCE !!!": "");
        }
       }
-      amok_bw_saturate_stop(h1->name,h1->port,&time1,&bw1);// NULL,NULL);
+      amok_bw_saturate_stop(h1->name,h1->port,&time1,&bw1);
 
       INFO2("Did an iteration on saturation pair in %ld sec (%.2f simulated sec)",
              time(NULL)-begin, gras_os_time()-begin_simulated);
@@ -219,7 +235,7 @@ static void full_fledged_saturation(int argc, char*argv[]) {
   free(bw_sat);
   free(bw);
   /* Game is over, friends */
-  amok_hm_group_shutdown ("saturate");
+  amok_pm_group_shutdown ("saturate");
 }
 
 
@@ -227,12 +243,12 @@ int maestro(int argc,char *argv[]) {
 
   gras_init(&argc,argv);
   amok_bw_init();
-  amok_hm_init();
+  amok_pm_init();
 
   gras_socket_server(atoi(argv[1]));
 
-  //  simple_saturation(argc,argv);
-  full_fledged_saturation(argc, argv);  
+  simple_saturation(argc,argv);
+  //full_fledged_saturation(argc, argv);  
 
   gras_exit();
   return 0;