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, int tag, MPI_Comm comm, MPI_Request *request)
103 int retval = MPI_SUCCESS;
107 retval = smpi_create_request(buf, count, datatype, src, 0, tag, comm, request);
108 if (NULL != *request && MPI_SUCCESS == retval) {
109 retval = smpi_mpi_irecv(*request);
117 int SMPI_MPI_Recv(void *buf, int count, MPI_Datatype datatype, int src, int tag, MPI_Comm comm, MPI_Status *status)
119 int retval = MPI_SUCCESS;
120 smpi_mpi_request_t request;
124 retval = smpi_create_request(buf, count, datatype, src, 0, tag, comm, &request);
125 if (NULL != request && MPI_SUCCESS == retval) {
126 retval = smpi_mpi_irecv(request);
127 if (MPI_SUCCESS == retval) {
128 retval = smpi_mpi_wait(request, status);
130 xbt_mallocator_release(smpi_global->request_mallocator, request);
138 int SMPI_MPI_Isend(void *buf, int count, MPI_Datatype datatype, int dst, int tag, MPI_Comm comm, MPI_Request *request)
140 int retval = MPI_SUCCESS;
144 retval = smpi_create_request(buf, count, datatype, 0, dst, tag, comm, request);
145 if (NULL != *request && MPI_SUCCESS == retval) {
146 retval = smpi_mpi_isend(*request);
154 int SMPI_MPI_Send(void *buf, int count, MPI_Datatype datatype, int dst, int tag, MPI_Comm comm)
156 int retval = MPI_SUCCESS;
157 smpi_mpi_request_t request;
161 retval = smpi_create_request(buf, count, datatype, 0, dst, tag, comm, &request);
162 if (NULL != request && MPI_SUCCESS == retval) {
163 retval = smpi_mpi_isend(request);
164 if (MPI_SUCCESS == retval) {
165 smpi_mpi_wait(request, MPI_STATUS_IGNORE);
167 xbt_mallocator_release(smpi_global->request_mallocator, request);
175 int SMPI_MPI_Wait(MPI_Request *request, MPI_Status *status) {
176 return smpi_mpi_wait(*request, status);
179 int SMPI_MPI_Bcast(void *buf, int count, MPI_Datatype datatype, int root, MPI_Comm comm) {
181 int retval = MPI_SUCCESS;
183 smpi_mpi_request_t request;
187 rank = smpi_mpi_comm_rank(comm);
190 retval = smpi_create_request(buf, count, datatype, root, (root + 1) % comm->size, 0, comm, &request);
191 request->forward = comm->size - 1;
192 smpi_mpi_isend(request);
194 retval = smpi_create_request(buf, count, datatype, MPI_ANY_SOURCE, rank, 0, comm, &request);
195 smpi_mpi_irecv(request);
198 smpi_mpi_wait(request, MPI_STATUS_IGNORE);
199 xbt_mallocator_release(smpi_global->request_mallocator, request);
206 // FIXME: needs to return null in event of MPI_UNDEFINED color...
207 // FIXME: seriously, this isn't pretty
208 int SMPI_MPI_Comm_split(MPI_Comm comm, int color, int key, MPI_Comm *comm_out)
210 int retval = MPI_SUCCESS;
213 smpi_mpi_request_t request;
215 smpi_mpi_status_t status;
219 // FIXME: need to test parameters
221 index = smpi_host_index();
222 rank = comm->index_to_rank_map[index];
225 int *colors = xbt_new(int, comm->size);
226 int *keys = xbt_new(int, comm->size);
228 smpi_mpi_communicator_t tempcomm = NULL;
231 int *keystmp = xbt_new(int, comm->size);
232 int *rankstmp = xbt_new(int, comm->size);
239 // FIXME: not efficient
240 for (i = 1; i < comm->size; i++) {
241 retval = smpi_create_request(colorkey, 2, MPI_INT, MPI_ANY_SOURCE, rank, MPI_ANY_TAG, comm, &request);
242 smpi_mpi_irecv(request);
243 smpi_mpi_wait(request, &status);
244 colors[status.MPI_SOURCE] = colorkey[0];
245 keys[status.MPI_SOURCE] = colorkey[1];
246 xbt_mallocator_release(smpi_global->request_mallocator, request);
249 for (i = 0; i < comm->size; i++) {
250 if (-1 == colors[i]) {
253 colortmp = colors[i];
255 for (j = i; j < comm->size; j++) {
256 if(colortmp == colors[j]) {
258 keystmp[keycount] = keys[j];
259 rankstmp[keycount] = j;
263 // FIXME: yes, mock me, bubble sort...
264 for (j = 0; j < keycount; j++) {
265 for (k = j; k < keycount - 1; k++) {
266 if (keystmp[k] > keystmp[k + 1]) {
268 keystmp[k] = keystmp[k + 1];
269 keystmp[k + 1] = tmpval;
271 tmpval = rankstmp[k];
272 rankstmp[k] = rankstmp[k + 1];
273 rankstmp[k + 1] = tmpval;
277 tempcomm = xbt_new(s_smpi_mpi_communicator_t, 1);
278 tempcomm->barrier_count = 0;
279 tempcomm->size = keycount;
280 tempcomm->barrier_mutex = SIMIX_mutex_init();
281 tempcomm->barrier_cond = SIMIX_cond_init();
282 tempcomm->rank_to_index_map = xbt_new(int, keycount);
283 tempcomm->index_to_rank_map = xbt_new(int, smpi_global->host_count);
284 for (j = 0; j < smpi_global->host_count; j++) {
285 tempcomm->index_to_rank_map[j] = -1;
287 for (j = 0; j < keycount; j++) {
288 indextmp = comm->rank_to_index_map[rankstmp[j]];
289 tempcomm->rank_to_index_map[j] = indextmp;
290 tempcomm->index_to_rank_map[indextmp] = j;
292 for (j = 0; j < keycount; j++) {
294 retval = smpi_create_request(&j, 1, MPI_INT, 0, rankstmp[j], 0, comm, &request);
295 request->data = tempcomm;
296 smpi_mpi_isend(request);
297 smpi_mpi_wait(request, &status);
298 xbt_mallocator_release(smpi_global->request_mallocator, request);
300 *comm_out = tempcomm;
307 retval = smpi_create_request(colorkey, 2, MPI_INT, rank, 0, 0, comm, &request);
308 smpi_mpi_isend(request);
309 smpi_mpi_wait(request, &status);
310 xbt_mallocator_release(smpi_global->request_mallocator, request);
311 retval = smpi_create_request(colorkey, 1, MPI_INT, 0, rank, 0, comm, &request);
312 smpi_mpi_irecv(request);
313 smpi_mpi_wait(request, &status);
314 *comm_out = request->data;