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 scm.gforge.inria.fr:/gitroot/simgrid/simgrid
[simgrid.git]
/
examples
/
msg
/
masterslave
/
masterslave_arg.c
diff --git
a/examples/msg/masterslave/masterslave_arg.c
b/examples/msg/masterslave/masterslave_arg.c
index
7ad5d0b
..
4facb5a
100644
(file)
--- a/
examples/msg/masterslave/masterslave_arg.c
+++ b/
examples/msg/masterslave/masterslave_arg.c
@@
-1,11
+1,11
@@
-/* Copyright (c) 2010. The SimGrid Team.
+/* Copyright (c) 2010
-2014
. 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. */
#include <stdio.h>
* 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. */
#include <stdio.h>
-#include "
msg/msg.h" /* Yeah! If you want to use msg, you need to include msg
/msg.h */
+#include "
simgrid/msg.h" /* Yeah! If you want to use msg, you need to include simgrid
/msg.h */
#include "xbt/sysdep.h" /* calloc, printf */
/* Create a log channel to have nice outputs. */
#include "xbt/sysdep.h" /* calloc, printf */
/* Create a log channel to have nice outputs. */
@@
-23,8
+23,9
@@
int slave(int argc, char *argv[]);
long number_of_jobs;
long number_of_slaves;
long number_of_jobs;
long number_of_slaves;
-long my_random(long n) {
- return n*(rand()/(RAND_MAX+1));
+static long my_random(long n)
+{
+ return n * (rand() / ((double)RAND_MAX + 1));
}
/** Emitter function */
}
/** Emitter function */
@@
-35,7
+36,7
@@
int master(int argc, char *argv[])
for (i = 1; i <= number_of_jobs; i++) {
char mailbox[256];
char sprintf_buffer[256];
for (i = 1; i <= number_of_jobs; i++) {
char mailbox[256];
char sprintf_buffer[256];
- m_task_t task = NULL;
+ m
sg
_task_t task = NULL;
sprintf(mailbox, "slave-%ld", i % number_of_slaves);
sprintf(sprintf_buffer, "Task_%d", i);
sprintf(mailbox, "slave-%ld", i % number_of_slaves);
sprintf(sprintf_buffer, "Task_%d", i);
@@
-54,7
+55,7
@@
int master(int argc, char *argv[])
char mailbox[80];
sprintf(mailbox, "slave-%ld", i % number_of_slaves);
char mailbox[80];
sprintf(mailbox, "slave-%ld", i % number_of_slaves);
- 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);
}
MSG_task_send(finalize, mailbox);
}
@@
-65,9
+66,8
@@
int master(int argc, char *argv[])
/** Receiver function */
int slave(int argc, char *argv[])
{
/** Receiver function */
int slave(int argc, char *argv[])
{
- m_task_t task = NULL;
+ m
sg
_task_t task = NULL;
_XBT_GNUC_UNUSED int res;
_XBT_GNUC_UNUSED int res;
- int id = -1;
XBT_DEBUG("mailbox: %s",MSG_process_get_name(MSG_process_self()));
while (1) {
XBT_DEBUG("mailbox: %s",MSG_process_get_name(MSG_process_self()));
while (1) {
@@
-92,17
+92,16
@@
int slave(int argc, char *argv[])
/** Main function */
int main(int argc, char *argv[])
{
/** Main function */
int main(int argc, char *argv[])
{
-
MSG
_error_t res = MSG_OK;
+
msg
_error_t res = MSG_OK;
long i;
long i;
- MSG_
global_
init(&argc, argv);
+ MSG_init(&argc, argv);
if (argc < 4) {
printf("Usage: %s platform_file number_of_jobs number_of_slaves\n", argv[0]);
printf("example: %s msg_platform.xml 10 5\n", argv[0]);
exit(1);
}
if (argc < 4) {
printf("Usage: %s platform_file number_of_jobs number_of_slaves\n", argv[0]);
printf("example: %s msg_platform.xml 10 5\n", argv[0]);
exit(1);
}
- MSG_set_channel_number(0);
MSG_function_register("master", master);
MSG_function_register("slave", slave);
MSG_function_register("master", master);
MSG_function_register("slave", slave);
@@
-110,32
+109,35
@@
int main(int argc, char *argv[])
number_of_jobs = atol(argv[2]);
number_of_slaves = atol(argv[3]);
number_of_jobs = atol(argv[2]);
number_of_slaves = atol(argv[3]);
+ xbt_dynar_t host_dynar = MSG_hosts_as_dynar();
+ long number_max = xbt_dynar_length(host_dynar);
+ XBT_INFO("Got %ld slaves, %ld tasks to process, and %ld hosts", number_of_slaves, number_of_jobs,number_max);
- XBT_INFO("Got %ld slaves, %ld tasks to process, and %d hosts", number_of_slaves, number_of_jobs,MSG_get_host_number());
-
- m_host_t *host_table = MSG_get_host_table();
+ msg_host_t *host_table = xbt_dynar_to_array(host_dynar);
+ //xbt_dynar_free(&host_dynar);
MSG_process_create( "master",
master,
NULL,
MSG_process_create( "master",
master,
NULL,
- host_table[my_random(number_
of_slaves
)]
+ host_table[my_random(number_
max
)]
);
for(i = 0 ; i<number_of_slaves; i++)
{
);
for(i = 0 ; i<number_of_slaves; i++)
{
- MSG_process_create(bprintf("slave-%ld",i),
+ char* name_host = bprintf("slave-%ld",i);
+ MSG_process_create( name_host,
slave,
NULL,
slave,
NULL,
- host_table[my_random(number_
of_slaves
)]
+ host_table[my_random(number_
max
)]
);
);
+ free(name_host);
}
}
+ xbt_free(host_table);
res = MSG_main();
XBT_INFO("Simulation time %g", MSG_get_clock());
res = MSG_main();
XBT_INFO("Simulation time %g", MSG_get_clock());
- MSG_clean();
-
if (res == MSG_OK)
return 0;
else
if (res == MSG_OK)
return 0;
else