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[]);
20 * Just promote each node into a host, with fixed power
22 void promoter_1(context_node_t node) {
24 s_sg_platf_host_cbarg_t host_parameters;
26 host_parameters.id = NULL;
27 host_parameters.power_peak = 1000000;
29 host_parameters.core_amount = 1;
30 host_parameters.power_scale = 1;
31 host_parameters.power_trace = NULL;
32 host_parameters.initial_state = SURF_RESOURCE_ON;
33 host_parameters.state_trace = NULL;
34 host_parameters.coord = NULL;
35 host_parameters.properties = NULL;
37 platf_graph_promote_to_host(node, &host_parameters);
42 * Set all links with the same bandwidth and latency
44 void labeler_1(context_edge_t edge) {
45 s_sg_platf_link_cbarg_t link_parameters;
46 link_parameters.id = NULL;
47 link_parameters.bandwidth = 1000000;
48 link_parameters.bandwidth_trace = NULL;
49 link_parameters.latency = 0.01;
50 link_parameters.latency_trace = NULL;
51 link_parameters.state = SURF_RESOURCE_ON;
52 link_parameters.state_trace = NULL;
53 link_parameters.policy = SURF_LINK_SHARED;
54 link_parameters.properties = NULL;
56 platf_graph_link_label(edge, &link_parameters);
59 /** Emitter function */
60 int master(int argc, char *argv[])
63 msg_host_t *slaves = NULL;
64 int number_of_tasks = 0;
65 double task_comp_size = 0;
66 double task_comm_size = 0;
69 number_of_tasks = 3*argc;
70 task_comp_size = 2400000*argc;
71 task_comm_size = 1000000;
73 { /* Process organisation */
75 slaves = xbt_new0(msg_host_t, slaves_count);
77 for (i = 0; i < argc; i++) {
78 slaves[i] = MSG_get_host_by_name(argv[i]);
79 if (slaves[i] == NULL) {
80 XBT_INFO("Unknown host %s. Stopping Now! ", argv[i]);
86 XBT_INFO("Got %d slave(s) :", slaves_count);
87 for (i = 0; i < slaves_count; i++)
88 XBT_INFO("%s", MSG_host_get_name(slaves[i]));
90 XBT_INFO("Got %d task to process :", number_of_tasks);
92 for (i = 0; i < number_of_tasks; i++) {
93 msg_task_t task = MSG_task_create("Task", task_comp_size, task_comm_size,
96 *((double *) task->data) = MSG_get_clock();
98 a = MSG_task_send(task,MSG_host_get_name(slaves[i % slaves_count]));
101 XBT_INFO("Send completed");
103 XBT_INFO("Hey ?! What's up ? ");
104 xbt_die( "Unexpected behavior");
109 ("All tasks have been dispatched. Let's tell everybody the computation is over.");
110 for (i = 0; i < slaves_count; i++) {
111 msg_task_t task = MSG_task_create("finalize", 0, 0, FINALIZE);
112 int a = MSG_task_send(task,MSG_host_get_name(slaves[i]));
114 XBT_INFO("Hey ?! What's up ? ");
115 xbt_die("Unexpected behavior with '%s': %d", MSG_host_get_name(slaves[i]), a);
119 XBT_INFO("Goodbye now!");
122 } /* end_of_master */
124 /** Receiver function */
125 int slave(int argc, char *argv[])
128 msg_task_t task = NULL;
132 time1 = MSG_get_clock();
133 a = MSG_task_receive( &(task), MSG_host_get_name(MSG_host_self()) );
134 time2 = MSG_get_clock();
136 XBT_INFO("Received \"%s\"", MSG_task_get_name(task));
137 if (MSG_task_get_data(task) == FINALIZE) {
138 MSG_task_destroy(task);
141 if (time1 < *((double *) task->data))
142 time1 = *((double *) task->data);
143 XBT_INFO("Communication time : \"%f\"", time2 - time1);
144 XBT_INFO("Processing \"%s\"", MSG_task_get_name(task));
145 a = MSG_task_execute(task);
147 XBT_INFO("\"%s\" done", MSG_task_get_name(task));
149 MSG_task_destroy(task);
151 XBT_INFO("Hey ?! What's up ? ");
152 xbt_die("Unexpected behavior");
155 XBT_INFO("Hey ?! What's up ? error %d", a);
156 xbt_die("Unexpected behavior");
159 XBT_INFO("I'm done. See you!");
165 * Create the platform, list the available hosts and give them some work
167 int main(int argc, char **argv) {
169 unsigned long seed[] = {134, 233445, 865, 2634, 424242, 876543};
174 MSG_init(&argc, argv);
176 //Set up the seed for the platform generation
177 platf_random_seed(seed);
179 XBT_INFO("creating nodes...");
180 platf_graph_uniform(50);
183 XBT_INFO("creating links...");
184 platf_graph_clear_links();
185 platf_graph_interconnect_uniform(0.15); //Unrealistic, but simple
186 XBT_INFO("done. Check connectivity...");
187 connected = platf_graph_is_connected();
188 XBT_INFO("Is it connected : %s", connected ? "yes" : (max_tries ? "no, retrying" : "no"));
189 } while(!connected && max_tries);
191 if(!connected && !max_tries) {
192 xbt_die("Impossible to connect the graph, aborting.");
195 XBT_INFO("registering callbacks...");
196 platf_graph_promoter(promoter_1);
197 platf_graph_labeler(labeler_1);
199 XBT_INFO("protmoting...");
202 XBT_INFO("labeling...");
205 XBT_INFO("Putting it in surf...");
208 XBT_INFO("Let's get the available hosts and dispatch work:");
211 msg_host_t host = NULL;
212 msg_host_t host_master = NULL;
213 xbt_dynar_t host_dynar = MSG_hosts_as_dynar();
214 char** hostname_list = malloc(sizeof(char*) * xbt_dynar_length(host_dynar));
216 xbt_dynar_foreach(host_dynar, i, host) {
217 MSG_process_create("slave", slave, NULL, host);
219 //The first node will also be the master
220 XBT_INFO("%s will be the master", MSG_host_get_name(host));
223 hostname_list[i] = (char*) MSG_host_get_name(host);
226 MSG_process_create_with_arguments("master", master, NULL, host_master, xbt_dynar_length(host_dynar), hostname_list);
228 XBT_INFO("Let's rock!");
230 XBT_INFO("Simulation time %g", MSG_get_clock());