Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
[trace] process category is deprecated (for now, at least)
[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,
16                              "Messages specific for this msg example");
17
18 int master(int argc, char *argv[]);
19 int slave(int argc, char *argv[]);
20 MSG_error_t test_all(const char *platform_file,
21                      const char *application_file);
22
23 /** Emitter function  */
24 int master(int argc, char *argv[])
25 {
26   long number_of_tasks = atol(argv[1]);
27   long slaves_count = atol(argv[4]);
28   int p = 1000000000;
29   int c = 10000000;
30
31   int i;
32   for (i = 0; i < number_of_tasks; i++) {
33     m_task_t task = NULL;
34     task = MSG_task_create("task_compute", p, c, NULL);
35     TRACE_msg_set_task_category(task, "compute");
36     MSG_task_send(task, "master_mailbox");
37     task = NULL;
38     task = MSG_task_create("task_request", p, c, NULL);
39     TRACE_msg_set_task_category(task, "request");
40     MSG_task_send(task, "master_mailbox");
41     task = NULL;
42     task = MSG_task_create("task_data", p, c, NULL);
43     TRACE_msg_set_task_category(task, "data");
44     MSG_task_send(task, "master_mailbox");
45   }
46
47   for (i = 0; i < slaves_count; i++) {
48     m_task_t finalize = MSG_task_create("finalize", 0, 1000, 0);
49     TRACE_msg_set_task_category(finalize, "finalize");
50     MSG_task_send(finalize, "master_mailbox");
51   }
52
53   return 0;
54 }
55
56 /** Receiver function  */
57 int slave(int argc, char *argv[])
58 {
59   m_task_t task = NULL;
60   int res;
61
62   while (1) {
63     res = MSG_task_receive(&(task), "master_mailbox");
64
65     if (!strcmp(MSG_task_get_name(task), "finalize")) {
66       MSG_task_destroy(task);
67       break;
68     }
69
70     MSG_task_execute(task);
71     MSG_task_destroy(task);
72     task = NULL;
73   }
74   return 0;
75 }
76
77 /** Test function */
78 MSG_error_t test_all(const char *platform_file,
79                      const char *application_file)
80 {
81   MSG_error_t res = MSG_OK;
82
83   {                             /*  Simulation setting */
84     MSG_set_channel_number(0);
85     MSG_create_environment(platform_file);
86   }
87   {
88     //--cfg=tracing/msg/volume
89     // - the communication volume among processes expects that:
90     //     - the processes involved have a category
91     //     - the sent tasks have a category
92
93     //declaring user categories (for tasks)
94     TRACE_category_with_color ("compute", "1 0 0"); //red
95     TRACE_category_with_color ("request", "0 1 0"); //green
96     TRACE_category_with_color ("data", "0 0 1");    //blue
97     TRACE_category_with_color ("finalize", "0 0 0");//black
98   }
99   {                             /*   Application deployment */
100     MSG_function_register("master", master);
101     MSG_function_register("slave", slave);
102     MSG_launch_application(application_file);
103   }
104   res = MSG_main();
105
106   INFO1("Simulation time %g", MSG_get_clock());
107   return res;
108 }
109
110
111 /** Main function */
112 int main(int argc, char *argv[])
113 {
114   MSG_error_t res = MSG_OK;
115
116   MSG_global_init(&argc, argv);
117   if (argc < 3) {
118     printf("Usage: %s platform_file deployment_file\n", argv[0]);
119     printf("example: %s msg_platform.xml msg_deployment.xml\n", argv[0]);
120     exit(1);
121   }
122
123   res = test_all(argv[1], argv[2]);
124   MSG_clean();
125
126   if (res == MSG_OK)
127     return 0;
128   else
129     return 1;
130 }                               /* end_of_main */