2 #include "simgrid/platf_generator.h"
7 XBT_LOG_NEW_DEFAULT_CATEGORY(test_generation,
8 "Messages specific for this msg example");
11 #define FINALIZE ((void*)221297) /* a magic number to tell people to stop working */
13 void promoter_1(context_node_t node);
14 void labeler_1(context_edge_t edge);
15 int master(int argc, char *argv[]);
16 int slave(int argc, char *argv[]);
19 * Just promote each node into a host, with fixed power
21 void promoter_1(context_node_t node) {
23 s_sg_platf_host_cbarg_t host_parameters;
25 host_parameters.id = NULL;
26 host_parameters.power_peak = 1000000;
28 host_parameters.core_amount = 1;
29 host_parameters.power_scale = 1;
30 host_parameters.power_trace = NULL;
31 host_parameters.initial_state = SURF_RESOURCE_ON;
32 host_parameters.state_trace = NULL;
33 host_parameters.coord = NULL;
34 host_parameters.properties = NULL;
36 platf_graph_promote_to_host(node, &host_parameters);
41 * Set all links with the same bandwidth and latency
43 void labeler_1(context_edge_t edge) {
44 s_sg_platf_link_cbarg_t link_parameters;
45 link_parameters.id = NULL;
46 link_parameters.bandwidth = 1000000;
47 link_parameters.bandwidth_trace = NULL;
48 link_parameters.latency = 0.01;
49 link_parameters.latency_trace = NULL;
50 link_parameters.state = SURF_RESOURCE_ON;
51 link_parameters.state_trace = NULL;
52 link_parameters.policy = SURF_LINK_SHARED;
53 link_parameters.properties = NULL;
55 platf_graph_link_label(edge, &link_parameters);
58 /** Emitter function */
59 int master(int argc, char *argv[])
62 msg_host_t *slaves = NULL;
63 int number_of_tasks = 0;
64 double task_comp_size = 0;
65 double task_comm_size = 0;
68 number_of_tasks = 3*argc;
69 task_comp_size = 2400000*argc;
70 task_comm_size = 1000000;
72 { /* Process organisation */
74 slaves = xbt_new0(msg_host_t, slaves_count);
76 for (i = 0; i < argc; i++) {
77 slaves[i] = MSG_get_host_by_name(argv[i]);
78 if (slaves[i] == NULL) {
79 XBT_INFO("Unknown host %s. Stopping Now! ", argv[i]);
85 XBT_INFO("Got %d slave(s) :", slaves_count);
86 for (i = 0; i < slaves_count; i++)
87 XBT_INFO("%s", MSG_host_get_name(slaves[i]));
89 XBT_INFO("Got %d task to process :", number_of_tasks);
91 for (i = 0; i < number_of_tasks; i++) {
92 msg_task_t task = MSG_task_create("Task", task_comp_size, task_comm_size,
95 *((double *) task->data) = MSG_get_clock();
97 a = MSG_task_send(task,MSG_host_get_name(slaves[i % slaves_count]));
100 XBT_INFO("Send completed");
102 XBT_INFO("Hey ?! What's up ? ");
103 xbt_die( "Unexpected behavior");
108 ("All tasks have been dispatched. Let's tell everybody the computation is over.");
109 for (i = 0; i < slaves_count; i++) {
110 msg_task_t task = MSG_task_create("finalize", 0, 0, FINALIZE);
111 int a = MSG_task_send(task,MSG_host_get_name(slaves[i]));
113 XBT_INFO("Hey ?! What's up ? ");
114 xbt_die("Unexpected behavior with '%s': %d", MSG_host_get_name(slaves[i]), a);
118 XBT_INFO("Goodbye now!");
121 } /* end_of_master */
123 /** Receiver function */
124 int slave(int argc, char *argv[])
127 msg_task_t task = NULL;
131 time1 = MSG_get_clock();
132 a = MSG_task_receive( &(task), MSG_host_get_name(MSG_host_self()) );
133 time2 = MSG_get_clock();
135 XBT_INFO("Received \"%s\"", MSG_task_get_name(task));
136 if (MSG_task_get_data(task) == FINALIZE) {
137 MSG_task_destroy(task);
140 if (time1 < *((double *) task->data))
141 time1 = *((double *) task->data);
142 XBT_INFO("Communication time : \"%f\"", time2 - time1);
143 XBT_INFO("Processing \"%s\"", MSG_task_get_name(task));
144 a = MSG_task_execute(task);
146 XBT_INFO("\"%s\" done", MSG_task_get_name(task));
148 MSG_task_destroy(task);
150 XBT_INFO("Hey ?! What's up ? ");
151 xbt_die("Unexpected behavior");
154 XBT_INFO("Hey ?! What's up ? error %d", a);
155 xbt_die("Unexpected behavior");
158 XBT_INFO("I'm done. See you!");
164 * Create the platform, list the available hosts and give them some work
166 int main(int argc, char **argv) {
168 unsigned long seed[] = {134, 233445, 865, 2634, 424242, 876543};
173 MSG_init(&argc, argv);
175 //Set up the seed for the platform generation
176 platf_random_seed(seed);
178 XBT_INFO("creating nodes...");
179 platf_graph_uniform(50);
182 XBT_INFO("creating links...");
183 platf_graph_clear_links();
184 platf_graph_interconnect_uniform(0.07); //Unrealistic, but simple
185 XBT_INFO("done. Check connectedness...");
186 connected = platf_graph_is_connected();
187 XBT_INFO("Is it connected : %s", connected ? "yes" : (max_tries ? "no, retrying" : "no"));
188 } while(!connected && max_tries);
190 if(!connected && !max_tries) {
191 xbt_die("Impossible to connect the graph, aborting.");
194 XBT_INFO("registering callbacks...");
195 platf_graph_promoter(promoter_1);
196 platf_graph_labeler(labeler_1);
198 XBT_INFO("protmoting...");
201 XBT_INFO("labeling...");
204 XBT_INFO("Putting it in surf...");
207 XBT_INFO("Let's get the available hosts and dispatch work:");
210 msg_host_t host = NULL;
211 msg_host_t host_master = NULL;
212 xbt_dynar_t host_dynar = MSG_hosts_as_dynar();
213 char** hostname_list = malloc(sizeof(char*) * xbt_dynar_length(host_dynar));
215 xbt_dynar_foreach(host_dynar, i, host) {
216 MSG_process_create("slave", slave, NULL, host);
218 //The first node will also be the master
219 XBT_INFO("%s will be the master", MSG_host_get_name(host));
222 hostname_list[i] = (char*) MSG_host_get_name(host);
225 MSG_process_create_with_arguments("master", master, NULL, host_master, xbt_dynar_length(host_dynar), hostname_list);
227 XBT_INFO("Let's rock!");
229 XBT_INFO("Simulation time %g", MSG_get_clock());