3 XBT_LOG_NEW_DEFAULT_SUBCATEGORY(smpi_mpi, smpi, "Logging specific to SMPI (mpi)");
5 int SMPI_MPI_Init(int *argc, char ***argv)
12 int SMPI_MPI_Finalize()
19 // right now this just exits the current node, should send abort signal to all
20 // hosts in the communicator;
21 int SMPI_MPI_Abort(MPI_Comm comm, int errorcode)
27 int SMPI_MPI_Comm_size(MPI_Comm comm, int *size)
29 int retval = MPI_SUCCESS;
34 retval = MPI_ERR_COMM;
35 } else if (NULL == size) {
46 int SMPI_MPI_Comm_rank(MPI_Comm comm, int *rank)
48 int retval = MPI_SUCCESS;
53 retval = MPI_ERR_COMM;
54 } else if (NULL == rank) {
57 *rank = smpi_mpi_comm_rank(comm);
65 int SMPI_MPI_Type_size(MPI_Datatype datatype, size_t *size)
67 int retval = MPI_SUCCESS;
71 if (NULL == datatype) {
72 retval = MPI_ERR_TYPE;
73 } else if (NULL == size) {
76 *size = datatype->size;
84 int SMPI_MPI_Barrier(MPI_Comm comm)
86 int retval = MPI_SUCCESS;
91 retval = MPI_ERR_COMM;
93 retval = smpi_mpi_barrier(comm);
101 int SMPI_MPI_Irecv(void *buf, int count, MPI_Datatype datatype, int src,
102 int tag, MPI_Comm comm, MPI_Request *request)
104 int retval = MPI_SUCCESS;
108 retval = smpi_create_request(buf, count, datatype, src, 0, tag, comm,
110 if (NULL != *request && MPI_SUCCESS == retval) {
111 retval = smpi_mpi_irecv(*request);
119 int SMPI_MPI_Recv(void *buf, int count, MPI_Datatype datatype, int src,
120 int tag, MPI_Comm comm, MPI_Status *status)
122 int retval = MPI_SUCCESS;
123 smpi_mpi_request_t request;
127 retval = smpi_create_request(buf, count, datatype, src, 0, tag, comm,
129 if (NULL != request && MPI_SUCCESS == retval) {
130 retval = smpi_mpi_irecv(request);
131 if (MPI_SUCCESS == retval) {
132 retval = smpi_mpi_wait(request, status);
134 xbt_mallocator_release(smpi_global->request_mallocator, request);
142 int SMPI_MPI_Isend(void *buf, int count, MPI_Datatype datatype, int dst,
143 int tag, MPI_Comm comm, MPI_Request *request)
145 int retval = MPI_SUCCESS;
149 retval = smpi_create_request(buf, count, datatype, 0, dst, tag, comm,
151 if (NULL != *request && MPI_SUCCESS == retval) {
152 retval = smpi_mpi_isend(*request);
160 int SMPI_MPI_Send(void *buf, int count, MPI_Datatype datatype, int dst,
161 int tag, MPI_Comm comm)
163 int retval = MPI_SUCCESS;
164 smpi_mpi_request_t request;
168 retval = smpi_create_request(buf, count, datatype, 0, dst, tag, comm,
170 if (NULL != request && MPI_SUCCESS == retval) {
171 retval = smpi_mpi_isend(request);
172 if (MPI_SUCCESS == retval) {
173 smpi_mpi_wait(request, MPI_STATUS_IGNORE);
175 xbt_mallocator_release(smpi_global->request_mallocator, request);
183 int SMPI_MPI_Wait(MPI_Request *request, MPI_Status *status) {
184 return smpi_mpi_wait(*request, status);
187 int SMPI_MPI_Bcast(void *buf, int count, MPI_Datatype datatype, int root,
191 int retval = MPI_SUCCESS;
193 smpi_mpi_request_t request;
197 rank = smpi_mpi_comm_rank(comm);
200 retval = smpi_create_request(buf, count, datatype, root,
201 (root + 1) % comm->size, 0, comm, &request);
202 request->forward = comm->size - 1;
203 smpi_mpi_isend(request);
205 retval = smpi_create_request(buf, count, datatype, MPI_ANY_SOURCE, rank,
207 smpi_mpi_irecv(request);
210 smpi_mpi_wait(request, MPI_STATUS_IGNORE);
211 xbt_mallocator_release(smpi_global->request_mallocator, request);
218 // used by comm_split to sort ranks based on key values
219 int smpi_compare_rankkeys(const void *a, const void *b);
220 int smpi_compare_rankkeys(const void *a, const void *b) {
224 if (x[1] < y[1]) return -1;
227 if (x[0] < y[0]) return -1;
228 if (x[0] == y[0]) return 0;
235 int SMPI_MPI_Comm_split(MPI_Comm comm, int color, int key, MPI_Comm *comm_out)
237 int retval = MPI_SUCCESS;
240 smpi_mpi_request_t request;
242 smpi_mpi_status_t status;
246 // FIXME: need to test parameters
248 index = smpi_host_index();
249 rank = comm->index_to_rank_map[index];
254 // root node does most of the real work
256 int colormap[comm->size];
257 int keymap[comm->size];
258 int rankkeymap[comm->size * 2];
260 smpi_mpi_communicator_t tempcomm = NULL;
267 // FIXME: use scatter/gather or similar instead of individual comms
268 for (i = 1; i < comm->size; i++) {
269 retval = smpi_create_request(colorkey, 2, MPI_INT, MPI_ANY_SOURCE,
270 rank, MPI_ANY_TAG, comm, &request);
271 smpi_mpi_irecv(request);
272 smpi_mpi_wait(request, &status);
273 colormap[status.MPI_SOURCE] = colorkey[0];
274 keymap[status.MPI_SOURCE] = colorkey[1];
275 xbt_mallocator_release(smpi_global->request_mallocator, request);
278 for (i = 0; i < comm->size; i++) {
279 if (MPI_UNDEFINED == colormap[i]) {
283 // make a list of nodes with current color and sort by keys
285 for (j = i; j < comm->size; j++) {
286 if(colormap[i] == colormap[j]) {
287 colormap[j] = MPI_UNDEFINED;
288 rankkeymap[count * 2] = j;
289 rankkeymap[count * 2 + 1] = keymap[j];
293 qsort(rankkeymap, count, sizeof(int) * 2,
294 &smpi_compare_rankkeys);
297 tempcomm = xbt_new(s_smpi_mpi_communicator_t, 1);
298 tempcomm->barrier_count = 0;
299 tempcomm->size = count;
300 tempcomm->barrier_mutex = SIMIX_mutex_init();
301 tempcomm->barrier_cond = SIMIX_cond_init();
302 tempcomm->rank_to_index_map = xbt_new(int, count);
303 tempcomm->index_to_rank_map = xbt_new(int, smpi_global->host_count);
304 for (j = 0; j < smpi_global->host_count; j++) {
305 tempcomm->index_to_rank_map[j] = -1;
307 for (j = 0; j < count; j++) {
308 indextmp = comm->rank_to_index_map[rankkeymap[j*2]];
309 tempcomm->rank_to_index_map[j] = indextmp;
310 tempcomm->index_to_rank_map[indextmp] = j;
312 for (j = 0; j < count; j++) {
313 if (rankkeymap[j*2]) {
314 retval = smpi_create_request(&j, 1, MPI_INT, 0,
315 rankkeymap[j*2], 0, comm, &request);
316 request->data = tempcomm;
317 smpi_mpi_isend(request);
318 smpi_mpi_wait(request, &status);
319 xbt_mallocator_release(smpi_global->request_mallocator,
322 *comm_out = tempcomm;
329 retval = smpi_create_request(colorkey, 2, MPI_INT, rank, 0, 0, comm,
331 smpi_mpi_isend(request);
332 smpi_mpi_wait(request, &status);
333 xbt_mallocator_release(smpi_global->request_mallocator, request);
334 if (MPI_UNDEFINED != color) {
335 retval = smpi_create_request(colorkey, 1, MPI_INT, 0, rank, 0, comm,
337 smpi_mpi_irecv(request);
338 smpi_mpi_wait(request, &status);
339 *comm_out = request->data;