This source file includes following definitions.
- ADIOI_NFS_WriteContig
- ADIOI_NFS_WriteStrided
1
2
3
4
5
6
7
8 #include "ad_nfs.h"
9 #include "adio_extern.h"
10
11 void ADIOI_NFS_WriteContig(ADIO_File fd, const void *buf, int count,
12 MPI_Datatype datatype, int file_ptr_type,
13 ADIO_Offset offset, ADIO_Status *status, int *error_code)
14 {
15 int err=-1;
16 MPI_Count datatype_size, len;
17 static char myname[] = "ADIOI_NFS_WRITECONTIG";
18
19 MPI_Type_size_x(datatype, &datatype_size);
20 len = datatype_size * count;
21
22 if (file_ptr_type == ADIO_EXPLICIT_OFFSET) {
23 if (fd->fp_sys_posn != offset) {
24 #ifdef ADIOI_MPE_LOGGING
25 MPE_Log_event( ADIOI_MPE_lseek_a, 0, NULL );
26 #endif
27 lseek(fd->fd_sys, offset, SEEK_SET);
28 #ifdef ADIOI_MPE_LOGGING
29 MPE_Log_event( ADIOI_MPE_lseek_b, 0, NULL );
30 #endif
31 }
32 ADIOI_WRITE_LOCK(fd, offset, SEEK_SET, len);
33 #ifdef ADIOI_MPE_LOGGING
34 MPE_Log_event( ADIOI_MPE_write_a, 0, NULL );
35 #endif
36 err = write(fd->fd_sys, buf, len);
37 #ifdef ADIOI_MPE_LOGGING
38 MPE_Log_event( ADIOI_MPE_write_b, 0, NULL );
39 #endif
40 ADIOI_UNLOCK(fd, offset, SEEK_SET, len);
41 fd->fp_sys_posn = offset + err;
42
43 }
44 else {
45 offset = fd->fp_ind;
46 if (fd->fp_sys_posn != fd->fp_ind) {
47 #ifdef ADIOI_MPE_LOGGING
48 MPE_Log_event( ADIOI_MPE_lseek_a, 0, NULL );
49 #endif
50 lseek(fd->fd_sys, fd->fp_ind, SEEK_SET);
51 #ifdef ADIOI_MPE_LOGGING
52 MPE_Log_event( ADIOI_MPE_lseek_b, 0, NULL );
53 #endif
54 }
55 ADIOI_WRITE_LOCK(fd, offset, SEEK_SET, len);
56 #ifdef ADIOI_MPE_LOGGING
57 MPE_Log_event( ADIOI_MPE_write_a, 0, NULL );
58 #endif
59 err = write(fd->fd_sys, buf, len);
60 #ifdef ADIOI_MPE_LOGGING
61 MPE_Log_event( ADIOI_MPE_write_b, 0, NULL );
62 #endif
63 ADIOI_UNLOCK(fd, offset, SEEK_SET, len);
64 fd->fp_ind += err;
65 fd->fp_sys_posn = fd->fp_ind;
66 }
67
68
69 if (err == -1) {
70 *error_code = MPIO_Err_create_code(MPI_SUCCESS, MPIR_ERR_RECOVERABLE,
71 myname, __LINE__, MPI_ERR_IO,
72 "**io",
73 "**io %s", strerror(errno));
74 return;
75 }
76
77
78 #ifdef HAVE_STATUS_SET_BYTES
79 MPIR_Status_set_bytes(status, datatype, err);
80 #endif
81
82 *error_code = MPI_SUCCESS;
83 }
84
85
86
87
88 #ifdef ADIOI_MPE_LOGGING
89 #define ADIOI_BUFFERED_WRITE \
90 { \
91 if (req_off >= writebuf_off + writebuf_len) { \
92 MPE_Log_event( ADIOI_MPE_lseek_a, 0, NULL ); \
93 lseek(fd->fd_sys, writebuf_off, SEEK_SET); \
94 MPE_Log_event( ADIOI_MPE_lseek_b, 0, NULL ); \
95 MPE_Log_event( ADIOI_MPE_write_a, 0, NULL ); \
96 err = write(fd->fd_sys, writebuf, writebuf_len); \
97 MPE_Log_event( ADIOI_MPE_write_b, 0, NULL ); \
98 if (!(fd->atomicity)) ADIOI_UNLOCK(fd, writebuf_off, SEEK_SET, writebuf_len); \
99 if (err == -1) err_flag = 1; \
100 writebuf_off = req_off; \
101 writebuf_len = (int) (ADIOI_MIN(max_bufsize,end_offset-writebuf_off+1));\
102 if (!(fd->atomicity)) ADIOI_WRITE_LOCK(fd, writebuf_off, SEEK_SET, writebuf_len); \
103 MPE_Log_event( ADIOI_MPE_lseek_a, 0, NULL ); \
104 lseek(fd->fd_sys, writebuf_off, SEEK_SET); \
105 MPE_Log_event( ADIOI_MPE_lseek_b, 0, NULL ); \
106 MPE_Log_event( ADIOI_MPE_read_a, 0, NULL ); \
107 err = read(fd->fd_sys, writebuf, writebuf_len); \
108 MPE_Log_event( ADIOI_MPE_read_b, 0, NULL ); \
109 if (err == -1) { \
110 *error_code = MPIO_Err_create_code(MPI_SUCCESS, \
111 MPIR_ERR_RECOVERABLE, myname, \
112 __LINE__, MPI_ERR_IO, \
113 "**ioRMWrdwr", 0); \
114 goto fn_exit; \
115 } \
116 } \
117 write_sz = (int) (ADIOI_MIN(req_len, writebuf_off + writebuf_len - req_off)); \
118 memcpy(writebuf+req_off-writebuf_off, (char *)buf +userbuf_off, write_sz);\
119 while (write_sz != req_len) { \
120 MPE_Log_event( ADIOI_MPE_lseek_a, 0, NULL ); \
121 lseek(fd->fd_sys, writebuf_off, SEEK_SET); \
122 MPE_Log_event( ADIOI_MPE_lseek_b, 0, NULL ); \
123 MPE_Log_event( ADIOI_MPE_write_a, 0, NULL ); \
124 err = write(fd->fd_sys, writebuf, writebuf_len); \
125 MPE_Log_event( ADIOI_MPE_write_b, 0, NULL ); \
126 if (!(fd->atomicity)) ADIOI_UNLOCK(fd, writebuf_off, SEEK_SET, writebuf_len); \
127 if (err == -1) err_flag = 1; \
128 req_len -= write_sz; \
129 userbuf_off += write_sz; \
130 writebuf_off += writebuf_len; \
131 writebuf_len = (int) (ADIOI_MIN(max_bufsize,end_offset-writebuf_off+1));\
132 if (!(fd->atomicity)) ADIOI_WRITE_LOCK(fd, writebuf_off, SEEK_SET, writebuf_len); \
133 MPE_Log_event( ADIOI_MPE_lseek_a, 0, NULL ); \
134 lseek(fd->fd_sys, writebuf_off, SEEK_SET); \
135 MPE_Log_event( ADIOI_MPE_lseek_b, 0, NULL ); \
136 MPE_Log_event( ADIOI_MPE_read_a, 0, NULL ); \
137 err = read(fd->fd_sys, writebuf, writebuf_len); \
138 MPE_Log_event( ADIOI_MPE_read_b, 0, NULL ); \
139 if (err == -1) { \
140 *error_code = MPIO_Err_create_code(MPI_SUCCESS, \
141 MPIR_ERR_RECOVERABLE, myname, \
142 __LINE__, MPI_ERR_IO, \
143 "**ioRMWrdwr", 0); \
144 goto fn_exit; \
145 } \
146 write_sz = ADIOI_MIN(req_len, writebuf_len); \
147 memcpy(writebuf, (char *)buf + userbuf_off, write_sz);\
148 } \
149 }
150 #else
151 #define ADIOI_BUFFERED_WRITE \
152 { \
153 if (req_off >= writebuf_off + writebuf_len) { \
154 lseek(fd->fd_sys, writebuf_off, SEEK_SET); \
155 err = write(fd->fd_sys, writebuf, writebuf_len); \
156 if (!(fd->atomicity)) ADIOI_UNLOCK(fd, writebuf_off, SEEK_SET, writebuf_len); \
157 if (err == -1) err_flag = 1; \
158 writebuf_off = req_off; \
159 writebuf_len = (int) (ADIOI_MIN(max_bufsize,end_offset-writebuf_off+1));\
160 if (!(fd->atomicity)) ADIOI_WRITE_LOCK(fd, writebuf_off, SEEK_SET, writebuf_len); \
161 lseek(fd->fd_sys, writebuf_off, SEEK_SET); \
162 err = read(fd->fd_sys, writebuf, writebuf_len); \
163 if (err == -1) { \
164 *error_code = MPIO_Err_create_code(MPI_SUCCESS, \
165 MPIR_ERR_RECOVERABLE, myname, \
166 __LINE__, MPI_ERR_IO, \
167 "**ioRMWrdwr", 0); \
168 goto fn_exit; \
169 } \
170 } \
171 write_sz = (int) (ADIOI_MIN(req_len, writebuf_off + writebuf_len - req_off)); \
172 memcpy(writebuf+req_off-writebuf_off, (char *)buf +userbuf_off, write_sz);\
173 while (write_sz != req_len) { \
174 lseek(fd->fd_sys, writebuf_off, SEEK_SET); \
175 err = write(fd->fd_sys, writebuf, writebuf_len); \
176 if (!(fd->atomicity)) ADIOI_UNLOCK(fd, writebuf_off, SEEK_SET, writebuf_len); \
177 if (err == -1) err_flag = 1; \
178 req_len -= write_sz; \
179 userbuf_off += write_sz; \
180 writebuf_off += writebuf_len; \
181 writebuf_len = (int) (ADIOI_MIN(max_bufsize,end_offset-writebuf_off+1));\
182 if (!(fd->atomicity)) ADIOI_WRITE_LOCK(fd, writebuf_off, SEEK_SET, writebuf_len); \
183 lseek(fd->fd_sys, writebuf_off, SEEK_SET); \
184 err = read(fd->fd_sys, writebuf, writebuf_len); \
185 if (err == -1) { \
186 *error_code = MPIO_Err_create_code(MPI_SUCCESS, \
187 MPIR_ERR_RECOVERABLE, myname, \
188 __LINE__, MPI_ERR_IO, \
189 "**ioRMWrdwr", 0); \
190 goto fn_exit; \
191 } \
192 write_sz = ADIOI_MIN(req_len, writebuf_len); \
193 memcpy(writebuf, (char *)buf + userbuf_off, write_sz);\
194 } \
195 }
196 #endif
197
198
199
200 #ifdef ADIOI_MPE_LOGGING
201 #define ADIOI_BUFFERED_WRITE_WITHOUT_READ \
202 { \
203 if (req_off >= writebuf_off + writebuf_len) { \
204 MPE_Log_event( ADIOI_MPE_lseek_a, 0, NULL ); \
205 lseek(fd->fd_sys, writebuf_off, SEEK_SET); \
206 MPE_Log_event( ADIOI_MPE_lseek_b, 0, NULL ); \
207 if (!(fd->atomicity)) ADIOI_WRITE_LOCK(fd, writebuf_off, SEEK_SET, writebuf_len); \
208 MPE_Log_event( ADIOI_MPE_write_a, 0, NULL ); \
209 err = write(fd->fd_sys, writebuf, writebuf_len); \
210 MPE_Log_event( ADIOI_MPE_write_b, 0, NULL ); \
211 if (!(fd->atomicity)) ADIOI_UNLOCK(fd, writebuf_off, SEEK_SET, writebuf_len); \
212 if (err == -1) err_flag = 1; \
213 writebuf_off = req_off; \
214 writebuf_len = (int) (ADIOI_MIN(max_bufsize,end_offset-writebuf_off+1));\
215 } \
216 write_sz = (int) (ADIOI_MIN(req_len, writebuf_off + writebuf_len - req_off)); \
217 memcpy(writebuf+req_off-writebuf_off, (char *)buf +userbuf_off, write_sz);\
218 while (write_sz != req_len) { \
219 MPE_Log_event( ADIOI_MPE_lseek_a, 0, NULL ); \
220 lseek(fd->fd_sys, writebuf_off, SEEK_SET); \
221 MPE_Log_event( ADIOI_MPE_lseek_b, 0, NULL ); \
222 if (!(fd->atomicity)) ADIOI_WRITE_LOCK(fd, writebuf_off, SEEK_SET, writebuf_len); \
223 MPE_Log_event( ADIOI_MPE_write_a, 0, NULL ); \
224 err = write(fd->fd_sys, writebuf, writebuf_len); \
225 MPE_Log_event( ADIOI_MPE_write_b, 0, NULL ); \
226 if (!(fd->atomicity)) ADIOI_UNLOCK(fd, writebuf_off, SEEK_SET, writebuf_len); \
227 if (err == -1) err_flag = 1; \
228 req_len -= write_sz; \
229 userbuf_off += write_sz; \
230 writebuf_off += writebuf_len; \
231 writebuf_len = (int) (ADIOI_MIN(max_bufsize,end_offset-writebuf_off+1));\
232 write_sz = ADIOI_MIN(req_len, writebuf_len); \
233 memcpy(writebuf, (char *)buf + userbuf_off, write_sz);\
234 } \
235 }
236 #else
237 #define ADIOI_BUFFERED_WRITE_WITHOUT_READ \
238 { \
239 if (req_off >= writebuf_off + writebuf_len) { \
240 lseek(fd->fd_sys, writebuf_off, SEEK_SET); \
241 if (!(fd->atomicity)) ADIOI_WRITE_LOCK(fd, writebuf_off, SEEK_SET, writebuf_len); \
242 err = write(fd->fd_sys, writebuf, writebuf_len); \
243 if (!(fd->atomicity)) ADIOI_UNLOCK(fd, writebuf_off, SEEK_SET, writebuf_len); \
244 if (err == -1) err_flag = 1; \
245 writebuf_off = req_off; \
246 writebuf_len = (int) (ADIOI_MIN(max_bufsize,end_offset-writebuf_off+1));\
247 } \
248 write_sz = (int) (ADIOI_MIN(req_len, writebuf_off + writebuf_len - req_off)); \
249 memcpy(writebuf+req_off-writebuf_off, (char *)buf +userbuf_off, write_sz);\
250 while (write_sz != req_len) { \
251 lseek(fd->fd_sys, writebuf_off, SEEK_SET); \
252 if (!(fd->atomicity)) ADIOI_WRITE_LOCK(fd, writebuf_off, SEEK_SET, writebuf_len); \
253 err = write(fd->fd_sys, writebuf, writebuf_len); \
254 if (!(fd->atomicity)) ADIOI_UNLOCK(fd, writebuf_off, SEEK_SET, writebuf_len); \
255 if (err == -1) err_flag = 1; \
256 req_len -= write_sz; \
257 userbuf_off += write_sz; \
258 writebuf_off += writebuf_len; \
259 writebuf_len = (int) (ADIOI_MIN(max_bufsize,end_offset-writebuf_off+1));\
260 write_sz = ADIOI_MIN(req_len, writebuf_len); \
261 memcpy(writebuf, (char *)buf + userbuf_off, write_sz);\
262 } \
263 }
264 #endif
265
266
267 void ADIOI_NFS_WriteStrided(ADIO_File fd, const void *buf, int count,
268 MPI_Datatype datatype, int file_ptr_type,
269 ADIO_Offset offset, ADIO_Status *status, int
270 *error_code)
271 {
272
273
274 ADIOI_Flatlist_node *flat_buf, *flat_file;
275 int i, j, k, err=-1, bwr_size, st_index=0;
276 int num, size, sum, n_etypes_in_filetype, size_in_filetype;
277 MPI_Count bufsize;
278 int n_filetypes, etype_in_filetype;
279 ADIO_Offset abs_off_in_filetype=0;
280 int req_len;
281 MPI_Count filetype_size, etype_size, buftype_size;
282 MPI_Aint filetype_extent, buftype_extent, lb;
283 int buf_count, buftype_is_contig, filetype_is_contig;
284 ADIO_Offset userbuf_off;
285 ADIO_Offset off, req_off, disp, end_offset=0, writebuf_off, start_off;
286 char *writebuf=NULL, *value;
287 int st_n_filetypes, writebuf_len, write_sz;
288 ADIO_Offset fwr_size = 0, new_fwr_size, st_fwr_size;
289 int new_bwr_size, err_flag=0, info_flag, max_bufsize;
290 static char myname[] = "ADIOI_NFS_WRITESTRIDED";
291
292 ADIOI_Datatype_iscontig(datatype, &buftype_is_contig);
293 ADIOI_Datatype_iscontig(fd->filetype, &filetype_is_contig);
294
295 MPI_Type_size_x(fd->filetype, &filetype_size);
296 if ( ! filetype_size ) {
297 #ifdef HAVE_STATUS_SET_BYTES
298 MPIR_Status_set_bytes(status, datatype, 0);
299 #endif
300 *error_code = MPI_SUCCESS;
301 return;
302 }
303
304 MPI_Type_get_extent(fd->filetype, &lb, &filetype_extent);
305 MPI_Type_size_x(datatype, &buftype_size);
306 MPI_Type_get_extent(datatype, &lb, &buftype_extent);
307 etype_size = fd->etype_size;
308
309 bufsize = buftype_size * count;
310
311
312
313 value = (char *) ADIOI_Malloc((MPI_MAX_INFO_VAL+1)*sizeof(char));
314 ADIOI_Info_get(fd->info, "ind_wr_buffer_size", MPI_MAX_INFO_VAL, value,
315 &info_flag);
316 max_bufsize = atoi(value);
317 ADIOI_Free(value);
318
319 if (!buftype_is_contig && filetype_is_contig) {
320
321
322
323 flat_buf = ADIOI_Flatten_and_find(datatype);
324
325 off = (file_ptr_type == ADIO_INDIVIDUAL) ? fd->fp_ind :
326 fd->disp + etype_size * offset;
327
328 start_off = off;
329 end_offset = off + bufsize - 1;
330 writebuf_off = off;
331 writebuf = (char *) ADIOI_Malloc(max_bufsize);
332 writebuf_len = (int) (ADIOI_MIN(max_bufsize,end_offset-writebuf_off+1));
333
334
335 if (fd->atomicity)
336 ADIOI_WRITE_LOCK(fd, start_off, SEEK_SET, end_offset-start_off+1);
337
338 for (j=0; j<count; j++)
339 for (i=0; i<flat_buf->count; i++) {
340 userbuf_off = j*buftype_extent + flat_buf->indices[i];
341 req_off = off;
342 req_len = flat_buf->blocklens[i];
343 ADIOI_BUFFERED_WRITE_WITHOUT_READ
344 off += flat_buf->blocklens[i];
345 }
346
347
348 #ifdef ADIOI_MPE_LOGGING
349 MPE_Log_event( ADIOI_MPE_lseek_a, 0, NULL );
350 #endif
351 lseek(fd->fd_sys, writebuf_off, SEEK_SET);
352 #ifdef ADIOI_MPE_LOGGING
353 MPE_Log_event( ADIOI_MPE_lseek_b, 0, NULL );
354 #endif
355 if (!(fd->atomicity)) ADIOI_WRITE_LOCK(fd, writebuf_off, SEEK_SET, writebuf_len);
356 #ifdef ADIOI_MPE_LOGGING
357 MPE_Log_event( ADIOI_MPE_write_a, 0, NULL );
358 #endif
359 err = write(fd->fd_sys, writebuf, writebuf_len);
360 #ifdef ADIOI_MPE_LOGGING
361 MPE_Log_event( ADIOI_MPE_write_b, 0, NULL );
362 #endif
363 if (!(fd->atomicity)) ADIOI_UNLOCK(fd, writebuf_off, SEEK_SET, writebuf_len);
364 if (err == -1) err_flag = 1;
365
366 if (fd->atomicity)
367 ADIOI_UNLOCK(fd, start_off, SEEK_SET, end_offset-start_off+1);
368
369 if (file_ptr_type == ADIO_INDIVIDUAL) fd->fp_ind = off;
370 if (err_flag) {
371 *error_code = MPIO_Err_create_code(MPI_SUCCESS,
372 MPIR_ERR_RECOVERABLE, myname,
373 __LINE__, MPI_ERR_IO, "**io",
374 "**io %s", strerror(errno));
375 }
376 else *error_code = MPI_SUCCESS;
377 }
378
379 else {
380
381
382 flat_file = ADIOI_Flatlist;
383 while (flat_file->type != fd->filetype) flat_file = flat_file->next;
384 disp = fd->disp;
385
386 if (file_ptr_type == ADIO_INDIVIDUAL) {
387
388 offset = fd->fp_ind - disp;
389 n_filetypes = (offset - flat_file->indices[0]) / filetype_extent;
390 offset -= (ADIO_Offset)n_filetypes * filetype_extent;
391
392
393
394 for (i=0; i<flat_file->count; i++) {
395 ADIO_Offset dist;
396 if (flat_file->blocklens[i] == 0) continue;
397 dist = flat_file->indices[i] + flat_file->blocklens[i] - offset;
398
399 if (dist == 0) {
400 i++;
401 offset = flat_file->indices[i];
402 fwr_size = flat_file->blocklens[i];
403 break;
404 }
405 if (dist > 0) {
406 fwr_size = dist;
407 break;
408 }
409 }
410 st_index = i;
411 offset += disp + (ADIO_Offset)n_filetypes*filetype_extent;
412 }
413 else {
414 n_etypes_in_filetype = filetype_size/etype_size;
415 n_filetypes = (int) (offset / n_etypes_in_filetype);
416 etype_in_filetype = (int) (offset % n_etypes_in_filetype);
417 size_in_filetype = etype_in_filetype * etype_size;
418
419 sum = 0;
420 for (i=0; i<flat_file->count; i++) {
421 sum += flat_file->blocklens[i];
422 if (sum > size_in_filetype) {
423 st_index = i;
424 fwr_size = sum - size_in_filetype;
425 abs_off_in_filetype = flat_file->indices[i] +
426 size_in_filetype - (sum - flat_file->blocklens[i]);
427 break;
428 }
429 }
430
431
432 offset = disp + (ADIO_Offset) n_filetypes*filetype_extent +
433 abs_off_in_filetype;
434 }
435
436 start_off = offset;
437
438
439
440 if (buftype_is_contig && bufsize <= fwr_size) {
441 ADIO_WriteContig(fd, buf, bufsize, MPI_BYTE, ADIO_EXPLICIT_OFFSET,
442 offset, status, error_code);
443
444 if (file_ptr_type == ADIO_INDIVIDUAL) {
445
446
447 fd->fp_ind = offset + bufsize;
448 if (bufsize == fwr_size) {
449 do {
450 st_index++;
451 if (st_index == flat_file->count) {
452 st_index = 0;
453 n_filetypes++;
454 }
455 } while (flat_file->blocklens[st_index] == 0);
456 fd->fp_ind = disp + flat_file->indices[st_index]
457 + (ADIO_Offset)n_filetypes*filetype_extent;
458 }
459 }
460 fd->fp_sys_posn = -1;
461 #ifdef HAVE_STATUS_SET_BYTES
462 MPIR_Status_set_bytes(status, datatype, bufsize);
463 #endif
464 return;
465 }
466
467
468
469
470 st_fwr_size = fwr_size;
471 st_n_filetypes = n_filetypes;
472 i = 0;
473 j = st_index;
474 off = offset;
475 fwr_size = ADIOI_MIN(st_fwr_size, bufsize);
476 while (i < bufsize) {
477 i += fwr_size;
478 end_offset = off + fwr_size - 1;
479 j = (j+1) % flat_file->count;
480 n_filetypes += (j == 0) ? 1 : 0;
481 while (flat_file->blocklens[j]==0) {
482 j = (j+1) % flat_file->count;
483 n_filetypes += (j == 0) ? 1 : 0;
484 }
485
486 off = disp + flat_file->indices[j] +
487 (ADIO_Offset) n_filetypes*filetype_extent;
488 fwr_size = ADIOI_MIN(flat_file->blocklens[j], bufsize-i);
489 }
490
491
492 if (fd->atomicity)
493 ADIOI_WRITE_LOCK(fd, start_off, SEEK_SET, end_offset-start_off+1);
494
495
496 writebuf_off = offset;
497 writebuf = (char *) ADIOI_Malloc(max_bufsize);
498 writebuf_len = (int)(ADIOI_MIN(max_bufsize,end_offset-writebuf_off+1));
499 if (!(fd->atomicity)) ADIOI_WRITE_LOCK(fd, writebuf_off, SEEK_SET, writebuf_len);
500 #ifdef ADIOI_MPE_LOGGING
501 MPE_Log_event( ADIOI_MPE_lseek_a, 0, NULL );
502 #endif
503 lseek(fd->fd_sys, writebuf_off, SEEK_SET);
504 #ifdef ADIOI_MPE_LOGGING
505 MPE_Log_event( ADIOI_MPE_lseek_b, 0, NULL );
506 #endif
507 #ifdef ADIOI_MPE_LOGGING
508 MPE_Log_event( ADIOI_MPE_read_a, 0, NULL );
509 #endif
510 err = read(fd->fd_sys, writebuf, writebuf_len);
511 #ifdef ADIOI_MPE_LOGGING
512 MPE_Log_event( ADIOI_MPE_read_b, 0, NULL );
513 #endif
514 if (err == -1) {
515 *error_code = MPIO_Err_create_code(MPI_SUCCESS,
516 MPIR_ERR_RECOVERABLE,
517 myname, __LINE__,
518 MPI_ERR_IO,
519 "ADIOI_NFS_WriteStrided: ROMIO tries to optimize this access by doing a read-modify-write, but is unable to read the file. Please give the file read permission and open it with MPI_MODE_RDWR.", 0);
520 goto fn_exit;
521 }
522
523 if (buftype_is_contig && !filetype_is_contig) {
524
525
526
527
528 i = 0;
529 j = st_index;
530 off = offset;
531 n_filetypes = st_n_filetypes;
532 fwr_size = ADIOI_MIN(st_fwr_size, bufsize);
533 while (i < bufsize) {
534 if (fwr_size) {
535
536
537
538
539
540 req_off = off;
541 req_len = fwr_size;
542 userbuf_off = i;
543 ADIOI_BUFFERED_WRITE
544 }
545 i += fwr_size;
546
547 if (off + fwr_size < disp + flat_file->indices[j] +
548 flat_file->blocklens[j] + (ADIO_Offset) n_filetypes*filetype_extent)
549 off += fwr_size;
550
551
552 else {
553 j = (j+1) % flat_file->count;
554 n_filetypes += (j == 0) ? 1 : 0;
555 while (flat_file->blocklens[j]==0) {
556 j = (j+1) % flat_file->count;
557 n_filetypes += (j == 0) ? 1 : 0;
558 }
559 off = disp + flat_file->indices[j] +
560 (ADIO_Offset) n_filetypes*filetype_extent;
561 fwr_size = ADIOI_MIN(flat_file->blocklens[j], bufsize-i);
562 }
563 }
564 }
565 else {
566
567
568 ADIO_Offset i;
569 flat_buf = ADIOI_Flatten_and_find(datatype);
570
571 k = num = buf_count = 0;
572 i = flat_buf->indices[0];
573 j = st_index;
574 off = offset;
575 n_filetypes = st_n_filetypes;
576 fwr_size = st_fwr_size;
577 bwr_size = flat_buf->blocklens[0];
578
579 while (num < bufsize) {
580 size = ADIOI_MIN(fwr_size, bwr_size);
581 if (size) {
582
583
584
585 req_off = off;
586 req_len = size;
587 userbuf_off = i;
588 ADIOI_BUFFERED_WRITE
589 }
590
591 new_fwr_size = fwr_size;
592 new_bwr_size = bwr_size;
593
594 if (size == fwr_size) {
595
596 j = (j+1) % flat_file->count;
597 n_filetypes += (j == 0) ? 1 : 0;
598 while (flat_file->blocklens[j]==0) {
599 j = (j+1) % flat_file->count;
600 n_filetypes += (j == 0) ? 1 : 0;
601 }
602
603 off = disp + flat_file->indices[j] +
604 (ADIO_Offset) n_filetypes*filetype_extent;
605
606 new_fwr_size = flat_file->blocklens[j];
607 if (size != bwr_size) {
608 i += size;
609 new_bwr_size -= size;
610 }
611 }
612
613 if (size == bwr_size) {
614
615
616 k = (k + 1)%flat_buf->count;
617 buf_count++;
618 i = buftype_extent*(buf_count/flat_buf->count) +
619 flat_buf->indices[k];
620 new_bwr_size = flat_buf->blocklens[k];
621 if (size != fwr_size) {
622 off += size;
623 new_fwr_size -= size;
624 }
625 }
626 num += size;
627 fwr_size = new_fwr_size;
628 bwr_size = new_bwr_size;
629 }
630 }
631
632
633 #ifdef ADIOI_MPE_LOGGING
634 MPE_Log_event( ADIOI_MPE_lseek_a, 0, NULL );
635 #endif
636 lseek(fd->fd_sys, writebuf_off, SEEK_SET);
637 #ifdef ADIOI_MPE_LOGGING
638 MPE_Log_event( ADIOI_MPE_lseek_b, 0, NULL );
639 #endif
640 if (!(fd->atomicity)) ADIOI_WRITE_LOCK(fd, writebuf_off, SEEK_SET, writebuf_len);
641 #ifdef ADIOI_MPE_LOGGING
642 MPE_Log_event( ADIOI_MPE_write_a, 0, NULL );
643 #endif
644 err = write(fd->fd_sys, writebuf, writebuf_len);
645 #ifdef ADIOI_MPE_LOGGING
646 MPE_Log_event( ADIOI_MPE_write_b, 0, NULL );
647 #endif
648
649 if (!(fd->atomicity))
650 ADIOI_UNLOCK(fd, writebuf_off, SEEK_SET, writebuf_len);
651 else ADIOI_UNLOCK(fd, start_off, SEEK_SET, end_offset-start_off+1);
652
653 if (err == -1) err_flag = 1;
654
655 if (file_ptr_type == ADIO_INDIVIDUAL) fd->fp_ind = off;
656 if (err_flag) {
657 *error_code = MPIO_Err_create_code(MPI_SUCCESS,
658 MPIR_ERR_RECOVERABLE, myname,
659 __LINE__, MPI_ERR_IO, "**io",
660 "**io %s", strerror(errno));
661 }
662 else *error_code = MPI_SUCCESS;
663 }
664
665 fd->fp_sys_posn = -1;
666
667 #ifdef HAVE_STATUS_SET_BYTES
668 MPIR_Status_set_bytes(status, datatype, bufsize);
669
670
671 #endif
672
673 if (!buftype_is_contig) ADIOI_Delete_flattened(datatype);
674 fn_exit:
675 if (writebuf != NULL) ADIOI_Free(writebuf);
676
677 return;
678 }