Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
Merge branches 'auto_restart' and 'auto_restart' of framagit.org:simgrid/simgrid
[simgrid.git] / examples / msg / platform-failures / platform-failures.c
index 5e44285..f1d5d5b 100644 (file)
@@ -1,11 +1,12 @@
-/* Copyright (c) 2007-2015. The SimGrid Team.
- * All rights reserved.                                                     */
+/* Copyright (c) 2007-2018. The SimGrid Team. All rights reserved.          */
 
 /* This program is free software; you can redistribute it and/or modify it
  * under the terms of the license (GNU LGPL) which comes with this package. */
 
 #include "simgrid/msg.h"
 
+#include <stdio.h> /* snprintf */
+
 XBT_LOG_NEW_DEFAULT_CATEGORY(msg_test, "Messages specific for this msg example");
 
 #define FINALIZE ((void*)221297)        /* a magic number to tell people to stop working */
@@ -24,13 +25,13 @@ static int master(int argc, char *argv[])
   for (i = 0; i < number_of_tasks; i++) {
     char mailbox[256];
     snprintf(mailbox, 255, "worker-%ld", i % workers_count);
-
+    XBT_INFO("Send a message to %s", mailbox);
     msg_task_t task = MSG_task_create("Task", task_comp_size, task_comm_size, xbt_new0(double, 1));
     *((double *) task->data) = MSG_get_clock();
 
     switch ( MSG_task_send_with_timeout(task,mailbox,10.0) ) {
     case MSG_OK:
-      XBT_INFO("Send completed");
+      XBT_INFO("Send to %s completed", mailbox);
       break;
 
     case MSG_HOST_FAILURE:
@@ -102,24 +103,25 @@ static int worker(int argc, char *argv[])
   while (1) {
     double time1 = MSG_get_clock();
     msg_task_t task = NULL;
+    XBT_INFO("Waiting a message on %s", mailbox);
     int retcode = MSG_task_receive( &(task), mailbox);
     double time2 = MSG_get_clock();
     if (retcode == MSG_OK) {
-      XBT_INFO("Received \"%s\"", MSG_task_get_name(task));
       if (MSG_task_get_data(task) == FINALIZE) {
         MSG_task_destroy(task);
         break;
       }
       if (time1 < *((double *) task->data))
         time1 = *((double *) task->data);
-      XBT_INFO("Communication time : \"%f\"", time2 - time1);
-      XBT_INFO("Processing \"%s\"", MSG_task_get_name(task));
+      XBT_INFO("Start execution...");
       retcode = MSG_task_execute(task);
       if (retcode == MSG_OK) {
-        XBT_INFO("\"%s\" done", MSG_task_get_name(task));
+        XBT_INFO("Execution complete.");
+        free(task->data);
         MSG_task_destroy(task);
       } else if (retcode == MSG_HOST_FAILURE) {
         XBT_INFO("Gloups. The cpu on which I'm running just turned off!. See you!");
+        free(task->data);
         MSG_task_destroy(task);
         return 0;
       } else {
@@ -141,8 +143,6 @@ static int worker(int argc, char *argv[])
 
 int main(int argc, char *argv[])
 {
-  msg_error_t res = MSG_OK;
-
   MSG_init(&argc, argv);
   xbt_assert(argc > 2, "Usage: %s platform_file deployment_file\n"
              "\tExample: %s msg_platform.xml msg_deployment.xml\n", argv[0], argv[0]);
@@ -153,7 +153,7 @@ int main(int argc, char *argv[])
   MSG_function_register("worker", worker);
   MSG_launch_application(argv[2]);
 
-  res = MSG_main();
+  msg_error_t res = MSG_main();
 
   XBT_INFO("Simulation time %g", MSG_get_clock());