5 #include "xbt/asserts.h"
7 XBT_LOG_NEW_DEFAULT_CATEGORY(msg_test,"Messages specific for this msg example");
9 int master(int argc, char *argv[]);
10 int slave(int argc, char *argv[]);
11 MSG_error_t test_all(const char *platform_file, const char *application_file);
18 //keep a pointer to all surf running tasks.
21 double start_time, end_time, elapsed_time;
22 double gl_data_size[NTASKS];
23 m_task_t gl_task_array[NTASKS];
24 const char * slavenames[NTASKS];
25 const char * masternames[NTASKS];
26 int gl_task_array_id=0;
28 #define FINALIZE ((void*)221297) /* a magic number to tell people to stop working */
31 int master(int argc, char *argv[])
33 char *slavename = NULL;
34 double task_comm_size = 0;
38 //unique id to control statistics
42 INFO1("Strange number of arguments expected 3 got %d", argc-1 );
46 xbt_assert1(sscanf(argv[1],"%lg", &task_comm_size),
47 "Invalid argument %s\n", argv[1]);
52 sprintf(id_alias, "%d",id);
53 slavenames[id] = slavename;
55 masternames[id] = MSG_host_get_name(MSG_host_self());
57 { /* Task creation. */
58 char sprintf_buffer[64] = "Task_0";
59 todo = MSG_task_create(sprintf_buffer, 0, task_comm_size, NULL);
60 //keep track of running tasks
61 gl_task_array[id] = todo;
62 gl_data_size[id]=task_comm_size;
65 { /* Process organisation */
66 slave = MSG_get_host_by_name(slavename);
69 /* time measurement */
70 start_time = MSG_get_clock();
71 //MSG_task_put(todo, slave, PORT_22);
72 MSG_task_send(todo, id_alias);
74 end_time = MSG_get_clock();
75 INFO3("Send completed (to %s). Transfer time: %f\t Agregate bandwidth: %f",
76 slave->name, (end_time - start_time), task_comm_size/(end_time-start_time));
77 INFO2("Completed peer: %s time: %f", slave->name, (end_time-start_time));
82 /** Receiver function */
83 int slave(int argc, char *argv[])
93 INFO1("Strange number of arguments expected 1 got %d", argc-1 );
97 sprintf(id_alias, "%d",id);
100 //a = MSG_task_get(&(task), PORT_22);
101 a = MSG_task_receive(&(task), id_alias );
105 INFO0("Hey?! What's up?");
106 xbt_assert0(0,"Unexpected behavior.");
109 elapsed_time = MSG_get_clock() - start_time;
113 for(id=0; id<NTASKS; id++){
114 if(gl_task_array[id] == NULL){
116 }else if(gl_task_array[id] == task){
117 INFO5("===> Estimated Bw of FLOW[%d] : %f ; message from %s to %s with remaining : %f", id, gl_data_size[id]/elapsed_time, masternames[id], slavenames[id], 0.0);
119 remaining = MSG_task_get_remaining_communication(gl_task_array[id]);
120 INFO5("===> Estimated Bw of FLOW[%d] : %f ; message from %s to %s with remaining : %f", id, (gl_data_size[id]-remaining)/elapsed_time, masternames[id], slavenames[id], remaining);
126 MSG_task_destroy(task);
133 MSG_error_t test_all(const char *platform_file,
134 const char *application_file)
136 MSG_error_t res = MSG_OK;
138 /* MSG_config("workstation_model", "GTNETS"); */
139 /* MSG_config("workstation_model","KCCFLN05"); */
140 { /* Simulation setting */
141 MSG_set_channel_number(MAX_CHANNEL);
142 //MSG_paje_output("msg_test.trace");
143 MSG_create_environment(platform_file);
145 { /* Application deployment */
146 MSG_function_register("master", master);
147 MSG_function_register("slave", slave);
148 MSG_launch_application(application_file);
152 } /* end_of_test_all */
155 int main(int argc, char *argv[])
157 MSG_error_t res = MSG_OK;
160 MSG_global_init(&argc,argv);
162 printf ("Usage: %s platform_file deployment_file\n",argv[0]);
165 res = test_all(argv[1],argv[2]);
169 if(res==MSG_OK) return 0;