This source file includes following definitions.
- ADIOI_GEN_WriteStrided_naive
1
2
3
4
5
6
7
8 #include "adio.h"
9 #include "adio_extern.h"
10
11 void ADIOI_GEN_WriteStrided_naive(ADIO_File fd, const void *buf, int count,
12 MPI_Datatype buftype, int file_ptr_type,
13 ADIO_Offset offset, ADIO_Status *status, int
14 *error_code)
15 {
16
17
18 ADIOI_Flatlist_node *flat_buf, *flat_file;
19
20 ADIO_Offset bwr_size, fwr_size=0, sum, size_in_filetype;
21 int b_index;
22 MPI_Count bufsize;
23 ADIO_Offset n_etypes_in_filetype;
24 ADIO_Offset size, n_filetypes, etype_in_filetype;
25 ADIO_Offset abs_off_in_filetype=0, req_len;
26 MPI_Count filetype_size, etype_size, buftype_size;
27 MPI_Aint filetype_extent, buftype_extent, lb;
28 int buf_count, buftype_is_contig, filetype_is_contig;
29 ADIO_Offset userbuf_off;
30 ADIO_Offset off, req_off, disp, end_offset=0, start_off;
31 ADIO_Status status1;
32
33 *error_code = MPI_SUCCESS;
34
35 ADIOI_Datatype_iscontig(buftype, &buftype_is_contig);
36 ADIOI_Datatype_iscontig(fd->filetype, &filetype_is_contig);
37
38 MPI_Type_size_x(fd->filetype, &filetype_size);
39 if ( ! filetype_size ) {
40 #ifdef HAVE_STATUS_SET_BYTES
41 MPIR_Status_set_bytes(status, buftype, 0);
42 #endif
43 *error_code = MPI_SUCCESS;
44 return;
45 }
46
47 MPI_Type_get_extent(fd->filetype, &lb, &filetype_extent);
48 MPI_Type_size_x(buftype, &buftype_size);
49 MPI_Type_get_extent(buftype, &lb, &buftype_extent);
50 etype_size = fd->etype_size;
51
52 ADIOI_Assert((buftype_size * count) == ((ADIO_Offset)(unsigned)buftype_size * (ADIO_Offset)count));
53 bufsize = buftype_size * count;
54
55
56
57 if (!buftype_is_contig && filetype_is_contig) {
58 int b_count;
59
60
61 flat_buf = ADIOI_Flatten_and_find(buftype);
62
63 off = (file_ptr_type == ADIO_INDIVIDUAL) ? fd->fp_ind :
64 fd->disp + (ADIO_Offset)etype_size * offset;
65
66 start_off = off;
67 end_offset = off + bufsize - 1;
68
69
70 if ((fd->atomicity) && ADIO_Feature(fd, ADIO_LOCKS))
71 {
72 ADIOI_WRITE_LOCK(fd, start_off, SEEK_SET, end_offset-start_off+1);
73 }
74
75
76
77
78 for (b_count=0; b_count < count; b_count++) {
79 for (b_index=0; b_index < flat_buf->count; b_index++) {
80 userbuf_off = (ADIO_Offset)b_count*(ADIO_Offset)buftype_extent +
81 flat_buf->indices[b_index];
82 req_off = off;
83 req_len = flat_buf->blocklens[b_index];
84
85 ADIOI_Assert(req_len == (int) req_len);
86 ADIOI_Assert((((ADIO_Offset)(MPIU_Upint)buf) + userbuf_off) == (ADIO_Offset)(MPIU_Upint)((MPIU_Upint)buf + userbuf_off));
87 ADIO_WriteContig(fd,
88 (char *) buf + userbuf_off,
89 (int)req_len,
90 MPI_BYTE,
91 ADIO_EXPLICIT_OFFSET,
92 req_off,
93 &status1,
94 error_code);
95 if (*error_code != MPI_SUCCESS) return;
96
97
98 off += flat_buf->blocklens[b_index];
99 }
100 }
101
102 if ((fd->atomicity) && ADIO_Feature(fd, ADIO_LOCKS))
103 {
104 ADIOI_UNLOCK(fd, start_off, SEEK_SET, end_offset-start_off+1);
105 }
106
107 if (file_ptr_type == ADIO_INDIVIDUAL) fd->fp_ind = off;
108
109 }
110
111 else {
112 int f_index, st_index = 0;
113 ADIO_Offset st_fwr_size, st_n_filetypes;
114 int flag;
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131 flat_file = ADIOI_Flatlist;
132 while (flat_file->type != fd->filetype) flat_file = flat_file->next;
133 disp = fd->disp;
134
135 if (file_ptr_type == ADIO_INDIVIDUAL) {
136 start_off = fd->fp_ind;
137 n_filetypes = -1;
138 flag = 0;
139 while (!flag) {
140 n_filetypes++;
141 for (f_index=0; f_index < flat_file->count; f_index++) {
142 if (disp + flat_file->indices[f_index] +
143 n_filetypes*(ADIO_Offset)filetype_extent +
144 flat_file->blocklens[f_index] >= start_off)
145 {
146
147
148 st_index = f_index;
149 fwr_size = disp + flat_file->indices[f_index] +
150 n_filetypes*(ADIO_Offset)filetype_extent +
151 flat_file->blocklens[f_index] - start_off;
152 flag = 1;
153 break;
154 }
155 }
156 }
157 }
158 else {
159 n_etypes_in_filetype = filetype_size/etype_size;
160 n_filetypes = offset / n_etypes_in_filetype;
161 etype_in_filetype = offset % n_etypes_in_filetype;
162 size_in_filetype = etype_in_filetype * etype_size;
163
164 sum = 0;
165 for (f_index=0; f_index < flat_file->count; f_index++) {
166 sum += flat_file->blocklens[f_index];
167 if (sum > size_in_filetype) {
168 st_index = f_index;
169 fwr_size = sum - size_in_filetype;
170 abs_off_in_filetype = flat_file->indices[f_index] +
171 size_in_filetype -
172 (sum - flat_file->blocklens[f_index]);
173 break;
174 }
175 }
176
177
178 start_off = disp + n_filetypes*(ADIO_Offset)filetype_extent +
179 abs_off_in_filetype;
180 }
181
182 st_fwr_size = fwr_size;
183 st_n_filetypes = n_filetypes;
184
185
186
187
188
189
190
191
192 userbuf_off = 0;
193 f_index = st_index;
194 off = start_off;
195 fwr_size = ADIOI_MIN(st_fwr_size, bufsize);
196 while (userbuf_off < bufsize) {
197 userbuf_off += fwr_size;
198 end_offset = off + fwr_size - 1;
199
200 if (f_index < (flat_file->count - 1)) f_index++;
201 else {
202 f_index = 0;
203 n_filetypes++;
204 }
205
206 off = disp + flat_file->indices[f_index] +
207 n_filetypes*(ADIO_Offset)filetype_extent;
208 fwr_size = ADIOI_MIN(flat_file->blocklens[f_index],
209 bufsize-(unsigned)userbuf_off);
210 }
211
212
213
214
215
216
217
218
219
220
221
222 if ((fd->atomicity) && ADIO_Feature(fd, ADIO_LOCKS))
223 {
224 ADIOI_WRITE_LOCK(fd, start_off, SEEK_SET, end_offset-start_off+1);
225 }
226
227 if (buftype_is_contig && !filetype_is_contig) {
228
229
230
231
232 userbuf_off = 0;
233 f_index = st_index;
234 off = start_off;
235 n_filetypes = st_n_filetypes;
236 fwr_size = ADIOI_MIN(st_fwr_size, bufsize);
237
238
239 while (userbuf_off < bufsize) {
240 if (fwr_size) {
241
242
243 req_off = off;
244 req_len = fwr_size;
245
246 ADIOI_Assert(req_len == (int) req_len);
247 ADIOI_Assert((((ADIO_Offset)(MPIU_Upint)buf) + userbuf_off) == (ADIO_Offset)(MPIU_Upint)((MPIU_Upint)buf + userbuf_off));
248 ADIO_WriteContig(fd,
249 (char *) buf + userbuf_off,
250 (int)req_len,
251 MPI_BYTE,
252 ADIO_EXPLICIT_OFFSET,
253 req_off,
254 &status1,
255 error_code);
256 if (*error_code != MPI_SUCCESS) return;
257 }
258 userbuf_off += fwr_size;
259
260 if (off + fwr_size < disp + flat_file->indices[f_index] +
261 flat_file->blocklens[f_index] +
262 n_filetypes*(ADIO_Offset)filetype_extent)
263 {
264
265
266
267
268 off += fwr_size;
269 }
270
271
272
273 else {
274 if (f_index < (flat_file->count - 1)) f_index++;
275 else {
276 f_index = 0;
277 n_filetypes++;
278 }
279 off = disp + flat_file->indices[f_index] +
280 n_filetypes*(ADIO_Offset)filetype_extent;
281 fwr_size = ADIOI_MIN(flat_file->blocklens[f_index],
282 bufsize-(unsigned)userbuf_off);
283 }
284 }
285 }
286 else {
287 ADIO_Offset i_offset, tmp_bufsize = 0;
288
289
290 flat_buf = ADIOI_Flatten_and_find(buftype);
291
292 b_index = buf_count = 0;
293 i_offset = flat_buf->indices[0];
294 f_index = st_index;
295 off = start_off;
296 n_filetypes = st_n_filetypes;
297 fwr_size = st_fwr_size;
298 bwr_size = flat_buf->blocklens[0];
299
300
301 while (tmp_bufsize < bufsize) {
302 ADIO_Offset new_bwr_size = bwr_size, new_fwr_size = fwr_size;
303
304 size = ADIOI_MIN(fwr_size, bwr_size);
305 if (size) {
306 req_off = off;
307 req_len = size;
308 userbuf_off = i_offset;
309
310 ADIOI_Assert(req_len == (int) req_len);
311 ADIOI_Assert((((ADIO_Offset)(MPIU_Upint)buf) + userbuf_off) == (ADIO_Offset)(MPIU_Upint)((MPIU_Upint)buf + userbuf_off));
312 ADIO_WriteContig(fd,
313 (char *) buf + userbuf_off,
314 (int)req_len,
315 MPI_BYTE,
316 ADIO_EXPLICIT_OFFSET,
317 req_off,
318 &status1,
319 error_code);
320 if (*error_code != MPI_SUCCESS) return;
321 }
322
323 if (size == fwr_size) {
324
325 if (f_index < (flat_file->count - 1)) f_index++;
326 else {
327 f_index = 0;
328 n_filetypes++;
329 }
330
331 off = disp + flat_file->indices[f_index] +
332 n_filetypes*(ADIO_Offset)filetype_extent;
333
334 new_fwr_size = flat_file->blocklens[f_index];
335 if (size != bwr_size) {
336 i_offset += size;
337 new_bwr_size -= size;
338 }
339 }
340
341 if (size == bwr_size) {
342
343
344 b_index = (b_index + 1)%flat_buf->count;
345 buf_count++;
346 i_offset = (ADIO_Offset)buftype_extent*(ADIO_Offset)(buf_count/flat_buf->count) +
347 flat_buf->indices[b_index];
348 new_bwr_size = flat_buf->blocklens[b_index];
349 if (size != fwr_size) {
350 off += size;
351 new_fwr_size -= size;
352 }
353 }
354 tmp_bufsize += size;
355 fwr_size = new_fwr_size;
356 bwr_size = new_bwr_size;
357 }
358 }
359
360
361 if ((fd->atomicity) && ADIO_Feature(fd, ADIO_LOCKS))
362 {
363 ADIOI_UNLOCK(fd, start_off, SEEK_SET, end_offset-start_off+1);
364 }
365
366 if (file_ptr_type == ADIO_INDIVIDUAL) fd->fp_ind = off;
367 }
368
369 fd->fp_sys_posn = -1;
370
371 #ifdef HAVE_STATUS_SET_BYTES
372 MPIR_Status_set_bytes(status, buftype, bufsize);
373
374
375
376 #endif
377
378 if (!buftype_is_contig) ADIOI_Delete_flattened(buftype);
379 }