+int MPI_Recv_init(void* buf, int count, MPI_Datatype datatype, int src, int tag, MPI_Comm comm, MPI_Request* request) {
+ int retval;
+ int rank = comm != MPI_COMM_NULL ? smpi_comm_rank(comm) : -1;
+
+ smpi_bench_end(rank, "Recv_init");
+ if(request == NULL) {
+ retval = MPI_ERR_ARG;
+ } else if (comm == MPI_COMM_NULL) {
+ retval = MPI_ERR_COMM;
+ } else {
+ *request = smpi_mpi_recv_init(buf, count, datatype, src, tag, comm);
+ retval = MPI_SUCCESS;
+ }
+ smpi_bench_begin(rank, "Recv_init");
+ return retval;
+}
+
+int MPI_Start(MPI_Request* request) {
+ int retval;
+ MPI_Comm comm = (*request)->comm;
+ int rank = comm != MPI_COMM_NULL ? smpi_comm_rank(comm) : -1;
+
+ smpi_bench_end(rank, "Start");
+ if(request == NULL) {
+ retval = MPI_ERR_ARG;
+ } else {
+ smpi_mpi_start(*request);
+ retval = MPI_SUCCESS;
+ }
+ smpi_bench_begin(rank, "Start");
+ return retval;
+}
+
+int MPI_Startall(int count, MPI_Request* requests) {
+ int retval;
+ MPI_Comm comm = count > 0 && requests ? requests[0]->comm : MPI_COMM_NULL;
+ int rank = comm != MPI_COMM_NULL ? smpi_comm_rank(comm) : -1;
+
+ smpi_bench_end(rank, "Startall");
+ if(requests == NULL) {
+ retval = MPI_ERR_ARG;
+ } else {
+ smpi_mpi_startall(count, requests);
+ retval = MPI_SUCCESS;
+ }
+ smpi_bench_begin(rank, "Startall");
+ return retval;
+}
+
+int MPI_Request_free(MPI_Request* request) {
+ int retval;
+ MPI_Comm comm = (*request)->comm;
+ int rank = comm != MPI_COMM_NULL ? smpi_comm_rank(comm) : -1;
+
+ smpi_bench_end(rank, "Request_free");
+ if(request == NULL) {
+ retval = MPI_ERR_ARG;
+ } else {
+ smpi_mpi_request_free(request);
+ retval = MPI_SUCCESS;
+ }
+ smpi_bench_begin(rank, "Request_free");
+ return retval;
+}
+
+int MPI_Irecv(void* buf, int count, MPI_Datatype datatype, int src, int tag, MPI_Comm comm, MPI_Request* request) {
+ int retval;
+ int rank = comm != MPI_COMM_NULL ? smpi_comm_rank(comm) : -1;
+
+ smpi_bench_end(rank, "Irecv");
+#ifdef HAVE_TRACING
+ int src_traced = smpi_group_rank(smpi_comm_group(comm), src);
+ TRACE_smpi_ptp_in (rank, src_traced, rank, __FUNCTION__);
+#endif
+ if(request == NULL) {
+ retval = MPI_ERR_ARG;
+ } else if (comm == MPI_COMM_NULL) {
+ retval = MPI_ERR_COMM;
+ } else {
+ *request = smpi_mpi_irecv(buf, count, datatype, src, tag, comm);
+ retval = MPI_SUCCESS;
+ }
+#ifdef HAVE_TRACING
+ TRACE_smpi_ptp_out (rank, src_traced, rank, __FUNCTION__);
+ (*request)->recv = 1;
+#endif
+ smpi_bench_begin(rank, "Irecv");
+ return retval;
+}
+
+int MPI_Isend(void* buf, int count, MPI_Datatype datatype, int dst, int tag, MPI_Comm comm, MPI_Request* request) {
+ int retval;
+ int rank = comm != MPI_COMM_NULL ? smpi_comm_rank(comm) : -1;
+
+ smpi_bench_end(rank, "Isend");
+#ifdef HAVE_TRACING
+ int dst_traced = smpi_group_rank(smpi_comm_group(comm), dst);
+ TRACE_smpi_ptp_in (rank, rank, dst_traced, __FUNCTION__);
+ TRACE_smpi_send (rank, rank, dst_traced);
+#endif
+ if(request == NULL) {
+ retval = MPI_ERR_ARG;
+ } else if (comm == MPI_COMM_NULL) {
+ retval = MPI_ERR_COMM;
+ } else {
+ *request = smpi_mpi_isend(buf, count, datatype, dst, tag, comm);
+ retval = MPI_SUCCESS;
+ }
+#ifdef HAVE_TRACING
+ TRACE_smpi_ptp_out (rank, rank, dst_traced, __FUNCTION__);
+ (*request)->send = 1;
+#endif
+ smpi_bench_begin(rank, "Isend");
+ return retval;
+}
+
+int MPI_Recv(void* buf, int count, MPI_Datatype datatype, int src, int tag, MPI_Comm comm, MPI_Status* status) {
+ int retval;
+ int rank = comm != MPI_COMM_NULL ? smpi_comm_rank(comm) : -1;
+
+ smpi_bench_end(rank, "Recv");
+#ifdef HAVE_TRACING
+ int src_traced = smpi_group_rank(smpi_comm_group(comm), src);
+ TRACE_smpi_ptp_in (rank, src_traced, rank, __FUNCTION__);
+#endif
+ if (comm == MPI_COMM_NULL) {
+ retval = MPI_ERR_COMM;
+ } else {
+ smpi_mpi_recv(buf, count, datatype, src, tag, comm, status);
+ retval = MPI_SUCCESS;
+ }
+#ifdef HAVE_TRACING
+ TRACE_smpi_ptp_out (rank, src_traced, rank, __FUNCTION__);
+ TRACE_smpi_recv (rank, src_traced, rank);
+#endif
+ smpi_bench_begin(rank, "Recv");
+ return retval;
+}
+
+int MPI_Send(void* buf, int count, MPI_Datatype datatype, int dst, int tag, MPI_Comm comm) {
+ int retval;
+ int rank = comm != MPI_COMM_NULL ? smpi_comm_rank(comm) : -1;
+
+ smpi_bench_end(rank, "Send");
+#ifdef HAVE_TRACING
+ int dst_traced = smpi_group_rank(smpi_comm_group(comm), dst);
+ TRACE_smpi_ptp_in (rank, rank, dst_traced, __FUNCTION__);
+ TRACE_smpi_send (rank, rank, dst_traced);
+#endif
+ if (comm == MPI_COMM_NULL) {
+ retval = MPI_ERR_COMM;
+ } else {
+ smpi_mpi_send(buf, count, datatype, dst, tag, comm);
+ retval = MPI_SUCCESS;
+ }
+#ifdef HAVE_TRACING
+ TRACE_smpi_ptp_out (rank, rank, dst_traced, __FUNCTION__);
+#endif
+ smpi_bench_begin(rank, "Send");
+ return retval;
+}
+
+int 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) {
+ int retval;
+ int rank = comm != MPI_COMM_NULL ? smpi_comm_rank(comm) : -1;
+
+ smpi_bench_end(rank, "Sendrecv");
+#ifdef HAVE_TRACING
+ int dst_traced = smpi_group_rank(smpi_comm_group(comm), dst);
+ int src_traced = smpi_group_rank(smpi_comm_group(comm), src);
+ TRACE_smpi_ptp_in (rank, src_traced, dst_traced, __FUNCTION__);
+ TRACE_smpi_send (rank, rank, dst_traced);
+ TRACE_smpi_send (rank, src_traced, rank);
+#endif
+ if (comm == MPI_COMM_NULL) {
+ retval = MPI_ERR_COMM;
+ } else if (sendtype == MPI_DATATYPE_NULL || recvtype == MPI_DATATYPE_NULL) {
+ retval = MPI_ERR_TYPE;
+ } else {
+ smpi_mpi_sendrecv(sendbuf, sendcount, sendtype, dst, sendtag, recvbuf, recvcount, recvtype, src, recvtag, comm, status);
+ retval = MPI_SUCCESS;
+ }
+#ifdef HAVE_TRACING
+ TRACE_smpi_ptp_out (rank, src_traced, dst_traced, __FUNCTION__);
+ TRACE_smpi_recv (rank, rank, dst_traced);
+ TRACE_smpi_recv (rank, src_traced, rank);
+#endif
+ smpi_bench_begin(rank, "Sendrecv");
+ return retval;
+}
+
+int MPI_Sendrecv_replace(void* buf, int count, MPI_Datatype datatype, int dst, int sendtag, int src, int recvtag, MPI_Comm comm, MPI_Status* status) {
+ //TODO: suboptimal implementation
+ void* recvbuf;
+ int retval, size;
+
+ size = smpi_datatype_size(datatype) * count;
+ recvbuf = xbt_new(char, size);
+ retval = MPI_Sendrecv(buf, count, datatype, dst, sendtag, recvbuf, count, datatype, src, recvtag, comm, status);
+ memcpy(buf, recvbuf, size * sizeof(char));
+ xbt_free(recvbuf);
+ return retval;
+}
+
+int MPI_Test(MPI_Request* request, int* flag, MPI_Status* status) {
+ int retval;
+ int rank = request && (*request)->comm != MPI_COMM_NULL
+ ? smpi_comm_rank((*request)->comm)
+ : -1;
+
+ smpi_bench_end(rank, "Test");
+ if(request == NULL || flag == NULL) {
+ retval = MPI_ERR_ARG;
+ } else if(*request == MPI_REQUEST_NULL) {
+ retval = MPI_ERR_REQUEST;
+ } else {
+ *flag = smpi_mpi_test(request, status);
+ retval = MPI_SUCCESS;
+ }
+ smpi_bench_begin(rank, "Test");
+ return retval;
+}
+
+int MPI_Testany(int count, MPI_Request requests[], int* index, int* flag, MPI_Status* status) {
+ int retval;
+
+ smpi_bench_end(-1, NULL); //FIXME
+ if(index == NULL || flag == NULL) {
+ retval = MPI_ERR_ARG;
+ } else {
+ *flag = smpi_mpi_testany(count, requests, index, status);
+ retval = MPI_SUCCESS;
+ }
+ smpi_bench_begin(-1, NULL);
+ return retval;
+}
+
+int MPI_Wait(MPI_Request* request, MPI_Status* status) {
+ int retval;
+ int rank = request && (*request)->comm != MPI_COMM_NULL
+ ? smpi_comm_rank((*request)->comm)
+ : -1;
+
+ smpi_bench_end(rank, "Wait");
+#ifdef HAVE_TRACING
+ MPI_Group group = smpi_comm_group((*request)->comm);
+ int src_traced = smpi_group_rank (group , (*request)->src);
+ int dst_traced = smpi_group_rank (group , (*request)->dst);
+ int is_wait_for_receive = (*request)->recv;
+ TRACE_smpi_ptp_in (rank, src_traced, dst_traced, __FUNCTION__);
+#endif
+ if(request == NULL) {
+ retval = MPI_ERR_ARG;
+ } else if(*request == MPI_REQUEST_NULL) {
+ retval = MPI_ERR_REQUEST;
+ } else {
+ smpi_mpi_wait(request, status);
+ retval = MPI_SUCCESS;
+ }
+#ifdef HAVE_TRACING
+ TRACE_smpi_ptp_out (rank, src_traced, dst_traced, __FUNCTION__);
+ if (is_wait_for_receive){
+ TRACE_smpi_recv (rank, src_traced, dst_traced);
+ }
+#endif
+ smpi_bench_begin(rank, "Wait");
+ return retval;
+}