+ double time;
+
+ smpi_bench_end();
+ time = SIMIX_get_clock();
+ smpi_bench_begin();
+ return time;
+}
+
+int SMPI_MPI_Gather(void* sendbuf, int sendcount, MPI_Datatype sendtype,
+ void* recvbuf, int recvcount, MPI_Datatype recvtype,
+ int root, MPI_Comm comm)
+{
+ int retval = MPI_SUCCESS;
+ int system_tag = 666;
+ int rank, size;
+
+ smpi_bench_end();
+ rank = smpi_mpi_comm_rank(comm);
+ size = comm->size;
+ if(rank != root) {
+ // Send buffer to root
+ smpi_mpi_request_t request;
+
+ retval = smpi_create_request(sendbuf, sendcount, sendtype,
+ rank, root, system_tag, comm, &request);
+ smpi_mpi_isend(request);
+ smpi_mpi_wait(request, MPI_STATUS_IGNORE);
+ xbt_mallocator_release(smpi_global->request_mallocator, request);
+ } else {
+ // Receive buffers from senders
+ int src;
+ smpi_mpi_request_t* requests;
+
+ requests = xbt_malloc((size-1) * sizeof(smpi_mpi_request_t));
+ for(src = 0; src < size; src++) {
+ if(src == root) {
+ // Local copy from root
+ memcpy(&((char*)recvbuf)[src*recvcount*recvtype->size],
+ sendbuf, sendcount*sendtype->size*sizeof(char));
+ } else {
+ int index = src < root ? src : src - 1;
+ retval = smpi_create_request(&((char*)recvbuf)[src*recvcount*recvtype->size],
+ recvcount, recvtype, src, root, system_tag,
+ comm, &requests[index]);
+ if(NULL != requests[index] && MPI_SUCCESS == retval) {
+ smpi_mpi_irecv(requests[index]);
+ }
+ }
+ }
+ // Wait for completion of irecv's.
+ for(src = 0; src < size - 1; src++) {
+ int index = MPI_UNDEFINED;
+ smpi_mpi_waitany(size - 1, requests, &index, MPI_STATUS_IGNORE);
+ xbt_mallocator_release(smpi_global->request_mallocator, requests[index]);
+ }
+ xbt_free(requests);
+ }
+ smpi_bench_begin();
+ return retval;
+}
+
+int SMPI_MPI_Gatherv(void* sendbuf, int sendcount, MPI_Datatype sendtype,
+ void* recvbuf, int* recvcounts, int* displs, MPI_Datatype recvtype,
+ int root, MPI_Comm comm)
+{
+ int retval = MPI_SUCCESS;
+ int system_tag = 666;
+ int rank, size;
+
+ smpi_bench_end();
+ rank = smpi_mpi_comm_rank(comm);
+ size = comm->size;
+ if(rank != root) {
+ // Send buffer to root
+ smpi_mpi_request_t request;
+
+ retval = smpi_create_request(sendbuf, sendcount, sendtype,
+ rank, root, system_tag, comm, &request);
+ smpi_mpi_isend(request);
+ smpi_mpi_wait(request, MPI_STATUS_IGNORE);
+ xbt_mallocator_release(smpi_global->request_mallocator, request);
+ } else {
+ // Receive buffers from senders
+ int src;
+ smpi_mpi_request_t* requests;
+
+ requests = xbt_malloc((size-1) * sizeof(smpi_mpi_request_t));
+ for(src = 0; src < size; src++) {
+ if(src == root) {
+ // Local copy from root
+ memcpy(&((char*)recvbuf)[displs[src]],
+ sendbuf, sendcount*sendtype->size*sizeof(char));
+ } else {
+ int index = src < root ? src : src - 1;
+ retval = smpi_create_request(&((char*)recvbuf)[displs[src]],
+ recvcounts[src], recvtype, src, root, system_tag,
+ comm, &requests[index]);
+ if(NULL != requests[index] && MPI_SUCCESS == retval) {
+ smpi_mpi_irecv(requests[index]);
+ }
+ }
+ }
+ // Wait for completion of irecv's.
+ for(src = 0; src < size - 1; src++) {
+ int index = MPI_UNDEFINED;
+ smpi_mpi_waitany(size - 1, requests, &index, MPI_STATUS_IGNORE);
+ xbt_mallocator_release(smpi_global->request_mallocator, requests[index]);
+ }
+ xbt_free(requests);
+ }
+ smpi_bench_begin();
+ return retval;