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
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101#include "fc_feature_defs.inc"
102PROGRAM unstruct_halo_exchang
103 USE mpi
109
110#if defined __PGI && ( __PGIC__ == 15 || __PGIC__ == 14 )
113#endif
114 IMPLICIT NONE
115
116 INTEGER :: comm_rank, comm_size
117 INTEGER :: i, j, rank, ierror
118
119 INTEGER(xi) :: local_indices(12, 0:2), idx
120 INTEGER(xi) :: halo_indices(5, 0:2)
121 INTEGER(xi) :: src_indices(12, 0:2), tgt_indices(5, 0:2)
122 INTEGER :: src_offsets(12)
123 INTEGER :: tgt_offsets(5)
124
125 TYPE(xt_idxlist) :: src_idxlist, tgt_idxlist
126 TYPE(xt_xmap) :: xmap
127 TYPE(xt_redist) :: redist
128 DOUBLE PRECISION :: src_data(12), tgt_data(12)
129
130 CHARACTER(64) :: fmt
131
132 CALL mpi_init(ierror)
133 IF (ierror /= mpi_success) stop 1
135 CALL mpi_comm_rank(mpi_comm_world, comm_rank, ierror)
136 IF (ierror /= mpi_success) stop 1
137 CALL mpi_comm_size (mpi_comm_world, comm_size, ierror)
138 IF (ierror /= mpi_success) stop 1
139
140 IF (comm_size /= 3) stop 3
141
142
143 local_indices(:,0) = (/ 1_xi, 4_xi, 8_xi, &
144 & 0_xi, 3_xi, 7_xi, 12_xi, &
145 & 2_xi, 6_xi, 11_xi, &
146 & 5_xi, 10_xi /)
147 local_indices(:,1) = (/ 4_xi, 8_xi, 13_xi, &
148 & 3_xi, 7_xi, 12_xi, 17_xi, &
149 & 6_xi, 11_xi, 16_xi, &
150 & 10_xi, 15_xi /)
151 local_indices(:,2) = (/ 3_xi, 7_xi, 12_xi, &
152 & 2_xi, 6_xi, 11_xi, 16_xi, &
153 & 5_xi, 10_xi, 15_xi, &
154 & 9_xi, 14_xi /)
155
156
157 halo_indices(:,0) = (/ 8_xi, 12_xi, 11_xi, 10_xi, 5_xi /)
158 halo_indices(:,1) = (/ 4_xi, 3_xi, 6_xi, 10_xi, 15_xi /)
159 halo_indices(:,2) = (/ 3_xi, 7_xi, 12_xi, 2_xi, 16_xi /)
160
161 DO rank = 0, comm_size - 1
162 DO i = 1, SIZE(local_indices, 1)
163 idx = local_indices(i, rank)
164 src_indices(i, rank) = merge(-1_xi, idx, any(halo_indices(:, rank) == idx))
165 END DO
166 tgt_indices(:, rank) = halo_indices(:, rank)
167 END DO
168
169
170 src_idxlist =
xt_idxvec_new(src_indices(:,comm_rank),
SIZE(src_indices, 1))
171 tgt_idxlist =
xt_idxvec_new(tgt_indices(:,comm_rank),
SIZE(tgt_indices, 1))
172
173
175
176
177 src_offsets = (/(i, i = 0, SIZE(src_indices, 1) - 1)/)
178 DO i = 1, SIZE(halo_indices, 1)
179 DO j = 1, SIZE(local_indices, 1)
180 IF (halo_indices(i, comm_rank) == local_indices(j, comm_rank)) &
181 tgt_offsets(i) = j - 1
182 END DO
183 END DO
185 & mpi_double_precision)
186
187
188 src_data(:) = dble(src_indices(:,comm_rank))
189 tgt_data(:) = dble(src_indices(:,comm_rank))
190
191 fmt = '(I1, " ", A, " exchange: ", xx(I3))'
192 WRITE(fmt(29:30), '(I2)') SIZE(src_data, 1)
193 print fmt, comm_rank, 'before', int(src_data(:))
194
195
197
198 print fmt, comm_rank, 'after ', int(tgt_data(:))
199
200
205
206
208 CALL mpi_finalize(ierror)
209 IF (ierror /= mpi_success) stop 1
210END PROGRAM unstruct_halo_exchang
211
212
213
214
215
216
217
218
219
220
221
void xt_initialize(MPI_Comm default_comm)
void xt_idxlist_delete(Xt_idxlist idxlist)
Xt_idxlist xt_idxvec_new(const Xt_int *idxlist, int num_indices)
void xt_redist_delete(Xt_redist redist)
void xt_redist_s_exchange(Xt_redist redist, int num_arrays, const void *const src_data[], void *const dst_data[])
Xt_redist xt_redist_p2p_off_new(Xt_xmap xmap, const int *src_offsets, const int *dst_offsets, MPI_Datatype datatype)
void xt_xmap_delete(Xt_xmap xmap)
Xt_xmap xt_xmap_all2all_new(Xt_idxlist src_idxlist, Xt_idxlist dst_idxlist, MPI_Comm comm)