Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
Avoid timeouts on very large platforms by blocking for ever
[simgrid.git] / examples / gras / mutual_exclusion / simple_token / simple_token.c
index 2460b60..f0d8fcb 100644 (file)
@@ -30,6 +30,8 @@ typedef struct {
   int remaining_loop; /* number of loops to do until done */
   int create;        /* whether I have to create the token */
   gras_socket_t tosuccessor; /* how to connect to the successor on ring */
+  double start_time; /* to measure the elapsed time. Only used by the 
+                        node that creates the token */
 } node_data_t;
 
 
@@ -91,7 +93,9 @@ static int node_cb_stoken_handler(gras_msg_cb_ctx_t ctx, void *payload) {
    
   /* 8. Repport the hop number to the user at the end */
   if (globals->remaining_loop == -1 && globals->create) {
+    double elapsed = gras_os_time() - globals->start_time; 
     INFO1("Shut down the token-ring. There was %d hops.",msg);
+    VERB1("Elapsed time: %g", elapsed);
   }
 
   /* 9. Tell GRAS that we consummed this message */
@@ -129,32 +133,34 @@ int node (int argc,char *argv[]) {
   globals->tosuccessor = NULL;
 
   if (!gras_os_getpid() % 100)
-  INFO4("Launch node %ld (successor on %s:%d; listening on %d)",
+  INFO4("Launch node %d (successor on %s:%d; listening on %d)",
        gras_os_getpid(), host,peerport, myport);
 
-  /* 4. Create my master socket for listening */
+  /* 4. Register the known messages.  */
+  gras_msgtype_declare("stoken", gras_datadesc_by_name("int"));
+   
+  /* 5. Create my master socket for listening */
   globals->sock = gras_socket_server(myport);
   gras_os_sleep(1.0); /* Make sure all server sockets are created */
-
-  /* 5. Create socket to the successor on the ring */
+   
+  /* 6. Create socket to the successor on the ring */
   DEBUG2("Connect to my successor on %s:%d",host,peerport);
 
   globals->tosuccessor = gras_socket_client(host,peerport);
   
-  /* 6. Register the known messages.  */
-  gras_msgtype_declare("stoken", gras_datadesc_by_name("int"));
-   
   /* 7. Register my callback */
   gras_cb_register("stoken",&node_cb_stoken_handler);  
 
   /* 8. One node has to create the token at startup. 
         It's specified by a command line argument */
-  if (argc >= 5 && !strncmp("--create-token", argv[4],strlen(argv[4])))
+  if (argc >= 5 && !strncmp("--create-token", argv[4],strlen("--create-token")))
     globals->create=1;
 
   if (globals->create) {
     int token = 0;
-            
+
+    globals->start_time = gras_os_time();
+
     globals->remaining_loop = NBLOOPS - 1;
       
     INFO3("Create the token (with value %d) and send it to %s:%d",
@@ -169,7 +175,7 @@ int node (int argc,char *argv[]) {
   
   /* 8. Wait up to 10 seconds for an incomming message to handle */
   while (globals->remaining_loop > (globals->create ? -1 : 0)) {
-    gras_msg_handle(10.0);
+    gras_msg_handle(-1);
   
     DEBUG1("looping (remaining_loop=%d)", globals->remaining_loop);
   }