-int PMPI_Cart_create(MPI_Comm comm_old, int ndims, int* dims, int* periodic, int reorder, MPI_Comm* comm_cart) {
- if (comm_old == MPI_COMM_NULL){
- return MPI_ERR_COMM;
- } else if (ndims < 0 || (ndims > 0 && (dims == nullptr || periodic == nullptr)) || comm_cart == nullptr) {
- return MPI_ERR_ARG;
- } else{
- simgrid::smpi::Topo_Cart* topo = new simgrid::smpi::Topo_Cart(comm_old, ndims, dims, periodic, reorder, comm_cart);
- if(*comm_cart==MPI_COMM_NULL)
- delete topo;
- return MPI_SUCCESS;
+int PMPI_Cart_create(MPI_Comm comm_old, int ndims, const int* dims, const int* periodic, int reorder, MPI_Comm* comm_cart) {
+ CHECK_COMM2(1, comm_old)
+ if (ndims > 0){
+ CHECK_NULL(3, MPI_ERR_ARG, dims)
+ CHECK_NULL(4, MPI_ERR_ARG, periodic)
+ CHECK_NULL(6, MPI_ERR_ARG, comm_cart)
+ }
+ CHECK_NEGATIVE(2, MPI_ERR_ARG, ndims)
+ for (int i = 0; i < ndims; i++)
+ CHECK_NEGATIVE(2, MPI_ERR_ARG, dims[i])
+ const simgrid::smpi::Topo_Cart* topo =
+ new simgrid::smpi::Topo_Cart(comm_old, ndims, dims, periodic, reorder, comm_cart);
+ if (*comm_cart == MPI_COMM_NULL) {
+ delete topo;
+ } else {
+ xbt_assert((*comm_cart)->topo().get() == topo);