ad_xfs_fcntl.c

来自「MPICH是MPI的重要研究,提供了一系列的接口函数,为并行计算的实现提供了编程」· C语言 代码 · 共 143 行

C
143
字号
/* -*- Mode: C; c-basic-offset:4 ; -*- *//*  *   $Id: ad_xfs_fcntl.c,v 1.6 2002/10/24 17:01:09 gropp Exp $     * *   Copyright (C) 1997 University of Chicago.  *   See COPYRIGHT notice in top-level directory. */#include "ad_xfs.h"#include "adio_extern.h"#ifdef MPISGI#include "mpisgi2.h"#endifvoid ADIOI_XFS_Fcntl(ADIO_File fd, int flag, ADIO_Fcntl_t *fcntl_struct, int *error_code){    MPI_Datatype copy_etype, copy_filetype;    int combiner, i, j, k, filetype_is_contig, err;    ADIOI_Flatlist_node *flat_file;    struct flock64 fl;#ifndef PRINT_ERR_MSG    static char myname[] = "ADIOI_XFS_FCNTL";#endif    switch(flag) {    case ADIO_FCNTL_SET_VIEW:        /* free copies of old etypes and filetypes and delete flattened            version of filetype if necessary */	MPI_Type_get_envelope(fd->etype, &i, &j, &k, &combiner);	if (combiner != MPI_COMBINER_NAMED) MPI_Type_free(&(fd->etype));	ADIOI_Datatype_iscontig(fd->filetype, &filetype_is_contig);	if (!filetype_is_contig) ADIOI_Delete_flattened(fd->filetype);	MPI_Type_get_envelope(fd->filetype, &i, &j, &k, &combiner);	if (combiner != MPI_COMBINER_NAMED) MPI_Type_free(&(fd->filetype));	/* set new info */	ADIO_SetInfo(fd, fcntl_struct->info, &err);        /* set new etypes and filetypes */	MPI_Type_get_envelope(fcntl_struct->etype, &i, &j, &k, &combiner);	if (combiner == MPI_COMBINER_NAMED) fd->etype = fcntl_struct->etype;	else {	    MPI_Type_contiguous(1, fcntl_struct->etype, &copy_etype);	    MPI_Type_commit(&copy_etype);	    fd->etype = copy_etype;	}	MPI_Type_get_envelope(fcntl_struct->filetype, &i, &j, &k, &combiner);	if (combiner == MPI_COMBINER_NAMED) 	    fd->filetype = fcntl_struct->filetype;	else {	    MPI_Type_contiguous(1, fcntl_struct->filetype, &copy_filetype);	    MPI_Type_commit(&copy_filetype);	    fd->filetype = copy_filetype;	    ADIOI_Flatten_datatype(fd->filetype);            /* this function will not flatten the filetype if it turns out               to be all contiguous. */	}	MPI_Type_size(fd->etype, &(fd->etype_size));	fd->disp = fcntl_struct->disp;        /* reset MPI-IO file pointer to point to the first byte that can           be accessed in this view. */        ADIOI_Datatype_iscontig(fd->filetype, &filetype_is_contig);	if (filetype_is_contig) fd->fp_ind = fcntl_struct->disp;	else {	    flat_file = ADIOI_Flatlist;	    while (flat_file->type != fd->filetype) 		flat_file = flat_file->next;	    for (i=0; i<flat_file->count; i++) {		if (flat_file->blocklens[i]) {		    fd->fp_ind = fcntl_struct->disp + flat_file->indices[i];		    break;		}	    }	}	*error_code = MPI_SUCCESS;	break;    case ADIO_FCNTL_GET_FSIZE:	fcntl_struct->fsize = lseek64(fd->fd_sys, 0, SEEK_END);#ifdef PRINT_ERR_MSG	*error_code = (fcntl_struct->fsize == -1) ? MPI_ERR_UNKNOWN : MPI_SUCCESS;#else	if (fcntl_struct->fsize == -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	break;    case ADIO_FCNTL_SET_DISKSPACE:	i = 0;	fl.l_start = 0;	fl.l_whence = SEEK_SET;	fl.l_len = fcntl_struct->diskspace;	err = fcntl(fd->fd_sys, F_RESVSP64, &fl);	if (err) i = 1;	if (fcntl_struct->diskspace > lseek64(fd->fd_sys, 0, SEEK_END)) {	    /* also need to set the file size */	    err = ftruncate64(fd->fd_sys, fcntl_struct->diskspace);	    if (err) i = 1;	}#ifdef PRINT_ERR_MSG	*error_code = (i == 0) ? MPI_SUCCESS : MPI_ERR_UNKNOWN;#else	if (i == 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	break;    case ADIO_FCNTL_SET_IOMODE:        /* for implementing PFS I/O modes. will not occur in MPI-IO           implementation.*/	if (fd->iomode != fcntl_struct->iomode) {	    fd->iomode = fcntl_struct->iomode;	    MPI_Barrier(MPI_COMM_WORLD);	}	*error_code = MPI_SUCCESS;	break;    case ADIO_FCNTL_SET_ATOMICITY:	fd->atomicity = (fcntl_struct->atomicity == 0) ? 0 : 1;	*error_code = MPI_SUCCESS;	break;    default:	FPRINTF(stderr, "Unknown flag passed to ADIOI_XFS_Fcntl\n");	MPI_Abort(MPI_COMM_WORLD, 1);    }}

⌨️ 快捷键说明

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