-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathreduce.c
329 lines (283 loc) · 10.9 KB
/
reduce.c
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
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
/*
* Copyright (C) Bull S.A.S - 2024
*
* This program is free software; you can redistribute it and/or modify it under the terms of the
* GNU General Public License as published by the Free Software Foundation; either version 2 of the
* License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without
* even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* General Public License for more details.
*
* You should have received a copy of the GNU General Public License along with this program; if
* not, write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
* 02110-1301, USA.
*
* BXI Low Level Team
*
*/
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include "portals4.h"
#include "portals4_ext.h"
/*
* This example show how to make a sum calculus with more than two knots (here four knots).
*
* ┌──────────────────┐ ┌──────────────────┐ ┌──────────────────┐ ┌──────────────────┐
* │ │ │ │ │ │ │ │
* │ md = {1,2,3} │ │ md = {4,5,6} │ │ md = {7,8,9} │ │ md = {10,11,12} │
* │ │ │ │ │ │ │ │
* └──────────────────┴─┬─┴──────────────────┘ └──────────────────┴─┬─┴──────────────────┘
* │ │
* │ PtlAtomic(_, PTL_SUM, _) │ PtlAtomic(_, PTL_SUM, _)
* │ │
* ┌─────▼──────┐ ┌─────▼──────┐
* │ me0 = │ │ me0 = │
* │ {5,7,9} │ │ {17,19,21} │
* └─────┬──────┘ └─────┬──────┘
* │ md point to me.start │ md point to me.start
* ┌─────────▼──────────┐ ┌─────────▼──────────┐
* │ │ │ │
* │ md = {5,7,9} │ │ md = {17,19,21} │
* │ │ │ │
* └────────────────────┴─────────────┬────────────┴────────────────────┘
* │
* │ PtlTriggeredAtomic(_, PTL_SUM, _)
* │
* ┌──────────▼──────────┐
* │ │
* │ me1 = {22,26,30} │
* │ │
* └─────────────────────┘
*
*/
struct rank_info {
ptl_handle_ct_t counter;
int size;
int data[3]; /* represent the data of the first md */
int *middle_data; /* reprensent the data of me 0 */
int *final_data; /* represent the data of me1 */
};
/* used to link rank number to his rank_info */
struct rank_info ranks[4];
int rank_main(int rank, ptl_handle_ni_t nih, ptl_process_t id)
{
char *side;
ptl_handle_le_t leh;
ptl_handle_md_t mdh;
char msg[PTL_EV_STR_SIZE];
ptl_event_t ev;
ptl_ct_event_t ct_ev;
ptl_handle_eq_t eqh;
ptl_index_t pti0;
ptl_index_t pti1;
int ret = PtlEQAlloc(nih, 10, &eqh);
if (ret != PTL_OK) {
fprintf(stderr, "PtlEQAlloc failed : %s \n", PtlToStr(ret, PTL_STR_ERROR));
return 1;
}
ret = PtlPTAlloc(nih, 0, eqh, PTL_PT_ANY, &pti0);
if (ret != PTL_OK) {
fprintf(stderr, "PtlPTAlloc failed : %s \n", PtlToStr(ret, PTL_STR_ERROR));
return 1;
}
/* init me0 */
ptl_me_t me0 = { .start = ranks[rank].middle_data,
.length = ranks[rank].size,
.ct_handle = ranks[rank].counter,
.uid = PTL_UID_ANY,
.options = PTL_ME_OP_PUT | PTL_ME_EVENT_CT_COMM,
.match_id = PTL_NID_ANY,
.match_bits = 0,
.ignore_bits = 0,
.min_free = 0 };
ret = PtlCTGet(ranks[rank].counter, &ct_ev);
printf("success : %d \n", (int)ct_ev.success);
printf("failure : %d \n", (int)ct_ev.failure);
ret = PtlLEAppend(nih, pti0, &me0, PTL_PRIORITY_LIST, NULL, &leh);
if (ret != PTL_OK) {
fprintf(stderr, "PtlLEAppend failed : %s \n", PtlToStr(ret, PTL_STR_ERROR));
return 1;
}
/* wait for the link event */
ret = PtlEQWait(eqh, &ev);
if (ret != PTL_OK) {
fprintf(stderr, "PtlEQWait failed : %s \n", PtlToStr(ret, PTL_STR_ERROR));
return 1;
}
PtlEvToStr(0, &ev, msg);
printf("Event : %s", msg);
ptl_md_t md = { .start = ranks[rank].data,
.length = ranks[rank].size,
.options = 0,
.eq_handle = eqh,
.ct_handle = PTL_CT_NONE };
ret = PtlMDBind(nih, &md, &mdh);
if (ret != PTL_OK) {
fprintf(stderr, "PtlMDBind failed : %s \n", PtlToStr(ret, PTL_STR_ERROR));
return 1;
}
/* sending the content of md to me0 */
ret = PtlAtomic(mdh, 0, ranks[rank].size, PTL_ACK_REQ, id, pti0, 0, 0, NULL, 0, PTL_SUM,
PTL_UINT32_T);
if (ret != PTL_OK) {
fprintf(stderr, "PtlAtomic failed : %s \n", PtlToStr(ret, PTL_STR_ERROR));
return 1;
}
for (int i = 0; i < 3; i++) {
/* wait for the send, ack and atomic event */
ret = PtlEQWait(eqh, &ev);
if (ret != PTL_OK) {
fprintf(stderr, "PtlEQWait failed : %s \n", PtlToStr(ret, PTL_STR_ERROR));
return 1;
}
PtlEvToStr(0, &ev, msg);
printf("Event : %s", msg);
}
ret = PtlCTGet(ranks[rank].counter, &ct_ev);
printf("success : %d \n", (int)ct_ev.success);
printf("failure : %d \n", (int)ct_ev.failure);
if (rank % 2 == 0) {
side = "left";
} else {
side = "right";
}
int *num0 = me0.start;
printf("content of me0 %s: {%d,%d,%d} \n\n", side, num0[0], num0[1], num0[2]);
/* if we have completed me0 with both md */
ret = PtlPTAlloc(nih, 0, eqh, PTL_PT_ANY, &pti1);
if (ret != PTL_OK) {
fprintf(stderr, "PtlPTAlloc failed : %s \n", PtlToStr(ret, PTL_STR_ERROR));
return 1;
}
if (rank % 2 == 1) {
printf("counter is ready, let's perform triggered operation ! \n\n");
ptl_me_t me1 = { .start = ranks[rank].final_data,
.length = ranks[rank].size,
.ct_handle = ranks[rank].counter,
.uid = PTL_UID_ANY,
.options = PTL_ME_OP_PUT,
.match_id = PTL_NID_ANY,
.match_bits = 0,
.ignore_bits = 0,
.min_free = 0 };
ret = PtlLEAppend(nih, pti1, &me1, PTL_PRIORITY_LIST, NULL, &leh);
if (ret != PTL_OK) {
fprintf(stderr, "PtlLEAppend failed : %s \n", PtlToStr(ret, PTL_STR_ERROR));
return 1;
}
/* wait for the link event */
ret = PtlEQWait(eqh, &ev);
if (ret != PTL_OK) {
fprintf(stderr, "PtlEQWait failed : %s \n", PtlToStr(ret, PTL_STR_ERROR));
return 1;
}
PtlEvToStr(0, &ev, msg);
printf("Event : %s", msg);
/* we copy the start of me0 to the start of md */
md.start = me0.start;
ret = PtlMDBind(nih, &md, &mdh);
if (ret != PTL_OK) {
fprintf(stderr, "PtlMDBind failed : %s \n", PtlToStr(ret, PTL_STR_ERROR));
return 1;
}
ret = PtlTriggeredAtomic(mdh, 0, ranks[rank].size, PTL_ACK_REQ, id, pti1, 0, 0,
NULL, 0, PTL_SUM, PTL_UINT32_T, ranks[rank].counter, 2);
if (ret != PTL_OK) {
fprintf(stderr, "PtlAtomic failed : %s \n", PtlToStr(ret, PTL_STR_ERROR));
return 1;
}
for (int i = 0; i < 3; i++) {
/* wait for the send, ack and atomic event */
ret = PtlEQWait(eqh, &ev);
if (ret != PTL_OK) {
fprintf(stderr, "PtlEQWait failed : %s \n",
PtlToStr(ret, PTL_STR_ERROR));
return 1;
}
PtlEvToStr(0, &ev, msg);
printf("Event : %s", msg);
}
int *num0 = me1.start;
printf("content of me1 : {%d,%d,%d} \n\n", num0[0], num0[1], num0[2]);
}
return 0;
}
int main(void)
{
int ret;
ptl_handle_ni_t nih;
ptl_process_t id;
ptl_handle_ct_t counter0;
ptl_handle_ct_t counter1;
int rank0[3] = { 1, 2, 3 };
int rank1[3] = { 4, 5, 6 };
int rank2[3] = { 7, 8, 9 };
int rank3[3] = { 10, 11, 12 };
int data0[3] = { 0, 0, 0 };
int data1[3] = { 0, 0, 0 };
int data2[3] = { 0, 0, 0 };
/* init interface and handles */
ret = PtlInit();
if (ret != PTL_OK) {
fprintf(stderr, "PtlInit failed : %s \n", PtlToStr(ret, PTL_STR_ERROR));
return 1;
}
ret = PtlNIInit(PTL_IFACE_DEFAULT, PTL_NI_NO_MATCHING | PTL_NI_PHYSICAL, PTL_PID_ANY, NULL,
NULL, &nih);
if (ret != PTL_OK) {
fprintf(stderr, "PtlNIInit failed : %s \n", PtlToStr(ret, PTL_STR_ERROR));
return 1;
}
ret = PtlCTAlloc(nih, &counter0);
if (ret != PTL_OK) {
fprintf(stderr, "PtlCTAlloc failed : %s \n", PtlToStr(ret, PTL_STR_ERROR));
return 1;
}
ret = PtlCTAlloc(nih, &counter1);
if (ret != PTL_OK) {
fprintf(stderr, "PtlCTAlloc failed : %s \n", PtlToStr(ret, PTL_STR_ERROR));
return 1;
}
ret = PtlGetId(nih, &id);
if (ret != PTL_OK) {
fprintf(stderr, "PtlGetId failed : %s \n", PtlToStr(ret, PTL_STR_ERROR));
return 1;
}
/* start our atomic/triggered operations */
ranks[0].counter = counter0;
ranks[0].size = sizeof(rank0);
memcpy(ranks[0].data, rank0, 3 * sizeof(int));
ranks[0].middle_data = data0;
ret = rank_main(0, nih, id);
if (ret == 1) {
return 1;
}
ranks[1].counter = counter0;
ranks[1].size = sizeof(rank1);
memcpy(ranks[1].data, rank1, 3 * sizeof(int));
ranks[1].middle_data = data0;
ranks[1].final_data = data2;
ret = rank_main(1, nih, id);
if (ret == 1) {
return 1;
}
ranks[2].counter = counter1;
ranks[2].size = sizeof(rank2);
memcpy(ranks[2].data, rank2, 3 * sizeof(int));
ranks[2].middle_data = data1;
ret = rank_main(2, nih, id);
if (ret == 1) {
return 1;
}
ranks[3].counter = counter1;
ranks[3].size = sizeof(rank3);
memcpy(ranks[3].data, rank3, 3 * sizeof(int));
ranks[3].middle_data = data1;
ranks[3].final_data = data2;
ret = rank_main(3, nih, id);
if (ret == 1) {
return 1;
}
}