+ }else{
+ xbt_die("freeing an already free request");
+ }
+}
+
+MPI_Request smpi_isend_init(void *buf, int count, MPI_Datatype datatype,
+ int dst, int tag, MPI_Comm comm)
+{
+ MPI_Request request =
+ build_request(buf==MPI_BOTTOM ? (void*)0 : buf , count, datatype, smpi_process_index(), smpi_group_index(smpi_comm_group(comm), dst), tag,
+ comm, NON_PERSISTENT | ISEND | SEND | PREPARED);
+
+ return request;
+}
+
+MPI_Request smpi_mpi_isend(void *buf, int count, MPI_Datatype datatype,
+ int dst, int tag, MPI_Comm comm)
+{
+ MPI_Request request =
+ build_request(buf==MPI_BOTTOM?(void*)0:buf, count, datatype, smpi_process_index(), smpi_group_index(smpi_comm_group(comm), dst), tag,
+ comm, NON_PERSISTENT | ISEND | SEND);
+
+ smpi_mpi_start(request);
+ return request;
+}
+
+MPI_Request smpi_mpi_issend(void *buf, int count, MPI_Datatype datatype,
+ int dst, int tag, MPI_Comm comm)
+{
+ MPI_Request request =
+ build_request(buf==MPI_BOTTOM ? (void*)0 : buf, count, datatype, smpi_process_index(), smpi_group_index(smpi_comm_group(comm), dst), tag,
+ comm, NON_PERSISTENT | ISEND | SSEND | SEND);
+ smpi_mpi_start(request);
+ return request;
+}
+
+
+
+MPI_Request smpi_irecv_init(void *buf, int count, MPI_Datatype datatype,
+ int src, int tag, MPI_Comm comm)
+{
+ MPI_Request request =
+ build_request(buf==MPI_BOTTOM ? (void*)0 : buf, count, datatype, src == MPI_ANY_SOURCE ? MPI_ANY_SOURCE : smpi_group_index(smpi_comm_group(comm), src), smpi_process_index(), tag,
+ comm, NON_PERSISTENT | RECV | PREPARED);
+ return request;
+}
+
+MPI_Request smpi_mpi_irecv(void *buf, int count, MPI_Datatype datatype,
+ int src, int tag, MPI_Comm comm)
+{
+ MPI_Request request =
+ build_request(buf==MPI_BOTTOM ? (void*)0 : buf, count, datatype, src == MPI_ANY_SOURCE ? MPI_ANY_SOURCE : smpi_group_index(smpi_comm_group(comm), src), smpi_process_index(), tag,
+ comm, NON_PERSISTENT | RECV);
+
+ smpi_mpi_start(request);
+ return request;
+}
+
+void smpi_mpi_recv(void *buf, int count, MPI_Datatype datatype, int src,
+ int tag, MPI_Comm comm, MPI_Status * status)
+{
+ MPI_Request request;
+ request = smpi_mpi_irecv(buf, count, datatype, src, tag, comm);
+ smpi_mpi_wait(&request, status);
+}
+
+
+
+void smpi_mpi_send(void *buf, int count, MPI_Datatype datatype, int dst,
+ int tag, MPI_Comm comm)
+{
+ MPI_Request request =
+ build_request(buf==MPI_BOTTOM ? (void*)0 : buf, count, datatype, smpi_process_index(), smpi_group_index(smpi_comm_group(comm), dst), tag,
+ comm, NON_PERSISTENT | SEND);
+ smpi_mpi_start(request);
+ smpi_mpi_wait(&request, MPI_STATUS_IGNORE);
+
+}
+
+void smpi_mpi_ssend(void *buf, int count, MPI_Datatype datatype,
+ int dst, int tag, MPI_Comm comm)
+{
+ MPI_Request request =
+ build_request(buf==MPI_BOTTOM ? (void*)0 : buf, count, datatype, smpi_process_index(), smpi_group_index(smpi_comm_group(comm), dst), tag,
+ comm, NON_PERSISTENT | SSEND | SEND);
+
+ smpi_mpi_start(request);
+ smpi_mpi_wait(&request, MPI_STATUS_IGNORE);
+}
+
+void smpi_mpi_sendrecv(void *sendbuf, int sendcount, MPI_Datatype sendtype,
+ int dst, int sendtag, void *recvbuf, int recvcount,
+ MPI_Datatype recvtype, int src, int recvtag,
+ MPI_Comm comm, MPI_Status * status)
+{
+ MPI_Request requests[2];
+ MPI_Status stats[2];
+ int myid=smpi_process_index();
+ if ((smpi_group_index(smpi_comm_group(comm), dst) == myid) && (smpi_group_index(smpi_comm_group(comm), src) == myid)) {
+ smpi_datatype_copy(sendbuf, sendcount, sendtype,
+ recvbuf, recvcount, recvtype);
+ return;
+ }
+ requests[0] =
+ smpi_isend_init(sendbuf, sendcount, sendtype, dst, sendtag, comm);
+ requests[1] =
+ smpi_irecv_init(recvbuf, recvcount, recvtype, src, recvtag, comm);
+ smpi_mpi_startall(2, requests);
+ smpi_mpi_waitall(2, requests, stats);
+ if(status != MPI_STATUS_IGNORE) {
+ // Copy receive status
+ *status = stats[1];
+ }
+}
+
+int smpi_mpi_get_count(MPI_Status * status, MPI_Datatype datatype)
+{
+ return status->count / smpi_datatype_size(datatype);
+}
+
+static void finish_wait(MPI_Request * request, MPI_Status * status)
+{
+ MPI_Request req = *request;
+ if(status != MPI_STATUS_IGNORE)
+ smpi_empty_status(status);
+
+ if(!(req->detached && req->flags & SEND) && !(req->flags & PREPARED)){
+ if(status != MPI_STATUS_IGNORE) {
+ int src = req->src == MPI_ANY_SOURCE ? req->real_src : req->src;
+ status->MPI_SOURCE = smpi_group_rank(smpi_comm_group(req->comm), src);
+ status->MPI_TAG = req->tag == MPI_ANY_TAG ? req->real_tag : req->tag;
+ status->MPI_ERROR = req->truncated ? MPI_ERR_TRUNCATE : MPI_SUCCESS;
+ // this handles the case were size in receive differs from size in send
+ // FIXME: really this should just contain the count of receive-type blocks,
+ // right?
+ status->count = req->real_size;
+ }
+
+ print_request("Finishing", req);
+ MPI_Datatype datatype = req->old_type;
+
+ if(datatype->has_subtype == 1){
+ // This part handles the problem of non-contignous memory
+ // the unserialization at the reception
+ s_smpi_subtype_t *subtype = datatype->substruct;
+ if(req->flags & RECV) {
+ subtype->unserialize(req->buf, req->old_buf, req->real_size/smpi_datatype_size(datatype) , datatype->substruct);