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 if (NULL == request) {
106 retval = MPI_ERR_ARG;
109 retval = smpi_create_request(buf, count, datatype, src, dst, tag, comm, request);
110 if (NULL != *request && MPI_SUCCESS == retval) {
111 retval = smpi_mpi_irecv(*request);
120 int MPI_Recv(void *buf, int count, MPI_Datatype datatype, int src, int tag, MPI_Comm comm, MPI_Status *status)
122 int retval = MPI_SUCCESS;
124 smpi_mpi_request_t request;
128 retval = smpi_create_request(buf, count, datatype, src, dst, tag, comm, &request);
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 MPI_Isend(void *buf, int count, MPI_Datatype datatype, int dst, int tag, MPI_Comm comm, MPI_Request *request)
144 int retval = MPI_SUCCESS;
148 if (NULL == request) {
149 retval = MPI_ERR_ARG;
152 retval = smpi_create_request(buf, count, datatype, src, dst, tag, comm, request);
153 if (NULL != *request && MPI_SUCCESS == retval) {
154 retval = smpi_mpi_isend(*request);
163 int MPI_Send(void *buf, int count, MPI_Datatype datatype, int dst, int tag, MPI_Comm comm)
165 int retval = MPI_SUCCESS;
167 smpi_mpi_request_t request;
171 retval = smpi_create_request(buf, count, datatype, src, dst, tag, comm, &request);
172 if (NULL != request && MPI_SUCCESS == retval) {
173 retval = smpi_mpi_isend(request);
174 if (MPI_SUCCESS == retval) {
175 smpi_mpi_wait(request, MPI_STATUS_IGNORE);
177 xbt_mallocator_release(smpi_global->request_mallocator, request);
185 // FIXME: needs to return null in event of MPI_UNDEFINED color...
186 int MPI_Comm_split(MPI_Comm comm, int color, int key, MPI_Comm *comm_out)
188 int retval = MPI_SUCCESS;
191 smpi_mpi_request_t request;
193 smpi_mpi_status_t status;
197 // FIXME: need to test parameters
199 index = smpi_host_index();
200 rank = comm->index_to_rank_map[index];
203 int *colors = xbt_new(int, comm->size);
204 int *keys = xbt_new(int, comm->size);
206 smpi_mpi_communicator_t tempcomm = NULL;
209 int *keystmp = xbt_new(int, comm->size);
210 int *rankstmp = xbt_new(int, comm->size);
217 // FIXME: not efficient
218 for (i = 1; i < comm->size; i++) {
219 retval = smpi_create_request(colorkey, 2, MPI_INT, MPI_ANY_SOURCE, rank, MPI_ANY_TAG, comm, &request);
220 smpi_mpi_irecv(request);
221 smpi_mpi_wait(request, &status);
222 xbt_mallocator_release(smpi_global->request_mallocator, request);
223 colors[i] = colorkey[0];
224 keys[i] = colorkey[1];
227 for (i = 0; i < comm->size; i++) {
228 if (-1 == colors[i]) {
231 colortmp = colors[i];
233 for (j = i; j < comm->size; j++) {
234 if(colortmp == colors[j]) {
236 keystmp[keycount] = keys[j];
237 rankstmp[keycount] = j;
242 // FIXME: yes, mock me, bubble sort...
243 for (j = 0; j < keycount; j++) {
244 for (k = keycount - 1; k > j; k--) {
245 if (keystmp[k] < keystmp[k - 1]) {
247 keystmp[k] = keystmp[k - 1];
248 keystmp[k - 1] = tmpval;
250 tmpval = rankstmp[k];
251 rankstmp[k] = rankstmp[k - 1];
252 rankstmp[k - 1] = tmpval;
256 tempcomm = xbt_new(s_smpi_mpi_communicator_t, 1);
257 tempcomm->barrier_count = 0;
258 tempcomm->barrier_mutex = SIMIX_mutex_init();
259 tempcomm->barrier_cond = SIMIX_cond_init();
260 tempcomm->rank_to_index_map = xbt_new(int, keycount);
261 tempcomm->index_to_rank_map = xbt_new(int, smpi_global->host_count);
262 for (j = 0; j < smpi_global->host_count; j++) {
263 tempcomm->index_to_rank_map[j] = -1;
265 for (j = 0; j < keycount; j++) {
266 indextmp = comm->rank_to_index_map[rankstmp[j]];
267 tempcomm->rank_to_index_map[j] = indextmp;
268 tempcomm->index_to_rank_map[indextmp] = j;
270 for (j = 0; j < keycount; j++) {
271 retval = smpi_create_request(&j, 1, MPI_INT, 0, rankstmp[j], 0, comm, &request);
272 request->data = tempcomm;
273 smpi_mpi_isend(request);
274 smpi_mpi_wait(request, &status);
275 xbt_mallocator_release(smpi_global->request_mallocator, request);
282 retval = smpi_create_request(colorkey, 2, MPI_INT, rank, 0, 0, comm, &request);
283 smpi_mpi_isend(request);
284 smpi_mpi_wait(request, &status);
285 xbt_mallocator_release(smpi_global->request_mallocator, request);
286 retval = smpi_create_request(colorkey, 1, MPI_INT, 0, rank, 0, comm, &request);
287 smpi_mpi_irecv(request);
288 smpi_mpi_wait(request, &status);
289 comm_out = request->data;