int ADIOI_SCI_aio(ADIO_File fd, void *buf, int len, ADIO_Offset offset, int wr, void *handle) { int err=-1, fd_sys; #ifndef NO_AIO int error_code; #ifdef AIO_SUN aio_result_t *result; #else struct aiocb *aiocbp; #endif #endif fd_sys = fd->fd_sys; #ifdef AIO_SUN result = (aio_result_t *) ADIOI_Malloc(sizeof(aio_result_t)); result->aio_return = AIO_INPROGRESS; if (wr) err = aiowrite(fd_sys, buf, len, offset, SEEK_SET, result); else err = aioread(fd_sys, buf, len, offset, SEEK_SET, result); if (err == -1) { if (errno == EAGAIN) { /* the man pages say EPROCLIM, but in reality errno is set to EAGAIN! */ /* exceeded the max. no. of outstanding requests. complete all previous async. requests and try again.*/ ADIOI_Complete_async(&error_code); if (wr) err = aiowrite(fd_sys, buf, len, offset, SEEK_SET, result); else err = aioread(fd_sys, buf, len, offset, SEEK_SET, result); while (err == -1) { if (errno == EAGAIN) { /* sleep and try again */ sleep(1); if (wr) err = aiowrite(fd_sys, buf, len, offset, SEEK_SET, result); else err = aioread(fd_sys, buf, len, offset, SEEK_SET, result); } else { FPRINTF(stderr, "Unknown errno %d in ADIOI_SCI_aio\n", errno); MPI_Abort(MPI_COMM_WORLD, 1); } } } else { FPRINTF(stderr, "Unknown errno %d in ADIOI_SCI_aio\n", errno); MPI_Abort(MPI_COMM_WORLD, 1); } } *((aio_result_t **) handle) = result; #endif #ifdef NO_FD_IN_AIOCB /* IBM */ aiocbp = (struct aiocb *) ADIOI_Malloc(sizeof(struct aiocb)); aiocbp->aio_whence = SEEK_SET; aiocbp->aio_offset = offset; aiocbp->aio_buf = buf; aiocbp->aio_nbytes = len; if (wr) err = aio_write(fd_sys, aiocbp); else err = aio_read(fd_sys, aiocbp); if (err == -1) { if (errno == EAGAIN) { /* exceeded the max. no. of outstanding requests. complete all previous async. requests and try again. */ ADIOI_Complete_async(&error_code); if (wr) err = aio_write(fd_sys, aiocbp); else err = aio_read(fd_sys, aiocbp); while (err == -1) { if (errno == EAGAIN) { /* sleep and try again */ sleep(1); if (wr) err = aio_write(fd_sys, aiocbp); else err = aio_read(fd_sys, aiocbp); } else { FPRINTF(stderr, "Unknown errno %d in ADIOI_SCI_aio\n", errno); MPI_Abort(MPI_COMM_WORLD, 1); } } } else { FPRINTF(stderr, "Unknown errno %d in ADIOI_SCI_aio\n", errno); MPI_Abort(MPI_COMM_WORLD, 1); } } *((struct aiocb **) handle) = aiocbp; #elif (!defined(NO_AIO) && !defined(AIO_SUN)) /* DEC, SGI IRIX 5 and 6 */ aiocbp = (struct aiocb *) ADIOI_Calloc(sizeof(struct aiocb), 1); aiocbp->aio_fildes = fd_sys; aiocbp->aio_offset = offset; aiocbp->aio_buf = buf; aiocbp->aio_nbytes = len; #ifdef AIO_PRIORITY_DEFAULT /* DEC */ aiocbp->aio_reqprio = AIO_PRIO_DFL; /* not needed in DEC Unix 4.0 */ aiocbp->aio_sigevent.sigev_signo = 0; #else aiocbp->aio_reqprio = 0; #endif #ifdef AIO_SIGNOTIFY_NONE /* SGI IRIX 6 */ aiocbp->aio_sigevent.sigev_notify = SIGEV_NONE; #else aiocbp->aio_sigevent.sigev_signo = 0; #endif if (wr) err = aio_write(aiocbp); else err = aio_read(aiocbp); if (err == -1) { if (errno == EAGAIN) { /* exceeded the max. no. of outstanding requests. complete all previous async. requests and try again. */ ADIOI_Complete_async(&error_code); if (wr) err = aio_write(aiocbp); else err = aio_read(aiocbp); while (err == -1) { if (errno == EAGAIN) { /* sleep and try again */ sleep(1); if (wr) err = aio_write(aiocbp); else err = aio_read(aiocbp); } else { FPRINTF(stderr, "Unknown errno %d in ADIOI_SCI_aio\n", errno); MPI_Abort(MPI_COMM_WORLD, 1); } } } else { FPRINTF(stderr, "Unknown errno %d in ADIOI_SCI_aio\n", errno); MPI_Abort(MPI_COMM_WORLD, 1); } } *((struct aiocb **) handle) = aiocbp; #endif return err; }
void ADIOI_PFS_IwriteContig(ADIO_File fd, void *buf, int count, MPI_Datatype datatype, int file_ptr_type, ADIO_Offset offset, ADIO_Request *request, int *error_code) { long *id_sys; ADIO_Offset off; int len, typesize, err; #ifndef PRINT_ERR_MSG static char myname[] = "ADIOI_PFS_IWRITECONTIG"; #endif *request = ADIOI_Malloc_request(); (*request)->optype = ADIOI_WRITE; (*request)->fd = fd; (*request)->datatype = datatype; MPI_Type_size(datatype, &typesize); len = count * typesize; id_sys = (long *) ADIOI_Malloc(sizeof(long)); (*request)->handle = (void *) id_sys; off = (file_ptr_type == ADIO_INDIVIDUAL) ? fd->fp_ind : offset; lseek(fd->fd_sys, off, SEEK_SET); *id_sys = _iwrite(fd->fd_sys, buf, len); if ((*id_sys == -1) && (errno == EQNOMID)) { /* the man pages say EMREQUEST, but in reality errno is set to EQNOMID! */ /* exceeded the max. no. of outstanding requests. */ /* complete all previous async. requests */ ADIOI_Complete_async(&err); /* try again */ *id_sys = _iwrite(fd->fd_sys, buf, len); if ((*id_sys == -1) && (errno == EQNOMID)) { #ifdef PRINT_ERR_MSG FPRINTF(stderr, "Error in asynchronous I/O\n"); MPI_Abort(MPI_COMM_WORLD, 1); #else *error_code = MPIR_Err_setmsg(MPI_ERR_IO, MPIR_ADIO_ERROR, myname, "I/O Error", "%s", strerror(errno)); ADIOI_Error(fd, *error_code, myname); return; #endif } } else if (*id_sys == -1) { #ifdef PRINT_ERR_MSG FPRINTF(stderr, "Unknown errno %d in ADIOI_PFS_IwriteContig\n", errno); MPI_Abort(MPI_COMM_WORLD, 1); #else *error_code = MPIR_Err_setmsg(MPI_ERR_IO, MPIR_ADIO_ERROR, myname, "I/O Error", "%s", strerror(errno)); ADIOI_Error(fd, *error_code, myname); return; #endif } if (file_ptr_type == ADIO_INDIVIDUAL) fd->fp_ind += len; (*request)->queued = 1; (*request)->nbytes = len; ADIOI_Add_req_to_list(request); fd->async_count++; fd->fp_sys_posn = -1; /* set it to null. */ #ifdef PRINT_ERR_MSG *error_code = (*id_sys == -1) ? MPI_ERR_UNKNOWN : MPI_SUCCESS; #else if (*id_sys == -1) { *error_code = MPIR_Err_setmsg(MPI_ERR_IO, MPIR_ADIO_ERROR, myname, "I/O Error", "%s", strerror(errno)); ADIOI_Error(fd, *error_code, myname); } else *error_code = MPI_SUCCESS; #endif }
void ADIOI_PFS_IwriteContig(ADIO_File fd, void *buf, int count, MPI_Datatype datatype, int file_ptr_type, ADIO_Offset offset, ADIO_Request *request, int *error_code) { long *id_sys; ADIO_Offset off; int len, typesize, err; static char myname[] = "ADIOI_PFS_IWRITECONTIG"; *request = ADIOI_Malloc_request(); (*request)->optype = ADIOI_WRITE; (*request)->fd = fd; (*request)->datatype = datatype; MPI_Type_size(datatype, &typesize); len = count * typesize; id_sys = (long *) ADIOI_Malloc(sizeof(long)); (*request)->handle = (void *) id_sys; off = (file_ptr_type == ADIO_INDIVIDUAL) ? fd->fp_ind : offset; lseek(fd->fd_sys, off, SEEK_SET); *id_sys = _iwrite(fd->fd_sys, buf, len); if ((*id_sys == -1) && (errno == EQNOMID)) { /* the man pages say EMREQUEST, but in reality errno is set to EQNOMID! */ /* exceeded the max. no. of outstanding requests. */ /* complete all previous async. requests */ ADIOI_Complete_async(error_code); if (error_code != MPI_SUCCESS) return; /* try again */ *id_sys = _iwrite(fd->fd_sys, buf, len); if ((*id_sys == -1) && (errno == EQNOMID)) { *error_code = MPIO_Err_create_code(MPI_SUCCESS, MPIR_ERR_RECOVERABLE, myname, __LINE__, MPI_ERR_IO, "**io", "**io %s", strerror(errno)); return; } } else if (*id_sys == -1) { *error_code = MPIO_Err_create_code(MPI_SUCCESS, MPIR_ERR_RECOVERABLE, myname, __LINE__, MPI_ERR_IO, "**io", "**io %s", strerror(errno)); return; } if (file_ptr_type == ADIO_INDIVIDUAL) fd->fp_ind += len; (*request)->queued = 1; (*request)->nbytes = len; ADIOI_Add_req_to_list(request); fd->async_count++; fd->fp_sys_posn = -1; /* set it to null. */ if (*id_sys == -1) { *error_code = MPIO_Err_create_code(MPI_SUCCESS, MPIR_ERR_RECOVERABLE, myname, __LINE__, MPI_ERR_IO, "**io", "**io %s", strerror(errno)); } else *error_code = MPI_SUCCESS; }
int ADIOI_NTFS_aio(ADIO_File fd, int wr, ADIO_Request request,int blocking, DWORD *error_code) { BOOL err,restart,check=TRUE; int CompleteError,Counter =0; FD_TYPE fd_sys; OVERLAPPED *result; LARGE_INTEGER *LI = (LARGE_INTEGER*)&request->offset; DWORD written; *error_code = NO_ERROR; fd_sys = fd->fd_sys; if(!request->totransfer) { request->handle = NULL; SetFilePointer(fd_sys,LI->LowPart,&LI->HighPart,FILE_BEGIN); return 0; } result = GetOverlappedStruct(); do { check = TRUE; result->Offset = LI->LowPart; result->OffsetHigh = LI->HighPart; restart = FALSE; if (wr) err = WriteFile(fd_sys,request->buf,request->totransfer,&written,result); else err = ReadFile(fd_sys,request->buf,request->totransfer,&written,result); while(check) { check = FALSE; if(!err) { *error_code = GetLastError(); switch (*error_code) { case ERROR_LOCK_VIOLATION: restart = TRUE; Sleep(1); break; case ERROR_HANDLE_EOF: FreeOverlappedStruct(result); result = NULL; request->totransfer -= written; err = 1; break; case ERROR_IO_PENDING: if(blocking) { err = GetOverlappedResult(fd_sys,result,&written,TRUE); if(!err) { check = TRUE; } else { request->totransfer -= written; if(request->totransfer>0) { request->buf += written; request->offset += written; restart = TRUE; } else { *error_code = ERROR_SUCCESS; FreeOverlappedStruct(result); result = NULL; } err = 1; } } break; case ERROR_INVALID_USER_BUFFER : case ERROR_NOT_ENOUGH_MEMORY : ADIOI_Complete_async(&CompleteError); restart = TRUE; if(++Counter<10) { Sleep(1); break; } /* else fall through */ default: fprintf(stderr,"Error %d in ADIOI_NTFS_aio\n", *error_code); fflush(stderr); /*MPI_Abort(MPI_COMM_WORLD, *error_code);*/ break; } } else { request->totransfer -= written; if(request->totransfer>0) { request->buf += written; request->offset += written; restart = TRUE; } else { FreeOverlappedStruct(result); result = NULL; *error_code = ERROR_SUCCESS; } } } } while (restart && Counter <10); request->handle = result; return (err?0:-1); }