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

📄 ad_pvfs2_write.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 "ad_pvfs2.h"#include "adio_extern.h"#include "ad_pvfs2_common.h"void ADIOI_PVFS2_WriteContig(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_WRITECONTIG";    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_contiguous (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_contiguous (file)", 0);	return;    }    /* --END ERROR HANDLING-- */    if (file_ptr_type == ADIO_EXPLICIT_OFFSET) {#ifdef ADIOI_MPE_LOGGING        MPE_Log_event( ADIOI_MPE_write_a, 0, NULL );#endif	ret = PVFS_sys_write(pvfs_fs->object_ref, file_req, offset,  buf, 			     mem_req, &(pvfs_fs->credentials), &resp_io);#ifdef ADIOI_MPE_LOGGING        MPE_Log_event( ADIOI_MPE_write_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_write", 0);	    goto fn_exit;	}	/* --END ERROR HANDLING-- */	fd->fp_sys_posn = offset + (int) resp_io.total_completed;    }    else {#ifdef ADIOI_MPE_LOGGING        MPE_Log_event( ADIOI_MPE_write_a, 0, NULL );#endif	ret = PVFS_sys_write(pvfs_fs->object_ref, file_req, fd->fp_ind, buf, 			     mem_req, &(pvfs_fs->credentials), &resp_io);#ifdef ADIOI_MPE_LOGGING        MPE_Log_event( ADIOI_MPE_write_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_write", 0);	    goto fn_exit;	}	/* --END ERROR HANDLING-- */	fd->fp_ind += (int)resp_io.total_completed;	fd->fp_sys_posn = fd->fp_ind;    }#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(&file_req);    PVFS_Request_free(&mem_req);    return;}void ADIOI_PVFS2_WriteStrided(ADIO_File fd, void *buf, int count,			      MPI_Datatype datatype, int file_ptr_type,			      ADIO_Offset offset, ADIO_Status *status,			      int *error_code){    /* as with all the other WriteStrided functions, offset is in units of     * etype relative to the filetype */    /* Since PVFS2 does not support file locking, can't do buffered writes       as on Unix */    ADIOI_Flatlist_node *flat_buf, *flat_file;    int i, j, k, bwr_size, fwr_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_fwr_size, st_n_filetypes;    int err_flag=0;    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_write;    int max_mem_list, max_file_list;    int b_blks_wrote;    int f_data_wrote;    int size_wrote=0, n_write_lists, extra_blks;    int end_bwr_size, end_fwr_size;    int start_k, start_j, new_file_write, new_buffer_write;    int start_mem_offset;    PVFS_Request mem_req, file_req;    ADIOI_PVFS2_fs * pvfs_fs;    PVFS_sysresp_io resp_io;    MPI_Offset total_bytes_written=0;    static char myname[] = "ADIOI_PVFS2_WRITESTRIDED";    /* note: don't increase this: several parts of PVFS2 now      * assume this limit*/#define MAX_ARRAY_SIZE 64    /* --BEGIN ERROR HANDLING-- */    if (fd->atomicity) {	*error_code = MPIO_Err_create_code(MPI_SUCCESS,					   MPIR_ERR_RECOVERABLE,					   myname, __LINE__,					   MPI_ERR_ARG,					   "Atomic noncontiguous writes are not supported by PVFS2", 0);	return;    }    /* --END ERROR HANDLING-- */    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;		if (file_ptr_type == ADIO_EXPLICIT_OFFSET) {	    off = fd->disp + etype_size * offset;	}	else off = fd->fp_ind;	file_list_count = 1;	file_offsets = off;	file_lengths = 0;	total_blks_to_write = count*flat_buf->count;	b_blks_wrote = 0;	/* allocate arrays according to max usage */	if (total_blks_to_write > MAX_ARRAY_SIZE)	    mem_list_count = MAX_ARRAY_SIZE;	else mem_list_count = total_blks_to_write;	mem_offsets = (PVFS_size*)ADIOI_Malloc(mem_list_count*sizeof(PVFS_size));	mem_lengths = (int*)ADIOI_Malloc(mem_list_count*sizeof(int));	j = 0;	/* step through each block in memory, filling memory arrays */	while (b_blks_wrote < total_blks_to_write) {	    for (i=0; i<flat_buf->count; i++) {		mem_offsets[b_blks_wrote % MAX_ARRAY_SIZE] = 		    /* TODO: fix this warning by casting to an integer that's		     * the same size as a char * and /then/ casting to		     * PVFS_size */		    ((PVFS_size)buf + j*buftype_extent + flat_buf->indices[i]);		mem_lengths[b_blks_wrote % MAX_ARRAY_SIZE] = 		    flat_buf->blocklens[i];		file_lengths += flat_buf->blocklens[i];		b_blks_wrote++;		if (!(b_blks_wrote % MAX_ARRAY_SIZE) ||		    (b_blks_wrote == total_blks_to_write)) {		    /* in the case of the last write list call,		       adjust mem_list_count */		    if (b_blks_wrote == total_blks_to_write) {		        mem_list_count = total_blks_to_write % MAX_ARRAY_SIZE;			/* in case last write 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);		    /* --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_Request_hindexed (memory)", 0);			break;		    }		    /* --END ERROR HANDLING-- */		    err_flag = PVFS_Request_contiguous(file_lengths, 						       PVFS_BYTE, &file_req);		    /* --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_Request_contiguous (file)", 0);			break;		    }		    /* --END ERROR HANDLING-- */#ifdef ADIOI_MPE_LOGGING                    MPE_Log_event( ADIOI_MPE_write_a, 0, NULL );#endif		    err_flag = PVFS_sys_write(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_write_b, 0, NULL );#endif		    total_bytes_written += resp_io.total_completed;		  		    /* in the case of error or the last write list call, 		     * leave here */		    /* --BEGIN ERROR HANDLING-- */		    if (err_flag) {			*error_code = MPIO_Err_create_code(MPI_SUCCESS,							   MPIR_ERR_RECOVERABLE,							   myname, __LINE__,							   ADIOI_PVFS2_error_convert(err_flag),							   "Error in PVFS_sys_write", 0);			break;		    }		    /* --END ERROR HANDLING-- */		    if (b_blks_wrote == total_blks_to_write) break;		    file_offsets += file_lengths;		    file_lengths = 0;		    PVFS_Request_free(&mem_req);		    PVFS_Request_free(&file_req);		} 	    } /* for (i=0; i<flat_buf->count; i++) */	    j++;	} /* while (b_blks_wrote < total_blks_to_write) */	ADIOI_Free(mem_offsets);	ADIOI_Free(mem_lengths);	if (file_ptr_type == ADIO_INDIVIDUAL) 	    fd->fp_ind += total_bytes_written;	if (!err_flag)  *error_code = MPI_SUCCESS;	fd->fp_sys_posn = -1;   /* clear this. */#ifdef HAVE_STATUS_SET_BYTES	MPIR_Status_set_bytes(status, datatype, bufsize);/* This is a temporary way of filling in status. The right way is to    keep track of how much data was actually written by ADIOI_BUFFERED_WRITE. */#endif	ADIOI_Delete_flattened(datatype);	return;    } /* if (!buftype_is_contig && filetype_is_contig) */    /* already know that 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 offset       (file offset in bytes), n_filetypes (how many filetypes into file        to start), fwr_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) {

⌨️ 快捷键说明

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