Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
Convert to amok/hostmanagement; kill ENV from here
[simgrid.git] / examples / amok / saturate / saturate.c
index 833d558..4eebdf0 100644 (file)
@@ -14,6 +14,7 @@
 
 #include "gras.h"
 #include "amok/bandwidth.h"
+#include "amok/hostmanagement.h"
 
 XBT_LOG_NEW_DEFAULT_CATEGORY(saturate,"Messages specific to this example");
 
@@ -21,27 +22,28 @@ XBT_LOG_NEW_DEFAULT_CATEGORY(saturate,"Messages specific to this example");
  * Sensor code
  * **********************************************************************/
 
-/* Global private data */
-typedef struct {
-  gras_socket_t sock;
-} sensor_data_t;
-
 /* Function prototypes */
 int sensor (int argc,char *argv[]);
 
 int sensor (int argc,char *argv[]) {
-  sensor_data_t *g;
+  gras_socket_t mysock;
+  gras_socket_t master;
 
-  gras_init(&argc,argv);
+  gras_init(&argc, argv);
   amok_bw_init();
-
-  g=gras_userdata_new(sensor_data_t);  
-  g->sock = gras_socket_server(4000);
-
-  while (1) {
-    gras_msg_handle(60.0);
-  }
-
+  amok_hm_init();
+  mysock = gras_socket_server_range(3000,9999,0,0);
+  INFO1("Sensor starting (on port %d)",gras_os_myport());
+  gras_os_sleep(0.5); /* let the master get ready */
+  master = gras_socket_client_from_string(argv[1]);
+                                             
+  amok_hm_group_join(master,"saturate");
+  amok_hm_mainloop(600);
+
+  gras_socket_close(mysock);
+  gras_socket_close(master);
+  gras_exit();
   return 0;
 }
 
@@ -52,18 +54,22 @@ int sensor (int argc,char *argv[]) {
 /* Function prototypes */
 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 sat_size = 1024 * 1024 * 10;
+const double min_duration = 1;
+
 static double XP(const char *bw1, const char *bw2,
                 const char *sat1, const char *sat2) {
 
-  int buf_size=32 * 1024;
-  int exp_size=64 * 1024;
-  int msg_size=64 * 1024;
-  int sat_size=msg_size * 10;
   double sec, bw, sec_sat,bw_sat;
 
+  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,&sec,&bw);
+                 buf_size,exp_size,msg_size,min_duration,&sec,&bw);
   INFO4("BW(%s,%s) => %f sec, achieving %f Mb/s",
        bw1, bw2, sec, (bw/1024.0/1024.0));
 
@@ -73,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,&sec_sat,&bw_sat);
+                 buf_size,exp_size,msg_size,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);
   
@@ -88,25 +94,52 @@ static double XP(const char *bw1, const char *bw2,
   return bw_sat/bw;
 }
 
+static void kill_buddy(char *name,int port){
+  gras_socket_t sock=gras_socket_client(name,port);
+  gras_msg_send(sock,gras_msgtype_by_name("kill"),NULL);
+  gras_socket_close(sock);
+}
+static void kill_buddy_dynar(void *b) {
+  xbt_host_t buddy=*(xbt_host_t*)b;
+  kill_buddy(buddy->name,buddy->port);
+}
+
 static void free_host(void *d){
   xbt_host_t h=*(xbt_host_t*)d;
   free(h->name);
   free(h);
 }
