1 /* Copyright (c) 2012-2014. The SimGrid Team.
2 * All rights reserved. */
4 /* This program is free software; you can redistribute it and/or modify it
5 * under the terms of the license (GNU LGPL) which comes with this package. */
7 #include "simgrid/platf_generator.h"
12 XBT_LOG_NEW_DEFAULT_CATEGORY(test_generation,
13 "Messages specific for this msg example");
16 #define FINALIZE ((void*)221297) /* a magic number to tell people to stop working */
18 void promoter_1(context_node_t node);
19 void labeler_1(context_edge_t edge);
20 int master(int argc, char *argv[]);
21 int slave(int argc, char *argv[]);
24 * Just promote each node into a host, with fixed power
26 void promoter_1(context_node_t node) {
28 s_sg_platf_host_cbarg_t host_parameters;
30 host_parameters.id = NULL;
31 host_parameters.power_peak = xbt_dynar_new(sizeof(double), NULL);
32 xbt_dynar_push_as(host_parameters.power_peak, double, 1000000.0);
33 host_parameters.core_amount = 1;
34 host_parameters.power_scale = 1;
35 host_parameters.power_trace = NULL;
36 host_parameters.initial_state = SURF_RESOURCE_ON;
37 host_parameters.state_trace = NULL;
38 host_parameters.coord = NULL;
39 host_parameters.properties = NULL;
41 platf_graph_promote_to_host(node, &host_parameters);
46 * Set all links with the same bandwidth and latency
48 void labeler_1(context_edge_t edge) {
49 s_sg_platf_link_cbarg_t link_parameters;
50 link_parameters.id = NULL;
51 link_parameters.bandwidth = 1000000;
52 link_parameters.bandwidth_trace = NULL;
53 link_parameters.latency = 0.01;
54 link_parameters.latency_trace = NULL;
55 link_parameters.state = SURF_RESOURCE_ON;
56 link_parameters.state_trace = NULL;
57 link_parameters.policy = SURF_LINK_SHARED;
58 link_parameters.properties = NULL;
60 platf_graph_link_label(edge, &link_parameters);
63 /** Emitter function */
64 int master(int argc, char *argv[])
67 msg_host_t *slaves = NULL;
68 int number_of_tasks = 0;
69 double task_comp_size = 0;
70 double task_comm_size = 0;
73 number_of_tasks = 3*argc;
74 task_comp_size = 2400000*argc;
75 task_comm_size = 1000000;
77 { /* Process organisation */
79 slaves = xbt_new0(msg_host_t, slaves_count);
81 for (i = 0; i < argc; i++) {
82 slaves[i] = MSG_get_host_by_name(argv[i]);
83 if (slaves[i] == NULL) {
84 XBT_INFO("Unknown host %s. Stopping Now! ", argv[i]);
90 XBT_INFO("Got %d slave(s) :", slaves_count);
91 for (i = 0; i < slaves_count; i++)
92 XBT_INFO("%s", MSG_host_get_name(slaves[i]));
94 XBT_INFO("Got %d task to process :", number_of_tasks);
96 for (i = 0; i < number_of_tasks; i++) {
97 msg_task_t task = MSG_task_create("Task", task_comp_size, task_comm_size,
100 *((double *) task->data) = MSG_get_clock();
102 a = MSG_task_send(task,MSG_host_get_name(slaves[i % slaves_count]));
105 XBT_INFO("Send completed");
107 XBT_INFO("Hey ?! What's up ? ");
108 xbt_die( "Unexpected behavior");
113 ("All tasks have been dispatched. Let's tell everybody the computation is over.");
114 for (i = 0; i < slaves_count; i++) {
115 msg_task_t task = MSG_task_create("finalize", 0, 0, FINALIZE);
116 int a = MSG_task_send(task,MSG_host_get_name(slaves[i]));
118 XBT_INFO("Hey ?! What's up ? ");
119 xbt_die("Unexpected behavior with '%s': %d", MSG_host_get_name(slaves[i]), a);
123 XBT_INFO("Goodbye now!");
126 } /* end_of_master */
128 /** Receiver function */
129 int slave(int argc, char *argv[])
132 msg_task_t task = NULL;
136 time1 = MSG_get_clock();
137 a = MSG_task_receive( &(task), MSG_host_get_name(MSG_host_self()) );
138 time2 = MSG_get_clock();
140 XBT_INFO("Received \"%s\"", MSG_task_get_name(task));
141 if (MSG_task_get_data(task) == FINALIZE) {
142 MSG_task_destroy(task);
145 if (time1 < *((double *) task->data))
146 time1 = *((double *) task->data);
147 XBT_INFO("Communication time : \"%f\"", time2 - time1);
148 XBT_INFO("Processing \"%s\"", MSG_task_get_name(task));
149 a = MSG_task_execute(task);
151 XBT_INFO("\"%s\" done", MSG_task_get_name(task));
153 MSG_task_destroy(task);
155 XBT_INFO("Hey ?! What's up ? ");
156 xbt_die("Unexpected behavior");
159 XBT_INFO("Hey ?! What's up ? error %d", a);
160 xbt_die("Unexpected behavior");
163 XBT_INFO("I'm done. See you!");
169 * Create the platform, list the available hosts and give them some work
171 int main(int argc, char **argv) {
173 unsigned long seed[] = {134, 233445, 865, 2634, 424242, 876543};
178 MSG_init(&argc, argv);
180 //Set up the seed for the platform generation
181 platf_random_seed(seed);
183 XBT_INFO("creating nodes...");
184 platf_graph_uniform(50);
187 XBT_INFO("creating links...");
188 platf_graph_clear_links();
189 platf_graph_interconnect_uniform(0.07); //Unrealistic, but simple
190 XBT_INFO("done. Check connectedness...");
191 connected = platf_graph_is_connected();
192 XBT_INFO("Is it connected : %s", connected ? "yes" : (max_tries ? "no, retrying" : "no"));
193 } while(!connected && max_tries);
195 if(!connected && !max_tries) {
196 xbt_die("Impossible to connect the graph, aborting.");
199 XBT_INFO("registering callbacks...");
200 platf_graph_promoter(promoter_1);
201 platf_graph_labeler(labeler_1);
203 XBT_INFO("protmoting...");
206 XBT_INFO("labeling...");
209 XBT_INFO("Putting it in surf...");
212 XBT_INFO("Let's get the available hosts and dispatch work:");
215 msg_host_t host = NULL;
216 msg_host_t host_master = NULL;
217 xbt_dynar_t host_dynar = MSG_hosts_as_dynar();
218 char** hostname_list = xbt_malloc(sizeof(char*) * xbt_dynar_length(host_dynar));
220 xbt_dynar_foreach(host_dynar, i, host) {
221 MSG_process_create("slave", slave, NULL, host);
223 //The first node will also be the master
224 XBT_INFO("%s will be the master", MSG_host_get_name(host));
227 hostname_list[i] = (char*) MSG_host_get_name(host);
230 MSG_process_create_with_arguments("master", master, NULL, host_master, xbt_dynar_length(host_dynar), hostname_list);
232 XBT_INFO("Let's rock!");
234 XBT_INFO("Simulation time %g", MSG_get_clock());