Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
Merge branch 'master' of git+ssh://scm.gforge.inria.fr//gitroot//simgrid/simgrid
[simgrid.git] / examples / msg / chord / chord.c
index 082a555..038c754 100644 (file)
@@ -9,9 +9,7 @@
 #include "msg/msg.h"
 #include "xbt/log.h"
 #include "xbt/asserts.h"
-#include "mc/modelchecker.h"
-#include "mc/mc.h"
-#include "xbt/xbt_os_time.h"
+#include "simgrid/modelchecker.h"
 
 XBT_LOG_NEW_DEFAULT_CATEGORY(msg_chord,
                              "Messages specific for this msg example");
@@ -82,6 +80,7 @@ static int *powers2;
 
 // utility functions
 static void chord_initialize(void);
+static void chord_exit(void);
 static int normalize(int id);
 static int is_in_interval(int id, int start, int end);
 static void get_mailbox(int host_id, char* mailbox);
@@ -127,6 +126,11 @@ static void chord_initialize(void)
   XBT_DEBUG("Sets nb_keys to %d", nb_keys);
 }
 
+static void chord_exit(void)
+{
+  xbt_free(powers2);
+}
+
 /**
  * \brief Turns an id into an equivalent id in [0, nb_keys).
  * \param id an id
@@ -139,7 +143,7 @@ static int normalize(int id)
 }
 
 /**
- * \brief Returns whether a id belongs to the interval [start, end].
+ * \brief Returns whether an id belongs to the interval [start, end].
  *
  * The parameters are noramlized to make sure they are between 0 and nb_keys - 1).
  * 1 belongs to [62, 3]
@@ -342,7 +346,9 @@ int node(int argc, char *argv[])
           MSG_process_sleep(5);
         }
       }
-      else {
+
+      if (node.comm_receive && MSG_comm_test(node.comm_receive)) {
+
         // a transfer has occured
 
         MSG_error_t status = MSG_comm_get_status(node.comm_receive);
@@ -455,7 +461,7 @@ static void handle_task(node_t node, m_task_t task) {
 
     case TASK_FIND_SUCCESSOR_ANSWER:
     case TASK_GET_PREDECESSOR_ANSWER:
-      XBT_DEBUG("Ignoring unexpected task of type %d (%p)", type, task);
+      XBT_DEBUG("Ignoring unexpected task of type %d (%p)", (int)type, task);
       task_free(task);
       break;
   }
@@ -620,7 +626,7 @@ static int remote_find_successor(node_t node, int ask_to, int id)
 
       if (res != MSG_OK) {
         XBT_DEBUG("Failed to receive the answer to my 'Find Successor' request (task %p): %d",
-            task_sent, res);
+                  task_sent, (int)res);
         stop = 1;
        MSG_comm_destroy(node->comm_receive);
        node->comm_receive = NULL;
@@ -701,7 +707,7 @@ static int remote_get_predecessor(node_t node, int ask_to)
 
       if (res != MSG_OK) {
         XBT_DEBUG("Failed to receive the answer to my 'Get Predecessor' request (task %p): %d",
-            task_sent, res);
+                  task_sent, (int)res);
         stop = 1;
        MSG_comm_destroy(node->comm_receive);
        node->comm_receive = NULL;
@@ -868,14 +874,13 @@ static void random_lookup(node_t node)
  */
 int main(int argc, char *argv[])
 {
+  MSG_global_init(&argc, argv);
   if (argc < 3) {
     printf("Usage: %s [-nb_bits=n] [-timeout=t] platform_file deployment_file\n", argv[0]);
     printf("example: %s ../msg_platform.xml chord.xml\n", argv[0]);
     exit(1);
   }
 
-  MSG_global_init(&argc, argv);
-
   char **options = &argv[1];
   while (!strncmp(options[0], "-", 1)) {
 
@@ -903,7 +908,6 @@ int main(int argc, char *argv[])
 
   chord_initialize();
 
-  MSG_set_channel_number(0);
   MSG_create_environment(platform_file);
 
   MSG_function_register("node", node);
@@ -914,6 +918,7 @@ int main(int argc, char *argv[])
   XBT_INFO("Simulated time: %g", MSG_get_clock());
 
   MSG_clean();
+  chord_exit();
 
   if (res == MSG_OK)
     return 0;