4 #include "smpi_mpi_dt_private.h"
6 XBT_LOG_NEW_CATEGORY(smpi, "All SMPI categories");
8 XBT_LOG_NEW_DEFAULT_SUBCATEGORY(smpi_kernel, smpi,
9 "Logging specific to SMPI (kernel)");
11 smpi_global_t smpi_global = NULL;
13 void *smpi_request_new(void);
15 void *smpi_request_new()
17 smpi_mpi_request_t request = xbt_new(s_smpi_mpi_request_t, 1);
20 request->completed = 0;
21 request->consumed = 0;
22 request->mutex = SIMIX_mutex_init();
23 request->cond = SIMIX_cond_init();
30 void smpi_request_free(void *pointer);
32 void smpi_request_free(void *pointer)
35 smpi_mpi_request_t request = pointer;
37 SIMIX_cond_destroy(request->cond);
38 SIMIX_mutex_destroy(request->mutex);
44 void smpi_request_reset(void *pointer);
46 void smpi_request_reset(void *pointer)
48 smpi_mpi_request_t request = pointer;
51 request->completed = 0;
52 request->consumed = 0;
60 void *smpi_message_new(void);
62 void *smpi_message_new()
64 smpi_received_message_t message = xbt_new(s_smpi_received_message_t, 1);
69 void smpi_message_free(void *pointer);
71 void smpi_message_free(void *pointer)
77 void smpi_message_reset(void *pointer);
79 void smpi_message_reset(void *pointer)
81 smpi_received_message_t message = pointer;
86 int smpi_create_request(void *buf, int count, smpi_mpi_datatype_t datatype,
87 int src, int dst, int tag,
88 smpi_mpi_communicator_t comm,
89 smpi_mpi_request_t * requestptr)
91 int retval = MPI_SUCCESS;
93 smpi_mpi_request_t request = NULL;
95 // parameter checking prob belongs in smpi_mpi, but this is less repeat code
97 retval = MPI_ERR_INTERN;
98 } else if (0 > count) {
99 retval = MPI_ERR_COUNT;
100 } else if (NULL == datatype) {
101 retval = MPI_ERR_TYPE;
102 } else if (MPI_ANY_SOURCE != src && (0 > src || comm->size <= src)) {
103 retval = MPI_ERR_RANK;
104 } else if (0 > dst || comm->size <= dst) {
105 retval = MPI_ERR_RANK;
106 } else if (MPI_ANY_TAG != tag && 0 > tag) {
107 retval = MPI_ERR_TAG;
108 } else if (NULL == comm) {
109 retval = MPI_ERR_COMM;
110 } else if (NULL == requestptr) {
111 retval = MPI_ERR_ARG;
113 request = xbt_mallocator_get(smpi_global->request_mallocator);
114 request->comm = comm;
119 request->datatype = datatype;
120 request->count = count;
122 *requestptr = request;
127 /* FIXME: understand what they do and put the prototypes in a header file (live in smpi_base.c) */
128 void smpi_mpi_land_func(void *a, void *b, int *length,
129 MPI_Datatype * datatype);
130 void smpi_mpi_sum_func(void *a, void *b, int *length,
131 MPI_Datatype * datatype);
132 void smpi_mpi_prod_func(void *a, void *b, int *length,
133 MPI_Datatype * datatype);
134 void smpi_mpi_min_func(void *a, void *b, int *length,
135 MPI_Datatype * datatype);
136 void smpi_mpi_max_func(void *a, void *b, int *length,
137 MPI_Datatype * datatype);
139 void smpi_global_init()
143 /* Connect our log channels: that must be done manually under windows */
144 #ifdef XBT_LOG_CONNECT
145 XBT_LOG_CONNECT(smpi_base, smpi);
146 XBT_LOG_CONNECT(smpi_bench, smpi);
147 XBT_LOG_CONNECT(smpi_kernel, smpi);
148 XBT_LOG_CONNECT(smpi_mpi, smpi);
149 XBT_LOG_CONNECT(smpi_receiver, smpi);
150 XBT_LOG_CONNECT(smpi_sender, smpi);
151 XBT_LOG_CONNECT(smpi_util, smpi);
154 smpi_global = xbt_new(s_smpi_global_t, 1);
157 smpi_global->reference_speed =
158 xbt_cfg_get_double(_surf_cfg_set, "reference_speed");
161 smpi_global->request_mallocator =
162 xbt_mallocator_new(SMPI_REQUEST_MALLOCATOR_SIZE, smpi_request_new,
163 smpi_request_free, smpi_request_reset);
164 smpi_global->message_mallocator =
165 xbt_mallocator_new(SMPI_MESSAGE_MALLOCATOR_SIZE, smpi_message_new,
166 smpi_message_free, smpi_message_reset);
168 smpi_global->process_count = SIMIX_process_count();
169 DEBUG1("There is %d processes", smpi_global->process_count);
171 // sender/receiver processes
172 smpi_global->main_processes =
173 xbt_new(smx_process_t, smpi_global->process_count);
176 smpi_global->timer = xbt_os_timer_new();
177 smpi_global->timer_cond = SIMIX_cond_init();
179 smpi_global->do_once_duration_nodes = NULL;
180 smpi_global->do_once_duration = NULL;
181 smpi_global->do_once_mutex = SIMIX_mutex_init();
184 smpi_mpi_global = xbt_new(s_smpi_mpi_global_t, 1);
186 // global communicator
187 smpi_mpi_global->mpi_comm_world = xbt_new(s_smpi_mpi_communicator_t, 1);
188 smpi_mpi_global->mpi_comm_world->size = smpi_global->process_count;
189 smpi_mpi_global->mpi_comm_world->barrier_count = 0;
190 smpi_mpi_global->mpi_comm_world->barrier_mutex = SIMIX_mutex_init();
191 smpi_mpi_global->mpi_comm_world->barrier_cond = SIMIX_cond_init();
192 smpi_mpi_global->mpi_comm_world->rank_to_index_map =
193 xbt_new(int, smpi_global->process_count);
194 smpi_mpi_global->mpi_comm_world->index_to_rank_map =
195 xbt_new(int, smpi_global->process_count);
196 for (i = 0; i < smpi_global->process_count; i++) {
197 smpi_mpi_global->mpi_comm_world->rank_to_index_map[i] = i;
198 smpi_mpi_global->mpi_comm_world->index_to_rank_map[i] = i;
202 smpi_mpi_global->mpi_byte = xbt_new(s_smpi_mpi_datatype_t, 1); /* we can think of it as a placeholder for value*/
203 smpi_mpi_global->mpi_byte->size = (size_t) 1;
204 smpi_mpi_global->mpi_byte->lb = (ptrdiff_t) 0;
205 smpi_mpi_global->mpi_byte->ub = smpi_mpi_global->mpi_byte->lb + smpi_mpi_global->mpi_byte->size;
206 smpi_mpi_global->mpi_byte->flags = DT_FLAG_BASIC;
208 smpi_mpi_global->mpi_char = xbt_new(s_smpi_mpi_datatype_t, 1);
209 smpi_mpi_global->mpi_char->size = (size_t) 1;
210 smpi_mpi_global->mpi_char->lb = (ptrdiff_t) 0; //&(smpi_mpi_global->mpi_char);
211 smpi_mpi_global->mpi_char->ub = smpi_mpi_global->mpi_char->lb + smpi_mpi_global->mpi_char->size;
212 smpi_mpi_global->mpi_char->flags = DT_FLAG_BASIC;
214 smpi_mpi_global->mpi_int = xbt_new(s_smpi_mpi_datatype_t, 1);
215 smpi_mpi_global->mpi_int->size = sizeof(int);
216 smpi_mpi_global->mpi_int->lb = (ptrdiff_t) 0; // &(smpi_mpi_global->mpi_int);
217 smpi_mpi_global->mpi_int->ub = smpi_mpi_global->mpi_int->lb + smpi_mpi_global->mpi_int->size;
218 smpi_mpi_global->mpi_int->flags = DT_FLAG_BASIC;
220 smpi_mpi_global->mpi_float = xbt_new(s_smpi_mpi_datatype_t, 1);
221 smpi_mpi_global->mpi_float->size = sizeof(float);
222 smpi_mpi_global->mpi_float->lb = (ptrdiff_t) 0; // &(smpi_mpi_global->mpi_float);
223 smpi_mpi_global->mpi_float->ub = smpi_mpi_global->mpi_float->lb + smpi_mpi_global->mpi_float->size;
224 smpi_mpi_global->mpi_float->flags = DT_FLAG_BASIC;
226 smpi_mpi_global->mpi_double = xbt_new(s_smpi_mpi_datatype_t, 1);
227 smpi_mpi_global->mpi_double->size = sizeof(double);
228 smpi_mpi_global->mpi_double->lb = (ptrdiff_t) 0; //&(smpi_mpi_global->mpi_float);
229 smpi_mpi_global->mpi_double->ub = smpi_mpi_global->mpi_double->lb + smpi_mpi_global->mpi_double->size;
230 smpi_mpi_global->mpi_double->flags = DT_FLAG_BASIC;
233 smpi_mpi_global->mpi_land = xbt_new(s_smpi_mpi_op_t, 1);
234 smpi_mpi_global->mpi_land->func = smpi_mpi_land_func;
235 smpi_mpi_global->mpi_sum = xbt_new(s_smpi_mpi_op_t, 1);
236 smpi_mpi_global->mpi_sum->func = smpi_mpi_sum_func;
237 smpi_mpi_global->mpi_prod = xbt_new(s_smpi_mpi_op_t, 1);
238 smpi_mpi_global->mpi_prod->func = smpi_mpi_prod_func;
239 smpi_mpi_global->mpi_min = xbt_new(s_smpi_mpi_op_t, 1);
240 smpi_mpi_global->mpi_min->func = smpi_mpi_min_func;
241 smpi_mpi_global->mpi_max = xbt_new(s_smpi_mpi_op_t, 1);
242 smpi_mpi_global->mpi_max->func = smpi_mpi_max_func;
246 void smpi_global_destroy()
248 smpi_do_once_duration_node_t curr, next;
251 xbt_free(smpi_global->main_processes);
254 xbt_mallocator_free(smpi_global->request_mallocator);
255 xbt_mallocator_free(smpi_global->message_mallocator);
257 xbt_os_timer_free(smpi_global->timer);
258 SIMIX_cond_destroy(smpi_global->timer_cond);
260 for (curr = smpi_global->do_once_duration_nodes; NULL != curr; curr = next) {
262 xbt_free(curr->file);
266 SIMIX_mutex_destroy(smpi_global->do_once_mutex);
268 xbt_free(smpi_global);
271 /* free smpi_mpi_global */
272 SIMIX_mutex_destroy(smpi_mpi_global->mpi_comm_world->barrier_mutex);
273 SIMIX_cond_destroy(smpi_mpi_global->mpi_comm_world->barrier_cond);
274 xbt_free(smpi_mpi_global->mpi_comm_world->rank_to_index_map);
275 xbt_free(smpi_mpi_global->mpi_comm_world);
277 xbt_free(smpi_mpi_global->mpi_byte);
278 xbt_free(smpi_mpi_global->mpi_char);
279 xbt_free(smpi_mpi_global->mpi_int);
280 xbt_free(smpi_mpi_global->mpi_double);
281 xbt_free(smpi_mpi_global->mpi_float);
283 xbt_free(smpi_mpi_global->mpi_land);
284 xbt_free(smpi_mpi_global->mpi_sum);
285 xbt_free(smpi_mpi_global->mpi_prod);
286 xbt_free(smpi_mpi_global->mpi_max);
287 xbt_free(smpi_mpi_global->mpi_min);
289 xbt_free(smpi_mpi_global);
293 int smpi_process_index()
295 smpi_process_data_t pdata =
296 (smpi_process_data_t) SIMIX_process_get_data(SIMIX_process_self());
300 smx_mutex_t smpi_process_mutex()
302 smpi_process_data_t pdata =
303 (smpi_process_data_t) SIMIX_process_get_data(SIMIX_process_self());
307 smx_cond_t smpi_process_cond()
309 smpi_process_data_t pdata =
310 (smpi_process_data_t) SIMIX_process_get_data(SIMIX_process_self());
314 static void smpi_cfg_cb_host_speed(const char *name, int pos)
318 smpi_global->reference_speed =
319 xbt_cfg_get_double_at(_surf_cfg_set, name, pos);
323 int smpi_run_simulation(int *argc, char **argv)
325 srand(SMPI_RAND_SEED);
327 double default_reference_speed = 20000.0;
328 xbt_cfg_register(&_surf_cfg_set, "reference_speed",
329 "Power of the host running the simulation (in flop/s). Used to bench the operations.",
330 xbt_cfgelm_double, &default_reference_speed, 1, 1,
331 smpi_cfg_cb_host_speed, NULL);
333 int default_display_timing = 0;
334 xbt_cfg_register(&_surf_cfg_set, "display_timing",
335 "Boolean indicating whether we should display the timing after simulation.",
336 xbt_cfgelm_int, &default_display_timing, 1, 1, NULL, NULL);
338 SIMIX_global_init(argc, argv);
341 // parse the platform file: get the host list
342 SIMIX_create_environment(argv[1]);
344 SIMIX_function_register("smpi_simulated_main", smpi_simulated_main);
345 SIMIX_launch_application(argv[2]);
347 // must initialize globals between creating environment and launching app....
350 /* Clean IO before the run */
355 while (SIMIX_solve(NULL, NULL) != -1.0);
357 // FIXME: cleanup incomplete
359 if (xbt_cfg_get_int(_surf_cfg_set, "display_timing"))
360 INFO1("simulation time %g", SIMIX_get_clock());
362 smpi_global_destroy();
368 int main(int argc, char** argv)
370 return smpi_run_simulation(&argc, argv);