1 /* Copyright (c) 2008-2010, 2012-2015. 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. */
9 #include "simgrid/msg.h"
10 #include "surf/surf_private.h"
12 int host(int argc, char *argv[]);
13 unsigned int task_comp_size = 50000000;
14 unsigned int task_comm_size = 1000000;
16 int nb_hosts; /* All declared hosts */
18 XBT_LOG_NEW_DEFAULT_CATEGORY(ring,
19 "Messages specific for this msg example");
21 /** @addtogroup MSG_examples
23 * - <b>token_ring/token_bypass.c</b>: Classical token ring with a bypass deployment.
24 * A token is exchanged along a ring to reach every participant.
28 int host(int argc, char *argv[])
30 int host_number = atoi(MSG_process_get_name(MSG_process_self()));
32 msg_task_t task = NULL;
33 XBT_ATTRIB_UNUSED int res;
34 if (host_number == 0){ //master send then receive
35 sprintf(mailbox, "%d", host_number+1);
36 task = MSG_task_create("Token", task_comp_size, task_comm_size, NULL);
37 XBT_INFO("Host \"%d\" send '%s' to Host \"%s\"",host_number,task->name,mailbox);
38 MSG_task_send(task, mailbox);
40 res = MSG_task_receive(&(task), MSG_process_get_name(MSG_process_self()));
41 xbt_assert(res == MSG_OK, "MSG_task_get failed");
42 XBT_INFO("Host \"%d\" received \"%s\"",host_number, MSG_task_get_name(task));
43 MSG_task_destroy(task);
45 else{ //slave receive then send
46 res = MSG_task_receive(&(task), MSG_process_get_name(MSG_process_self()));
47 xbt_assert(res == MSG_OK, "MSG_task_get failed");
48 XBT_INFO("Host \"%d\" received \"%s\"",host_number, MSG_task_get_name(task));
50 if(host_number+1 == nb_hosts)
51 sprintf(mailbox, "0");
53 sprintf(mailbox, "%d", host_number+1);
54 XBT_INFO("Host \"%d\" send '%s' to Host \"%s\"",host_number,task->name,mailbox);
55 MSG_task_send(task, mailbox);
60 static int surf_parse_bypass_platform(void)
63 s_sg_platf_AS_cbarg_t AS = SG_PLATF_AS_INITIALIZER;
65 AS.routing = A_surfxml_AS_routing_Full;
66 sg_platf_new_AS_begin(&AS);
68 s_sg_platf_host_cbarg_t bob = SG_PLATF_HOST_INITIALIZER;
70 bob.power_peak = xbt_dynar_new(sizeof(double), NULL);
71 xbt_dynar_push_as(bob.power_peak, double, 98095000.0);
72 sg_platf_new_host(&bob);
74 s_sg_platf_host_cbarg_t alice = SG_PLATF_HOST_INITIALIZER;
76 alice.power_peak = xbt_dynar_new(sizeof(double), NULL);
77 xbt_dynar_push_as(alice.power_peak, double, 98095000.0);
78 sg_platf_new_host(&alice);
80 s_sg_platf_link_cbarg_t link = SG_PLATF_LINK_INITIALIZER;
82 link.latency = 0.000278066;
83 link.bandwidth = 27946250;
84 sg_platf_new_link(&link);
86 s_sg_platf_route_cbarg_t route= SG_PLATF_ROUTE_INITIALIZER;
89 sg_platf_route_begin(&route);
90 sg_platf_route_add_link("link1", &route);
91 sg_platf_route_end(&route);
93 sg_platf_new_AS_end();
99 int main(int argc, char **argv)
102 msg_error_t res = MSG_OK;
104 MSG_init(&argc, argv);
105 surf_parse = surf_parse_bypass_platform;
106 MSG_create_environment(NULL);
108 MSG_function_register("host", host);
110 xbt_dynar_t hosts = MSG_hosts_as_dynar();
111 nb_hosts = xbt_dynar_length(hosts);
113 XBT_INFO("Number of host '%d'",nb_hosts);
114 for(i = 0 ; i<nb_hosts; i++)
116 char* name_host = bprintf("%d",i);
117 MSG_process_create( name_host, host, NULL, xbt_dynar_get_as(hosts,i,msg_host_t) );
120 xbt_dynar_free(&hosts);
123 XBT_INFO("Simulation time %g", MSG_get_clock());