1 /* Copyright (c) 2007-2014. The SimGrid Team.
2 * All rights reserved. */
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. */
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 */
11 /* Create a log channel to have nice outputs. */
13 #include "xbt/asserts.h"
14 XBT_LOG_NEW_DEFAULT_CATEGORY(msg_test,
15 "Messages specific for this msg example");
17 /** @addtogroup MSG_examples
19 * - <b>parallel_task/parallel_task.c</b>: Demonstrates the use of
20 * @ref MSG_parallel_task_create, to create special tasks that run
21 * on several hosts at the same time. The resulting simulations are
22 * very close to what can be achieved in @ref SD_API, but still
23 * allows to use the other features of MSG (it'd be cool to be able
24 * to mix interfaces, but it's not possible ATM).
27 int test(int argc, char *argv[]);
28 msg_error_t test_all(const char *platform_file);
30 /** Emitter function */
31 int test(int argc, char *argv[])
33 xbt_dynar_t slaves_dynar;
35 msg_host_t *slaves = NULL;
36 double task_comp_size = 100000;
37 double task_comm_size = 10000;
38 double *computation_amount = NULL;
39 double *communication_amount = NULL;
40 msg_task_t ptask = NULL;
43 slaves_dynar = MSG_hosts_as_dynar();
44 slaves_count = xbt_dynar_length(slaves_dynar);
45 slaves = xbt_dynar_to_array(slaves_dynar);
47 computation_amount = xbt_new0(double, slaves_count);
48 communication_amount = xbt_new0(double, slaves_count * slaves_count);
50 for (i = 0; i < slaves_count; i++)
51 computation_amount[i] = task_comp_size;
53 for (i = 0; i < slaves_count; i++)
54 for (j = i + 1; j < slaves_count; j++)
55 communication_amount[i * slaves_count + j] = task_comm_size;
57 ptask = MSG_parallel_task_create("parallel task",
60 communication_amount, NULL);
61 MSG_parallel_task_execute(ptask);
63 MSG_task_destroy(ptask);
64 /* There is no need to free that! */
65 /* free(communication_amount); */
66 /* free(computation_amount); */
68 XBT_INFO("Goodbye now!");
74 msg_error_t test_all(const char *platform_file)
76 msg_error_t res = MSG_OK;
77 xbt_dynar_t all_hosts;
78 msg_host_t first_host;
80 MSG_config("workstation/model", "ptask_L07");
81 MSG_create_environment(platform_file);
83 all_hosts = MSG_hosts_as_dynar();
84 first_host = xbt_dynar_getfirst_as(all_hosts,msg_host_t);
85 MSG_process_create("test", test, NULL, first_host);
87 xbt_dynar_free(&all_hosts);
89 XBT_INFO("Simulation time %g", MSG_get_clock());
93 int main(int argc, char *argv[])
95 msg_error_t res = MSG_OK;
97 MSG_init(&argc, argv);
99 printf("Usage: %s platform_file\n", argv[0]);
100 printf("example: %s msg_platform.xml\n", argv[0]);
103 res = test_all(argv[1]);