Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
Enhanced gtnets example program now remaining feature is active.
[simgrid.git] / examples / msg / gtnets / gtnets_onelink.c
1 #include <stdio.h>
2 #include <stdlib.h>
3 #include "msg/msg.h"
4 /* Create a log channel to have nice outputs. */
5 #include "xbt/log.h"
6 #include "xbt/asserts.h"
7
8 XBT_LOG_NEW_DEFAULT_CATEGORY(msg_test,"Messages specific for this msg example");
9
10 int master(int argc, char *argv[]);
11 int slave(int argc, char *argv[]);
12 MSG_error_t test_all(const char *platform_file, const char *application_file);
13
14
15 typedef enum {
16   PORT_22 = 0,
17   MAX_CHANNEL
18 } channel_t;
19
20
21 double time=0;
22 double task_comm_size=0.0;
23
24 #define FINALIZE ((void*)221297) /* a magic number to tell people to stop working */
25
26 /** Master */
27 int master(int argc, char *argv[]){
28   char *slavename = NULL;
29   m_task_t todo = NULL;
30   m_host_t slave;
31   MSG_error_t a;
32   
33   if(argc != 3){
34     xbt_assert1(0, "Invalid number of arguments in master process, expected 4 got %d\n", argc);
35   }
36
37   /* data size */
38   xbt_assert1(sscanf(argv[1],"%lg", &task_comm_size),
39       "Invalid argument %s\n", argv[1]);
40   INFO1("task_comm_size : %f\n", task_comm_size);
41  
42   /* slave name */
43   slavename = argv[2];
44
45
46   /*  Task creation.  */
47   char sprintf_buffer[64] = "Task_0";
48   todo = MSG_task_create(sprintf_buffer, 0, task_comm_size, NULL);
49   
50   /* Process organisation */
51   slave = MSG_get_host_by_name(slavename);
52     
53   /* Time measurement */
54   time = MSG_get_clock();
55
56   a = MSG_task_put(todo, slave, PORT_22);
57   xbt_assert0(!a,"MSG_task_put failure"); 
58
59   return 0;
60 } /* end_of_master */
61
62
63 /** Receiver function  */
64 int slave(int argc, char *argv[])
65
66   m_task_t task = NULL;
67   int a;
68
69   a = MSG_task_get(&(task), PORT_22);
70   xbt_assert0(!a, "MSG_task_get failure");
71
72   /* Elapsed time */
73   time = MSG_get_clock() - time;
74   
75   INFO1("Total transmission time: %f", time);
76   INFO1("Hockney estimated bandwidth: %f", ((task_comm_size*8)/time)/1000);
77
78   MSG_task_destroy(task);
79   return 0;
80 } /* end_of_slave */
81
82
83
84
85 /** Test function */
86 MSG_error_t test_all(const char *platform_file,
87                      const char *application_file){
88   MSG_error_t res = MSG_OK;
89
90   /*  Simulation setting */
91   MSG_set_channel_number(MAX_CHANNEL);
92   MSG_paje_output("msg_test.trace");
93   MSG_create_environment(platform_file);
94     
95   /*   Application deployment */
96   MSG_function_register("master", master);
97   MSG_function_register("slave", slave);
98   MSG_launch_application(application_file);
99   
100   res = MSG_main();
101   return res;
102 } /* end_of_test_all */
103
104
105 /** Main function */
106 int main(int argc, char *argv[]){
107   MSG_error_t res = MSG_OK;
108
109   MSG_global_init(&argc,argv);
110   if (argc < 3) {
111      printf ("Usage: %s platform_file deployment_file\n",argv[0]);
112      exit(1);
113   }
114   res = test_all(argv[1],argv[2]);
115
116   MSG_clean();
117
118   if(res==MSG_OK) return 0; 
119   else return 1;
120 } /* end_of_main */