This source file includes following definitions.
- MPI_Cart_rank
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/topo.h"
33 #include "ompi/memchecker.h"
34
35 #if OMPI_BUILD_MPI_PROFILING
36 #if OPAL_HAVE_WEAK_SYMBOLS
37 #pragma weak MPI_Cart_rank = PMPI_Cart_rank
38 #endif
39 #define MPI_Cart_rank PMPI_Cart_rank
40 #endif
41
42 static const char FUNC_NAME[] = "MPI_Cart_rank";
43
44 int MPI_Cart_rank(MPI_Comm comm, const int coords[], int *rank)
45 {
46 int i, err;
47
48 MEMCHECKER(
49 memchecker_comm(comm);
50 );
51
52
53 if (MPI_PARAM_CHECK) {
54 mca_topo_base_comm_cart_2_2_0_t* cart;
55 OMPI_ERR_INIT_FINALIZE(FUNC_NAME);
56 if (ompi_comm_invalid(comm)) {
57 return OMPI_ERRHANDLER_INVOKE (MPI_COMM_WORLD, MPI_ERR_COMM,
58 FUNC_NAME);
59 }
60 if (OMPI_COMM_IS_INTER(comm)) {
61 return OMPI_ERRHANDLER_INVOKE (comm, MPI_ERR_COMM,
62 FUNC_NAME);
63 }
64
65
66
67
68 if (!OMPI_COMM_IS_CART(comm)) {
69 return OMPI_ERRHANDLER_INVOKE (comm, MPI_ERR_TOPOLOGY,
70 FUNC_NAME);
71 }
72
73 cart = comm->c_topo->mtc.cart;
74
75
76 if (((NULL == coords) &&
77 (cart->ndims >= 1)) ||
78 (NULL == rank)){
79 return OMPI_ERRHANDLER_INVOKE (comm, MPI_ERR_ARG,
80 FUNC_NAME);
81 }
82
83
84
85 for (i = 0; i < cart->ndims; ++i) {
86 if (!cart->periods[i] &&
87 (coords[i] < 0 ||
88 coords[i] >= cart->dims[i])) {
89 return OMPI_ERRHANDLER_INVOKE(comm, MPI_ERR_ARG, FUNC_NAME);
90 }
91 }
92 } else {
93
94
95 if (!OMPI_COMM_IS_CART(comm)) {
96 return OMPI_ERRHANDLER_INVOKE (comm, MPI_ERR_TOPOLOGY,
97 FUNC_NAME);
98 }
99 }
100 OPAL_CR_ENTER_LIBRARY();
101
102 err = comm->c_topo->topo.cart.cart_rank(comm, coords, rank);
103 OPAL_CR_EXIT_LIBRARY();
104
105 OMPI_ERRHANDLER_RETURN(err, comm, err, FUNC_NAME);
106 }