Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
cosmetics
[simgrid.git] / examples / gras / pmm / pmm.c
index b41dfad..101ab30 100755 (executable)
@@ -80,6 +80,7 @@ typedef struct {
 int master (int argc,char *argv[]) {
 
   int i;
+  double init_delay;
 
   xbt_matrix_t A,B,C;
   result_t result;
@@ -92,7 +93,7 @@ int master (int argc,char *argv[]) {
 
   /* Init the GRAS's infrastructure */
   gras_init(&argc, argv);
-  amok_hm_init();
+  amok_pm_init();
   register_messages();
       
   /* Initialize data matrices */
@@ -101,10 +102,18 @@ int master (int argc,char *argv[]) {
   C = xbt_matrix_double_new_zeros(DATA_MATRIX_SIZE,DATA_MATRIX_SIZE);
        
   /* Create the connexions */
+  xbt_assert0(argc>1, "Usage: master <port>");
   gras_socket_server(atoi(argv[1]));
-  peers=amok_hm_group_new("pmm");
-  INFO0("Wait for peers for 10 sec");
-  gras_msg_handleall(10); /* friends, we're ready. Come and play */
+  peers=amok_pm_group_new("pmm");
+   
+  /* friends, we're ready. Come and play */
+  if (gras_if_RL()) {
+     init_delay = 5;
+  } else {
+     init_delay = 15; /* no idea why I have to wait that long in simulation */
+  }
+  INFO1("Wait for peers for %.0f sec",init_delay);
+  gras_msg_handleall(init_delay);
   INFO1("Got %ld pals",xbt_dynar_length(peers));
 
   for (i=0;
@@ -112,6 +121,7 @@ int master (int argc,char *argv[]) {
        i++) {
 
     xbt_dynar_get_cpy(peers,i,&grid[i]);
+    INFO2("Connecting to %s:%d.",grid[i]->name,grid[i]->port);
     socket[i]=gras_socket_client(grid[i]->name,grid[i]->port);
     INFO2("Connected to %s:%d.",grid[i]->name,grid[i]->port);
   }
@@ -123,8 +133,9 @@ int master (int argc,char *argv[]) {
   for (i=SLAVE_COUNT; i<xbt_dynar_length(peers); ) {
     xbt_peer_t h;
 
-    xbt_dynar_get_cpy(peers,i,&h);
-    amok_hm_kill_hp(h->name,h->port);
+    xbt_dynar_remove_at(peers,i,&h);
+    INFO2("Too much slaves. Killing %s:%d", h->name, h->port);
+    amok_pm_kill_hp(h->name,h->port);
     free(h);
   }
 
@@ -193,7 +204,7 @@ int master (int argc,char *argv[]) {
      INFO1("Matrix size too big (%d>30) to be displayed here",DATA_MATRIX_SIZE);
   }
 
-  amok_hm_group_shutdown ("pmm");   /* Ok, we're out of here */
+  amok_pm_group_shutdown ("pmm");   /* Ok, we're out of here */
 
   for(i=0; i<SLAVE_COUNT; i++) {
      gras_socket_close(socket[i]);
@@ -357,7 +368,7 @@ int slave(int argc,char *argv[]) {
 
   /* Init the GRAS's infrastructure */
   gras_init(&argc, argv);
-  amok_hm_init();
+  amok_pm_init();
 
   /*  Register the known messages and my callback */
   register_messages();
@@ -365,13 +376,13 @@ int slave(int argc,char *argv[]) {
 
   /* Create the connexions */
   mysock = gras_socket_server_range(3000,9999,0,0);
+  gras_os_sleep(1); /* let the master get ready */
   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]);
                                
   /* Join and run the group */
-  amok_hm_group_join(master,"pmm");
-  amok_hm_mainloop(600);
+  amok_pm_group_join(master,"pmm");
+  amok_pm_mainloop(600);
 
   /* housekeeping */
   gras_socket_close(mysock);