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 / cloud-multicore / cloud-multicore.c
index c8ad9f6..ebb0a22 100644 (file)
@@ -49,6 +49,7 @@ static void test_pm_pin(void)
   msg_host_t pm0 = xbt_dynar_get_as(hosts_dynar, 0, msg_host_t);
   msg_host_t pm1 = xbt_dynar_get_as(hosts_dynar, 1, msg_host_t);
   msg_host_t pm2 = xbt_dynar_get_as(hosts_dynar, 2, msg_host_t);
+  xbt_dynar_free(&hosts_dynar);
 
   struct task_data t1;
   struct task_data t2;
@@ -60,12 +61,12 @@ static void test_pm_pin(void)
   t3.task = MSG_task_create("Task3", 1e16, 0, NULL);
   t4.task = MSG_task_create("Task4", 1e16, 0, NULL);
 
-  MSG_process_create("worker1", worker_main, t1.task, pm1);
-  MSG_process_create("worker2", worker_main, t2.task, pm1);
-  MSG_process_create("worker3", worker_main, t3.task, pm1);
-  MSG_process_create("worker4", worker_main, t4.task, pm1);
+  MSG_process_create("worker1", worker_main, t1.task, pm2);
+  MSG_process_create("worker2", worker_main, t2.task, pm2);
+  MSG_process_create("worker3", worker_main, t3.task, pm2);
+  MSG_process_create("worker4", worker_main, t4.task, pm2);
 
-  XBT_INFO("## 1. start 4 tasks on PM1 (2 cores)");
+  XBT_INFO("## 1. start 4 tasks on PM2 (2 cores)");
   task_data_init_clock(&t1);
   task_data_init_clock(&t2);
   task_data_init_clock(&t3);
@@ -78,10 +79,10 @@ static void test_pm_pin(void)
   task_data_get_clock(&t4);
 
   XBT_INFO("## 2. pin all tasks to CPU0");
-  MSG_task_set_affinity(t1.task, pm1, 0x01);
-  MSG_task_set_affinity(t2.task, pm1, 0x01);
-  MSG_task_set_affinity(t3.task, pm1, 0x01);
-  MSG_task_set_affinity(t4.task, pm1, 0x01);
+  MSG_task_set_affinity(t1.task, pm2, 0x01);
+  MSG_task_set_affinity(t2.task, pm2, 0x01);
+  MSG_task_set_affinity(t3.task, pm2, 0x01);
+  MSG_task_set_affinity(t4.task, pm2, 0x01);
 
   MSG_process_sleep(10);
   task_data_get_clock(&t1);
@@ -90,7 +91,7 @@ static void test_pm_pin(void)
   task_data_get_clock(&t4);
 
   XBT_INFO("## 3. clear the affinity of task4");
-  MSG_task_set_affinity(t4.task, pm1, 0);
+  MSG_task_set_affinity(t4.task, pm2, 0);
 
   MSG_process_sleep(10);
   task_data_get_clock(&t1);
@@ -99,7 +100,7 @@ static void test_pm_pin(void)
   task_data_get_clock(&t4);
 
   XBT_INFO("## 4. clear the affinity of task3");
-  MSG_task_set_affinity(t3.task, pm1, 0);
+  MSG_task_set_affinity(t3.task, pm2, 0);
 
   MSG_process_sleep(10);
   task_data_get_clock(&t1);
@@ -108,7 +109,7 @@ static void test_pm_pin(void)
   task_data_get_clock(&t4);
 
   XBT_INFO("## 5. clear the affinity of task2");
-  MSG_task_set_affinity(t2.task, pm1, 0);
+  MSG_task_set_affinity(t2.task, pm2, 0);
 
   MSG_process_sleep(10);
   task_data_get_clock(&t1);
@@ -119,8 +120,8 @@ static void test_pm_pin(void)
   XBT_INFO("## 6. pin all tasks to CPU0 of another PM (no effect now)");
   MSG_task_set_affinity(t1.task, pm0, 0);
   MSG_task_set_affinity(t2.task, pm0, 0);
-  MSG_task_set_affinity(t3.task, pm2, 0);
-  MSG_task_set_affinity(t4.task, pm2, 0);
+  MSG_task_set_affinity(t3.task, pm1, 0);
+  MSG_task_set_affinity(t4.task, pm1, 0);
 
   MSG_process_sleep(10);
   task_data_get_clock(&t1);
@@ -145,12 +146,13 @@ static void test_vm_pin(void)
   msg_host_t pm0 = xbt_dynar_get_as(hosts_dynar, 0, msg_host_t); // 1 cores
   msg_host_t pm1 = xbt_dynar_get_as(hosts_dynar, 1, msg_host_t); // 2 cores
   msg_host_t pm2 = xbt_dynar_get_as(hosts_dynar, 2, msg_host_t); // 4 cores
+  xbt_dynar_free(&hosts_dynar);
 
-  /* set up VMs on PM2 (4 cores) */
-  msg_vm_t vm0 = MSG_vm_create_core(pm2, "VM0");
-  msg_vm_t vm1 = MSG_vm_create_core(pm2, "VM1");
-  msg_vm_t vm2 = MSG_vm_create_core(pm2, "VM2");
-  msg_vm_t vm3 = MSG_vm_create_core(pm2, "VM3");
+  /* set up VMs on PM1 (4 cores) */
+  msg_vm_t vm0 = MSG_vm_create_core(pm1, "VM0");
+  msg_vm_t vm1 = MSG_vm_create_core(pm1, "VM1");
+  msg_vm_t vm2 = MSG_vm_create_core(pm1, "VM2");
+  msg_vm_t vm3 = MSG_vm_create_core(pm1, "VM3");
 
   s_vm_params_t params;
   memset(&params, 0, sizeof(params));
