3 /* Copyright (c) 2002,2003,2004 Arnaud Legrand. All rights reserved. */
5 /* This program is free software; you can redistribute it and/or modify it
6 * under the terms of the license (GNU LGPL) which comes with this package. */
8 #include "msg/msg.h" /* Yeah! If you want to use msg, you need to include msg/msg.h */
9 #include "xbt/sysdep.h" /* calloc */
12 /* Create a log channel to have nice outputs. */
14 #include "xbt/asserts.h"
15 XBT_LOG_NEW_DEFAULT_CATEGORY(msg_test,"Messages specific for this msg example");
17 int sender(int argc, char *argv[]);
18 int receiver(int argc, char *argv[]);
20 MSG_error_t test_all(const char *platform_file, const char *application_file);
28 double task_comm_size_lat = 1;
29 double task_comm_size_bw = 100000000;
31 /** Emitter function */
32 int sender(int argc,char *argv[] )
35 m_host_t *hosts = NULL;
38 double task_comp_size = 0;
40 char sprintf_buffer[64];
45 hosts = calloc(nbr, sizeof(m_host_t));
47 for (i = 1; i < argc; i++)
49 INFO2("host [%d]= %s",i-1, argv[i]);
50 hosts[i-1] = MSG_get_host_by_name(argv[i]);
53 INFO1("Unknown host %s. Stopping Now! ", argv[i]);
58 for (i = 0; i < nbr; i++)
62 task = MSG_task_create(sprintf_buffer, task_comp_size, task_comm_size_lat, NULL);
63 INFO1("task = %p",task);
64 task->data=xbt_new0(double,1);
65 *(double*)(task->data)=time;
66 INFO1("task->data = %le", *(double*)(task->data));
67 INFO2("host [%d]=%s ",i, argv[i+1]);
68 MSG_task_put(task, hosts[i],PORT_22);
72 task = MSG_task_create(sprintf_buffer, task_comp_size, task_comm_size_bw, NULL);
73 task->data=xbt_new0(double,1);
74 *(double*)(task->data)=time;
75 MSG_task_put(task, hosts[i % nbr],PORT_22);
83 /** Receiver function */
84 int receiver(int argc, char *argv[])
87 double communication_time=0;
92 double time, time1, sender_time;
97 a=MSG_task_get(&task,PORT_22);
101 time1=MSG_get_clock();
102 sender_time=(*(double*)(task->data));
104 /* if (sender_time > time) */
106 communication_time=time1-time;
107 INFO1("Communic. time %.35f",communication_time);
108 MSG_task_destroy(task);
109 INFO1("Communic. time %le",communication_time);
111 INFO1("--- bw %f ----",task_comm_size_bw/communication_time);
115 xbt_assert0(0,"Unexpected behavior");
119 }/* end_of_receiver */
123 MSG_error_t test_all(const char *platform_file,
124 const char *application_file)
127 MSG_error_t res = MSG_OK;
130 /* Simulation setting */
131 MSG_set_channel_number(MAX_CHANNEL);
132 MSG_paje_output("msg_test.trace");
133 MSG_create_environment(platform_file);
135 /* Application deployment */
136 MSG_function_register("sender", sender);
137 MSG_function_register("receiver", receiver);
139 MSG_launch_application(application_file);
143 } /* end_of_test_all */
147 int main(int argc, char *argv[])
149 MSG_error_t res = MSG_OK;
151 MSG_global_init(&argc,argv);
154 CRITICAL1 ("Usage: %s platform_file deployment_file\n",argv[0]);
155 CRITICAL1 ("example: %s msg_platform.xml msg_deployment.xml\n",argv[0]);
158 res = test_all(argv[1],argv[2]);
161 if(res==MSG_OK) return 0;