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;
192 smpi_mpi_request_t request;
196 rank = smpi_mpi_comm_rank(comm);
199 retval = smpi_create_request(buf, count, datatype, root, (root + 1) % comm->size, 0, comm, &request);
200 request->forward = comm->size - 1;
201 smpi_mpi_isend(request);
202 smpi_mpi_wait(request, MPI_STATUS_IGNORE);
203 xbt_mallocator_release(smpi_global->request_mallocator, request);
205 retval = smpi_create_request(buf, count, datatype, MPI_ANY_SOURCE, rank, 0, comm, &request);
206 smpi_mpi_irecv(request);
207 smpi_mpi_wait(request, MPI_STATUS_IGNORE);
208 xbt_mallocator_release(smpi_global->request_mallocator, request);
216 // FIXME: needs to return null in event of MPI_UNDEFINED color...
217 // FIXME: seriously, this isn't pretty
218 int MPI_Comm_split(MPI_Comm comm, int color, int key, MPI_Comm *comm_out)
220 int retval = MPI_SUCCESS;
223 smpi_mpi_request_t request;
225 smpi_mpi_status_t status;
229 // FIXME: need to test parameters
231 index = smpi_host_index();
232 rank = comm->index_to_rank_map[index];
235 int *colors = xbt_new(int, comm->size);
236 int *keys = xbt_new(int, comm->size);
238 smpi_mpi_communicator_t tempcomm = NULL;
241 int *keystmp = xbt_new(int, comm->size);
242 int *rankstmp = xbt_new(int, comm->size);
249 // FIXME: not efficient
250 for (i = 1; i < comm->size; i++) {
251 retval = smpi_create_request(colorkey, 2, MPI_INT, MPI_ANY_SOURCE, rank, MPI_ANY_TAG, comm, &request);
252 smpi_mpi_irecv(request);
253 smpi_mpi_wait(request, &status);
254 xbt_mallocator_release(smpi_global->request_mallocator, request);
255 colors[i] = colorkey[0];
256 keys[i] = colorkey[1];
259 for (i = 0; i < comm->size; i++) {
260 if (-1 == colors[i]) {
263 colortmp = colors[i];
265 for (j = i; j < comm->size; j++) {
266 if(colortmp == colors[j]) {
268 keystmp[keycount] = keys[j];
269 rankstmp[keycount] = j;
274 // FIXME: yes, mock me, bubble sort...
275 for (j = 0; j < keycount; j++) {
276 for (k = keycount - 1; k > j; k--) {
277 if (keystmp[k] < keystmp[k - 1]) {
279 keystmp[k] = keystmp[k - 1];
280 keystmp[k - 1] = tmpval;
282 tmpval = rankstmp[k];
283 rankstmp[k] = rankstmp[k - 1];
284 rankstmp[k - 1] = tmpval;
288 tempcomm = xbt_new(s_smpi_mpi_communicator_t, 1);
289 tempcomm->barrier_count = 0;
290 tempcomm->barrier_mutex = SIMIX_mutex_init();
291 tempcomm->barrier_cond = SIMIX_cond_init();
292 tempcomm->rank_to_index_map = xbt_new(int, keycount);
293 tempcomm->index_to_rank_map = xbt_new(int, smpi_global->host_count);
294 for (j = 0; j < smpi_global->host_count; j++) {
295 tempcomm->index_to_rank_map[j] = -1;
297 for (j = 0; j < keycount; j++) {
298 indextmp = comm->rank_to_index_map[rankstmp[j]];
299 tempcomm->rank_to_index_map[j] = indextmp;
300 tempcomm->index_to_rank_map[indextmp] = j;
302 for (j = 0; j < keycount; j++) {
303 retval = smpi_create_request(&j, 1, MPI_INT, 0, rankstmp[j], 0, comm, &request);
304 request->data = tempcomm;
305 smpi_mpi_isend(request);
306 smpi_mpi_wait(request, &status);
307 xbt_mallocator_release(smpi_global->request_mallocator, request);
314 retval = smpi_create_request(colorkey, 2, MPI_INT, rank, 0, 0, comm, &request);
315 smpi_mpi_isend(request);
316 smpi_mpi_wait(request, &status);
317 xbt_mallocator_release(smpi_global->request_mallocator, request);
318 retval = smpi_create_request(colorkey, 1, MPI_INT, 0, rank, 0, comm, &request);
319 smpi_mpi_irecv(request);
320 smpi_mpi_wait(request, &status);
321 *comm_out = request->data;