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

📄 ad_nfs_write.c

📁 mpi并行计算的c++代码 可用vc或gcc编译通过 可以用来搭建并行计算试验环境
💻 C
📖 第 1 页 / 共 2 页
字号:
/* -*- Mode: C; c-basic-offset:4 ; -*- *//*  * *   Copyright (C) 1997 University of Chicago.  *   See COPYRIGHT notice in top-level directory. */#include "ad_nfs.h"#include "adio_extern.h"void ADIOI_NFS_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 err=-1, datatype_size, len;    static char myname[] = "ADIOI_NFS_WRITECONTIG";    MPI_Type_size(datatype, &datatype_size);    len = datatype_size * count;    if (file_ptr_type == ADIO_EXPLICIT_OFFSET) {	if (fd->fp_sys_posn != offset)	    lseek(fd->fd_sys, offset, SEEK_SET);	ADIOI_WRITE_LOCK(fd, offset, SEEK_SET, len);	err = write(fd->fd_sys, buf, len);	ADIOI_UNLOCK(fd, offset, SEEK_SET, len);	fd->fp_sys_posn = offset + err;	/* individual file pointer not updated */            }    else { /* write from curr. location of ind. file pointer */	offset = fd->fp_ind;	if (fd->fp_sys_posn != fd->fp_ind)	    lseek(fd->fd_sys, fd->fp_ind, SEEK_SET);	ADIOI_WRITE_LOCK(fd, offset, SEEK_SET, len);	err = write(fd->fd_sys, buf, len);	ADIOI_UNLOCK(fd, offset, SEEK_SET, len);	fd->fp_ind += err;	fd->fp_sys_posn = fd->fp_ind;    }    /* --BEGIN ERROR HANDLING-- */    if (err == -1) {	*error_code = MPIO_Err_create_code(MPI_SUCCESS, MPIR_ERR_RECOVERABLE,					   myname, __LINE__, MPI_ERR_IO,					   "**io",					   "**io %s", strerror(errno));	return;    }    /* --END ERROR HANDLING-- */#ifdef HAVE_STATUS_SET_BYTES    MPIR_Status_set_bytes(status, datatype, err);#endif    *error_code = MPI_SUCCESS;}#define ADIOI_BUFFERED_WRITE \{ \    if (req_off >= writebuf_off + writebuf_len) { \	lseek(fd->fd_sys, writebuf_off, SEEK_SET); \	err = write(fd->fd_sys, writebuf, writebuf_len); \        if (!(fd->atomicity)) ADIOI_UNLOCK(fd, writebuf_off, SEEK_SET, writebuf_len); \        if (err == -1) err_flag = 1; \	writebuf_off = req_off; \        writebuf_len = (int) (ADIOI_MIN(max_bufsize,end_offset-writebuf_off+1));\	if (!(fd->atomicity)) ADIOI_WRITE_LOCK(fd, writebuf_off, SEEK_SET, writebuf_len); \	lseek(fd->fd_sys, writebuf_off, SEEK_SET); \	err = read(fd->fd_sys, writebuf, writebuf_len); \        if (err == -1) { \            *error_code = MPIO_Err_create_code(MPI_SUCCESS, \					       MPIR_ERR_RECOVERABLE, myname, \					       __LINE__, MPI_ERR_IO, \					       "**ioRMWrdwr", 0); \	    return; \        } \    } \    write_sz = (int) (ADIOI_MIN(req_len, writebuf_off + writebuf_len - req_off)); \    memcpy(writebuf+req_off-writebuf_off, (char *)buf +userbuf_off, write_sz);\    while (write_sz != req_len) { \	lseek(fd->fd_sys, writebuf_off, SEEK_SET); \	err = write(fd->fd_sys, writebuf, writebuf_len); \        if (!(fd->atomicity)) ADIOI_UNLOCK(fd, writebuf_off, SEEK_SET, writebuf_len); \        if (err == -1) err_flag = 1; \        req_len -= write_sz; \        userbuf_off += write_sz; \        writebuf_off += writebuf_len; \        writebuf_len = (int) (ADIOI_MIN(max_bufsize,end_offset-writebuf_off+1));\	if (!(fd->atomicity)) ADIOI_WRITE_LOCK(fd, writebuf_off, SEEK_SET, writebuf_len); \	lseek(fd->fd_sys, writebuf_off, SEEK_SET); \	err = read(fd->fd_sys, writebuf, writebuf_len); \        if (err == -1) { \	    *error_code = MPIO_Err_create_code(MPI_SUCCESS, \					       MPIR_ERR_RECOVERABLE, myname, \					       __LINE__, MPI_ERR_IO, \					       "**ioRMWrdwr", 0); \	    return; \        } \        write_sz = ADIOI_MIN(req_len, writebuf_len); \        memcpy(writebuf, (char *)buf + userbuf_off, write_sz);\    } \}/* this macro is used when filetype is contig and buftype is not contig.   it does not do a read-modify-write and does not lock*/#define ADIOI_BUFFERED_WRITE_WITHOUT_READ \{ \    if (req_off >= writebuf_off + writebuf_len) { \	lseek(fd->fd_sys, writebuf_off, SEEK_SET); \	if (!(fd->atomicity)) ADIOI_WRITE_LOCK(fd, writebuf_off, SEEK_SET, writebuf_len); \	err = write(fd->fd_sys, writebuf, writebuf_len); \        if (!(fd->atomicity)) ADIOI_UNLOCK(fd, writebuf_off, SEEK_SET, writebuf_len); \        if (err == -1) err_flag = 1; \	writebuf_off = req_off; \        writebuf_len = (int) (ADIOI_MIN(max_bufsize,end_offset-writebuf_off+1));\    } \    write_sz = (int) (ADIOI_MIN(req_len, writebuf_off + writebuf_len - req_off)); \    memcpy(writebuf+req_off-writebuf_off, (char *)buf +userbuf_off, write_sz);\    while (write_sz != req_len) { \	lseek(fd->fd_sys, writebuf_off, SEEK_SET); \	if (!(fd->atomicity)) ADIOI_WRITE_LOCK(fd, writebuf_off, SEEK_SET, writebuf_len); \	err = write(fd->fd_sys, writebuf, writebuf_len); \        if (!(fd->atomicity)) ADIOI_UNLOCK(fd, writebuf_off, SEEK_SET, writebuf_len); \        if (err == -1) err_flag = 1; \        req_len -= write_sz; \        userbuf_off += write_sz; \        writebuf_off += writebuf_len; \        writebuf_len = (int) (ADIOI_MIN(max_bufsize,end_offset-writebuf_off+1));\        write_sz = ADIOI_MIN(req_len, writebuf_len); \        memcpy(writebuf, (char *)buf + userbuf_off, write_sz);\    } \}void ADIOI_NFS_WriteStrided(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, err=-1, bwr_size, fwr_size=0, st_index=0;    int bufsize, num, size, 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, req_len;    MPI_Aint filetype_extent, buftype_extent;     int buf_count, buftype_is_contig, filetype_is_contig;    ADIO_Offset userbuf_off;    ADIO_Offset off, req_off, disp, end_offset=0, writebuf_off, start_off;    char *writebuf, *value;    int flag, st_fwr_size, st_n_filetypes, writebuf_len, write_sz;    int new_bwr_size, new_fwr_size, err_flag=0, info_flag, max_bufsize;    static char myname[] = "ADIOI_NFS_WRITESTRIDED";    ADIOI_Datatype_iscontig(datatype, &buftype_is_contig);    ADIOI_Datatype_iscontig(fd->filetype, &filetype_is_contig);    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;/* get max_bufsize from the info object. */    value = (char *) ADIOI_Malloc((MPI_MAX_INFO_VAL+1)*sizeof(char));    MPI_Info_get(fd->info, "ind_wr_buffer_size", MPI_MAX_INFO_VAL, value,                  &info_flag);    max_bufsize = atoi(value);    ADIOI_Free(value);    if (!buftype_is_contig && filetype_is_contig) {/* noncontiguous in memory, contiguous in file. */	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;        start_off = off;	end_offset = off + bufsize - 1;        writebuf_off = off;        writebuf = (char *) ADIOI_Malloc(max_bufsize);        writebuf_len = (int) (ADIOI_MIN(max_bufsize,end_offset-writebuf_off+1));/* if atomicity is true, lock the region to be accessed */        if (fd->atomicity)             ADIOI_WRITE_LOCK(fd, start_off, SEEK_SET, end_offset-start_off+1);        for (j=0; j<count; j++)             for (i=0; i<flat_buf->count; i++) {                userbuf_off = j*buftype_extent + flat_buf->indices[i];		req_off = off;		req_len = flat_buf->blocklens[i];		ADIOI_BUFFERED_WRITE_WITHOUT_READ                off += flat_buf->blocklens[i];            }        /* write the buffer out finally */	lseek(fd->fd_sys, writebuf_off, SEEK_SET); 	if (!(fd->atomicity)) ADIOI_WRITE_LOCK(fd, writebuf_off, SEEK_SET, writebuf_len);	err = write(fd->fd_sys, writebuf, writebuf_len);         if (!(fd->atomicity)) ADIOI_UNLOCK(fd, writebuf_off, SEEK_SET, writebuf_len);        if (err == -1) err_flag = 1;         if (fd->atomicity)             ADIOI_UNLOCK(fd, start_off, SEEK_SET, end_offset-start_off+1);	ADIOI_Free(writebuf); /* malloced in the buffered_write macro */        if (file_ptr_type == ADIO_INDIVIDUAL) fd->fp_ind = off;	if (err_flag) {	    *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;    }

⌨️ 快捷键说明

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