@@ -185,7 +187,7 @@ static void test_vm_pin(void)
   MSG_process_create("worker3", worker_main, t3.task, vm3);
 
   /* start experiments */
-  XBT_INFO("## 1. start 4 VMs on PM2 (4 cores)");
+  XBT_INFO("## 1. start 4 VMs on PM1 (4 cores)");
   task_data_init_clock(&t0);
   task_data_init_clock(&t1);
   task_data_init_clock(&t2);
@@ -197,11 +199,11 @@ static void test_vm_pin(void)
   task_data_get_clock(&t2);
   task_data_get_clock(&t3);
 
-  XBT_INFO("## 2. pin all VMs to CPU0 of PM2");
-  MSG_vm_set_affinity(vm0, pm2, 0x01);
-  MSG_vm_set_affinity(vm1, pm2, 0x01);
-  MSG_vm_set_affinity(vm2, pm2, 0x01);
-  MSG_vm_set_affinity(vm3, pm2, 0x01);
+  XBT_INFO("## 2. pin all VMs to CPU0 of PM1");
+  MSG_vm_set_affinity(vm0, pm1, 0x01);
+  MSG_vm_set_affinity(vm1, pm1, 0x01);
+  MSG_vm_set_affinity(vm2, pm1, 0x01);
+  MSG_vm_set_affinity(vm3, pm1, 0x01);
 
   MSG_process_sleep(10);
   task_data_get_clock(&t0);
@@ -209,12 +211,12 @@ static void test_vm_pin(void)
   task_data_get_clock(&t2);
   task_data_get_clock(&t3);
 
-  XBT_INFO("## 3. pin all VMs to CPU0 of PM(no effect at now)");
+  XBT_INFO("## 3. pin all VMs to CPU0 of PM2(no effect at now)");
   /* Because VMs are on PM2, the below operations do not effect computation now. */
-  MSG_vm_set_affinity(vm0, pm1, 0x01);
-  MSG_vm_set_affinity(vm1, pm1, 0x01);
-  MSG_vm_set_affinity(vm2, pm1, 0x01);
-  MSG_vm_set_affinity(vm3, pm1, 0x01);
+  MSG_vm_set_affinity(vm0, pm2, 0x01);
+  MSG_vm_set_affinity(vm1, pm2, 0x01);
+  MSG_vm_set_affinity(vm2, pm2, 0x01);
+  MSG_vm_set_affinity(vm3, pm2, 0x01);
 
   MSG_process_sleep(10);
   task_data_get_clock(&t0);
@@ -222,10 +224,10 @@ static void test_vm_pin(void)
   task_data_get_clock(&t2);
   task_data_get_clock(&t3);
 
-  XBT_INFO("## 4. unpin VM0, and pin VM2 and VM3 to CPU1 of PM2");
-  MSG_vm_set_affinity(vm0, pm2, 0x00);
-  MSG_vm_set_affinity(vm2, pm2, 0x02);
-  MSG_vm_set_affinity(vm3, pm2, 0x02);
+  XBT_INFO("## 4. unpin VM0, and pin VM2 and VM3 to CPU1 of PM1");
+  MSG_vm_set_affinity(vm0, pm1, 0x00);
+  MSG_vm_set_affinity(vm2, pm1, 0x02);
+  MSG_vm_set_affinity(vm3, pm1, 0x02);
 
   MSG_process_sleep(10);
   task_data_get_clock(&t0);
@@ -251,11 +253,11 @@ static void test_vm_pin(void)
   task_data_get_clock(&t2);
   task_data_get_clock(&t3);
 
-  XBT_INFO("## 6. migrate all VMs to PM1 (2 CPU cores, with affinity settings)");
-  MSG_vm_migrate(vm0, pm1);
-  MSG_vm_migrate(vm1, pm1);
-  MSG_vm_migrate(vm2, pm1);
-  MSG_vm_migrate(vm3, pm1);
+  XBT_INFO("## 6. migrate all VMs to PM2 (2 CPU cores, with affinity settings)");
+  MSG_vm_migrate(vm0, pm2);
+  MSG_vm_migrate(vm1, pm2);
+  MSG_vm_migrate(vm2, pm2);
+  MSG_vm_migrate(vm3, pm2);
 
   MSG_process_sleep(10);
   task_data_get_clock(&t0);
@@ -271,10 +273,10 @@ static void test_vm_pin(void)
 
 
   XBT_INFO("## 7. clear affinity settings on PM1");
-  MSG_vm_set_affinity(vm0, pm1, 0);
-  MSG_vm_set_affinity(vm1, pm1, 0);
-  MSG_vm_set_affinity(vm2, pm1, 0);
-  MSG_vm_set_affinity(vm3, pm1, 0);
+  MSG_vm_set_affinity(vm0, pm2, 0);
+  MSG_vm_set_affinity(vm1, pm2, 0);
+  MSG_vm_set_affinity(vm2, pm2, 0);
+  MSG_vm_set_affinity(vm3, pm2, 0);
 
   MSG_process_sleep(10);
   task_data_get_clock(&t0);
@@ -333,6 +335,7 @@ int main(int argc, char *argv[])
   msg_host_t pm0 = xbt_dynar_get_as(hosts_dynar, 0, msg_host_t);
   msg_host_t pm1 = xbt_dynar_get_as(hosts_dynar, 1, msg_host_t);
   msg_host_t pm2 = xbt_dynar_get_as(hosts_dynar, 2, msg_host_t);
+  xbt_dynar_free(&hosts_dynar);
 
   XBT_INFO("%s: %d core(s), %f flops/s per each", MSG_host_get_name(pm0), MSG_host_get_core_number(pm0),
            MSG_host_get_speed(pm0));