00001 
00002 
00003 
00004 
00005 
00006 
00007 
00008 #include "ad_pvfs2.h"
00009 #include "adio_extern.h"
00010 #include "ad_pvfs2_io.h"
00011 #include "ad_pvfs2_common.h"
00012 
00013 void ADIOI_PVFS2_WriteContig(ADIO_File fd, void *buf, int count, 
00014                  MPI_Datatype datatype, int file_ptr_type,
00015                  ADIO_Offset offset, ADIO_Status *status,
00016                  int *error_code)
00017 {
00018     int ret, datatype_size, len;
00019     PVFS_Request file_req, mem_req;
00020     PVFS_sysresp_io resp_io;
00021     ADIOI_PVFS2_fs *pvfs_fs;
00022     static char myname[] = "ADIOI_PVFS2_WRITECONTIG";
00023 
00024     pvfs_fs = (ADIOI_PVFS2_fs*)fd->fs_ptr;
00025 
00026     MPI_Type_size(datatype, &datatype_size);
00027     len = datatype_size * count;
00028 
00029     ret = PVFS_Request_contiguous(len, PVFS_BYTE, &mem_req);
00030     
00031     if (ret != 0) {
00032     *error_code = MPIO_Err_create_code(MPI_SUCCESS,
00033                        MPIR_ERR_RECOVERABLE,
00034                        myname, __LINE__,
00035                        ADIOI_PVFS2_error_convert(ret),
00036                        "Error in PVFS_Request_contiguous (memory)", 0);
00037     return;
00038     }
00039     
00040 
00041     ret = PVFS_Request_contiguous(len, PVFS_BYTE, &file_req);
00042     
00043     if (ret != 0) {
00044     *error_code = MPIO_Err_create_code(MPI_SUCCESS,
00045                        MPIR_ERR_RECOVERABLE,
00046                        myname, __LINE__,
00047                        ADIOI_PVFS2_error_convert(ret),
00048                        "Error in PVFS_Request_contiguous (file)", 0);
00049     return;
00050     }
00051     
00052 
00053     if (file_ptr_type == ADIO_EXPLICIT_OFFSET) {
00054 #ifdef ADIOI_MPE_LOGGING
00055         MPE_Log_event( ADIOI_MPE_write_a, 0, NULL );
00056 #endif
00057     ret = PVFS_sys_write(pvfs_fs->object_ref, file_req, offset,  buf, 
00058                  mem_req, &(pvfs_fs->credentials), &resp_io);
00059 #ifdef ADIOI_MPE_LOGGING
00060         MPE_Log_event( ADIOI_MPE_write_b, 0, NULL );
00061 #endif
00062     
00063     if (ret != 0) {
00064         *error_code = MPIO_Err_create_code(MPI_SUCCESS,
00065                            MPIR_ERR_RECOVERABLE,
00066                            myname, __LINE__,
00067                            ADIOI_PVFS2_error_convert(ret),
00068                            "Error in PVFS_sys_write", 0);
00069         goto fn_exit;
00070     }
00071     
00072 
00073     fd->fp_sys_posn = offset + (int) resp_io.total_completed;
00074     }
00075     else {
00076 #ifdef ADIOI_MPE_LOGGING
00077         MPE_Log_event( ADIOI_MPE_write_a, 0, NULL );
00078 #endif
00079     ret = PVFS_sys_write(pvfs_fs->object_ref, file_req, fd->fp_ind, buf, 
00080                  mem_req, &(pvfs_fs->credentials), &resp_io);
00081 #ifdef ADIOI_MPE_LOGGING
00082         MPE_Log_event( ADIOI_MPE_write_b, 0, NULL );
00083 #endif
00084     
00085     if (ret != 0) {
00086         *error_code = MPIO_Err_create_code(MPI_SUCCESS,
00087                            MPIR_ERR_RECOVERABLE,
00088                            myname, __LINE__,
00089                            ADIOI_PVFS2_error_convert(ret),
00090                            "Error in PVFS_sys_write", 0);
00091         goto fn_exit;
00092     }
00093     
00094     fd->fp_ind += (int)resp_io.total_completed;
00095     fd->fp_sys_posn = fd->fp_ind;
00096     }
00097 #ifdef HAVE_STATUS_SET_BYTES
00098     MPIR_Status_set_bytes(status, datatype, (int)resp_io.total_completed);
00099 #endif
00100     *error_code = MPI_SUCCESS;
00101 fn_exit:
00102     PVFS_Request_free(&file_req);
00103     PVFS_Request_free(&mem_req);
00104     return;
00105 }
00106 
00107 int ADIOI_PVFS2_WriteStridedListIO(ADIO_File fd, void *buf, int count,
00108                    MPI_Datatype datatype, int file_ptr_type,
00109                    ADIO_Offset offset, ADIO_Status *status,
00110                    int *error_code)
00111 {
00112     return ADIOI_PVFS2_StridedListIO(fd, buf, count,
00113                      datatype, file_ptr_type,
00114                      offset, status,
00115                      error_code, WRITE);
00116 }
00117 
00118 int ADIOI_PVFS2_WriteStridedDtypeIO(ADIO_File fd, void *buf, int count,
00119                     MPI_Datatype datatype, int file_ptr_type,
00120                     ADIO_Offset offset, ADIO_Status *status, 
00121                     int *error_code)
00122 {
00123     return ADIOI_PVFS2_StridedDtypeIO(fd, buf, count,
00124                       datatype, file_ptr_type,
00125                       offset, status, error_code,
00126                       WRITE);
00127 }
00128 
00129 
00130 void ADIOI_PVFS2_WriteStrided(ADIO_File fd, void *buf, int count,
00131                   MPI_Datatype datatype, int file_ptr_type,
00132                   ADIO_Offset offset, ADIO_Status *status,
00133                   int *error_code)
00134 {
00135     
00136 
00137 
00138 
00139 
00140 
00141 
00142 
00143 
00144     
00145 
00146 
00147     int ret = -1;
00148     if ( fd->hints->fs_hints.pvfs2.posix_write == ADIOI_HINT_ENABLE) {
00149         ADIOI_GEN_WriteStrided_naive(fd, buf, count,
00150                                      datatype, file_ptr_type,
00151                                      offset, status, error_code);
00152         return;
00153     }
00154     if ( fd->hints->fs_hints.pvfs2.dtype_write == ADIOI_HINT_ENABLE) {
00155         ret = ADIOI_PVFS2_WriteStridedDtypeIO(fd, buf, count,
00156                                               datatype, file_ptr_type,
00157                                               offset, status, error_code);
00158 
00159         
00160         if (ret != 0)
00161         {
00162             fprintf(stderr,
00163                     "Falling back to list I/O since datatype I/O failed\n");
00164             ret = ADIOI_PVFS2_WriteStridedListIO(fd, buf, count,
00165                                                  datatype, file_ptr_type,
00166                                                  offset, status, error_code);
00167         }
00168         return;
00169     }
00170     
00171     if (fd->hints->fs_hints.pvfs2.listio_write == ADIOI_HINT_ENABLE) {
00172     ret = ADIOI_PVFS2_WriteStridedListIO(fd, buf, count, datatype, 
00173             file_ptr_type, offset, status, error_code);
00174     return;
00175     }
00176 
00177     
00178     ADIOI_PVFS2_OldWriteStrided(fd, buf, count, datatype,
00179         file_ptr_type, offset, status, error_code);
00180     return;
00181 }