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 typedef struct s_smpi_process_data {
13 xbt_fifo_t pending_sent;
14 xbt_fifo_t pending_recv;
17 } s_smpi_process_data_t;
19 static smpi_process_data_t* process_data = NULL;
20 static int process_count = 0;
22 MPI_Comm MPI_COMM_WORLD = MPI_COMM_NULL;
24 smpi_process_data_t smpi_process_data(void) {
25 return SIMIX_process_get_data(SIMIX_process_self());
28 smpi_process_data_t smpi_process_remote_data(int index) {
29 return process_data[index];
32 int smpi_process_count(void) {
36 int smpi_process_index(void) {
37 smpi_process_data_t data = smpi_process_data();
42 xbt_os_timer_t smpi_process_timer(void) {
43 smpi_process_data_t data = smpi_process_data();
48 MPI_Comm smpi_process_comm_self(void) {
49 smpi_process_data_t data = smpi_process_data();
51 return data->comm_self;
54 void print_request(const char* message, MPI_Request request) {
55 char* req = bprintf("[buf = %p, size = %zu, src = %d, dst = %d, tag= %d, complete = %d, flags = %u]",
56 request->buf, request->size, request->src, request->dst, request->tag, request->complete, request->flags);
58 DEBUG5("%s (request %p with rdv %p and match %p) %s",
59 message, request, request->rdv, request->match, req);
63 void smpi_process_post_send(MPI_Comm comm, MPI_Request request) {
64 int index = smpi_group_index(smpi_comm_group(comm), request->dst);
65 smpi_process_data_t data = smpi_process_remote_data(index);
69 print_request("Isend", request);
70 xbt_fifo_foreach(data->pending_recv, item, req, MPI_Request) {
71 if(req->comm == request->comm
72 && (req->src == MPI_ANY_SOURCE || req->src == request->src)
73 && (req->tag == MPI_ANY_TAG || req->tag == request->tag)){
74 print_request("Match found", req);
75 xbt_fifo_remove_item(data->pending_recv, item);
76 /* Materialize the *_ANY_* fields from corresponding irecv request */
77 req->src = request->src;
78 req->tag = request->tag;
80 request->rdv = req->rdv;
85 request->rdv = SIMIX_rdv_create(NULL);
86 xbt_fifo_push(data->pending_sent, request);
89 void smpi_process_post_recv(MPI_Request request) {
90 smpi_process_data_t data = smpi_process_data();
94 print_request("Irecv", request);
95 xbt_fifo_foreach(data->pending_sent, item, req, MPI_Request) {
96 if(req->comm == request->comm
97 && (request->src == MPI_ANY_SOURCE || req->src == request->src)
98 && (request->tag == MPI_ANY_TAG || req->tag == request->tag)){
99 print_request("Match found", req);
100 xbt_fifo_remove_item(data->pending_sent, item);
101 /* Materialize the *_ANY_* fields from the irecv request */
102 req->match = request;
103 request->src = req->src;
104 request->tag = req->tag;
105 request->rdv = req->rdv;
106 request->match = req;
110 request->rdv = SIMIX_rdv_create(NULL);
111 xbt_fifo_push(data->pending_recv, request);
114 void smpi_global_init(void) {
118 SIMIX_network_set_copy_data_callback(&SIMIX_network_copy_buffer_callback);
119 process_count = SIMIX_process_count();
120 process_data = xbt_new(smpi_process_data_t, process_count);
121 for(i = 0; i < process_count; i++) {
122 process_data[i] = xbt_new(s_smpi_process_data_t, 1);
123 process_data[i]->index = i;
124 process_data[i]->pending_sent = xbt_fifo_new();
125 process_data[i]->pending_recv = xbt_fifo_new();
126 process_data[i]->timer = xbt_os_timer_new();
127 group = smpi_group_new(1);
128 process_data[i]->comm_self = smpi_comm_new(group);
129 smpi_group_set_mapping(group, i, 0);
131 group = smpi_group_new(process_count);
132 MPI_COMM_WORLD = smpi_comm_new(group);
133 for(i = 0; i < process_count; i++) {
134 smpi_group_set_mapping(group, i, i);
138 void smpi_global_destroy(void) {
139 int count = smpi_process_count();
142 smpi_comm_destroy(MPI_COMM_WORLD);
143 MPI_COMM_WORLD = MPI_COMM_NULL;
144 for(i = 0; i < count; i++) {
145 smpi_comm_destroy(process_data[i]->comm_self);
146 xbt_os_timer_free(process_data[i]->timer);
147 xbt_fifo_free(process_data[i]->pending_recv);
148 xbt_fifo_free(process_data[i]->pending_sent);
149 xbt_free(process_data[i]);
151 xbt_free(process_data);
155 int main(int argc, char **argv)
157 srand(SMPI_RAND_SEED);
159 double default_reference_speed = 20000.0;
160 xbt_cfg_register(&_surf_cfg_set, "smpi/running_power",
161 "Power of the host running the simulation (in flop/s). Used to bench the operations.",
162 xbt_cfgelm_double, &default_reference_speed, 1, 1, NULL, NULL);
164 int default_display_timing = 0;
165 xbt_cfg_register(&_surf_cfg_set, "smpi/display_timing",
166 "Boolean indicating whether we should display the timing after simulation.",
167 xbt_cfgelm_int, &default_display_timing, 1, 1, NULL, NULL);
169 int default_display_smpe = 0;
170 xbt_cfg_register(&_surf_cfg_set, "smpi/log_events",
171 "Boolean indicating whether we should display simulated time spent in MPI calls.",
172 xbt_cfgelm_int, &default_display_smpe, 1, 1, NULL, NULL);
174 double default_threshold = 1e-6;
175 xbt_cfg_register(&_surf_cfg_set, "smpi/cpu_threshold",
176 "Minimal computation time (in seconds) not discarded.",
177 xbt_cfgelm_double, &default_threshold, 1, 1, NULL, NULL);
179 SIMIX_global_init(&argc, argv);
181 // parse the platform file: get the host list
182 SIMIX_create_environment(argv[1]);
184 SIMIX_function_register("smpi_simulated_main", smpi_simulated_main);
185 SIMIX_launch_application(argv[2]);
189 /* Clean IO before the run */
194 while (SIMIX_solve(NULL, NULL) != -1.0);
196 if (xbt_cfg_get_int(_surf_cfg_set, "smpi/display_timing"))
197 INFO1("simulation time %g", SIMIX_get_clock());
199 smpi_global_destroy();
201 SIMIX_message_sizes_output("toto.txt");