⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 ad_pvfs2_read.c

📁 fortran并行计算包
💻 C
📖 第 1 页 / 共 3 页
字号:
/* -*- Mode: C; c-basic-offset:4 ; -*-  *     vim: ts=8 sts=4 sw=4 noexpandtab  *  *   Copyright (C) 1997 University of Chicago.  *   See COPYRIGHT notice in top-level directory. */#include "adio.h"#include "adio_extern.h"#include "ad_pvfs2.h"#include "ad_pvfs2_common.h"void ADIOI_PVFS2_ReadContig(ADIO_File fd, void *buf, int count, 			    MPI_Datatype datatype, int file_ptr_type,			    ADIO_Offset offset, ADIO_Status *status,			    int *error_code){    int ret, datatype_size, len;    PVFS_Request file_req, mem_req;    PVFS_sysresp_io resp_io;    ADIOI_PVFS2_fs *pvfs_fs;    static char myname[] = "ADIOI_PVFS2_READCONTIG";    pvfs_fs = (ADIOI_PVFS2_fs*)fd->fs_ptr;    MPI_Type_size(datatype, &datatype_size);    len = datatype_size * count;    ret = PVFS_Request_contiguous(len, PVFS_BYTE, &mem_req);    /* --BEGIN ERROR HANDLING-- */    if (ret != 0) {	*error_code = MPIO_Err_create_code(MPI_SUCCESS,					   MPIR_ERR_RECOVERABLE,					   myname, __LINE__,					   ADIOI_PVFS2_error_convert(ret),					   "Error in pvfs_request_contig (memory)", 0);	return;    }    /* --END ERROR HANDLING-- */    ret = PVFS_Request_contiguous(len, PVFS_BYTE, &file_req);    /* --BEGIN ERROR HANDLING-- */    if (ret != 0) {	*error_code = MPIO_Err_create_code(MPI_SUCCESS,					   MPIR_ERR_RECOVERABLE,					   myname, __LINE__,					   ADIOI_PVFS2_error_convert(ret),					   "Error in pvfs_request_contig (file)", 0);	return;    }    /* --END ERROR HANDLING-- */    if (file_ptr_type == ADIO_INDIVIDUAL) {	/* copy individual file pointer into offset variable, continue */	offset = fd->fp_ind;    }#ifdef ADIOI_MPE_LOGGING    MPE_Log_event( ADIOI_MPE_read_a, 0, NULL );#endif    ret = PVFS_sys_read(pvfs_fs->object_ref, file_req, offset, buf, 			mem_req, &(pvfs_fs->credentials), &resp_io);#ifdef ADIOI_MPE_LOGGING    MPE_Log_event( ADIOI_MPE_read_b, 0, NULL );#endif    /* --BEGIN ERROR HANDLING-- */    if (ret != 0 ) {	*error_code = MPIO_Err_create_code(MPI_SUCCESS,					   MPIR_ERR_RECOVERABLE,					   myname, __LINE__,					   ADIOI_PVFS2_error_convert(ret),					   "Error in PVFS_sys_read", 0);	goto fn_exit;    }    /* --END ERROR HANDLING-- */    if (file_ptr_type == ADIO_INDIVIDUAL) {	fd->fp_ind += (int) resp_io.total_completed;	/* TODO: WHY THE INT CAST? */    }    fd->fp_sys_posn = offset + (int)resp_io.total_completed;#ifdef HAVE_STATUS_SET_BYTES    MPIR_Status_set_bytes(status, datatype, (int)resp_io.total_completed);#endif    *error_code = MPI_SUCCESS;fn_exit:    PVFS_Request_free(&mem_req);    PVFS_Request_free(&file_req);    return;}void ADIOI_PVFS2_ReadStrided(ADIO_File fd, void *buf, int count,			     MPI_Datatype datatype, int file_ptr_type,			     ADIO_Offset offset, ADIO_Status *status, int			     *error_code){    /* offset is in units of etype relative to the filetype. */    ADIOI_Flatlist_node *flat_buf, *flat_file;    int i, j, k,  brd_size, frd_size=0, st_index=0;    int bufsize, sum, n_etypes_in_filetype, size_in_filetype;    int n_filetypes, etype_in_filetype;    ADIO_Offset abs_off_in_filetype=0;    int filetype_size, etype_size, buftype_size;    MPI_Aint filetype_extent, buftype_extent;     int buf_count, buftype_is_contig, filetype_is_contig;    ADIO_Offset off, disp, start_off, initial_off;    int flag, st_frd_size, st_n_filetypes;    int mem_list_count, file_list_count;    PVFS_size *mem_offsets;    int64_t *file_offsets;    int *mem_lengths;    int32_t *file_lengths;    int total_blks_to_read;    int max_mem_list, max_file_list;    int b_blks_read;    int f_data_read;    int size_read=0, n_read_lists, extra_blks;    int end_brd_size, end_frd_size;    int start_k, start_j, new_file_read, new_buffer_read;    int start_mem_offset;    PVFS_Request mem_req, file_req;    ADIOI_PVFS2_fs * pvfs_fs;    PVFS_sysresp_io resp_io;    int err_flag=0;    MPI_Offset total_bytes_read = 0;    static char myname[] = "ADIOI_PVFS2_ReadStrided";#define MAX_ARRAY_SIZE 64    *error_code = MPI_SUCCESS;  /* changed below if error */    ADIOI_Datatype_iscontig(datatype, &buftype_is_contig);    ADIOI_Datatype_iscontig(fd->filetype, &filetype_is_contig);    /* the HDF5 tests showed a bug in this list processing code (see many many     * lines down below).  We added a workaround, but common HDF5 file types     * are actually contiguous and do not need the expensive workarond */    if (!filetype_is_contig) {	flat_file = ADIOI_Flatlist;	while (flat_file->type != fd->filetype) flat_file = flat_file->next;	if (flat_file->count == 1 && !buftype_is_contig)	    filetype_is_contig = 1;    }    MPI_Type_size(fd->filetype, &filetype_size);    if ( ! filetype_size ) {	*error_code = MPI_SUCCESS; 	return;    }    MPI_Type_extent(fd->filetype, &filetype_extent);    MPI_Type_size(datatype, &buftype_size);    MPI_Type_extent(datatype, &buftype_extent);    etype_size = fd->etype_size;    bufsize = buftype_size * count;        pvfs_fs = (ADIOI_PVFS2_fs*)fd->fs_ptr;    if (!buftype_is_contig && filetype_is_contig) {/* noncontiguous in memory, contiguous in file. */        int64_t file_offsets;	int32_t file_lengths;	ADIOI_Flatten_datatype(datatype);	flat_buf = ADIOI_Flatlist;	while (flat_buf->type != datatype) flat_buf = flat_buf->next;	off = (file_ptr_type == ADIO_INDIVIDUAL) ? fd->fp_ind : 	    fd->disp + etype_size * offset;	file_list_count = 1;	file_offsets = off;	file_lengths = 0;	total_blks_to_read = count*flat_buf->count;	b_blks_read = 0;	/* allocate arrays according to max usage */	if (total_blks_to_read > MAX_ARRAY_SIZE)	    mem_list_count = MAX_ARRAY_SIZE;	else mem_list_count = total_blks_to_read;	mem_offsets = (PVFS_size*)ADIOI_Malloc(mem_list_count*sizeof(PVFS_size));	mem_lengths = (int*)ADIOI_Malloc(mem_list_count*sizeof(int));	/* TODO: CHECK RESULTS OF MEMORY ALLOCATION */	j = 0;	/* step through each block in memory, filling memory arrays */	while (b_blks_read < total_blks_to_read) {	    for (i=0; i<flat_buf->count; i++) {		mem_offsets[b_blks_read % MAX_ARRAY_SIZE] = 		    /* TODO: fix this compiler warning */		    ((PVFS_size)buf + j*buftype_extent + flat_buf->indices[i]);		mem_lengths[b_blks_read % MAX_ARRAY_SIZE] = 		    flat_buf->blocklens[i];		file_lengths += flat_buf->blocklens[i];		b_blks_read++;		if (!(b_blks_read % MAX_ARRAY_SIZE) ||		    (b_blks_read == total_blks_to_read)) {		    /* in the case of the last read list call,		       adjust mem_list_count */		    if (b_blks_read == total_blks_to_read) {		        mem_list_count = total_blks_to_read % MAX_ARRAY_SIZE;			/* in case last read list call fills max arrays */			if (!mem_list_count) mem_list_count = MAX_ARRAY_SIZE;		    }		    err_flag = PVFS_Request_hindexed(mem_list_count, 			    mem_lengths, mem_offsets, PVFS_BYTE, &mem_req);		    if (err_flag < 0) break;		    err_flag = PVFS_Request_contiguous(file_lengths, 			    PVFS_BYTE, &file_req);		    if (err_flag < 0) break;#ifdef ADIOI_MPE_LOGGING                    MPE_Log_event( ADIOI_MPE_read_a, 0, NULL );#endif		    err_flag = PVFS_sys_read(pvfs_fs->object_ref, file_req, 			    file_offsets, PVFS_BOTTOM, mem_req, 			    &(pvfs_fs->credentials), &resp_io);#ifdef ADIOI_MPE_LOGGING                    MPE_Log_event( ADIOI_MPE_read_b, 0, NULL );#endif		    /* --BEGIN ERROR HANDLING-- */		    if (err_flag != 0) {			*error_code = MPIO_Err_create_code(MPI_SUCCESS,							   MPIR_ERR_RECOVERABLE,							   myname, __LINE__,							   ADIOI_PVFS2_error_convert(err_flag),							   "Error in PVFS_sys_read", 0);			goto error_state;		    }		    PVFS_Request_free(&mem_req);		    PVFS_Request_free(&file_req);		    total_bytes_read += resp_io.total_completed;		    /* --END ERROR HANDLING-- */		  		    /* in the case of error or the last read list call, 		     * leave here */		    if (err_flag || b_blks_read == total_blks_to_read) break;		    file_offsets += file_lengths;		    file_lengths = 0;		} 	    } /* for (i=0; i<flat_buf->count; i++) */	    j++;	} /* while (b_blks_read < total_blks_to_read) */	ADIOI_Free(mem_offsets);	ADIOI_Free(mem_lengths);        if (file_ptr_type == ADIO_INDIVIDUAL) 	    fd->fp_ind += total_bytes_read;	fd->fp_sys_posn = -1;  /* set it to null. */#ifdef HAVE_STATUS_SET_BYTES	MPIR_Status_set_bytes(status, datatype, bufsize);	/* This isa temporary way of filling in status.  The right way is to	   keep tracke of how much data was actually read adn placed in buf	   by ADIOI_BUFFERED_READ. */#endif	ADIOI_Delete_flattened(datatype);	return;    } /* if (!buftype_is_contig && filetype_is_contig) */    /* know file is noncontiguous from above */    /* noncontiguous in file */    /* filetype already flattened in ADIO_Open */    flat_file = ADIOI_Flatlist;    while (flat_file->type != fd->filetype) flat_file = flat_file->next;    disp = fd->disp;    initial_off = offset;    /* for each case - ADIO_Individual pointer or explicit, find the file       offset in bytes (offset), n_filetypes (how many filetypes into       file to start), frd_size (remaining amount of data in present       file block), and st_index (start point in terms of blocks in       starting filetype) */    if (file_ptr_type == ADIO_INDIVIDUAL) {        offset = fd->fp_ind; /* in bytes */	n_filetypes = -1;	flag = 0;	while (!flag) {	    n_filetypes++;	    for (i=0; i<flat_file->count; i++) {	        if (disp + flat_file->indices[i] + 		    ((ADIO_Offset) n_filetypes)*filetype_extent +		    flat_file->blocklens[i]  >= offset) {		    st_index = i;		    frd_size = (int) (disp + flat_file->indices[i] + 				    ((ADIO_Offset) n_filetypes)*filetype_extent				      + flat_file->blocklens[i] - offset);		    flag = 1;		    break;		}	    }	} /* while (!flag) */    } /* if (file_ptr_type == ADIO_INDIVIDUAL) */    else {        n_etypes_in_filetype = filetype_size/etype_size;	n_filetypes = (int) (offset / n_etypes_in_filetype);	etype_in_filetype = (int) (offset % n_etypes_in_filetype);	size_in_filetype = etype_in_filetype * etype_size;		sum = 0;	for (i=0; i<flat_file->count; i++) {	    sum += flat_file->blocklens[i];	    if (sum > size_in_filetype) {	        st_index = i;		frd_size = sum - size_in_filetype;		abs_off_in_filetype = flat_file->indices[i] +		    size_in_filetype - (sum - flat_file->blocklens[i]);		break;	    }	}		/* abs. offset in bytes in the file */	offset = disp + ((ADIO_Offset) n_filetypes)*filetype_extent + 	    abs_off_in_filetype;

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -