X-Git-Url: http://info.iut-bm.univ-fcomte.fr/pub/gitweb/simgrid.git/blobdiff_plain/f28d984fb76ea5e45562168a2e67b60a8b1d0fb2..aafaaf396698612d5174bb0780c0a548e5422d84:/examples/msg/cloud/masterslave_virtual_machines.c diff --git a/examples/msg/cloud/masterslave_virtual_machines.c b/examples/msg/cloud/masterslave_virtual_machines.c index ed1ac279b6..e1527eb61e 100644 --- a/examples/msg/cloud/masterslave_virtual_machines.c +++ b/examples/msg/cloud/masterslave_virtual_machines.c @@ -43,9 +43,10 @@ static void work_batch(int slaves_count) { int master(int argc, char *argv[]) { int slaves_count = 10; - m_host_t *slaves = xbt_new(m_host_t,10); + msg_host_t *slaves = xbt_new(msg_host_t,10); - int i; + msg_vm_t vm; + unsigned int i; /* Retrive the hostnames constituting our playground today */ for (i = 1; i < argc; i++) { @@ -62,10 +63,15 @@ int master(int argc, char *argv[]) { argv[0] = xbt_strdup(slavename); argv[1] = bprintf("%d",i); argv[2] = NULL; - msg_vm_t vm = MSG_vm_start(slaves[i],2); + + char vmName[64]; + snprintf(vmName, 64, "vm_%d", i); + + msg_vm_t vm = MSG_vm_start(slaves[i],vmName,2); MSG_vm_bind(vm, MSG_process_create_with_arguments(slavename,slave_fun,NULL,slaves[i],2,argv)); } + xbt_dynar_t vms = MSG_vms_as_dynar(); XBT_INFO("Launched %ld VMs", xbt_dynar_length(vms)); @@ -74,21 +80,23 @@ int master(int argc, char *argv[]) { work_batch(slaves_count); XBT_INFO("Now suspend all VMs, just for fun"); - for (i=0;i=2, "slave processes need to be given their rank as parameter"); - mailbox_name=bprintf("Slave_%s",argv[1]); - + sprintf(mailbox_name,"Slave_%s",argv[1]); + XBT_INFO("Slave listenning on %s",argv[1]); while (1) { res = MSG_task_receive(&(task),mailbox_name); xbt_assert(res == MSG_OK, "MSG_task_get failed"); @@ -160,22 +174,21 @@ int slave_fun(int argc, char *argv[]) task = NULL; } - free(mailbox_name); return 0; } /* end_of_slave */ /** Main function */ int main(int argc, char *argv[]) { - MSG_error_t res = MSG_OK; + msg_error_t res = MSG_OK; xbt_dynar_t hosts_dynar; - m_host_t*hosts= xbt_new(m_host_t,10); + msg_host_t*hosts= xbt_new(msg_host_t,10); char**hostnames= xbt_new(char*,10); char**masterargv=xbt_new(char*,12); int i; /* Get the arguments */ - MSG_global_init(&argc, argv); + MSG_init(&argc, argv); if (argc < 2) { printf("Usage: %s platform_file\n", argv[0]); printf("example: %s msg_platform.xml\n", argv[0]); @@ -193,7 +206,7 @@ int main(int argc, char *argv[]) "I need at least 10 hosts in the platform file, but %s contains only %ld hosts_dynar.", argv[1],xbt_dynar_length(hosts_dynar)); for (i=0;i<10;i++) { - hosts[i] = xbt_dynar_get_as(hosts_dynar,i,m_host_t); + hosts[i] = xbt_dynar_get_as(hosts_dynar,i,msg_host_t); hostnames[i] = xbt_strdup(MSG_host_get_name(hosts[i])); } masterargv[0]=xbt_strdup("master"); @@ -205,8 +218,9 @@ int main(int argc, char *argv[]) res = MSG_main(); XBT_INFO("Simulation time %g", MSG_get_clock()); - MSG_clean(); free(hosts); + for (i=0;i<10;i++) + free(hostnames[i]); free(hostnames); xbt_dynar_free(&hosts_dynar);