5 int MPI_Init(int *argc, char ***argv)
19 // right now this just exits the current node, should send abort signal to all
20 // hosts in the communicator;
21 int MPI_Abort(MPI_Comm comm, int errorcode)
27 int 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 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 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 MPI_Barrier(MPI_Comm comm)
86 int retval = MPI_SUCCESS;
91 retval = MPI_ERR_COMM;
93 retval = smpi_mpi_barrier(comm);
101 int 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 if (NULL == request) {
108 retval = MPI_ERR_ARG;
111 retval = smpi_create_request(buf, count, datatype, src, dst, tag, comm, request);
112 if (NULL != *request && MPI_SUCCESS == retval) {
113 retval = smpi_mpi_irecv(*request);
122 int MPI_Recv(void *buf, int count, MPI_Datatype datatype, int src, int tag, MPI_Comm comm, MPI_Status *status)
124 int retval = MPI_SUCCESS;
126 smpi_mpi_request_t request;
130 retval = smpi_create_request(buf, count, datatype, src, dst, tag, comm, &request);
131 if (NULL != request && MPI_SUCCESS == retval) {
132 retval = smpi_mpi_irecv(request);
133 if (MPI_SUCCESS == retval) {
134 retval = smpi_mpi_wait(request, status);
136 xbt_mallocator_release(smpi_global->request_mallocator, request);
144 int MPI_Isend(void *buf, int count, MPI_Datatype datatype, int dst, int tag, MPI_Comm comm, MPI_Request *request)
146 int retval = MPI_SUCCESS;
150 if (NULL == request) {
151 retval = MPI_ERR_ARG;
154 retval = smpi_create_request(buf, count, datatype, src, dst, tag, comm, request);
155 if (NULL != *request && MPI_SUCCESS == retval) {
156 retval = smpi_mpi_isend(*request);
165 int MPI_Send(void *buf, int count, MPI_Datatype datatype, int dst, int tag, MPI_Comm comm)
167 int retval = MPI_SUCCESS;
169 smpi_mpi_request_t request;
173 retval = smpi_create_request(buf, count, datatype, src, dst, tag, comm, &request);
174 if (NULL != request && MPI_SUCCESS == retval) {
175 retval = smpi_mpi_isend(request);
176 if (MPI_SUCCESS == retval) {
177 smpi_mpi_wait(request, MPI_STATUS_IGNORE);
179 xbt_mallocator_release(smpi_global->request_mallocator, request);
187 // FIXME: overly simplistic
188 int MPI_Bcast(void *buf, int count, MPI_Datatype datatype, int root, MPI_Comm comm) {
190 int retval = MPI_SUCCESS;
195 rank = smpi_mpi_comm_rank(comm);
199 smpi_mpi_request_t *requests = xbt_new(smpi_mpi_request_t, comm->size - 1);
200 for (i = 1; i < comm->size; i++) {
201 retval = smpi_create_request(buf, count, datatype, root, (root + i) % comm->size, 0, comm, requests + i - 1);
202 smpi_mpi_isend(requests[i - 1]);
204 for (i = 0; i < comm->size - 1; i++) {
205 smpi_mpi_wait(requests[i], MPI_STATUS_IGNORE);
206 xbt_mallocator_release(smpi_global->request_mallocator, requests[i]);
210 smpi_mpi_request_t request;
211 retval = smpi_create_request(buf, count, datatype, root, rank, 0, comm, &request);
212 smpi_mpi_irecv(request);
213 smpi_mpi_wait(request, MPI_STATUS_IGNORE);
214 xbt_mallocator_release(smpi_global->request_mallocator, request);
222 // FIXME: needs to return null in event of MPI_UNDEFINED color...
223 // FIXME: seriously, this isn't pretty
224 int MPI_Comm_split(MPI_Comm comm, int color, int key, MPI_Comm *comm_out)
226 int retval = MPI_SUCCESS;
229 smpi_mpi_request_t request;
231 smpi_mpi_status_t status;
235 // FIXME: need to test parameters
237 index = smpi_host_index();
238 rank = comm->index_to_rank_map[index];
241 int *colors = xbt_new(int, comm->size);
242 int *keys = xbt_new(int, comm->size);
244 smpi_mpi_communicator_t tempcomm = NULL;
247 int *keystmp = xbt_new(int, comm->size);
248 int *rankstmp = xbt_new(int, comm->size);
255 // FIXME: not efficient
256 for (i = 1; i < comm->size; i++) {
257 retval = smpi_create_request(colorkey, 2, MPI_INT, MPI_ANY_SOURCE, rank, MPI_ANY_TAG, comm, &request);
258 smpi_mpi_irecv(request);
259 smpi_mpi_wait(request, &status);
260 xbt_mallocator_release(smpi_global->request_mallocator, request);
261 colors[i] = colorkey[0];
262 keys[i] = colorkey[1];
265 for (i = 0; i < comm->size; i++) {
266 if (-1 == colors[i]) {
269 colortmp = colors[i];
271 for (j = i; j < comm->size; j++) {
272 if(colortmp == colors[j]) {
274 keystmp[keycount] = keys[j];
275 rankstmp[keycount] = j;
280 // FIXME: yes, mock me, bubble sort...
281 for (j = 0; j < keycount; j++) {
282 for (k = keycount - 1; k > j; k--) {
283 if (keystmp[k] < keystmp[k - 1]) {
285 keystmp[k] = keystmp[k - 1];
286 keystmp[k - 1] = tmpval;
288 tmpval = rankstmp[k];
289 rankstmp[k] = rankstmp[k - 1];
290 rankstmp[k - 1] = tmpval;
294 tempcomm = xbt_new(s_smpi_mpi_communicator_t, 1);
295 tempcomm->barrier_count = 0;
296 tempcomm->barrier_mutex = SIMIX_mutex_init();
297 tempcomm->barrier_cond = SIMIX_cond_init();
298 tempcomm->rank_to_index_map = xbt_new(int, keycount);
299 tempcomm->index_to_rank_map = xbt_new(int, smpi_global->host_count);
300 for (j = 0; j < smpi_global->host_count; j++) {
301 tempcomm->index_to_rank_map[j] = -1;
303 for (j = 0; j < keycount; j++) {
304 indextmp = comm->rank_to_index_map[rankstmp[j]];
305 tempcomm->rank_to_index_map[j] = indextmp;
306 tempcomm->index_to_rank_map[indextmp] = j;
308 for (j = 0; j < keycount; j++) {
309 retval = smpi_create_request(&j, 1, MPI_INT, 0, rankstmp[j], 0, comm, &request);
310 request->data = tempcomm;
311 smpi_mpi_isend(request);
312 smpi_mpi_wait(request, &status);
313 xbt_mallocator_release(smpi_global->request_mallocator, request);
320 retval = smpi_create_request(colorkey, 2, MPI_INT, rank, 0, 0, comm, &request);
321 smpi_mpi_isend(request);
322 smpi_mpi_wait(request, &status);
323 xbt_mallocator_release(smpi_global->request_mallocator, request);
324 retval = smpi_create_request(colorkey, 1, MPI_INT, 0, rank, 0, comm, &request);
325 smpi_mpi_irecv(request);
326 smpi_mpi_wait(request, &status);
327 *comm_out = request->data;