Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
Second commit for cmake in an other directory.
[simgrid.git] / examples / msg / parallel_task / parallel_task.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"            /* Yeah! If you want to use msg, you need to 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 test(int argc, char *argv[]);
19 MSG_error_t test_all(const char *platform_file);
20
21 /** Emitter function  */
22 int test(int argc, char *argv[])
23 {
24   int slaves_count = 0;
25   m_host_t *slaves = NULL;
26   double task_comp_size = 100000;
27   double task_comm_size = 10000;
28   double *computation_amount = NULL;
29   double *communication_amount = NULL;
30   m_task_t ptask = NULL;
31   int i, j;
32
33   slaves_count = MSG_get_host_number();
34   slaves = MSG_get_host_table();
35
36   computation_amount = xbt_new0(double, slaves_count);
37   communication_amount = xbt_new0(double, slaves_count * slaves_count);
38
39   for (i = 0; i < slaves_count; i++)
40     computation_amount[i] = task_comp_size;
41
42   for (i = 0; i < slaves_count; i++)
43     for (j = i + 1; j < slaves_count; j++)
44       communication_amount[i * slaves_count + j] = task_comm_size;
45
46   ptask = MSG_parallel_task_create("parallel task",
47                                    slaves_count, slaves,
48                                    computation_amount,
49                                    communication_amount, NULL);
50   MSG_parallel_task_execute(ptask);
51
52   /* There is no need to free that! */
53 /*   free(communication_amount); */
54 /*   free(computation_amount); */
55
56   INFO0("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
66   MSG_config("workstation/model", "ptask_L07");
67   MSG_set_channel_number(1);
68   MSG_create_environment(platform_file);
69
70   MSG_process_create("test", test, NULL, MSG_get_host_table()[0]);
71   res = MSG_main();
72
73   INFO1("Simulation time %g", MSG_get_clock());
74   return res;
75 }
76
77 int main(int argc, char *argv[])
78 {
79   MSG_error_t res = MSG_OK;
80
81   MSG_global_init(&argc, argv);
82   if (argc < 2) {
83     printf("Usage: %s platform_file\n", argv[0]);
84     printf("example: %s msg_platform.xml\n", argv[0]);
85     exit(1);
86   }
87   res = test_all(argv[1]);
88   MSG_clean();
89
90   if (res == MSG_OK)
91     return 0;
92   else
93     return 1;
94 }