root/ompi/mpi/c/cart_create.c

/* [<][>][^][v][top][bottom][index][help] */

DEFINITIONS

This source file includes following definitions.
  1. MPI_Cart_create

   1 /* -*- Mode: C; c-basic-offset:4 ; indent-tabs-mode:nil -*- */
   2 /*
   3  * Copyright (c) 2004-2007 The Trustees of Indiana University and Indiana
   4  *                         University Research and Technology
   5  *                         Corporation.  All rights reserved.
   6  * Copyright (c) 2004-2013 The University of Tennessee and The University
   7  *                         of Tennessee Research Foundation.  All rights
   8  *                         reserved.
   9  * Copyright (c) 2004-2008 High Performance Computing Center Stuttgart,
  10  *                         University of Stuttgart.  All rights reserved.
  11  * Copyright (c) 2004-2005 The Regents of the University of California.
  12  *                         All rights reserved.
  13  * Copyright (c) 2007-2008 Cisco Systems, Inc.  All rights reserved.
  14  * Copyright (c) 2012-2013 Los Alamos National Security, LLC.  All rights
  15  *                         reserved.
  16  * Copyright (c) 2012-2013 Inria.  All rights reserved.
  17  * Copyright (c) 2015      Research Organization for Information Science
  18  *                         and Technology (RIST). All rights reserved.
  19  * $COPYRIGHT$
  20  *
  21  * Additional copyrights may follow
  22  *
  23  * $HEADER$
  24  */
  25 #include "ompi_config.h"
  26 #include <stdio.h>
  27 
  28 #include "ompi/mpi/c/bindings.h"
  29 #include "ompi/runtime/params.h"
  30 #include "ompi/communicator/communicator.h"
  31 #include "ompi/errhandler/errhandler.h"
  32 #include "ompi/mca/topo/base/base.h"
  33 #include "ompi/memchecker.h"
  34 
  35 #if OMPI_BUILD_MPI_PROFILING
  36 #if OPAL_HAVE_WEAK_SYMBOLS
  37 #pragma weak MPI_Cart_create = PMPI_Cart_create
  38 #endif
  39 #define MPI_Cart_create PMPI_Cart_create
  40 #endif
  41 
  42 static const char FUNC_NAME[] = "MPI_Cart_create";
  43 
  44 
  45 int MPI_Cart_create(MPI_Comm old_comm, int ndims, const int dims[],
  46                     const int periods[], int reorder, MPI_Comm *comm_cart)
  47 {
  48     mca_topo_base_module_t* topo;
  49     int err;
  50 
  51     MEMCHECKER(
  52         memchecker_comm(old_comm);
  53     );
  54 
  55     /* check the arguments */
  56     if (MPI_PARAM_CHECK) {
  57         OMPI_ERR_INIT_FINALIZE(FUNC_NAME);
  58         if (ompi_comm_invalid(old_comm)) {
  59             return OMPI_ERRHANDLER_INVOKE (MPI_COMM_WORLD, MPI_ERR_COMM,
  60                                           FUNC_NAME);
  61         } else if (OMPI_COMM_IS_INTER(old_comm)) {
  62             return OMPI_ERRHANDLER_INVOKE(MPI_COMM_WORLD, MPI_ERR_COMM,
  63                                           FUNC_NAME);
  64         }
  65         if (ndims < 0) {
  66             return OMPI_ERRHANDLER_INVOKE (old_comm, MPI_ERR_ARG,
  67                                           FUNC_NAME);
  68         } else if (ndims >= 1 &&
  69                    (NULL == dims || NULL == periods || NULL == comm_cart)) {
  70             return OMPI_ERRHANDLER_INVOKE (old_comm, MPI_ERR_ARG,
  71                                           FUNC_NAME);
  72         }
  73 
  74         /* check if the number of processes on the grid are correct */
  75         {
  76            int i, count_nodes = 1;
  77            const int *p = dims;
  78            int parent_procs = ompi_comm_size(old_comm);
  79 
  80            for (i=0; i < ndims; i++, p++) {
  81                count_nodes *= *p;
  82            }
  83 
  84            if (parent_procs < count_nodes) {
  85                return OMPI_ERRHANDLER_INVOKE (old_comm, MPI_ERR_ARG,
  86                                               FUNC_NAME);
  87            }
  88         }
  89     }
  90 
  91     /*
  92      * everything seems to be alright with the communicator, we can go
  93      * ahead and select a topology module for this purpose and create
  94      * the new graph communicator
  95      */
  96     if (OMPI_SUCCESS != (err = mca_topo_base_comm_select(old_comm,
  97                                                          NULL,
  98                                                          &topo,
  99                                                          OMPI_COMM_CART))) {
 100         return err;
 101     }
 102 
 103     /* Now let that topology module rearrange procs/ranks if it wants to */
 104     err = topo->topo.cart.cart_create(topo, old_comm,
 105                                       ndims, dims, periods,
 106                                       (0 == reorder) ? false : true, comm_cart);
 107     OPAL_CR_EXIT_LIBRARY();
 108 
 109     if (MPI_SUCCESS != err) {
 110         OBJ_RELEASE(topo);
 111         return OMPI_ERRHANDLER_INVOKE(old_comm, err, FUNC_NAME);
 112     }
 113 
 114     /* All done */
 115     return MPI_SUCCESS;
 116 }

/* [<][>][^][v][top][bottom][index][help] */