This source file includes following definitions.
- mca_topo_base_cart_shift
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21 #include "ompi_config.h"
22 #include "ompi/mca/topo/base/base.h"
23 #include "ompi/communicator/communicator.h"
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40 int mca_topo_base_cart_shift(ompi_communicator_t* comm,
41 int direction,
42 int disp,
43 int *rank_source,
44 int *rank_dest)
45 {
46 int factor, thisdirection = 0, thisperiod = 0, ord;
47 int srcord, destord, i, *d, *q;
48
49
50
51
52 ord = ompi_comm_rank(comm);
53
54 if (disp == 0) {
55 *rank_dest = *rank_source = ord;
56 return MPI_SUCCESS;
57 }
58
59
60
61 factor = ompi_comm_size(comm);
62 d = comm->c_topo->mtc.cart->dims;
63 q = comm->c_topo->mtc.cart->periods;
64 for (i = 0; (i < comm->c_topo->mtc.cart->ndims) && (i <= direction); ++i, ++d, ++q) {
65 thisdirection = *d;
66 thisperiod = *q;
67
68 ord %= factor;
69 factor /= thisdirection;
70 }
71
72 ord /= factor;
73
74
75
76 *rank_source = *rank_dest = MPI_UNDEFINED;
77
78 srcord = ord - disp;
79 destord = ord + disp;
80 if ( ((destord < 0) || (destord >= thisdirection)) && (!thisperiod) ) {
81 *rank_dest = MPI_PROC_NULL;
82 } else {
83 destord %= thisdirection;
84 if (destord < 0) destord += thisdirection;
85 *rank_dest = ompi_comm_rank(comm);
86 *rank_dest += ((destord - ord) * factor);
87 }
88 if ( ((srcord < 0) || (srcord >= thisdirection)) && (!thisperiod) ) {
89 *rank_source = MPI_PROC_NULL;
90 } else {
91 srcord %= thisdirection;
92 if (srcord < 0) srcord += thisdirection;
93 *rank_source= ompi_comm_rank(comm);
94 *rank_source += ((srcord - ord) * factor);
95 }
96
97 return MPI_SUCCESS;
98 }