Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
Update copyright lines.
[simgrid.git] / examples / c / cloud-masterworker / cloud-masterworker.c
index 0fb1776..28f8cc9 100644 (file)
@@ -1,4 +1,4 @@
-/* Copyright (c) 2007-2020. The SimGrid Team. All rights reserved.          */
+/* Copyright (c) 2007-2021. 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. */
@@ -21,14 +21,14 @@ XBT_LOG_NEW_DEFAULT_CATEGORY(cloud_masterworker, "Messages specific for this exa
 #define FINALIZE 221297 /* a magic number to tell people to stop working */
 
 const double comp_size = 10000000;
-const double comm_size = 10000000;
+const long comm_size   = 10000000;
 
 static void send_tasks(int nb_workers)
 {
   for (int i = 0; i < nb_workers; i++) {
     char mbox_name[MAXMBOXLEN];
     snprintf(mbox_name, MAXMBOXLEN, "MBOX:WRK%02d", i);
-    double* payload   = (double*)malloc(sizeof(double));
+    double* payload   = xbt_malloc(sizeof(double));
     *payload          = comp_size;
     sg_mailbox_t mbox = sg_mailbox_by_name(mbox_name);
 
@@ -37,7 +37,7 @@ static void send_tasks(int nb_workers)
   }
 }
 
-static void worker_fun(XBT_ATTRIB_UNUSED int argc, XBT_ATTRIB_UNUSED char* argv[])
+static void worker_fun(int argc, char* argv[])
 {
   const char* pr_name = sg_actor_self_get_name();
   char mbox_name[MAXMBOXLEN];
@@ -63,13 +63,11 @@ static void worker_fun(XBT_ATTRIB_UNUSED int argc, XBT_ATTRIB_UNUSED char* argv[
   }
 }
 
-static void master_fun(XBT_ATTRIB_UNUSED int argc, XBT_ATTRIB_UNUSED char* argv[])
+static void master_fun(int argc, char* argv[])
 {
-  unsigned int i;
+  sg_host_t* worker_pms = sg_actor_self_get_data();
 
-  sg_host_t* worker_pms = sg_actor_self_data();
-
-  sg_vm_t* vms = (sg_vm_t*)malloc(2 * sizeof(sg_vm_t));
+  sg_vm_t* vms = xbt_malloc(2 * sizeof(sg_vm_t));
 
   /* Launch VMs and worker actors. One VM per PM, and one worker actor per VM. */
   XBT_INFO("# Launch 2 VMs");
@@ -116,9 +114,9 @@ static void master_fun(XBT_ATTRIB_UNUSED int argc, XBT_ATTRIB_UNUSED char* argv[
   sg_actor_sleep_for(10 - simgrid_get_clock());
 
   XBT_INFO("# Add one more actor on each VM");
-  for (unsigned int i = 0; i < 2; i++) {
-    char* vm_name = bprintf("VM%02u", i);
-    char* pr_name = bprintf("WRK%02u", i + 2);
+  for (int i = 0; i < 2; i++) {
+    char* vm_name = bprintf("VM%02d", i);
+    char* pr_name = bprintf("WRK%02d", i + 2);
 
     XBT_INFO("put an actor (%s) on %s", pr_name, vm_name);
     sg_actor_create(pr_name, (sg_host_t)vms[i], worker_fun, 0, NULL);
@@ -144,11 +142,11 @@ static void master_fun(XBT_ATTRIB_UNUSED int argc, XBT_ATTRIB_UNUSED char* argv[
   }
 
   XBT_INFO("# Shutdown the half of worker actors gracefully. The remaining half will be forcibly killed.");
-  for (i = 0; i < 2; i++) {
+  for (int i = 0; i < 2; i++) {
     char mbox_name[MAXMBOXLEN];
-    snprintf(mbox_name, MAXMBOXLEN, "MBOX:WRK%02u", i);
+    snprintf(mbox_name, MAXMBOXLEN, "MBOX:WRK%02d", i);
     sg_mailbox_t mbox = sg_mailbox_by_name(mbox_name);
-    double* payload   = (double*)malloc(sizeof(double));
+    double* payload   = xbt_malloc(sizeof(double));
     *payload          = FINALIZE;
     sg_mailbox_put(mbox, payload, 0);
   }
@@ -187,14 +185,14 @@ int main(int argc, char* argv[])
   /* the first pm is the master, the others are workers */
   sg_host_t master_pm = pms[0];
 
-  sg_host_t* worker_pms = (sg_host_t*)malloc(2 * sizeof(sg_host_t));
-  for (int i = 0; i < 2 + 1; i++)
+  sg_host_t* worker_pms = xbt_malloc(2 * sizeof(sg_host_t));
+  for (int i = 0; i < 2; i++)
     worker_pms[i] = pms[i + 1];
 
   free(pms);
 
   sg_actor_t actor = sg_actor_init("master", master_pm);
-  sg_actor_data_set(actor, worker_pms);
+  sg_actor_set_data(actor, worker_pms);
   sg_actor_start(actor, master_fun, 0, NULL);
 
   simgrid_run();