- if (comm == MPI_COMM_NULL)
- return MPI_ERR_COMM;
- if (((comm->rank() == root) && (sendtype == MPI_DATATYPE_NULL || not sendtype->is_valid())) ||
- ((recvbuf != MPI_IN_PLACE) && (recvtype == MPI_DATATYPE_NULL || not recvtype->is_valid())))
- return MPI_ERR_TYPE;
- if (((comm->rank() == root) && (sendcount < 0)) || ((recvbuf != MPI_IN_PLACE) && (recvcount < 0)))
- return MPI_ERR_COUNT;
- if ((sendbuf == recvbuf) || ((comm->rank() == root) && sendcount > 0 && (sendbuf == nullptr)) ||
- (recvcount > 0 && recvbuf == nullptr))
- return MPI_ERR_BUFFER;
- if (root < 0 || root >= comm->size())
- return MPI_ERR_ROOT;
- if (request == nullptr)
- return MPI_ERR_ARG;
+ CHECK_ARGS(comm == MPI_COMM_NULL, MPI_ERR_COMM,
+ "(I)Scatter: the communicator cannot be MPI_COMM_NULL");
+ CHECK_ARGS(recvbuf == nullptr && recvcount > 0, MPI_ERR_BUFFER,
+ "(I)Scatter: param 4 recvbuf cannot be NULL");
+ CHECK_ARGS(((sendbuf == recvbuf) || ((comm->rank() == root) && sendcount > 0 && (sendbuf == nullptr))), MPI_ERR_BUFFER,
+ "(I)Scatter: param 1 sendbuf cannot be NULL when sendcount > 0");
+ CHECK_ARGS(((comm->rank() == root) && (sendtype == MPI_DATATYPE_NULL || not sendtype->is_valid())), MPI_ERR_TYPE,
+ "(I)Scatter: param 3 sendtype cannot be MPI_DATATYPE_NULL or invalid on root");
+ CHECK_ARGS(((recvbuf != MPI_IN_PLACE) && (recvtype == MPI_DATATYPE_NULL || not recvtype->is_valid())), MPI_ERR_TYPE,
+ "(I)Scatter: param 6 recvtype cannot be MPI_DATATYPE_NULL or invalid when recvbuf is not MPI_IN_PLACE");
+ CHECK_ARGS(((comm->rank() == root) && (sendcount < 0)), MPI_ERR_COUNT,
+ "(I)Scatter: param 2 sendcount cannot be negative");
+ CHECK_ARGS(((recvbuf != MPI_IN_PLACE) && (recvcount < 0)), MPI_ERR_COUNT,
+ "(I)Scatter: param 5 recvcount cannot be negative");
+ CHECK_ARGS(root < 0, MPI_ERR_ROOT,
+ "(I)Scatter: root cannot be negative");
+ CHECK_ARGS(root >= comm->size(), MPI_ERR_ROOT,
+ "(I)Scatter: root (=%d) is larger than communicator size (=%d)", root,
+ comm->size());
+ CHECK_ARGS(request == nullptr, MPI_ERR_ARG,
+ "Iscatter: param 9 request cannot be NULL");