- for (i = 0; i < comm->size; i++) {
- if (MPI_UNDEFINED == colormap[i]) {
- continue;
- }
- // make a list of nodes with current color and sort by keys
- count = 0;
- for (j = i; j < comm->size; j++) {
- if (colormap[i] == colormap[j]) {
- colormap[j] = MPI_UNDEFINED;
- rankkeymap[count * 2] = j;
- rankkeymap[count * 2 + 1] = keymap[j];
- count++;
- }
- }
- qsort(rankkeymap, count, sizeof(int) * 2, &smpi_compare_rankkeys);
-
- // new communicator
- tempcomm = xbt_new(s_smpi_mpi_communicator_t, 1);
- tempcomm->barrier_count = 0;
- tempcomm->size = count;
- tempcomm->barrier_mutex = SIMIX_mutex_init();
- tempcomm->barrier_cond = SIMIX_cond_init();
- tempcomm->rank_to_index_map = xbt_new(int, count);
- tempcomm->index_to_rank_map = xbt_new(int, smpi_global->process_count);
- for (j = 0; j < smpi_global->process_count; j++) {
- tempcomm->index_to_rank_map[j] = -1;
- }
- for (j = 0; j < count; j++) {
- indextmp = comm->rank_to_index_map[rankkeymap[j * 2]];
- tempcomm->rank_to_index_map[j] = indextmp;
- tempcomm->index_to_rank_map[indextmp] = j;
- }
- for (j = 0; j < count; j++) {
- if (rankkeymap[j * 2]) {
- retval = smpi_create_request(&j, 1, MPI_INT, 0,
- rankkeymap[j * 2], 0, comm, &request);
- request->data = tempcomm;
- smpi_mpi_isend(request);
- smpi_mpi_wait(request, &status);
- xbt_mallocator_release(smpi_global->request_mallocator, request);
- } else {
- *comm_out = tempcomm;
- }
- }
+int MPI_Allgather(void* sendbuf, int sendcount, MPI_Datatype sendtype, void* recvbuf, int recvcount, MPI_Datatype recvtype, MPI_Comm comm) {
+ int retval;
+ int rank = comm != MPI_COMM_NULL ? smpi_comm_rank(comm) : -1;
+
+ smpi_bench_end(rank, "Allgather");
+ 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_allgather(sendbuf, sendcount, sendtype, recvbuf, recvcount, recvtype, comm);
+ retval = MPI_SUCCESS;
+ }
+ smpi_bench_begin(rank, "Allgather");
+ return retval;
+}
+
+int MPI_Allgatherv(void* sendbuf, int sendcount, MPI_Datatype sendtype, void* recvbuf, int* recvcounts, int* displs, MPI_Datatype recvtype, MPI_Comm comm) {
+ int retval;
+ int rank = comm != MPI_COMM_NULL ? smpi_comm_rank(comm) : -1;
+
+ smpi_bench_end(rank, "Allgatherv");
+ if(comm == MPI_COMM_NULL) {
+ retval = MPI_ERR_COMM;
+ } else if(sendtype == MPI_DATATYPE_NULL || recvtype == MPI_DATATYPE_NULL) {
+ retval = MPI_ERR_TYPE;
+ } else if(recvcounts == NULL || displs == NULL) {
+ retval = MPI_ERR_ARG;
+ } else {
+ smpi_mpi_allgatherv(sendbuf, sendcount, sendtype, recvbuf, recvcounts, displs, recvtype, comm);
+ retval = MPI_SUCCESS;
+ }
+ smpi_bench_begin(rank, "Allgatherv");
+ return retval;
+}
+
+int MPI_Scatter(void* sendbuf, int sendcount, MPI_Datatype sendtype, void* recvbuf, int recvcount, MPI_Datatype recvtype, int root, MPI_Comm comm) {
+ int retval;
+ int rank = comm != MPI_COMM_NULL ? smpi_comm_rank(comm) : -1;
+
+ smpi_bench_end(rank, "Scatter");
+ 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_scatter(sendbuf, sendcount, sendtype, recvbuf, recvcount, recvtype, root, comm);
+ retval = MPI_SUCCESS;
+ }
+ smpi_bench_begin(rank, "Scatter");
+ return retval;
+}
+
+int MPI_Scatterv(void* sendbuf, int* sendcounts, int* displs, MPI_Datatype sendtype, void* recvbuf, int recvcount, MPI_Datatype recvtype, int root, MPI_Comm comm) {
+ int retval;
+ int rank = comm != MPI_COMM_NULL ? smpi_comm_rank(comm) : -1;
+
+ smpi_bench_end(rank, "Scatterv");
+ if(comm == MPI_COMM_NULL) {
+ retval = MPI_ERR_COMM;
+ } else if(sendtype == MPI_DATATYPE_NULL || recvtype == MPI_DATATYPE_NULL) {
+ retval = MPI_ERR_TYPE;
+ } else if(sendcounts == NULL || displs == NULL) {
+ retval = MPI_ERR_ARG;
+ } else {
+ smpi_mpi_scatterv(sendbuf, sendcounts, displs, sendtype, recvbuf, recvcount, recvtype, root, comm);
+ retval = MPI_SUCCESS;
+ }
+ smpi_bench_begin(rank, "Scatterv");
+ return retval;
+}
+
+int MPI_Reduce(void* sendbuf, void* recvbuf, int count, MPI_Datatype datatype, MPI_Op op, int root, MPI_Comm comm) {
+ int retval;
+ int rank = comm != MPI_COMM_NULL ? smpi_comm_rank(comm) : -1;
+
+ smpi_bench_end(rank, "Reduce");
+ if(comm == MPI_COMM_NULL) {
+ retval = MPI_ERR_COMM;
+ } else if(datatype == MPI_DATATYPE_NULL || op == MPI_OP_NULL) {
+ retval = MPI_ERR_ARG;
+ } else {
+ smpi_mpi_reduce(sendbuf, recvbuf, count, datatype, op, root, comm);
+ retval = MPI_SUCCESS;
+ }
+ smpi_bench_begin(rank, "Reduce");
+ return retval;
+}
+
+int MPI_Allreduce(void* sendbuf, void* recvbuf, int count, MPI_Datatype datatype, MPI_Op op, MPI_Comm comm) {
+ int retval;
+ int rank = comm != MPI_COMM_NULL ? smpi_comm_rank(comm) : -1;
+
+ smpi_bench_end(rank, "Allreduce");
+ if(comm == MPI_COMM_NULL) {
+ retval = MPI_ERR_COMM;
+ } else if(datatype == MPI_DATATYPE_NULL) {
+ retval = MPI_ERR_TYPE;
+ } else if(op == MPI_OP_NULL) {
+ retval = MPI_ERR_OP;
+ } else {
+ smpi_mpi_allreduce(sendbuf, recvbuf, count, datatype, op, comm);
+ retval = MPI_SUCCESS;
+ }
+ smpi_bench_begin(rank, "Allreduce");
+ return retval;
+}
+
+int MPI_Scan(void* sendbuf, void* recvbuf, int count, MPI_Datatype datatype, MPI_Op op, MPI_Comm comm) {
+ int retval;
+ int rank = comm != MPI_COMM_NULL ? smpi_comm_rank(comm) : -1;
+
+ smpi_bench_end(rank, "Scan");
+ if(comm == MPI_COMM_NULL) {
+ retval = MPI_ERR_COMM;
+ } else if(datatype == MPI_DATATYPE_NULL) {
+ retval = MPI_ERR_TYPE;
+ } else if(op == MPI_OP_NULL) {
+ retval = MPI_ERR_OP;
+ } else {
+ smpi_mpi_scan(sendbuf, recvbuf, count, datatype, op, comm);
+ retval = MPI_SUCCESS;
+ }
+ smpi_bench_begin(rank, "Scan");
+ return retval;
+}
+
+int MPI_Reduce_scatter(void* sendbuf, void* recvbuf, int* recvcounts, MPI_Datatype datatype, MPI_Op op, MPI_Comm comm) {
+ int retval, i, size, count;
+ int* displs;
+ int rank = comm != MPI_COMM_NULL ? smpi_comm_rank(comm) : -1;
+
+ smpi_bench_end(rank, "Reduce_scatter");
+ if(comm == MPI_COMM_NULL) {
+ retval = MPI_ERR_COMM;
+ } else if(datatype == MPI_DATATYPE_NULL) {
+ retval = MPI_ERR_TYPE;
+ } else if(op == MPI_OP_NULL) {
+ retval = MPI_ERR_OP;
+ } else if(recvcounts == NULL) {
+ retval = MPI_ERR_ARG;
+ } else {
+ /* arbitrarily choose root as rank 0 */
+ /* TODO: faster direct implementation ? */
+ size = smpi_comm_size(comm);
+ count = 0;
+ displs = xbt_new(int, size);
+ for(i = 0; i < size; i++) {
+ count += recvcounts[i];
+ displs[i] = 0;