-int maestro(int argc,char *argv[]) {
+
+static void simple_saturation(int argc, char*argv[]) {
   xbt_ex_t e;
-  /* XP setups */
-  int buf_size=0;
-  int exp_size= 1024 * 1024;
-  int msg_size=exp_size;
-  int sat_size=msg_size * 100;
 
+  kill_buddy(argv[5],atoi(argv[6]));
+  kill_buddy(argv[7],atoi(argv[8]));
+
+  amok_bw_saturate_start(argv[1],atoi(argv[2]),argv[3],atoi(argv[4]),
+                        sat_size,5);
+  gras_os_sleep(3);
+  TRY {
+    amok_bw_saturate_stop(argv[1],atoi(argv[2]),NULL,NULL);
+  } CATCH(e) {
+    xbt_ex_free(e);
+  }
+
+  kill_buddy(argv[1],atoi(argv[2]));
+  kill_buddy(argv[3],atoi(argv[4]));
+}
+/********************************************************************************************/
+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; 
   int begin;
 
   /* where are the sensors */
-  xbt_dynar_t hosts = xbt_dynar_new(sizeof(xbt_host_t),&free_host);
+  xbt_dynar_t hosts;
   int nb_hosts;
 
   /* results */
@@ -117,26 +150,21 @@ int maestro(int argc,char *argv[]) {
   int i,j,k,l;
   xbt_host_t h1,h2,h3,h4;
 
-  gras_init(&argc,argv);
-  amok_bw_init();
-
-  /* Get the sensor location from argc/argv */
-  for (i=1; i<argc-1; i+=2){
-    xbt_host_t host=xbt_new(s_xbt_host_t,1);
-    host->name=strdup(argv[i]);
-    host->port=atoi(argv[i+1]);
-    INFO2("New sensor: %s:%d",host->name,host->port);
-    xbt_dynar_push(hosts,&host);
-  }
+  /* Init the group */
+  hosts=amok_hm_group_new("saturate");
+  INFO0("Wait for peers for 5 sec");
+  gras_msg_handleall(5); /* friends, we're ready. Come and play */
   nb_hosts = xbt_dynar_length(hosts);
 
+  INFO0("Let's go for the bw_matrix");
+
   /* Do the test without saturation */
   begin=time(NULL);
   begin_simulated=gras_os_time();
 
-  bw=amok_bw_matrix(hosts,buf_size,exp_size,msg_size);
+  bw=amok_bw_matrix(hosts,buf_size,exp_size,msg_size,min_duration);
 
-  INFO2("Did all BW tests in %ld sec (%.2f simulated sec)",
+  INFO2("Did all BW tests in %ld sec (%.2f simulated(?) sec)",
          time(NULL)-begin,gras_os_time()-begin_simulated);
 
   /* Do the test with saturation */
@@ -144,11 +172,11 @@ int maestro(int argc,char *argv[]) {
   xbt_dynar_foreach(hosts,i,h1) {
     xbt_dynar_foreach(hosts,j,h2) {
       if (i==j) continue;
-       
+
       TRY {
        amok_bw_saturate_start(h1->name,h1->port,
                               h2->name,h2->port,
-                              sat_size,360000000);
+                              sat_size, 0/* no timeout */);  
       } CATCH(e) {
        RETHROW0("Cannot ask hosts to saturate the link: %s");
       }
@@ -163,72 +191,46 @@ int maestro(int argc,char *argv[]) {
          double ratio;
          if (i==l || j==l || k==l) continue;
 
+         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,
-                         NULL,&(bw_sat[k*nb_hosts + l])); 
-         
+                         buf_size,exp_size,msg_size,min_duration,
+                         NULL,&(bw_sat[k*nb_hosts + l]));
+
          ratio=bw_sat[k*nb_hosts + l] / bw[k*nb_hosts + l];
          INFO8("SATURATED BW XP(%s %s // %s %s) => %f (%f vs %f)%s",
                h1->name,h2->name,h3->name,h4->name,
                ratio,
                bw[k*nb_hosts + l] , bw_sat[k*nb_hosts + l],
-
                ratio < 0.7 ? " THERE IS SOME INTERFERENCE !!!": "");
        }
       }
-
-      amok_bw_saturate_stop(h1->name,h1->port, NULL,NULL);
+      amok_bw_saturate_stop(h1->name,h1->port,&time1,&bw1);// NULL,NULL);
 
       INFO2("Did an iteration on saturation pair in %ld sec (%.2f simulated sec)",
              time(NULL)-begin, gras_os_time()-begin_simulated);
+       INFO2("the duration of the experiment >>>>> %.3f sec (%.3f bandwidth)",time1,bw1);
     }
   }
+  free(bw_sat);
+  free(bw);
+  /* Game is over, friends */
+  amok_hm_group_shutdown ("saturate");
+}
 
-  gras_os_sleep(5.0);
-  exit(0);
-#if 0
-  return 0;
-  /* start saturation */
-  fprintf(stderr,"MAESTRO: Start saturation with size %d",msg_size);
-  if ((errcode=grasbw_saturate_start(argv[5],atoi(argv[6]),argv[7],atoi(argv[8]),msg_size*10,60))) {
-    fprintf(stderr,"MAESTRO: Error %s encountered while starting saturation",
-           xbt_error_name(errcode));
-    return 1;
-  }
-  fprintf(stderr,"MAESTRO: Saturation started");
-  gras_os_sleep(5.0);
-
-  /* test with saturation */
-  if ((errcode=grasbw_request(argv[1],atoi(argv[2]),argv[3],atoi(argv[4]),
-                             buf_size,exp_size,msg_size,&sec,&bw))) {
-    fprintf(stderr,"MAESTRO: Error %s encountered while doing the test",xbt_error_name(errcode));
-    return 1;
-  }
-   
-  fprintf(stderr,"MAESTRO: Experience3 (%d ko in msgs of %d ko with saturation) took %f sec, achieving %f Mb/s",
-         exp_size/1024,msg_size/1024,
-         sec,bw);
-
-  /* stop saturation */
-  if ((errcode=grasbw_saturate_stop(argv[5],atoi(argv[6]),argv[7],atoi(argv[8])))) {
-    fprintf(stderr,"MAESTRO: Error %s encountered while stopping saturation",
-           xbt_error_name(errcode));
-    return 1;
-  }
 
-  /* test without saturation */
-  if ((errcode=grasbw_request(argv[1],atoi(argv[2]),argv[3],atoi(argv[4]),
-                             buf_size,exp_size,msg_size,&sec,&bw))) {
-    fprintf(stderr,"MAESTRO: Error %s encountered while doing the test",xbt_error_name(errcode));
-    return 1;
-  }
-   
-  fprintf(stderr,"MAESTRO: Experience4 (%d ko in msgs of %d ko, without saturation) took %f sec, achieving %f Mb/s",
-         exp_size/1024,msg_size/1024,
-         sec,bw);
-
-  gras_os_sleep(5.0);
-#endif
-   
+int maestro(int argc,char *argv[]) {
+
+  gras_init(&argc,argv);
+  amok_bw_init();
+  amok_hm_init();
+
+  gras_socket_server(atoi(argv[1]));
+
+  //  simple_saturation(argc,argv);
+  full_fledged_saturation(argc, argv);  
+
+  gras_exit();
   return 0;
+
 }