This source file includes following definitions.
- MPI_Cart_create
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
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
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
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
93
94
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
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
115 return MPI_SUCCESS;
116 }