Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
Use new style logging macros.
[simgrid.git] / examples / msg / parallel_task / parallel_task.c
1 /* Copyright (c) 2007, 2008, 2009, 2010. The SimGrid Team.
2  * All rights reserved.                                                     */
3
4 /* This program is free software; you can redistribute it and/or modify it
5  * under the terms of the license (GNU LGPL) which comes with this package. */
6
7 #include <stdio.h>
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 */
10
11 /* Create a log channel to have nice outputs. */
12 #include "xbt/log.h"
13 #include "xbt/asserts.h"
14 XBT_LOG_NEW_DEFAULT_CATEGORY(msg_test,
15                              "Messages specific for this msg example");
16
17 int test(int argc, char *argv[]);
18 MSG_error_t test_all(const char *platform_file);
19
20 /** Emitter function  */
21 int test(int argc, char *argv[])
22 {
23   int slaves_count = 0;
24   m_host_t *slaves = NULL;
25   double task_comp_size = 100000;
26   double task_comm_size = 10000;
27   double *computation_amount = NULL;
28   double *communication_amount = NULL;
29   m_task_t ptask = NULL;
30   int i, j;
31
32   slaves_count = MSG_get_host_number();
33   slaves = MSG_get_host_table();
34
35   computation_amount = xbt_new0(double, slaves_count);
36   communication_amount = xbt_new0(double, slaves_count * slaves_count);
37
38   for (i = 0; i < slaves_count; i++)
39     computation_amount[i] = task_comp_size;
40
41   for (i = 0; i < slaves_count; i++)
42     for (j = i + 1; j < slaves_count; j++)
43       communication_amount[i * slaves_count + j] = task_comm_size;
44
45   ptask = MSG_parallel_task_create("parallel task",
46                                    slaves_count, slaves,
47                                    computation_amount,
48                                    communication_amount, NULL);
49   MSG_parallel_task_execute(ptask);
50
51   MSG_task_destroy(ptask);
52   /* There is no need to free that! */
53 /*   free(communication_amount); */
54 /*   free(computation_amount); */
55
56   XBT_INFO("Goodbye now!");
57   free(slaves);
58   return 0;
59 }
60
61 /** Test function */
62 MSG_error_t test_all(const char *platform_file)
63 {
64   MSG_error_t res = MSG_OK;
65   m_host_t *hosts;
66
67   MSG_config("workstation/model", "ptask_L07");
68   MSG_set_channel_number(1);
69   MSG_create_environment(platform_file);
70
71   hosts = MSG_get_host_table();
72   MSG_process_create("test", test, NULL, hosts[0]);
73   res = MSG_main();
74   xbt_free(hosts);
75
76   XBT_INFO("Simulation time %g", MSG_get_clock());
77   return res;
78 }
79
80 int main(int argc, char *argv[])
81 {
82   MSG_error_t res = MSG_OK;
83
84   MSG_global_init(&argc, argv);
85   if (argc < 2) {
86     printf("Usage: %s platform_file\n", argv[0]);
87     printf("example: %s msg_platform.xml\n", argv[0]);
88     exit(1);
89   }
90   res = test_all(argv[1]);
91   MSG_clean();
92
93   if (res == MSG_OK)
94     return 0;
95   else
96     return 1;
97 }