A
lgorithmique
N
umérique
D
istribuée
Public GIT Repository
projects
/
simgrid.git
/ blobdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
|
commitdiff
|
tree
raw
|
inline
| side by side
Merge branch 'master' of git+ssh://scm.gforge.inria.fr//gitroot/simgrid/simgrid
[simgrid.git]
/
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
1bc53a2
..
bfbc81f
100644
(file)
--- 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;
int master(int argc, char *argv[]) {
int slaves_count = 10;
- m
_host_t *slaves = xbt_new(m
_host_t,10);
+ m
sg_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++) {
/* Retrive the hostnames constituting our playground today */
for (i = 1; i < argc; i++) {
@@
-66,6
+67,7
@@
int master(int argc, char *argv[]) {
MSG_vm_bind(vm, MSG_process_create_with_arguments(slavename,slave_fun,NULL,slaves[i],2,argv));
}
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));
xbt_dynar_t vms = MSG_vms_as_dynar();
XBT_INFO("Launched %ld VMs", xbt_dynar_length(vms));
@@
-74,21
+76,23
@@
int master(int argc, char *argv[]) {
work_batch(slaves_count);
XBT_INFO("Now suspend all VMs, just for fun");
work_batch(slaves_count);
XBT_INFO("Now suspend all VMs, just for fun");
- for (i=0;i<xbt_dynar_length(vms);i++)
- MSG_vm_suspend(xbt_dynar_get_as(vms,i,msg_vm_t));
+
+ xbt_dynar_foreach(vms,i,vm) {
+ MSG_vm_suspend(vm);
+ }
XBT_INFO("Wait a while");
MSG_process_sleep(2);
XBT_INFO("Enough. Let's resume everybody.");
XBT_INFO("Wait a while");
MSG_process_sleep(2);
XBT_INFO("Enough. Let's resume everybody.");
- for (i=0;i<xbt_dynar_length(vms);i++)
- MSG_vm_resume(
xbt_dynar_get_as(vms,i,msg_vm_t)
);
-
+ xbt_dynar_foreach(vms,i,vm) {
+ MSG_vm_resume(
vm
);
+ }
XBT_INFO("Sleep long enough for everyone to be done with previous batch of work");
MSG_process_sleep(1000-MSG_get_clock());
XBT_INFO("Add one more process per VM");
XBT_INFO("Sleep long enough for everyone to be done with previous batch of work");
MSG_process_sleep(1000-MSG_get_clock());
XBT_INFO("Add one more process per VM");
-
for (i=0;i<xbt_dynar_length(vms);i++
) {
+
xbt_dynar_foreach(vms,i,vm
) {
msg_vm_t vm = xbt_dynar_get_as(vms,i,msg_vm_t);
char slavename[64];
sprintf(slavename,"Slave %ld",i+xbt_dynar_length(vms));
msg_vm_t vm = xbt_dynar_get_as(vms,i,msg_vm_t);
char slavename[64];
sprintf(slavename,"Slave %ld",i+xbt_dynar_length(vms));
@@
-99,15
+103,19
@@
int master(int argc, char *argv[]) {
MSG_vm_bind(vm, MSG_process_create_with_arguments(slavename,slave_fun,NULL,slaves[i],2,argv));
}
MSG_vm_bind(vm, MSG_process_create_with_arguments(slavename,slave_fun,NULL,slaves[i],2,argv));
}
+ XBT_INFO("Reboot all the VMs");
+ xbt_dynar_foreach(vms,i,vm) {
+ MSG_vm_reboot(vm);
+ }
+
work_batch(slaves_count*2);
XBT_INFO("Migrate everyone to the second host.");
work_batch(slaves_count*2);
XBT_INFO("Migrate everyone to the second host.");
- for (i=0;i<xbt_dynar_length(vms);i++)
- MSG_vm_migrate(
xbt_dynar_get_as(vms,i,msg_vm_t)
,slaves[1]);
-
+ xbt_dynar_foreach(vms,i,vm) {
+ MSG_vm_migrate(
vm
,slaves[1]);
+ }
XBT_INFO("Suspend everyone, move them to the third host, and resume them.");
XBT_INFO("Suspend everyone, move them to the third host, and resume them.");
- for (i=0;i<xbt_dynar_length(vms);i++) {
- msg_vm_t vm = xbt_dynar_get_as(vms,i,msg_vm_t);
+ xbt_dynar_foreach(vms,i,vm) {
MSG_vm_suspend(vm);
MSG_vm_migrate(vm,slaves[2]);
MSG_vm_resume(vm);
MSG_vm_suspend(vm);
MSG_vm_migrate(vm,slaves[2]);
MSG_vm_resume(vm);
@@
-118,12
+126,11
@@
int master(int argc, char *argv[]) {
for (i = 0; i < slaves_count; i++) {
char mailbox_buffer[64];
sprintf(mailbox_buffer,"Slave_%d",i);
for (i = 0; i < slaves_count; i++) {
char mailbox_buffer[64];
sprintf(mailbox_buffer,"Slave_%d",i);
- m_task_t finalize = MSG_task_create("finalize", 0, 0, 0);
+ m
sg
_task_t finalize = MSG_task_create("finalize", 0, 0, 0);
MSG_task_send(finalize, mailbox_buffer);
}
MSG_task_send(finalize, mailbox_buffer);
}
- for (i=0;i<xbt_dynar_length(vms);i++) {
- msg_vm_t vm = xbt_dynar_get_as(vms,i,msg_vm_t);
+ xbt_dynar_foreach(vms,i,vm) {
MSG_vm_shutdown(vm);
MSG_vm_destroy(vm);
}
MSG_vm_shutdown(vm);
MSG_vm_destroy(vm);
}
@@
-137,14
+144,13
@@
int master(int argc, char *argv[]) {
/** Receiver function */
int slave_fun(int argc, char *argv[])
{
/** Receiver function */
int slave_fun(int argc, char *argv[])
{
- char
*mailbox_name
;
- m_task_t task = NULL;
+ char
mailbox_name[128]
;
+ m
sg
_task_t task = NULL;
_XBT_GNUC_UNUSED int res;
_XBT_GNUC_UNUSED int res;
-
/* since the slaves will move around, use slave_%d as mailbox names instead of hostnames */
xbt_assert(argc>=2, "slave processes need to be given their rank as parameter");
/* since the slaves will move around, use slave_%d as mailbox names instead of hostnames */
xbt_assert(argc>=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");
while (1) {
res = MSG_task_receive(&(task),mailbox_name);
xbt_assert(res == MSG_OK, "MSG_task_get failed");
@@
-161,16
+167,15
@@
int slave_fun(int argc, char *argv[])
task = NULL;
}
task = NULL;
}
- free(mailbox_name);
return 0;
} /* end_of_slave */
/** Main function */
int main(int argc, char *argv[])
{
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;
xbt_dynar_t hosts_dynar;
- m
_host_t*hosts= xbt_new(m
_host_t,10);
+ m
sg_host_t*hosts= xbt_new(msg
_host_t,10);
char**hostnames= xbt_new(char*,10);
char**masterargv=xbt_new(char*,12);
int i;
char**hostnames= xbt_new(char*,10);
char**masterargv=xbt_new(char*,12);
int i;
@@
-194,7
+199,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++) {
"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,m
sg
_host_t);
hostnames[i] = xbt_strdup(MSG_host_get_name(hosts[i]));
}
masterargv[0]=xbt_strdup("master");
hostnames[i] = xbt_strdup(MSG_host_get_name(hosts[i]));
}
masterargv[0]=xbt_strdup("master");
@@
-206,8
+211,9
@@
int main(int argc, char *argv[])
res = MSG_main();
XBT_INFO("Simulation time %g", MSG_get_clock());
res = MSG_main();
XBT_INFO("Simulation time %g", MSG_get_clock());
- MSG_clean();
free(hosts);
free(hosts);
+ for (i=0;i<10;i++)
+ free(hostnames[i]);
free(hostnames);
xbt_dynar_free(&hosts_dynar);
free(hostnames);
xbt_dynar_free(&hosts_dynar);