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);
141 smpi_global = xbt_new(s_smpi_global_t, 1);
144 void smpi_global_init()
148 /* Connect our log channels: that must be done manually under windows */
149 #ifdef XBT_LOG_CONNECT
150 XBT_LOG_CONNECT(smpi_base, smpi);
151 XBT_LOG_CONNECT(smpi_bench, smpi);
152 XBT_LOG_CONNECT(smpi_kernel, smpi);
153 XBT_LOG_CONNECT(smpi_mpi, smpi);
154 XBT_LOG_CONNECT(smpi_receiver, smpi);
155 XBT_LOG_CONNECT(smpi_sender, smpi);
156 XBT_LOG_CONNECT(smpi_util, smpi);
160 smpi_global->reference_speed =
161 xbt_cfg_get_double(_surf_cfg_set, "reference_speed");
164 smpi_global->request_mallocator =
165 xbt_mallocator_new(SMPI_REQUEST_MALLOCATOR_SIZE, smpi_request_new,
166 smpi_request_free, smpi_request_reset);
167 smpi_global->message_mallocator =
168 xbt_mallocator_new(SMPI_MESSAGE_MALLOCATOR_SIZE, smpi_message_new,
169 smpi_message_free, smpi_message_reset);
171 smpi_global->process_count = SIMIX_process_count();
172 DEBUG1("There is %d processes", smpi_global->process_count);
174 // sender/receiver processes
175 smpi_global->main_processes =
176 xbt_new(smx_process_t, smpi_global->process_count);
179 smpi_global->timer = xbt_os_timer_new();
180 smpi_global->timer_cond = SIMIX_cond_init();
182 smpi_global->do_once_duration_nodes = NULL;
183 smpi_global->do_once_duration = NULL;
184 smpi_global->do_once_mutex = SIMIX_mutex_init();
187 smpi_mpi_global = xbt_new(s_smpi_mpi_global_t, 1);
189 // global communicator
190 smpi_mpi_global->mpi_comm_world = xbt_new(s_smpi_mpi_communicator_t, 1);
191 smpi_mpi_global->mpi_comm_world->size = smpi_global->process_count;
192 smpi_mpi_global->mpi_comm_world->barrier_count = 0;
193 smpi_mpi_global->mpi_comm_world->barrier_mutex = SIMIX_mutex_init();
194 smpi_mpi_global->mpi_comm_world->barrier_cond = SIMIX_cond_init();
195 smpi_mpi_global->mpi_comm_world->rank_to_index_map =
196 xbt_new(int, smpi_global->process_count);
197 smpi_mpi_global->mpi_comm_world->index_to_rank_map =
198 xbt_new(int, smpi_global->process_count);
199 for (i = 0; i < smpi_global->process_count; i++) {
200 smpi_mpi_global->mpi_comm_world->rank_to_index_map[i] = i;
201 smpi_mpi_global->mpi_comm_world->index_to_rank_map[i] = i;
205 smpi_mpi_global->mpi_byte = xbt_new(s_smpi_mpi_datatype_t, 1); /* we can think of it as a placeholder for value*/
206 smpi_mpi_global->mpi_byte->size = (size_t) 1;
207 smpi_mpi_global->mpi_byte->lb = (ptrdiff_t) 0;
208 smpi_mpi_global->mpi_byte->ub = smpi_mpi_global->mpi_byte->lb + smpi_mpi_global->mpi_byte->size;
209 smpi_mpi_global->mpi_byte->flags = DT_FLAG_BASIC;
211 smpi_mpi_global->mpi_char = xbt_new(s_smpi_mpi_datatype_t, 1);
212 smpi_mpi_global->mpi_char->size = (size_t) 1;
213 smpi_mpi_global->mpi_char->lb = (ptrdiff_t) 0; //&(smpi_mpi_global->mpi_char);
214 smpi_mpi_global->mpi_char->ub = smpi_mpi_global->mpi_char->lb + smpi_mpi_global->mpi_char->size;
215 smpi_mpi_global->mpi_char->flags = DT_FLAG_BASIC;
217 smpi_mpi_global->mpi_int = xbt_new(s_smpi_mpi_datatype_t, 1);
218 smpi_mpi_global->mpi_int->size = sizeof(int);
219 smpi_mpi_global->mpi_int->lb = (ptrdiff_t) 0; // &(smpi_mpi_global->mpi_int);
220 smpi_mpi_global->mpi_int->ub = smpi_mpi_global->mpi_int->lb + smpi_mpi_global->mpi_int->size;
221 smpi_mpi_global->mpi_int->flags = DT_FLAG_BASIC;
223 smpi_mpi_global->mpi_float = xbt_new(s_smpi_mpi_datatype_t, 1);
224 smpi_mpi_global->mpi_float->size = sizeof(float);
225 smpi_mpi_global->mpi_float->lb = (ptrdiff_t) 0; // &(smpi_mpi_global->mpi_float);
226 smpi_mpi_global->mpi_float->ub = smpi_mpi_global->mpi_float->lb + smpi_mpi_global->mpi_float->size;
227 smpi_mpi_global->mpi_float->flags = DT_FLAG_BASIC;
229 smpi_mpi_global->mpi_double = xbt_new(s_smpi_mpi_datatype_t, 1);
230 smpi_mpi_global->mpi_double->size = sizeof(double);
231 smpi_mpi_global->mpi_double->lb = (ptrdiff_t) 0; //&(smpi_mpi_global->mpi_float);
232 smpi_mpi_global->mpi_double->ub = smpi_mpi_global->mpi_double->lb + smpi_mpi_global->mpi_double->size;
233 smpi_mpi_global->mpi_double->flags = DT_FLAG_BASIC;
236 smpi_mpi_global->mpi_land = xbt_new(s_smpi_mpi_op_t, 1);
237 smpi_mpi_global->mpi_land->func = smpi_mpi_land_func;
238 smpi_mpi_global->mpi_sum = xbt_new(s_smpi_mpi_op_t, 1);
239 smpi_mpi_global->mpi_sum->func = smpi_mpi_sum_func;
240 smpi_mpi_global->mpi_prod = xbt_new(s_smpi_mpi_op_t, 1);
241 smpi_mpi_global->mpi_prod->func = smpi_mpi_prod_func;
242 smpi_mpi_global->mpi_min = xbt_new(s_smpi_mpi_op_t, 1);
243 smpi_mpi_global->mpi_min->func = smpi_mpi_min_func;
244 smpi_mpi_global->mpi_max = xbt_new(s_smpi_mpi_op_t, 1);
245 smpi_mpi_global->mpi_max->func = smpi_mpi_max_func;
249 void smpi_global_destroy()
251 smpi_do_once_duration_node_t curr, next;
254 xbt_free(smpi_global->main_processes);
257 xbt_mallocator_free(smpi_global->request_mallocator);
258 xbt_mallocator_free(smpi_global->message_mallocator);
260 xbt_os_timer_free(smpi_global->timer);
261 SIMIX_cond_destroy(smpi_global->timer_cond);
263 for (curr = smpi_global->do_once_duration_nodes; NULL != curr; curr = next) {
265 xbt_free(curr->file);
269 SIMIX_mutex_destroy(smpi_global->do_once_mutex);
271 xbt_free(smpi_global);
274 /* free smpi_mpi_global */
275 SIMIX_mutex_destroy(smpi_mpi_global->mpi_comm_world->barrier_mutex);
276 SIMIX_cond_destroy(smpi_mpi_global->mpi_comm_world->barrier_cond);
277 xbt_free(smpi_mpi_global->mpi_comm_world->rank_to_index_map);
278 xbt_free(smpi_mpi_global->mpi_comm_world);
280 xbt_free(smpi_mpi_global->mpi_byte);
281 xbt_free(smpi_mpi_global->mpi_char);
282 xbt_free(smpi_mpi_global->mpi_int);
283 xbt_free(smpi_mpi_global->mpi_double);
284 xbt_free(smpi_mpi_global->mpi_float);
286 xbt_free(smpi_mpi_global->mpi_land);
287 xbt_free(smpi_mpi_global->mpi_sum);
288 xbt_free(smpi_mpi_global->mpi_prod);
289 xbt_free(smpi_mpi_global->mpi_max);
290 xbt_free(smpi_mpi_global->mpi_min);
292 xbt_free(smpi_mpi_global);
296 int smpi_process_index()
298 smpi_process_data_t pdata =
299 (smpi_process_data_t) SIMIX_process_get_data(SIMIX_process_self());
303 smx_mutex_t smpi_process_mutex()
305 smpi_process_data_t pdata =
306 (smpi_process_data_t) SIMIX_process_get_data(SIMIX_process_self());
310 smx_cond_t smpi_process_cond()
312 smpi_process_data_t pdata =
313 (smpi_process_data_t) SIMIX_process_get_data(SIMIX_process_self());
317 static void smpi_cfg_cb_host_speed(const char *name, int pos)
319 smpi_global->reference_speed =
320 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 // Allocate minimal things before parsing command line arguments
341 SIMIX_global_init(argc, argv);
344 // parse the platform file: get the host list
345 SIMIX_create_environment(argv[1]);
347 SIMIX_function_register("smpi_simulated_main", smpi_simulated_main);
348 SIMIX_launch_application(argv[2]);
350 // must initialize globals between creating environment and launching app....
353 /* Clean IO before the run */
358 while (SIMIX_solve(NULL, NULL) != -1.0);
360 // FIXME: cleanup incomplete
362 if (xbt_cfg_get_int(_surf_cfg_set, "display_timing"))
363 INFO1("simulation time %g", SIMIX_get_clock());
365 smpi_global_destroy();
371 int main(int argc, char** argv)
373 return smpi_run_simulation(&argc, argv);