Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
adding a new tesh to test the TRACE_VOLUME mask (and also serve as example)
[simgrid.git] / examples / msg / tracing / volume.c
1 /*      $Id$     */
2
3 /* Copyright (c) 2002,2003,2004 Arnaud Legrand. All rights reserved.        */
4
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. */
7
8 #include <stdio.h>
9 #include "msg/msg.h"
10 #include "xbt/sysdep.h" /* calloc, printf */
11
12 /* Create a log channel to have nice outputs. */
13 #include "xbt/log.h"
14 #include "xbt/asserts.h"
15 XBT_LOG_NEW_DEFAULT_CATEGORY(msg_test,"Messages specific for this msg example");
16
17 int master(int argc, char *argv[]);
18 int slave(int argc, char *argv[]);
19 MSG_error_t test_all(const char *platform_file, const char *application_file);
20
21 /** Emitter function  */
22 int master(int argc, char *argv[])
23 {
24   //defining the category of the master process
25   TRACE_msg_set_process_category (MSG_process_self(), "master");
26
27   long number_of_tasks = atol(argv[1]);
28   long slaves_count = atol(argv[4]);
29   int p = 1000000000;
30   int c = 10000000;
31
32   int i;
33   for (i = 0; i < number_of_tasks; i++){
34     m_task_t task = NULL;
35     task = MSG_task_create ("task_compute", p, c, NULL);
36     TRACE_msg_set_task_category (task, "compute");
37     MSG_task_send(task, "master_mailbox");
38     task = NULL;
39     task = MSG_task_create ("task_request", p, c, NULL);
40     TRACE_msg_set_task_category (task, "request");
41     MSG_task_send(task, "master_mailbox");
42     task = NULL;
43     task = MSG_task_create ("task_data", p, c, NULL);
44     TRACE_msg_set_task_category (task, "data");
45     MSG_task_send(task, "master_mailbox");
46   }
47   
48    for (i = 0; i < slaves_count; i++) { 
49      m_task_t finalize = MSG_task_create ("finalize", 0, 1000, 0);
50      TRACE_msg_set_task_category(finalize, "finalize");
51      MSG_task_send(finalize, "master_mailbox");
52    } 
53   
54   return 0;
55 }
56
57 /** Receiver function  */
58 int slave(int argc, char *argv[])
59 {
60   //defining the category of this slave process
61   TRACE_msg_set_process_category (MSG_process_self(), "slave");
62
63   m_task_t task = NULL;
64   int res;
65
66   while(1) {
67     res = MSG_task_receive(&(task), "master_mailbox");
68
69     if (!strcmp(MSG_task_get_name(task),"finalize")) {
70       MSG_task_destroy(task);
71         break;
72     }
73
74     MSG_task_execute(task);
75     MSG_task_destroy(task);
76     task = NULL;
77   }
78   return 0;
79 }
80
81 /** Test function */
82 MSG_error_t test_all(const char *platform_file,
83                             const char *application_file)
84 {
85   MSG_error_t res = MSG_OK;
86
87   {                             /*  Simulation setting */
88     MSG_set_channel_number(0);
89     MSG_create_environment(platform_file);
90   }
91   {                            /*   Application deployment */
92     MSG_function_register("master", master);
93     MSG_function_register("slave", slave);
94     MSG_launch_application(application_file);
95   }
96   res = MSG_main();
97   
98   INFO1("Simulation time %g",MSG_get_clock());
99   return res;
100 }
101
102
103 /** Main function */
104 int main(int argc, char *argv[])
105 {
106   MSG_error_t res = MSG_OK;
107
108   //starting the simulation tracing with the TRACE_VOLUME mask
109   // - the communication volume among processes expects that:
110   //     - the processes involved have a category
111   //     - the tasks sent have a category
112   TRACE_start_with_mask ("volume.trace", TRACE_VOLUME);
113
114   //declaring user categories (for tasks)
115   TRACE_category ("compute");
116   TRACE_category ("request");
117   TRACE_category ("data");
118   TRACE_category ("finalize");
119
120   //declaring user categories (for processes)
121   TRACE_category ("master");
122   TRACE_category ("slave");
123
124   MSG_global_init(&argc,argv);
125   if (argc < 3) {
126      printf ("Usage: %s platform_file deployment_file\n",argv[0]);
127      printf ("example: %s msg_platform.xml msg_deployment.xml\n",argv[0]);
128      exit(1);
129   }
130   res = test_all(argv[1],argv[2]);
131   MSG_clean();
132
133   //ending the simulation tracing
134   TRACE_end();
135
136   if(res==MSG_OK)
137     return 0;
138   else
139     return 1;
140 } /* end_of_main */