root/ompi/mca/io/romio321/romio/adio/ad_nfs/ad_nfs_write.c

/* [<][>][^][v][top][bottom][index][help] */

DEFINITIONS

This source file includes following definitions.
  1. ADIOI_NFS_WriteContig
  2. ADIOI_NFS_WriteStrided

   1 /* -*- Mode: C; c-basic-offset:4 ; indent-tabs-mode:nil ; -*- */
   2 /* 
   3  *
   4  *   Copyright (C) 1997 University of Chicago. 
   5  *   See COPYRIGHT notice in top-level directory.
   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         /* individual file pointer not updated */        
  43     }
  44     else { /* write from curr. location of ind. file pointer */
  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     /* --BEGIN ERROR HANDLING-- */
  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     /* --END ERROR HANDLING-- */
  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 /* this macro is used when filetype is contig and buftype is not contig.
 199    it does not do a read-modify-write and does not lock*/
 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 /* offset is in units of etype relative to the filetype. */
 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 /* get max_bufsize from the info object. */
 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 /* noncontiguous in memory, contiguous in file. */
 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 /* if atomicity is true, lock the region to be accessed */
 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         /* write the buffer out finally */
 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 {  /* noncontiguous in file */
 380 
 381 /* filetype already flattened in ADIO_Open */
 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        /* Wei-keng reworked type processing to be a bit more efficient */
 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             /* now offset is local to this extent */
 392 
 393             /* find the block where offset is located, skip blocklens[i]==0 */
 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                 /* fwr_size is from offset to the end of block i */
 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;  /* starting index in flat_file->indices[] */
 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             /* abs. offset in bytes in the file */
 432             offset = disp + (ADIO_Offset) n_filetypes*filetype_extent + 
 433                 abs_off_in_filetype;
 434         }
 435 
 436         start_off = offset;
 437        /* Wei-keng Liao:write request is within single flat_file contig block*/
 438        /* this could happen, for example, with subarray types that are
 439         * actually fairly contiguous */
 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                 /* update MPI-IO file pointer to point to the first byte 
 446                 * that can be accessed in the fileview. */
 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;   /* set it to null. */ 
 461 #ifdef HAVE_STATUS_SET_BYTES
 462            MPIR_Status_set_bytes(status, datatype, bufsize);
 463 #endif 
 464             return;
 465         }
 466 
 467        /* Calculate end_offset, the last byte-offset that will be accessed.
 468          e.g., if start_offset=0 and 100 bytes to be write, end_offset=99*/
 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 /* if atomicity is true, lock the region to be accessed */
 492         if (fd->atomicity) 
 493             ADIOI_WRITE_LOCK(fd, start_off, SEEK_SET, end_offset-start_off+1);
 494 
 495         /* initial read for the read-modify-write */
 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 /* contiguous in memory, noncontiguous in file. should be the most
 526    common case. */
 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                     /* TYPE_UB and TYPE_LB can result in 
 536                        fwr_size = 0. save system call in such cases */ 
 537                     /* lseek(fd->fd_sys, off, SEEK_SET);
 538                     err = write(fd->fd_sys, ((char *) buf) + i, fwr_size);*/
 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                 /* did not reach end of contiguous block in filetype.
 551                    no more I/O needed. off is incremented by fwr_size. */
 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 /* noncontiguous in memory as well as in file */
 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                     /* lseek(fd->fd_sys, off, SEEK_SET);
 583                     err = write(fd->fd_sys, ((char *) buf) + i, size); */
 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 /* reached end of contiguous block in file */
 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 /* reached end of contiguous block in memory */
 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         /* write the buffer out finally */      
 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;   /* set it to null. */
 666 
 667 #ifdef HAVE_STATUS_SET_BYTES
 668     MPIR_Status_set_bytes(status, datatype, bufsize);
 669 /* This is a temporary way of filling in status. The right way is to 
 670    keep track of how much data was actually written by ADIOI_BUFFERED_WRITE. */
 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 }

/* [<][>][^][v][top][bottom][index][help] */