diff --git a/src/collective/allgather.c b/src/collective/allgather.c index a59d7a726..eddb8ee31 100644 --- a/src/collective/allgather.c +++ b/src/collective/allgather.c @@ -4,6 +4,7 @@ #include #include #include "utils.h" +#include "error.h" int MPIX_Allgather(const void* sendbuf, @@ -466,25 +467,27 @@ int allgather_hier_bruck(const void *sendbuf, int sendcount, MPI_Datatype sendty void *recvbuf, int recvcount, MPI_Datatype recvtype, MPIX_Comm* comm) { int num_procs; - MPI_Comm_size(comm->global_comm, &num_procs); + MPI_ADVANCE_SUCCESS_OR_RETURN(MPI_Comm_size(comm->global_comm, &num_procs)); int recv_size; - MPI_Type_size(recvtype, &recv_size); + MPI_ADVANCE_SUCCESS_OR_RETURN(MPI_Type_size(recvtype, &recv_size)); int local_rank, PPN; - MPI_Comm_rank(comm->local_comm, &local_rank); - MPI_Comm_size(comm->local_comm, &PPN); + MPI_ADVANCE_SUCCESS_OR_RETURN(MPI_Comm_rank(comm->local_comm, &local_rank)); + MPI_ADVANCE_SUCCESS_OR_RETURN(MPI_Comm_size(comm->local_comm, &PPN)); char* tmpbuf = (char*)malloc(recvcount*num_procs*recv_size*sizeof(char)); - gather(sendbuf, sendcount, sendtype, tmpbuf, recvcount, recvtype, 0, comm->local_comm); + MPI_ADVANCE_SUCCESS_OR_RETURN(gather(sendbuf, sendcount, sendtype, tmpbuf, recvcount, recvtype, 0, comm->local_comm)); if (local_rank == 0) { - allgather_bruck(tmpbuf, recvcount*PPN, recvtype, recvbuf, recvcount*PPN, recvtype, comm->group_comm); + MPI_ADVANCE_SUCCESS_OR_RETURN(allgather_bruck(tmpbuf, recvcount*PPN, recvtype, recvbuf, recvcount*PPN, recvtype, comm->group_comm)); } - bcast(recvbuf, recvcount*num_procs, recvtype, 0, comm->local_comm); + MPI_ADVANCE_SUCCESS_OR_RETURN(bcast(recvbuf, recvcount*num_procs, recvtype, 0, comm->local_comm)); free(tmpbuf); + + return MPI_SUCCESS; } @@ -494,23 +497,23 @@ int allgather_mult_hier_bruck(const void *sendbuf, int sendcount, MPI_Datatype s void *recvbuf, int recvcount, MPI_Datatype recvtype, MPIX_Comm* comm) { int num_procs; - MPI_Comm_size(comm->global_comm, &num_procs); + MPI_ADVANCE_SUCCESS_OR_RETURN(MPI_Comm_size(comm->global_comm, &num_procs)); int recv_size; - MPI_Type_size(recvtype, &recv_size); + MPI_ADVANCE_SUCCESS_OR_RETURN(MPI_Type_size(recvtype, &recv_size)); int group_size; - MPI_Comm_size(comm->group_comm, &group_size); + MPI_ADVANCE_SUCCESS_OR_RETURN(MPI_Comm_size(comm->group_comm, &group_size)); int ppn; - MPI_Comm_size(comm->local_comm, &ppn); + MPI_ADVANCE_SUCCESS_OR_RETURN(MPI_Comm_size(comm->local_comm, &ppn)); char* tmpbuf = (char*)malloc(recvcount*num_procs*recv_size); char* recv_buffer = (char*)recvbuf; - allgather_bruck(sendbuf, sendcount, sendtype, tmpbuf, recvcount, recvtype, comm->group_comm); - allgather_bruck(tmpbuf, recvcount*group_size, recvtype, - tmpbuf, recvcount*group_size, recvtype, comm->local_comm); + MPI_ADVANCE_SUCCESS_OR_RETURN(allgather_bruck(sendbuf, sendcount, sendtype, tmpbuf, recvcount, recvtype, comm->group_comm)); + MPI_ADVANCE_SUCCESS_OR_RETURN(allgather_bruck(tmpbuf, recvcount*group_size, recvtype, + tmpbuf, recvcount*group_size, recvtype, comm->local_comm)); for (int i = 0; i < ppn; i++) { @@ -528,6 +531,7 @@ int allgather_mult_hier_bruck(const void *sendbuf, int sendcount, MPI_Datatype s } free(tmpbuf); + return MPI_SUCCESS; } diff --git a/src/collective/alltoall.c b/src/collective/alltoall.c index c993e4d7f..13ffbfbc7 100644 --- a/src/collective/alltoall.c +++ b/src/collective/alltoall.c @@ -2,6 +2,7 @@ #include #include #include "utils.h" +#include "error.h" // TODO : Add Locality-Aware Bruck Alltoall Algorithm! // TODO : Change to PMPI_Alltoall and test with profiling library! @@ -64,8 +65,8 @@ int alltoall_pairwise(const void* sendbuf, MPI_Comm comm) { int rank, num_procs; - MPI_Comm_rank(comm, &rank); - MPI_Comm_size(comm, &num_procs); + MPI_ADVANCE_SUCCESS_OR_RETURN(MPI_Comm_rank(comm, &rank)); + MPI_ADVANCE_SUCCESS_OR_RETURN(MPI_Comm_size(comm, &num_procs)); int tag = 102944; int send_proc, recv_proc; @@ -73,8 +74,8 @@ int alltoall_pairwise(const void* sendbuf, MPI_Status status; int send_size, recv_size; - MPI_Type_size(sendtype, &send_size); - MPI_Type_size(recvtype, &recv_size); + MPI_ADVANCE_SUCCESS_OR_RETURN(MPI_Type_size(sendtype, &send_size)); + MPI_ADVANCE_SUCCESS_OR_RETURN(MPI_Type_size(recvtype, &recv_size)); // Send to rank + i // Recv from rank - i @@ -89,10 +90,12 @@ int alltoall_pairwise(const void* sendbuf, send_pos = send_proc * sendcount * send_size; recv_pos = recv_proc * recvcount * recv_size; - MPI_Sendrecv(sendbuf + send_pos, sendcount, sendtype, send_proc, tag, + MPI_ADVANCE_SUCCESS_OR_RETURN(MPI_Sendrecv(sendbuf + send_pos, sendcount, sendtype, send_proc, tag, recvbuf + recv_pos, recvcount, recvtype, recv_proc, tag, - comm, &status); + comm, &status)); } + + return MPI_SUCCESS; } int alltoall_bruck(const void* sendbuf, diff --git a/src/collective/bcast.c b/src/collective/bcast.c index c85754fef..e7c288661 100644 --- a/src/collective/bcast.c +++ b/src/collective/bcast.c @@ -1,5 +1,6 @@ #include "bcast.h" #include +#include "error.h" // TODO : currently root is always 0 int bcast(void* buffer, @@ -9,8 +10,8 @@ int bcast(void* buffer, MPI_Comm comm) { int rank, num_procs; - MPI_Comm_rank(comm, &rank); - MPI_Comm_size(comm, &num_procs); + MPI_ADVANCE_SUCCESS_OR_RETURN(MPI_Comm_rank(comm, &rank)); + MPI_ADVANCE_SUCCESS_OR_RETURN(MPI_Comm_size(comm, &num_procs)); int num_steps = log2(num_procs); int tag = 204857; @@ -22,14 +23,15 @@ int bcast(void* buffer, if (rank % (stride*2) == 0) { // Sending Proc - MPI_Send(buffer, count, datatype, rank + stride, tag, comm); + MPI_ADVANCE_SUCCESS_OR_RETURN(MPI_Send(buffer, count, datatype, rank + stride, tag, comm)); } else if (rank % stride == 0) { // Recving Proc - MPI_Recv(buffer, count, datatype, rank - stride, tag, comm, &status); + MPI_ADVANCE_SUCCESS_OR_RETURN(MPI_Recv(buffer, count, datatype, rank - stride, tag, comm, &status)); } stride /= 2; } + return MPI_SUCCESS; } diff --git a/src/collective/gather.c b/src/collective/gather.c index 472b1b345..baf396f60 100644 --- a/src/collective/gather.c +++ b/src/collective/gather.c @@ -1,6 +1,8 @@ #include "gather.h" #include #include +#include "error.h" + // TODO : Currently root is always 0 int gather(const void* sendbuf, @@ -13,11 +15,11 @@ int gather(const void* sendbuf, MPI_Comm comm) { int rank, num_procs; - MPI_Comm_rank(comm, &rank); - MPI_Comm_size(comm, &num_procs); + MPI_ADVANCE_SUCCESS_OR_RETURN(MPI_Comm_rank(comm, &rank)); + MPI_ADVANCE_SUCCESS_OR_RETURN(MPI_Comm_size(comm, &num_procs)); int recv_size; - MPI_Type_size(recvtype, &recv_size); + MPI_ADVANCE_SUCCESS_OR_RETURN(MPI_Type_size(recvtype, &recv_size)); int num_steps = log2(num_procs); int tag = 204857; @@ -32,17 +34,18 @@ int gather(const void* sendbuf, if (rank % (stride*2)) { // Sending Proc - MPI_Send(recvbuf, recvcount*stride, recvtype, rank - stride, tag, comm); + MPI_ADVANCE_SUCCESS_OR_RETURN(MPI_Send(recvbuf, recvcount*stride, recvtype, rank - stride, tag, comm)); break; } else { // Recving Proc - MPI_Recv(&(recv_buffer[recvcount*stride*recv_size]), recvcount*stride, recvtype, - rank + stride, tag, comm, &status); + MPI_ADVANCE_SUCCESS_OR_RETURN(MPI_Recv(&(recv_buffer[recvcount*stride*recv_size]), recvcount*stride, recvtype, + rank + stride, tag, comm, &status)); } stride *= 2; } + return MPI_SUCCESS; } diff --git a/src/error.h b/src/error.h new file mode 100644 index 000000000..f56aef618 --- /dev/null +++ b/src/error.h @@ -0,0 +1,6 @@ +#pragma once + +#include + +#define MPI_ADVANCE_SUCCESS_OR_RETURN(_code) \ + {if (MPI_SUCCESS != _code) return _code; }