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

📄 ad_pvfs2_read.c

📁 fortran并行计算包
💻 C
📖 第 1 页 / 共 3 页
字号:
	    /*  fakes filling the readlist arrays of lengths found above  */	    k = start_k;	    j = start_j;	    for (i=0; i<mem_list_count; i++) {	     		if(i) {		    if (i == (mem_list_count - 1)) {			if (flat_buf->blocklens[k] == end_brd_size)			    brd_size = flat_buf->blocklens[(k+1)%							  flat_buf->count];			else {			    brd_size = flat_buf->blocklens[k] - end_brd_size;			    k--;			    buf_count--;			}		    }		}		buf_count++;		k = (k + 1)%flat_buf->count;	    } /* for (i=0; i<mem_list_count; i++) */	    for (i=0; i<file_list_count; i++) {		if (i) {		    if (i == (file_list_count - 1)) {			if (flat_file->blocklens[j] == end_frd_size)			    frd_size = flat_file->blocklens[(j+1)%							  flat_file->count];   			else {			    frd_size = flat_file->blocklens[j] - end_frd_size;			    j--;			}		    }		}		if (j < flat_file->count - 1) j++;		else {		    j = 0;		    n_filetypes++;		}	    } /* for (i=0; i<file_list_count; i++) */	    size_read += new_buffer_read;	    start_k = k;	    start_j = j;	    if (max_mem_list < mem_list_count)	        max_mem_list = mem_list_count;	    if (max_file_list < file_list_count)	        max_file_list = file_list_count;	} /* while (size_read < bufsize) */	/* one last check before we actually carry out the operation:	 * this code has hard-to-fix bugs when a noncontiguous file type has	 * such large pieces that the sum of the lengths of the memory type is	 * not larger than one of those pieces (and vice versa for large memory	 * types and many pices of file types.  In these cases, give up and	 * fall back to naive reads and writes.  The testphdf5 test created a	 * type with two very large memory regions and 600 very small file	 * regions.  The same test also created a type with one very large file	 * region and many (700) very small memory regions.  both cases caused	 * problems for this code */	if ( ( (file_list_count == 1) && 		    (new_file_read < flat_file->blocklens[0] ) ) ||		((mem_list_count == 1) && 		    (new_buffer_read < flat_buf->blocklens[0]) ) ||		((file_list_count == MAX_ARRAY_SIZE) && 		    (new_file_read < flat_buf->blocklens[0]) ) ||		( (mem_list_count == MAX_ARRAY_SIZE) &&		    (new_buffer_read < flat_file->blocklens[0])) )	{	    ADIOI_Delete_flattened(datatype);	    ADIOI_GEN_ReadStrided_naive(fd, buf, count, datatype,		    file_ptr_type, initial_off, status, error_code);	    return;	}	mem_offsets = (PVFS_size*)ADIOI_Malloc(max_mem_list*sizeof(PVFS_size));	mem_lengths = (int *)ADIOI_Malloc(max_mem_list*sizeof(int));	file_offsets = (int64_t *)ADIOI_Malloc(max_file_list*sizeof(int64_t));	file_lengths = (int32_t *)ADIOI_Malloc(max_file_list*sizeof(int32_t));	    	size_read = 0;	n_filetypes = st_n_filetypes;	frd_size = st_frd_size;	brd_size = flat_buf->blocklens[0];	buf_count = 0;	start_mem_offset = 0;	start_k = k = 0;	start_j = st_index;	/*  this section calculates mem_list_count and file_list_count	    and also finds the possibly odd sized last array elements	    in new_frd_size and new_brd_size  */		while (size_read < bufsize) {	    k = start_k;	    new_buffer_read = 0;	    mem_list_count = 0;	    while ((mem_list_count < MAX_ARRAY_SIZE) && 		   (new_buffer_read < bufsize-size_read)) {	        /* find mem_list_count and file_list_count such that both are		   less than MAX_ARRAY_SIZE, the sum of their lengths are		   equal, and the sum of all the data read and data to be		   read in the next immediate read list is less than		   bufsize */	        if(mem_list_count) {		    if((new_buffer_read + flat_buf->blocklens[k] + 			size_read) > bufsize) {		        end_brd_size = new_buffer_read + 			    flat_buf->blocklens[k] - (bufsize - size_read);			new_buffer_read = bufsize - size_read;		    }		    else {		        new_buffer_read += flat_buf->blocklens[k];			end_brd_size = flat_buf->blocklens[k];		    }		}		else {		    if (brd_size > (bufsize - size_read)) {		        new_buffer_read = bufsize - size_read;			brd_size = new_buffer_read;		    }		    else new_buffer_read = brd_size;		}		mem_list_count++;		k = (k + 1)%flat_buf->count;	     } /* while ((mem_list_count < MAX_ARRAY_SIZE) && 	       (new_buffer_read < bufsize-size_read)) */	    j = start_j;	    new_file_read = 0;	    file_list_count = 0;	    while ((file_list_count < MAX_ARRAY_SIZE) && 		   (new_file_read < new_buffer_read)) {	        if(file_list_count) {		    if((new_file_read + flat_file->blocklens[j]) > 		       new_buffer_read) {		        end_frd_size = new_buffer_read - new_file_read;			new_file_read = new_buffer_read;			j--;		    }		    else {		        new_file_read += flat_file->blocklens[j];			end_frd_size = flat_file->blocklens[j];		    }		}		else {		    if (frd_size > new_buffer_read) {		        new_file_read = new_buffer_read;			frd_size = new_file_read;		    }		    else new_file_read = frd_size;		}		file_list_count++;		if (j < (flat_file->count - 1)) j++;		else j = 0;				k = start_k;		if ((new_file_read < new_buffer_read) && 		    (file_list_count == MAX_ARRAY_SIZE)) {		    new_buffer_read = 0;		    mem_list_count = 0;		    while (new_buffer_read < new_file_read) {		        if(mem_list_count) {			    if((new_buffer_read + flat_buf->blocklens[k]) >			       new_file_read) {			        end_brd_size = new_file_read - new_buffer_read;				new_buffer_read = new_file_read;				k--;			    }			    else {			        new_buffer_read += flat_buf->blocklens[k];				end_brd_size = flat_buf->blocklens[k];			    }			}			else {			    new_buffer_read = brd_size;			    if (brd_size > (bufsize - size_read)) {			        new_buffer_read = bufsize - size_read;				brd_size = new_buffer_read;			    }			}			mem_list_count++;			k = (k + 1)%flat_buf->count;		    } /* while (new_buffer_read < new_file_read) */		} /* if ((new_file_read < new_buffer_read) && (file_list_count		     == MAX_ARRAY_SIZE)) */	    } /* while ((mem_list_count < MAX_ARRAY_SIZE) && 		 (new_buffer_read < bufsize-size_read)) */	    /*  fills the allocated readlist arrays  */	    k = start_k;	    j = start_j;	    for (i=0; i<mem_list_count; i++) {	     	        mem_offsets[i] = ((PVFS_size)buf + buftype_extent*					 (buf_count/flat_buf->count) +					 (int)flat_buf->indices[k]);		if(!i) {		    mem_lengths[0] = brd_size;		    mem_offsets[0] += flat_buf->blocklens[k] - brd_size;		}		else {		    if (i == (mem_list_count - 1)) {		        mem_lengths[i] = end_brd_size;			if (flat_buf->blocklens[k] == end_brd_size)			    brd_size = flat_buf->blocklens[(k+1)%							  flat_buf->count];			else {			    brd_size = flat_buf->blocklens[k] - end_brd_size;			    k--;			    buf_count--;			}		    }		    else {		        mem_lengths[i] = flat_buf->blocklens[k];		    }		}		buf_count++;		k = (k + 1)%flat_buf->count;	    } /* for (i=0; i<mem_list_count; i++) */	    for (i=0; i<file_list_count; i++) {	        file_offsets[i] = disp + flat_file->indices[j] + 		    ((ADIO_Offset)n_filetypes) * filetype_extent;	        if (!i) {		    file_lengths[0] = frd_size;		    file_offsets[0] += flat_file->blocklens[j] - frd_size;		}		else {		    if (i == (file_list_count - 1)) {		        file_lengths[i] = end_frd_size;			if (flat_file->blocklens[j] == end_frd_size)			    frd_size = flat_file->blocklens[(j+1)%							  flat_file->count];   			else {			    frd_size = flat_file->blocklens[j] - end_frd_size;			    j--;			}		    }		    else file_lengths[i] = flat_file->blocklens[j];		}		if (j < flat_file->count - 1) j++;		else {		    j = 0;		    n_filetypes++;		}	    } /* for (i=0; i<file_list_count; i++) */	    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);		goto error_state;	    }	    /* -- END ERROR HANDLING-- */	    err_flag = PVFS_Request_hindexed(file_list_count, file_lengths, 		    file_offsets, 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_hindexed (file)", 0);		goto error_state;	    }	    /* --END ERROR HANDLING-- */	    /* offset will be expressed in memory and file datatypes */#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, 0, 		    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);	    }	    /* --END ERROR HANDLING-- */	    PVFS_Request_free(&mem_req);	    PVFS_Request_free(&file_req);	    total_bytes_read += resp_io.total_completed;	    size_read += new_buffer_read;	    start_k = k;	    start_j = j;	} /* while (size_read < bufsize) */	ADIOI_Free(mem_offsets);	ADIOI_Free(mem_lengths);    }    ADIOI_Free(file_offsets);    ADIOI_Free(file_lengths);        /* Other ADIO routines will convert absolute bytes into counts of datatypes */    /* when incrementing fp_ind, need to also take into account the file type:     * consider an N-element 1-d subarray with a lb and ub: ( |---xxxxx-----|     * if we wrote N elements, offset needs to point at beginning of type, not     * at empty region at offset N+1) */    if (file_ptr_type == ADIO_INDIVIDUAL) {	/* this is closer, but still incorrect for the cases where a small	 * amount of a file type is "leftover" after a write */	fd->fp_ind = disp + flat_file->indices[j] + 	    ((ADIO_Offset)n_filetypes)*filetype_extent;    }    if (err_flag == 0) *error_code = MPI_SUCCESS;error_state:    fd->fp_sys_posn = -1;   /* set it to null. */#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 read and placed in buf        by ADIOI_BUFFERED_READ. */#endif        if (!buftype_is_contig) ADIOI_Delete_flattened(datatype);}/* * vim: ts=8 sts=4 sw=4 noexpandtab  */

⌨️ 快捷键说明

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