3 XBT_LOG_NEW_DEFAULT_SUBCATEGORY(smpi_mpi, smpi,
4 "Logging specific to SMPI (mpi)");
6 int SMPI_MPI_Init(int *argc, char ***argv)
13 int SMPI_MPI_Finalize()
16 smpi_process_finalize();
20 // right now this just exits the current node, should send abort signal to all
21 // hosts in the communicator (TODO)
22 int SMPI_MPI_Abort(MPI_Comm comm, int errorcode)
28 int SMPI_MPI_Comm_size(MPI_Comm comm, int *size)
30 int retval = MPI_SUCCESS;
35 retval = MPI_ERR_COMM;
36 } else if (NULL == size) {
47 int SMPI_MPI_Comm_rank(MPI_Comm comm, int *rank)
49 int retval = MPI_SUCCESS;
54 retval = MPI_ERR_COMM;
55 } else if (NULL == rank) {
58 *rank = smpi_mpi_comm_rank(comm);
66 int SMPI_MPI_Type_size(MPI_Datatype datatype, size_t * size)
68 int retval = MPI_SUCCESS;
72 if (NULL == datatype) {
73 retval = MPI_ERR_TYPE;
74 } else if (NULL == size) {
77 *size = datatype->size;
85 int SMPI_MPI_Barrier(MPI_Comm comm)
87 int retval = MPI_SUCCESS;
92 retval = MPI_ERR_COMM;
94 retval = smpi_mpi_barrier(comm);
102 int SMPI_MPI_Irecv(void *buf, int count, MPI_Datatype datatype, int src,
103 int tag, MPI_Comm comm, MPI_Request * request)
105 int retval = MPI_SUCCESS;
109 retval = smpi_create_request(buf, count, datatype, src, 0, tag, comm,
111 if (NULL != *request && MPI_SUCCESS == retval) {
112 retval = smpi_mpi_irecv(*request);
120 int SMPI_MPI_Recv(void *buf, int count, MPI_Datatype datatype, int src,
121 int tag, MPI_Comm comm, MPI_Status * status)
123 int retval = MPI_SUCCESS;
124 smpi_mpi_request_t request;
128 retval = smpi_create_request(buf, count, datatype, src, 0, tag, comm,
130 if (NULL != request && MPI_SUCCESS == retval) {
131 retval = smpi_mpi_irecv(request);
132 if (MPI_SUCCESS == retval) {
133 retval = smpi_mpi_wait(request, status);
135 xbt_mallocator_release(smpi_global->request_mallocator, request);
143 int SMPI_MPI_Isend(void *buf, int count, MPI_Datatype datatype, int dst,
144 int tag, MPI_Comm comm, MPI_Request * request)
146 int retval = MPI_SUCCESS;
150 retval = smpi_create_request(buf, count, datatype, 0, dst, tag, comm,
152 if (NULL != *request && MPI_SUCCESS == retval) {
153 retval = smpi_mpi_isend(*request);
161 int SMPI_MPI_Send(void *buf, int count, MPI_Datatype datatype, int dst,
162 int tag, MPI_Comm comm)
164 int retval = MPI_SUCCESS;
165 smpi_mpi_request_t request;
169 retval = smpi_create_request(buf, count, datatype, 0, dst, tag, comm,
171 if (NULL != request && MPI_SUCCESS == retval) {
172 retval = smpi_mpi_isend(request);
173 if (MPI_SUCCESS == retval) {
174 smpi_mpi_wait(request, MPI_STATUS_IGNORE);
176 xbt_mallocator_release(smpi_global->request_mallocator, request);
184 int SMPI_MPI_Wait(MPI_Request * request, MPI_Status * status)
186 return smpi_mpi_wait(*request, status);
189 int SMPI_MPI_Bcast(void *buf, int count, MPI_Datatype datatype, int root,
193 int retval = MPI_SUCCESS;
195 smpi_mpi_request_t request;
199 rank = smpi_mpi_comm_rank(comm);
202 retval = smpi_create_request(buf, count, datatype, root,
203 (root + 1) % comm->size, 0, comm, &request);
204 request->forward = comm->size - 1;
205 smpi_mpi_isend(request);
207 retval = smpi_create_request(buf, count, datatype, MPI_ANY_SOURCE, rank,
209 smpi_mpi_irecv(request);
212 smpi_mpi_wait(request, MPI_STATUS_IGNORE);
213 xbt_mallocator_release(smpi_global->request_mallocator, request);
220 // used by comm_split to sort ranks based on key values
221 int smpi_compare_rankkeys(const void *a, const void *b);
222 int smpi_compare_rankkeys(const void *a, const void *b)
241 int SMPI_MPI_Comm_split(MPI_Comm comm, int color, int key,
244 int retval = MPI_SUCCESS;
247 smpi_mpi_request_t request;
249 smpi_mpi_status_t status;
253 // FIXME: need to test parameters
255 index = smpi_host_index();
256 rank = comm->index_to_rank_map[index];
261 // root node does most of the real work
263 int colormap[comm->size];
264 int keymap[comm->size];
265 int rankkeymap[comm->size * 2];
267 smpi_mpi_communicator_t tempcomm = NULL;
274 // FIXME: use scatter/gather or similar instead of individual comms
275 for (i = 1; i < comm->size; i++) {
276 retval = smpi_create_request(colorkey, 2, MPI_INT, MPI_ANY_SOURCE,
277 rank, MPI_ANY_TAG, comm, &request);
278 smpi_mpi_irecv(request);
279 smpi_mpi_wait(request, &status);
280 colormap[status.MPI_SOURCE] = colorkey[0];
281 keymap[status.MPI_SOURCE] = colorkey[1];
282 xbt_mallocator_release(smpi_global->request_mallocator, request);
285 for (i = 0; i < comm->size; i++) {
286 if (MPI_UNDEFINED == colormap[i]) {
289 // make a list of nodes with current color and sort by keys
291 for (j = i; j < comm->size; j++) {
292 if (colormap[i] == colormap[j]) {
293 colormap[j] = MPI_UNDEFINED;
294 rankkeymap[count * 2] = j;
295 rankkeymap[count * 2 + 1] = keymap[j];
299 qsort(rankkeymap, count, sizeof(int) * 2, &smpi_compare_rankkeys);
302 tempcomm = xbt_new(s_smpi_mpi_communicator_t, 1);
303 tempcomm->barrier_count = 0;
304 tempcomm->size = count;
305 tempcomm->barrier_mutex = SIMIX_mutex_init();
306 tempcomm->barrier_cond = SIMIX_cond_init();
307 tempcomm->rank_to_index_map = xbt_new(int, count);
308 tempcomm->index_to_rank_map = xbt_new(int, smpi_global->host_count);
309 for (j = 0; j < smpi_global->host_count; j++) {
310 tempcomm->index_to_rank_map[j] = -1;
312 for (j = 0; j < count; j++) {
313 indextmp = comm->rank_to_index_map[rankkeymap[j * 2]];
314 tempcomm->rank_to_index_map[j] = indextmp;
315 tempcomm->index_to_rank_map[indextmp] = j;
317 for (j = 0; j < count; j++) {
318 if (rankkeymap[j * 2]) {
319 retval = smpi_create_request(&j, 1, MPI_INT, 0,
320 rankkeymap[j * 2], 0, comm, &request);
321 request->data = tempcomm;
322 smpi_mpi_isend(request);
323 smpi_mpi_wait(request, &status);
324 xbt_mallocator_release(smpi_global->request_mallocator, request);
326 *comm_out = tempcomm;
333 retval = smpi_create_request(colorkey, 2, MPI_INT, rank, 0, 0, comm,
335 smpi_mpi_isend(request);
336 smpi_mpi_wait(request, &status);
337 xbt_mallocator_release(smpi_global->request_mallocator, request);
338 if (MPI_UNDEFINED != color) {
339 retval = smpi_create_request(colorkey, 1, MPI_INT, 0, rank, 0, comm,
341 smpi_mpi_irecv(request);
342 smpi_mpi_wait(request, &status);
343 *comm_out = request->data;