3 int MPI_Init(int *argc, char ***argv)
17 // right now this just exits the current node, should send abort signal to all
18 // hosts in the communicator;
19 int MPI_Abort(MPI_Comm comm, int errorcode)
25 int MPI_Comm_size(MPI_Comm comm, int *size)
27 int retval = MPI_SUCCESS;
32 retval = MPI_ERR_COMM;
33 } else if (NULL == size) {
44 int MPI_Comm_rank(MPI_Comm comm, int *rank)
46 int retval = MPI_SUCCESS;
51 retval = MPI_ERR_COMM;
52 } else if (NULL == rank) {
55 *rank = smpi_mpi_comm_rank(comm);
63 int MPI_Type_size(MPI_Datatype datatype, size_t *size)
65 int retval = MPI_SUCCESS;
69 if (NULL == datatype) {
70 retval = MPI_ERR_TYPE;
71 } else if (NULL == size) {
74 *size = datatype->size;
82 int MPI_Barrier(MPI_Comm comm)
84 int retval = MPI_SUCCESS;
89 retval = MPI_ERR_COMM;
91 retval = smpi_mpi_barrier(comm);
99 int MPI_Irecv(void *buf, int count, MPI_Datatype datatype, int src, int tag, MPI_Comm comm, MPI_Request *request)
101 int retval = MPI_SUCCESS;
105 retval = smpi_create_request(buf, count, datatype, src, 0, tag, comm, request);
106 if (NULL != *request && MPI_SUCCESS == retval) {
107 retval = smpi_mpi_irecv(*request);
115 int MPI_Recv(void *buf, int count, MPI_Datatype datatype, int src, int tag, MPI_Comm comm, MPI_Status *status)
117 int retval = MPI_SUCCESS;
118 smpi_mpi_request_t request;
122 retval = smpi_create_request(buf, count, datatype, src, 0, tag, comm, &request);
123 if (NULL != request && MPI_SUCCESS == retval) {
124 retval = smpi_mpi_irecv(request);
125 if (MPI_SUCCESS == retval) {
126 retval = smpi_mpi_wait(request, status);
128 xbt_mallocator_release(smpi_global->request_mallocator, request);
136 int MPI_Isend(void *buf, int count, MPI_Datatype datatype, int dst, int tag, MPI_Comm comm, MPI_Request *request)
138 int retval = MPI_SUCCESS;
142 retval = smpi_create_request(buf, count, datatype, 0, dst, tag, comm, request);
143 if (NULL != *request && MPI_SUCCESS == retval) {
144 retval = smpi_mpi_isend(*request);
152 int MPI_Send(void *buf, int count, MPI_Datatype datatype, int dst, int tag, MPI_Comm comm)
154 int retval = MPI_SUCCESS;
155 smpi_mpi_request_t request;
159 retval = smpi_create_request(buf, count, datatype, 0, dst, tag, comm, &request);
160 if (NULL != request && MPI_SUCCESS == retval) {
161 retval = smpi_mpi_isend(request);
162 if (MPI_SUCCESS == retval) {
163 smpi_mpi_wait(request, MPI_STATUS_IGNORE);
165 xbt_mallocator_release(smpi_global->request_mallocator, request);
173 int MPI_Bcast(void *buf, int count, MPI_Datatype datatype, int root, MPI_Comm comm) {
175 int retval = MPI_SUCCESS;
177 smpi_mpi_request_t request;
181 rank = smpi_mpi_comm_rank(comm);
184 retval = smpi_create_request(buf, count, datatype, root, (root + 1) % comm->size, 0, comm, &request);
185 request->forward = comm->size - 1;
186 smpi_mpi_isend(request);
188 retval = smpi_create_request(buf, count, datatype, MPI_ANY_SOURCE, rank, 0, comm, &request);
189 smpi_mpi_irecv(request);
192 smpi_mpi_wait(request, MPI_STATUS_IGNORE);
193 xbt_mallocator_release(smpi_global->request_mallocator, request);
200 // FIXME: needs to return null in event of MPI_UNDEFINED color...
201 // FIXME: seriously, this isn't pretty
202 int MPI_Comm_split(MPI_Comm comm, int color, int key, MPI_Comm *comm_out)
204 int retval = MPI_SUCCESS;
207 smpi_mpi_request_t request;
209 smpi_mpi_status_t status;
213 // FIXME: need to test parameters
215 index = smpi_host_index();
216 rank = comm->index_to_rank_map[index];
219 int *colors = xbt_new(int, comm->size);
220 int *keys = xbt_new(int, comm->size);
222 smpi_mpi_communicator_t tempcomm = NULL;
225 int *keystmp = xbt_new(int, comm->size);
226 int *rankstmp = xbt_new(int, comm->size);
233 // FIXME: not efficient
234 for (i = 1; i < comm->size; i++) {
235 retval = smpi_create_request(colorkey, 2, MPI_INT, MPI_ANY_SOURCE, rank, MPI_ANY_TAG, comm, &request);
236 smpi_mpi_irecv(request);
237 smpi_mpi_wait(request, &status);
238 xbt_mallocator_release(smpi_global->request_mallocator, request);
239 colors[i] = colorkey[0];
240 keys[i] = colorkey[1];
243 for (i = 0; i < comm->size; i++) {
244 if (-1 == colors[i]) {
247 colortmp = colors[i];
249 for (j = i; j < comm->size; j++) {
250 if(colortmp == colors[j]) {
252 keystmp[keycount] = keys[j];
253 rankstmp[keycount] = j;
258 // FIXME: yes, mock me, bubble sort...
259 for (j = 0; j < keycount; j++) {
260 for (k = keycount - 1; k > j; k--) {
261 if (keystmp[k] < keystmp[k - 1]) {
263 keystmp[k] = keystmp[k - 1];
264 keystmp[k - 1] = tmpval;
266 tmpval = rankstmp[k];
267 rankstmp[k] = rankstmp[k - 1];
268 rankstmp[k - 1] = tmpval;
272 tempcomm = xbt_new(s_smpi_mpi_communicator_t, 1);
273 tempcomm->barrier_count = 0;
274 tempcomm->barrier_mutex = SIMIX_mutex_init();
275 tempcomm->barrier_cond = SIMIX_cond_init();
276 tempcomm->rank_to_index_map = xbt_new(int, keycount);
277 tempcomm->index_to_rank_map = xbt_new(int, smpi_global->host_count);
278 for (j = 0; j < smpi_global->host_count; j++) {
279 tempcomm->index_to_rank_map[j] = -1;
281 for (j = 0; j < keycount; j++) {
282 indextmp = comm->rank_to_index_map[rankstmp[j]];
283 tempcomm->rank_to_index_map[j] = indextmp;
284 tempcomm->index_to_rank_map[indextmp] = j;
286 for (j = 0; j < keycount; j++) {
287 retval = smpi_create_request(&j, 1, MPI_INT, 0, rankstmp[j], 0, comm, &request);
288 request->data = tempcomm;
289 smpi_mpi_isend(request);
290 smpi_mpi_wait(request, &status);
291 xbt_mallocator_release(smpi_global->request_mallocator, request);
298 retval = smpi_create_request(colorkey, 2, MPI_INT, rank, 0, 0, comm, &request);
299 smpi_mpi_isend(request);
300 smpi_mpi_wait(request, &status);
301 xbt_mallocator_release(smpi_global->request_mallocator, request);
302 retval = smpi_create_request(colorkey, 1, MPI_INT, 0, rank, 0, comm, &request);
303 smpi_mpi_irecv(request);
304 smpi_mpi_wait(request, &status);
305 *comm_out = request->data;