1 /* Copyright (c) 2008-2015. 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 "simgrid/msg.h" /* Yeah! If you want to use msg, you need to include simgrid/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 int execute(int argc, char *argv[]);
18 int redistribute(int argc, char *argv[]);
19 msg_error_t test_all(const char *platform_file,
20 const char *application_file);
23 int execute(int argc, char *argv[])
27 msg_host_t *m_host_list = NULL;
28 msg_task_t task = NULL;
30 double *computation_duration = NULL;
31 double *communication_table = NULL;
32 double communication_amount = 0;
33 double computation_amount = 0;
34 double execution_time;
37 host_list_size = argc - 3;
38 XBT_DEBUG("host_list_size=%d", host_list_size);
39 m_host_list = calloc(host_list_size, sizeof(msg_host_t));
40 for (i = 1; i <= host_list_size; i++) {
41 m_host_list[i - 1] = MSG_host_by_name(argv[i]);
42 xbt_assert(m_host_list[i - 1] != NULL,
43 "Unknown host %s. Stopping Now! ", argv[i]);
46 XBT_ATTRIB_UNUSED int read;
47 read = sscanf(argv[argc - 2], "%lg", &computation_amount);
48 xbt_assert(read, "Invalid argument %s\n", argv[argc - 2]);
49 read = sscanf(argv[argc - 1], "%lg", &communication_amount);
50 xbt_assert(read, "Invalid argument %s\n", argv[argc - 1]);
51 computation_duration = (double *) calloc(host_list_size, sizeof(double));
53 (double *) calloc(host_list_size * host_list_size, sizeof(double));
54 for (i = 0; i < host_list_size; i++) {
55 computation_duration[i] = computation_amount / host_list_size;
56 for (j = 0; j < host_list_size; j++)
57 communication_table[i * host_list_size + j] =
58 communication_amount / (host_list_size * host_list_size);
61 sprintf(buffer, "redist#0\n");
62 task = MSG_parallel_task_create(buffer,
66 communication_table, NULL);
68 execution_time = MSG_get_clock();
69 MSG_parallel_task_execute(task);
70 MSG_task_destroy(task);
71 xbt_free(m_host_list);
72 execution_time = MSG_get_clock() - execution_time;
74 XBT_INFO("execution_time=%g ", execution_time);
80 int redistribute(int argc, char *argv[])
84 msg_host_t *m_host_list = NULL;
85 msg_task_t task = NULL;
87 double *computation_duration = NULL;
88 double *communication_table = NULL;
89 double communication_amount = 0;
90 double redistribution_time;
93 host_list_size = argc - 2;
94 XBT_DEBUG("host_list_size=%d", host_list_size);
95 m_host_list = calloc(host_list_size, sizeof(msg_host_t));
96 for (i = 1; i <= host_list_size; i++) {
97 m_host_list[i - 1] = MSG_host_by_name(argv[i]);
98 xbt_assert(m_host_list[i - 1] != NULL,
99 "Unknown host %s. Stopping Now! ", argv[i]);
102 XBT_ATTRIB_UNUSED int read;
103 read = sscanf(argv[argc - 1], "%lg", &communication_amount);
104 xbt_assert(read, "Invalid argument %s\n", argv[argc - 1]);
105 computation_duration = (double *) calloc(host_list_size, sizeof(double));
106 communication_table =
107 (double *) calloc(host_list_size * host_list_size, sizeof(double));
108 for (i = 0; i < host_list_size; i++) {
109 for (j = 0; j < host_list_size; j++)
110 communication_table[i * host_list_size + j] =
111 communication_amount / (host_list_size * host_list_size);
114 sprintf(buffer, "redist#0\n");
115 task = MSG_parallel_task_create(buffer,
118 computation_duration,
119 communication_table, NULL);
121 redistribution_time = MSG_get_clock();
122 MSG_parallel_task_execute(task);
123 MSG_task_destroy(task);
124 xbt_free(m_host_list);
125 redistribution_time = MSG_get_clock() - redistribution_time;
127 XBT_INFO("redistribution_time=%g ", redistribution_time);
133 msg_error_t test_all(const char *platform_file,
134 const char *application_file)
136 msg_error_t res = MSG_OK;
139 MSG_config("host/model", "ptask_L07");
141 /* Simulation setting */
142 MSG_create_environment(platform_file);
144 /* Application deployment */
145 MSG_function_register("execute", execute);
146 MSG_function_register("redistribute", redistribute);
147 MSG_launch_application(application_file);
151 XBT_INFO("Simulation time %g", MSG_get_clock());
156 int main(int argc, char *argv[])
158 msg_error_t res = MSG_OK;
160 MSG_init(&argc, argv);
161 xbt_assert(argc > 2, "Usage: %s platform_file deployment_file\n"
162 "\tExample: %s msg_platform.xml msg_deployment.xml\n",
165 res = test_all(argv[1], argv[2]);
167 return res != MSG_OK;