Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
Add new entry in Release_Notes.
[simgrid.git] / examples / c / cloud-capping / cloud-capping.c
index 55676e6..f5988c6 100644 (file)
@@ -1,4 +1,4 @@
-/* Copyright (c) 2007-2020. The SimGrid Team. All rights reserved.          */
+/* Copyright (c) 2007-2023. 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. */
@@ -19,9 +19,9 @@ XBT_LOG_NEW_DEFAULT_CATEGORY(cloud_capping, "Messages specific for this example"
 static void worker_main(int argc, char* argv[])
 {
   xbt_assert(argc == 4);
-  double computation_amount = xbt_str_parse_double(argv[1], "Invalid computation amount: %s");
-  int use_bound             = xbt_str_parse_int(argv[2], "Second parameter (use_bound) should be 0 or 1 but is: %s");
-  double bound              = xbt_str_parse_double(argv[3], "Invalid bound: %s");
+  double computation_amount = xbt_str_parse_double(argv[1], "Invalid computation amount");
+  int use_bound             = !!xbt_str_parse_int(argv[2], "Second parameter (use_bound) should be 0 or 1 but is");
+  double bound              = xbt_str_parse_double(argv[3], "Invalid bound");
 
   double clock_sta = simgrid_get_clock();
 
@@ -50,8 +50,7 @@ static void launch_worker(sg_host_t host, const char* pr_name, double computatio
   char* argv3        = bprintf("%f", bound);
   const char* argv[] = {pr_name, argv1, argv2, argv3, NULL};
 
-  sg_actor_t actor = sg_actor_init(pr_name, host);
-  sg_actor_start(actor, worker_main, 4, argv);
+  sg_actor_create_(pr_name, host, worker_main, 4, argv);
 
   free(argv1);
   free(argv2);
@@ -92,17 +91,12 @@ static void test_dynamic_change()
   sg_vm_start(vm0);
   sg_vm_start(vm1);
 
-  int w0_argc           = 3;
   const char* w0_argv[] = {"worker0", "Task0", "-1.0", NULL};
-  sg_actor_t w0         = sg_actor_init("worker0", (sg_host_t)vm0);
-  sg_actor_start(w0, worker_busy_loop, w0_argc, w0_argv);
+  sg_actor_create_("worker0", (sg_host_t)vm0, worker_busy_loop, 3, w0_argv);
 
-  int w1_argc           = 3;
-  char* speed           = bprintf("%f", sg_host_speed(pm0));
+  char* speed           = bprintf("%f", sg_host_get_speed(pm0));
   const char* w1_argv[] = {"worker1", "Task1", speed, NULL};
-
-  sg_actor_t w1 = sg_actor_init("worker1", (sg_host_t)vm1);
-  sg_actor_start(w1, worker_busy_loop, w1_argc, w1_argv);
+  sg_actor_create_("worker1", (sg_host_t)vm1, worker_busy_loop, 3, w1_argv);
 
   sg_actor_sleep_for(3000); // let the tasks end
 
@@ -113,11 +107,11 @@ static void test_dynamic_change()
 
 static void test_one_task(sg_host_t hostA)
 {
-  const double cpu_speed          = sg_host_speed(hostA);
+  const double cpu_speed          = sg_host_get_speed(hostA);
   const double computation_amount = cpu_speed * 10;
   const char* hostA_name          = sg_host_get_name(hostA);
 
-  XBT_INFO("### Test: with/without MSG_task_set_bound");
+  XBT_INFO("### Test: with/without sg_exec_set_bound");
 
   XBT_INFO("### Test: no bound for Task1@%s", hostA_name);
   launch_worker(hostA, "worker0", computation_amount, 0, 0);
@@ -147,8 +141,8 @@ static void test_one_task(sg_host_t hostA)
 
 static void test_two_tasks(sg_host_t hostA, sg_host_t hostB)
 {
-  const double cpu_speed = sg_host_speed(hostA);
-  xbt_assert(cpu_speed == sg_host_speed(hostB));
+  const double cpu_speed = sg_host_get_speed(hostA);
+  xbt_assert(cpu_speed == sg_host_get_speed(hostB));
   const double computation_amount = cpu_speed * 10;
   const char* hostA_name          = sg_host_get_name(hostA);
   const char* hostB_name          = sg_host_get_name(hostB);
@@ -196,29 +190,29 @@ static void test_two_tasks(sg_host_t hostA, sg_host_t hostB)
   sg_actor_sleep_for(1000);
 }
 
-static void master_main(XBT_ATTRIB_UNUSED int argc, XBT_ATTRIB_UNUSED char* argv[])
+static void master_main(int argc, char* argv[])
 {
   sg_host_t pm0 = sg_host_by_name("Fafard");
   sg_host_t pm1 = sg_host_by_name("Fafard");
 
-  XBT_INFO("# 1. Put a single task on a PM. ");
+  XBT_INFO("# 1. Put a single task on a PM.");
   test_one_task(pm0);
-  XBT_INFO(" ");
+  XBT_INFO(".");
 
   XBT_INFO("# 2. Put two tasks on a PM.");
   test_two_tasks(pm0, pm0);
-  XBT_INFO(" ");
+  XBT_INFO(".");
 
   sg_vm_t vm0 = sg_vm_create_core(pm0, "VM0");
   sg_vm_start(vm0);
 
-  XBT_INFO("# 3. Put a single task on a VM. ");
+  XBT_INFO("# 3. Put a single task on a VM.");
   test_one_task((sg_host_t)vm0);
-  XBT_INFO(" ");
+  XBT_INFO(".");
 
   XBT_INFO("# 4. Put two tasks on a VM.");
   test_two_tasks((sg_host_t)vm0, (sg_host_t)vm0);
-  XBT_INFO(" ");
+  XBT_INFO(".");
 
   sg_vm_destroy(vm0);
 
@@ -227,26 +221,26 @@ static void master_main(XBT_ATTRIB_UNUSED int argc, XBT_ATTRIB_UNUSED char* argv
 
   XBT_INFO("# 6. Put a task on a PM and a task on a VM.");
   test_two_tasks(pm0, (sg_host_t)vm0);
-  XBT_INFO(" ");
+  XBT_INFO(".");
 
   sg_vm_destroy(vm0);
 
   vm0              = sg_vm_create_core(pm0, "VM0");
-  double cpu_speed = sg_host_speed(pm0);
+  double cpu_speed = sg_host_get_speed(pm0);
   sg_vm_set_bound(vm0, cpu_speed / 10);
   sg_vm_start(vm0);
 
   XBT_INFO("# 7. Put a single task on the VM capped by 10%%.");
   test_one_task((sg_host_t)vm0);
-  XBT_INFO(" ");
+  XBT_INFO(".");
 
   XBT_INFO("# 8. Put two tasks on the VM capped by 10%%.");
   test_two_tasks((sg_host_t)vm0, (sg_host_t)vm0);
-  XBT_INFO(" ");
+  XBT_INFO(".");
 
   XBT_INFO("# 9. Put a task on a PM and a task on the VM capped by 10%%.");
   test_two_tasks(pm0, (sg_host_t)vm0);
-  XBT_INFO(" ");
+  XBT_INFO(".");
 
   sg_vm_destroy(vm0);
 
@@ -255,7 +249,7 @@ static void master_main(XBT_ATTRIB_UNUSED int argc, XBT_ATTRIB_UNUSED char* argv
   sg_vm_set_ramsize(vm0, 1e9); // 1GB
   sg_vm_start(vm0);
 
-  cpu_speed = sg_host_speed(pm0);
+  cpu_speed = sg_host_get_speed(pm0);
   sg_vm_start(vm0);
 
   XBT_INFO("# 10. Test migration");
@@ -264,22 +258,22 @@ static void master_main(XBT_ATTRIB_UNUSED int argc, XBT_ATTRIB_UNUSED char* argv
   XBT_INFO("# 10. (a) Put a task on a VM without any bound.");
   launch_worker((sg_host_t)vm0, "worker0", computation_amount, 0, 0);
   sg_actor_sleep_for(1000);
-  XBT_INFO(" ");
+  XBT_INFO(".");
 
   XBT_INFO("# 10. (b) set 10%% bound to the VM, and then put a task on the VM.");
   sg_vm_set_bound(vm0, cpu_speed / 10);
   launch_worker((sg_host_t)vm0, "worker0", computation_amount, 0, 0);
   sg_actor_sleep_for(1000);
-  XBT_INFO(" ");
+  XBT_INFO(".");
 
   XBT_INFO("# 10. (c) migrate");
   sg_vm_migrate(vm0, pm1);
-  XBT_INFO(" ");
+  XBT_INFO(".");
 
   XBT_INFO("# 10. (d) Put a task again on the VM.");
   launch_worker((sg_host_t)vm0, "worker0", computation_amount, 0, 0);
   sg_actor_sleep_for(1000);
-  XBT_INFO(" ");
+  XBT_INFO(".");
 
   sg_vm_destroy(vm0);
 
@@ -298,8 +292,7 @@ int main(int argc, char* argv[])
 
   simgrid_load_platform(argv[1]);
 
-  sg_actor_t actor = sg_actor_init("master_", sg_host_by_name("Fafard"));
-  sg_actor_start(actor, master_main, 0, NULL);
+  sg_actor_create("master_", sg_host_by_name("Fafard"), master_main, 0, NULL);
 
   simgrid_run();
   XBT_INFO("Bye (simulation time %g)", simgrid_get_clock());