Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
Use homogeneous dictionaries whenever possible.
[simgrid.git] / examples / gras / replay / replay.c
index 6a79238..fb1babe 100644 (file)
@@ -54,11 +54,9 @@ int master(int argc, char *argv[])
   xbt_workload_sort_who_date(cmds);
   unsigned int cursor;
   xbt_workload_elm_t cmd;
-
-  xbt_ex_t e;
   xbt_dict_cursor_t dict_cursor;
 
-  xbt_dict_t pals_int = xbt_dict_new();
+  xbt_dict_t pals_int = xbt_dict_new_homogeneous(NULL);
   xbt_dynar_foreach(cmds, cursor, cmd) {
     int *p = xbt_dict_get_or_null(pals_int, cmd->who);
     if (!p) {
@@ -69,12 +67,12 @@ int master(int argc, char *argv[])
 
   /* friends, we're ready. Come and play */
   XBT_INFO("Wait for peers for a while. I need %d peers",
-        xbt_dict_size(pals_int));
-  while (xbt_dynar_length(peers) < xbt_dict_size(pals_int)) {
+        xbt_dict_length(pals_int));
+  while (xbt_dynar_length(peers) < xbt_dict_length(pals_int)) {
     TRY {
       gras_msg_handle(20);
     }
-    CATCH(e) {
+    CATCH_ANONYMOUS {
       xbt_dynar_foreach(peers, cursor, peer) {
         xbt_dict_remove(pals_int, peer->name);
       }
@@ -90,7 +88,7 @@ int master(int argc, char *argv[])
   xbt_dict_free(&pals_int);
 
   /* Check who came */
-  xbt_dict_t pals = xbt_dict_new();
+  xbt_dict_t pals = xbt_dict_new_homogeneous(NULL);
   gras_socket_t pal;
   xbt_dynar_foreach(peers, cursor, peer) {
     //XBT_INFO("%s is here",peer->name);
@@ -159,7 +157,6 @@ static int worker_commands_cb(gras_msg_cb_ctx_t ctx, void *payload)
 
 static void do_command(int rank, void *c)
 {
-  xbt_ex_t e;
   xbt_workload_elm_t cmd = *(xbt_workload_elm_t *) c;
   xbt_workload_data_chunk_t chunk;
 
@@ -176,7 +173,7 @@ static void do_command(int rank, void *c)
     TRY {
       gras_msg_wait(1000000, "chunk", NULL, &chunk);
     }
-    CATCH(e) {
+    CATCH_ANONYMOUS {
       SIMIX_display_process_status();
       RETHROWF("Exception while waiting for %f bytes from %s: %s",
                cmd->d_arg, cmd->str_arg);
@@ -202,7 +199,7 @@ int worker(int argc, char *argv[])
   int connected = 0;
 
   gras_cb_register("commands", worker_commands_cb);
-  globals->peers = xbt_dict_new();
+  globals->peers = xbt_dict_new_homogeneous(NULL);
 
   if (gras_if_RL())
     XBT_INFO("Sensor %s starting. Connecting to master on %s",
@@ -242,13 +239,14 @@ int worker(int argc, char *argv[])
         switch (cmd->action) {
         case XBT_WORKLOAD_COMPUTE:
           /* If any communication were queued, do them in parallel */
-          if (xbt_dynar_length(cmd_to_go)) {
+          if (!xbt_dynar_is_empty(cmd_to_go)) {
             TRY {
               xbt_dynar_dopar(cmd_to_go, do_command);
               xbt_dynar_reset(cmd_to_go);
             }
             CATCH(e) {
               SIMIX_display_process_status();
+              xbt_ex_free(e);
             }
             XBT_INFO("Communications all done");
             xbt_dynar_reset(cmd_to_go);
@@ -270,7 +268,7 @@ int worker(int argc, char *argv[])
     /* do in parallel any communication still queued */
     XBT_INFO("Do %ld pending communications after end of TODO list",
           xbt_dynar_length(cmd_to_go));
-    if (xbt_dynar_length(cmd_to_go)) {
+    if (!xbt_dynar_is_empty(cmd_to_go)) {
       xbt_dynar_dopar(cmd_to_go, do_command);
       xbt_dynar_reset(cmd_to_go);
     }