+ // FIXME: check for errors
+ smpi_datatype_extent(recvtype, &lb, &recvext);
+ // Local copy from root
+ smpi_datatype_copy(sendbuf, sendcount, sendtype,
+ (char *)recvbuf + displs[root] * recvext,
+ recvcounts[root], recvtype);
+ // Receive buffers from senders
+ requests = xbt_new(MPI_Request, size - 1);
+ index = 0;
+ for(src = 0; src < size; src++) {
+ if(src != root) {
+ requests[index] =
+ smpi_irecv_init((char *)recvbuf + displs[src] * recvext,
+ recvcounts[src], recvtype, src, system_tag, comm);
+ index++;
+ }
+ }
+ // Wait for completion of irecv's.
+ smpi_mpi_startall(size - 1, requests);
+ smpi_mpi_waitall(size - 1, requests, MPI_STATUS_IGNORE);
+ xbt_free(requests);
+ }
+}
+
+void smpi_mpi_allgather(void *sendbuf, int sendcount,
+ MPI_Datatype sendtype, void *recvbuf,
+ int recvcount, MPI_Datatype recvtype,
+ MPI_Comm comm)
+{
+ int system_tag = 666;
+ int rank, size, other, index;
+ MPI_Aint lb = 0, recvext = 0;
+ MPI_Request *requests;
+
+ rank = smpi_comm_rank(comm);
+ size = smpi_comm_size(comm);
+ // FIXME: check for errors
+ smpi_datatype_extent(recvtype, &lb, &recvext);
+ // Local copy from self
+ smpi_datatype_copy(sendbuf, sendcount, sendtype,
+ (char *)recvbuf + rank * recvcount * recvext, recvcount,
+ recvtype);
+ // Send/Recv buffers to/from others;
+ requests = xbt_new(MPI_Request, 2 * (size - 1));
+ index = 0;
+ for(other = 0; other < size; other++) {
+ if(other != rank) {
+ requests[index] =
+ smpi_isend_init(sendbuf, sendcount, sendtype, other, system_tag,
+ comm);
+ index++;
+ requests[index] = smpi_irecv_init((char *)recvbuf + other * recvcount * recvext,
+ recvcount, recvtype, other,
+ system_tag, comm);
+ index++;
+ }
+ }
+ // Wait for completion of all comms.
+ smpi_mpi_startall(2 * (size - 1), requests);
+ smpi_mpi_waitall(2 * (size - 1), requests, MPI_STATUS_IGNORE);
+ xbt_free(requests);
+}
+
+void smpi_mpi_allgatherv(void *sendbuf, int sendcount,
+ MPI_Datatype sendtype, void *recvbuf,
+ int *recvcounts, int *displs,
+ MPI_Datatype recvtype, MPI_Comm comm)
+{
+ int system_tag = 666;
+ int rank, size, other, index;
+ MPI_Aint lb = 0, recvext = 0;
+ MPI_Request *requests;