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, printf */
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 = 0;
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];
43 hosts = calloc(nbr, sizeof(m_host_t));
45 for (i = 1; i < argc; i++)
47 INFO2("host [%d]= %s",i-1, argv[i]);
48 hosts[i-1] = MSG_get_host_by_name(argv[i]);
51 INFO1("Unknown host %s. Stopping Now! ", argv[i]);
56 for (i = 0; i < nbr; i++)
59 /* time=MSG_get_clock(); */
60 /* task = MSG_task_create(sprintf_buffer, task_comp_size, task_comm_size_lat, NULL); */
61 /* INFO1("task = %p",task); */
62 /* task->data=xbt_new0(double,1); */
63 /* *(double*)(task->data)=time; */
64 /* INFO1("task->data = %le", *(double*)(task->data)); */
65 /* INFO2("host [%d]=%s ",i, argv[i+1]); */
66 /* MSG_task_put(task, hosts[i],PORT_22); */
70 task = MSG_task_create(sprintf_buffer, task_comp_size, task_comm_size_bw, NULL);
71 task->data=xbt_new0(double,1);
72 *(double*)(task->data)=time;
73 MSG_task_put(task, hosts[i % nbr],PORT_22);
81 /** Receiver function */
82 int receiver(int argc, char *argv[])
85 double communication_time=0;
88 double time, time1, sender_time;
93 a=MSG_task_get(&task,PORT_22);
97 time1=MSG_get_clock();
98 sender_time=(*(double*)(task->data));
100 if (sender_time > time)
102 communication_time=time1-time;
103 INFO1("Communic. time %le",communication_time);
104 MSG_task_destroy(task);
105 INFO1("Communic. time %le",communication_time);
107 INFO1("--- bw %f ----",task_comm_size_bw/communication_time);
111 xbt_assert0(0,"Unexpected behavior");
115 }/* end_of_receiver */
119 MSG_error_t test_all(const char *platform_file,
120 const char *application_file)
123 MSG_error_t res = MSG_OK;
124 /* Simulation setting */
125 MSG_set_channel_number(MAX_CHANNEL);
126 MSG_paje_output("msg_test.trace");
127 MSG_create_environment(platform_file);
129 /* Application deployment */
130 MSG_function_register("sender", sender);
131 MSG_function_register("receiver", receiver);
133 MSG_launch_application(application_file);
137 } /* end_of_test_all */
141 int main(int argc, char *argv[])
143 MSG_error_t res = MSG_OK;
145 MSG_global_init(&argc,argv);
148 printf ("Usage: %s platform_file deployment_file\n",argv[0]);
149 printf ("example: %s msg_platform.xml msg_deployment.xml\n",argv[0]);
152 res = test_all(argv[1],argv[2]);
155 if(res==MSG_OK) return 0;