+// hosts in the communicator (TODO)
+int SMPI_MPI_Abort(MPI_Comm comm, int errorcode)
+{
+ smpi_exit(errorcode);
+ return 0;
+}
+
+int SMPI_MPI_Comm_size(MPI_Comm comm, int *size)
+{
+ int retval = MPI_SUCCESS;
+
+ smpi_bench_end();
+
+ if (NULL == comm) {
+ retval = MPI_ERR_COMM;
+ } else if (NULL == size) {
+ retval = MPI_ERR_ARG;
+ } else {
+ *size = comm->size;
+ }
+
+ smpi_bench_begin();
+
+ return retval;
+}
+
+int SMPI_MPI_Comm_rank(MPI_Comm comm, int *rank)
+{
+ int retval = MPI_SUCCESS;
+
+ smpi_bench_end();
+
+ if (NULL == comm) {
+ retval = MPI_ERR_COMM;
+ } else if (NULL == rank) {
+ retval = MPI_ERR_ARG;
+ } else {
+ *rank = smpi_mpi_comm_rank(comm);
+ }
+
+ smpi_bench_begin();
+
+ return retval;
+}
+
+
+
+/**
+ * Barrier
+ **/
+int SMPI_MPI_Barrier(MPI_Comm comm)
+{
+ int retval = MPI_SUCCESS;
+ int arity=4;
+
+ smpi_bench_end();
+
+ if (NULL == comm) {
+ retval = MPI_ERR_COMM;
+ } else {
+
+ /*
+ * original implemantation:
+ * retval = smpi_mpi_barrier(comm);
+ * this one is unrealistic: it just cond_waits, means no time.
+ */
+ retval = nary_tree_barrier( comm, arity );
+ }
+
+ smpi_bench_begin();
+
+ return retval;
+}
+
+
+
+int SMPI_MPI_Irecv(void *buf, int count, MPI_Datatype datatype, int src,
+ int tag, MPI_Comm comm, MPI_Request * request)
+{
+ int retval = MPI_SUCCESS;
+
+ smpi_bench_end();
+
+ retval = smpi_create_request(buf, count, datatype, src, 0, tag, comm,
+ request);
+ if (NULL != *request && MPI_SUCCESS == retval) {
+ retval = smpi_mpi_irecv(*request);
+ }
+
+ smpi_bench_begin();
+
+ return retval;
+}
+
+int SMPI_MPI_Recv(void *buf, int count, MPI_Datatype datatype, int src,
+ int tag, MPI_Comm comm, MPI_Status * status)
+{
+ int retval = MPI_SUCCESS;
+ smpi_mpi_request_t request;
+
+ smpi_bench_end();
+
+ retval = smpi_create_request(buf, count, datatype, src, 0, tag, comm,
+ &request);
+ if (NULL != request && MPI_SUCCESS == retval) {
+ retval = smpi_mpi_irecv(request);
+ if (MPI_SUCCESS == retval) {
+ retval = smpi_mpi_wait(request, status);
+ }
+ xbt_mallocator_release(smpi_global->request_mallocator, request);
+ }
+
+ smpi_bench_begin();
+
+ return retval;
+}
+
+int SMPI_MPI_Isend(void *buf, int count, MPI_Datatype datatype, int dst,
+ int tag, MPI_Comm comm, MPI_Request * request)
+{
+ int retval = MPI_SUCCESS;
+
+ smpi_bench_end();
+
+ retval = smpi_create_request(buf, count, datatype, 0, dst, tag, comm,
+ request);
+ if (NULL != *request && MPI_SUCCESS == retval) {
+ retval = smpi_mpi_isend(*request);
+ }
+
+ smpi_bench_begin();
+
+ return retval;
+}
+
+/**
+ * MPI_Send user level
+ **/
+int SMPI_MPI_Send(void *buf, int count, MPI_Datatype datatype, int dst,
+ int tag, MPI_Comm comm)
+{
+ int retval = MPI_SUCCESS;
+ smpi_mpi_request_t request;
+
+ smpi_bench_end();
+
+ retval = smpi_create_request(buf, count, datatype, 0, dst, tag, comm,
+ &request);
+ if (NULL != request && MPI_SUCCESS == retval) {
+ retval = smpi_mpi_isend(request);
+ if (MPI_SUCCESS == retval) {
+ smpi_mpi_wait(request, MPI_STATUS_IGNORE);
+ }
+ xbt_mallocator_release(smpi_global->request_mallocator, request);
+ }
+
+ smpi_bench_begin();
+
+ return retval;
+}
+
+
+/**
+ * MPI_Sendrecv internal level
+ **/
+int smpi_mpi_sendrecv(void *sendbuf, int sendcount, MPI_Datatype sendtype, int dest, int sendtag,
+ void *recvbuf, int recvcount, MPI_Datatype recvtype, int source, int recvtag,
+ MPI_Comm comm, MPI_Status *status)
+{
+int rank;
+int retval = MPI_SUCCESS;
+smpi_mpi_request_t srequest;
+smpi_mpi_request_t rrequest;
+
+ rank = smpi_mpi_comm_rank(comm);
+
+ /* send */
+ retval = smpi_create_request(sendbuf, sendcount, sendtype,
+ rank,dest,sendtag,
+ comm, &srequest);
+ smpi_mpi_isend(srequest);
+
+ /* recv */
+ retval = smpi_create_request(recvbuf, recvcount, recvtype,
+ source, rank,recvtag,
+ comm, &rrequest);
+ smpi_mpi_irecv(rrequest);
+
+ smpi_mpi_wait(srequest, MPI_STATUS_IGNORE);
+ //printf("[%d] isend request src=%d dst=%d tag=%d COMPLETED (retval=%d) \n",rank,rank,dest,sendtag,retval);
+ smpi_mpi_wait(rrequest, MPI_STATUS_IGNORE);
+ //printf("[%d] irecv request src=%d -> dst=%d tag=%d COMPLETED (retval=%d)\n",rank,source,rank,recvtag,retval);
+
+ return(retval);
+}
+/**
+ * MPI_Sendrecv user entry point
+ **/
+int SMPI_MPI_Sendrecv(void *sendbuf, int sendcount, MPI_Datatype sendtype, int dest, int sendtag,
+ void *recvbuf, int recvcount, MPI_Datatype recvtype, int source, int recvtag,
+ MPI_Comm comm, MPI_Status *status)
+{
+int retval = MPI_SUCCESS;
+
+ smpi_bench_end();
+ smpi_mpi_sendrecv( sendbuf, sendcount, sendtype, dest, sendtag,
+ recvbuf, recvcount, recvtype, source, recvtag,
+ comm, status);
+ smpi_bench_begin();
+
+ return retval;
+
+
+}
+
+/**
+ * MPI_Wait and friends
+ **/
+int SMPI_MPI_Wait(MPI_Request * request, MPI_Status * status)
+{
+ return smpi_mpi_wait(*request, status);
+}
+
+int SMPI_MPI_Waitall(int count, MPI_Request requests[], MPI_Status status[])
+{
+ return smpi_mpi_waitall(count, requests, status);
+}
+
+int SMPI_MPI_Waitany(int count, MPI_Request requests[], int *index,
+ MPI_Status status[])
+{
+ return smpi_mpi_waitany(count, requests, index, status);
+}
+
+/**
+ * MPI_Bcast
+ **/
+
+/**
+ * flat bcast
+ **/
+int flat_tree_bcast(void *buf, int count, MPI_Datatype datatype, int root, MPI_Comm comm);
+int flat_tree_bcast(void *buf, int count, MPI_Datatype datatype, int root,
+ MPI_Comm comm)
+{
+ int rank;
+ int retval = MPI_SUCCESS;
+ smpi_mpi_request_t request;
+
+ rank = smpi_mpi_comm_rank(comm);
+ if (rank == root) {
+ retval = smpi_create_request(buf, count, datatype, root,
+ (root + 1) % comm->size, 0, comm, &request);
+ request->forward = comm->size - 1;
+ smpi_mpi_isend(request);
+ } else {
+ retval = smpi_create_request(buf, count, datatype, MPI_ANY_SOURCE, rank,
+ 0, comm, &request);
+ smpi_mpi_irecv(request);
+ }
+
+ smpi_mpi_wait(request, MPI_STATUS_IGNORE);
+ xbt_mallocator_release(smpi_global->request_mallocator, request);
+
+ return(retval);
+
+}
+/**
+ * Bcast internal level
+ **/
+int smpi_mpi_bcast(void *buf, int count, MPI_Datatype datatype, int root,
+ MPI_Comm comm)
+{
+ int retval = MPI_SUCCESS;
+ int rank = smpi_mpi_comm_rank(comm);
+
+ DEBUG1("<%d> entered smpi_mpi_bcast(). Calls nary_tree_bcast()",rank);
+ //retval = flat_tree_bcast(buf, count, datatype, root, comm);
+ retval = nary_tree_bcast(buf, count, datatype, root, comm, 2 );
+ return retval;
+}
+
+/**
+ * Bcast user entry point
+ **/
+int SMPI_MPI_Bcast(void *buf, int count, MPI_Datatype datatype, int root,
+ MPI_Comm comm)