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

📄 vnd.par.lib

📁 su 的源代码库
💻 LIB
📖 第 1 页 / 共 2 页
字号:
VND - large out-of-core multidimensional block matrix transposeThe VND routines are intended for avoiding the need for virtualmemory when prototyping large out-of-core problems where multidimensional matrix transposes are required.  The data are stored in a multidimensional block matrix transpose format where the dimension of the matrix is user defined.  The data are accessed by the user as vectors for any given dimension with all the other dimensions fixed or defined as a key.  The vector elements all have the same user defined number of bytes per element (or node).  The userspecifies how much memory he would like to allocate for bufferingVND I/O operations.  The VND routines break up the multidimensionalmatrix into chunks small enough to fit within this memory limitationif at all possible.  If not, the routines use the smallest amountof memory that they can.  If the data fits in memory, then itis put into memory and no I/O operations are required except to save on disk.A dimension over which the data need not be transposed can be defined as thepanel dimension.  If panels are used, then the file structure becomesthat of a sequence of block matrix transpose structures, one for each panel.  Normally, only one panel is stored in memory at a time.The user has the option to specify 2 or more simultaneously openpanels at the expense of using more memory.  The variable "iopanel"ranges from 0 to the number of open panels minus 1.  The variableipanel" ranges from 0 to the number of panels in the VND filesminus 1.  Two calls to VNDrw with different values of "iopanel"should not have the same value of "ipanel" unless both are only reading.There is a preferred dimension for Input/Output efficiency.  That isthe first dimension (idim=0, all of the indicies are zero based).  Inthe first dimension, a slice through the block matrix structure canbe read or written in one request.  In all all other dimensions, readingor writing a slice requires multiple I/O requests.  Therefore, itis best to choose the first dimension for the dimension with themost I/O activity.Real-to-Complex FFT's increase the number of bytes per node anddecrease the number of nodes in a give dimension by a factorof 2.  To allow this option in dimension 0, the number of nodesper block in dimension 0  is forced to be even.  This allowsone  to modify the number of bytes per node and number of nodesin the first dimension to change the data from real to complexshould that be necessary.  This option is not possible forother than the first dimension.  Clearly, which dimension is chosen to be the first is arbitrary other than for considerationsof Input/Output efficiency and this option.For some applications, it may be desirable to have two dimensionsof size NA and NB in memory at a time to allow rapid changes inaccess direction.  Define a single VND dimension withsize NA*NB and access values using the parameters defining startingelement and element increment in VNDrw.  This option keeps userbuffer sizes small and minimizes I/O overhead for some problems.For implementing the Fowler DMO algorithm, one would usetemporal frequency and velocity together as a function of CMPposition in a single dimension.  This would allow the VNDroutines to avoid swapping block matrix slices during the initial write of the VND files as the input CMP gathers are stacked fora range of velocities, Fourier transformed from time to frequency,and written out to the VND file.   The Unix operating system typically has a 2 gigabyte limit for each file system.  When this limit is too small, the VND routines can spread the data out over multiple file systems as defined by the user.  Only one physical file is actually open at one time to avoid the Unix limitationson the number of open files allowed.  The code is written in ANSI C and should not be limited to the Unix operating system.The call to VNDop with mode equal to 2 can take a long time as thefirst call initializes the file structure to have all zero bytes.This may involve a significant amount of I/O for large VND files.The VND user C interface consists of 4 routines:VND *VNDop(int mode, long lwmax, int ndim, long *N, long npanels, 		long nbytes, char *file, int ndir, char**dir, int noppanels)		Open block matrix file structure.	VND *VNDop	returns as pointer to VND I/O control structure			or NULL if failed 	int mode	0 for read only			1 for read and write (existing file)			2 for write and read (create new file)			3 for don't open, just compute buffer sizes 			and fill out structure	long lwmax	Maximum memory buffer size in bytes to use	int ndim	Number of block matrix transpose dimensions	long N[ndim]	List of number of nodes for each dimension	long npanels	Number of panels of block matrix structure	long nbytes	Number of bytes per node	char *file	File name from which other file names will be 			constructed.  The actual files used will have			.VND0, .VND1, ... extentions.  This name			should not have such an extention.	int ndir	Number of file directories available for holding data.			Set ndir=0 to use one file in current directory.			Set ndir=5 to spread data out over 5 files of			roughly equal size in the directories dir[j].			Set ndir=-1 to look at .VND file for directories			to use.  File format is "number of directories"			on first line and then one line per directory name.	char **dir	dir[j] = name of file directory for storing data.			If dir[0]="/users/junk" and file="file", then the 			first physical file will be "/users/junk/file.VND0"	int noppanels	Max number of panels to be open at one time	VNDop returns a value of NULL if open failed.void VNDrw(char iop, int iopanel, VND *vnd, int idim, long *key, long ipanel, 		char *values, long start, long incr, long nvalues,		int msgnum, char *msg)	Read or write a vector for dimension "idim" 	char iop	'r' for read; 'w' for write	int iopanel	Index of current open panel buffer 			(Ranges from 0 to noppanels-1.  Used to			allow access to multiple panels simultaneously.			For most applications, noppanels = 1 and 			iopanel will always equal 0.)		VND *vnd	Structure holding block matrix file information.	int idim	Current dimension for read or write                        (idim=0 is first dimension)	long key[]	List of node positions for each dimension 			(Value for dimension "idim" needs to be there			but it's value is irrelevant.)	long ipanel	Panel number for read or write.			(ipanel=0 is first panel)	char values[]	Returns as values read or input as values to be 			written.	long start	starting node (0 based, usually equals 0)	long incr	node increment (usually 1)	long nvalues	number of values to read or write 			(usually same as number of values in 			the specified dimension)	int msgnum	A message number to be written out if error occurs.	char *msg	A message to be written out if error occurs.void VNDcl(VND *vnd, int mode)	Close VND file structure.	VND *vnd	Structure holding VND block matrix file information.	int mode	0 means keep 			1 means deletevoid VNDflush(VND *vnd)	Flush out VND buffers to file.  	This may be important in applications where 	checkpoint/restart capabilities are needed.  	After VNDflush, the data written by the VNDrw	routine are safely stored on disk rather than 	just in a memory buffer where it could be lost in	the event of a machine failure.	VND *vnd	VND control structureWhen doing real to complex FFT's, the following routines maybe helpful.void VNDr2c(VND *vnd)	Convert dimension 0 from real to complex by scaling	the number of bytes/node by 2 and halving the	number of nodes.  (Note: only works for dimension 0)void VNDc2r(VND *vnd)	Convert dimension 0 from complex to real by dividing	the number of bytes/node by 2 and doubling the	number of nodes.  (Note: only works for dimension 0)When working in only 2 dimensions, the following routines maybe convenient as they have fewer parameters and don't requirethe user to allocate arrays for N or key.  These routinescall the VND routines and are completely compatible.  A FORTRANequivalent routine exists with the same calling sequence forall but the V2Dop routine.  The open routine assumes thata single VND file can be opened in the current directory.VND * V2Dop(int mode, long lwmax, long nbytes, char *file,long n0, long n1)	Open 2-D VND file structure.	int mode	0 for read only			1 for read and write (existing file)			2 for write and read (create new file)			3 for don't open, just compute buffer sizes 			and fill out structure	long lwmax	Maximum memory buffer size in bytes to use	long nbytes	Number of bytes per node	char *file	File name from which VND file name will be 			constructed.  The actual file used will have			.VND0 extention.  This name			should not have such an extention.	long n0		number of nodes in dimension 0	long n1		number of nodes in dimension 1void V2Dr0(VND *vnd,long key,char *buf,int msgnum)	read dimension 0void V2Dr1(VND *vnd,long key,char *buf,int msgnum)	read dimension 1void V2Dw0(VND *vnd,long key,char *buf,int msgnum)	write dimension 0void V2Dw1(VND *vnd,long key,char *buf,int msgnum)	write dimension 1Memory management within the VND routines is based uponthe following routines.  These routines, when used together,provide automatic error checking at the end of a jobduring the VNDfree() step for any buffer overruns tellingthe user if an overrun occured at the beginning of thebuffer or at the end.  To ensure that memory overrunshave not occured, a few extra bytes of information mustbe stored for each buffer that is not available to theuser program.  Therefore, memory allocatedby VNDemalloc() must be freed by VNDfree() rather thanthe standard free() routine.  It is sometimes convenientto find out the total amount of currently allocatedVND memory.  A routine exists for that purpose.  At theend of a job, you can ensure that all allocated VND buffers have been freed and checked for overruns byseeing if the total allocated memory at that pointis zero.void *VNDemalloc(size_t n,char *msg)	Allocate memory and return a pointer.  	Give error message and abort if fail.	size_t n	number of bytes of memory to allocate	char *msg	error message to print if abortvoid VNDmemchk( void *p , char * msg)				check for memory overrun and abort if error found	(can distinguish between overrun at beginning of	allocated buffer versus overrun at end of allocated	buffer)	void *p		pointer returned from VNDemalloc	char *msg	error message to print out if error foundlong VNDtotalmem()	return total current memory allocated by VNDemalloc	in charactersvoid VNDfree( void *p, char *msg)	free memory allocated by VNDemalloc	(also calls VNDmemchk to check for memory 	overflows during job)	void *p		pointer returned from VNDemalloc	char *msg	error message to print out if error found	The following routine returns a unique temporary fileroot name for VND files. VNDtempname() returns a name made up from the input root string, theprocess id, and a unique integer.  This is the only VNDroutine calling a UNIX specific function or using theheader files <sys/types.h> or <sys/errno.h>.  The otherroutines should be portable to non-Unix systems.char *VNDtempname(char *root)Memory associated with a VNDtempname() character stringmust be freed using VNDfree() rather than free().A short test program might check the VND_HOME file fora .VND file for file systems over which to spread the data.This has been accomplished by coding "ndir=-1" in VNDop.A 3 dimensional 50x50x5 block matrix system is set up over1 panel. The user wishes to use a memory buffer of 1000 integers. The data are initialized to equal the first dimensionindex and written out in vectors along the first dimension (idim=0).Then, the data are then read from the file along vectors in the second dimension (idim=1) and dumped to check and see if they are correct.  Note that it would have required memory thesize of 12500 integers to hold the entire 3-D matrix in memory.include "VND.h"int main(){	int i;	int j;      	int k;      	static long N[3]={50,50,5};	long key[3];	long buf[50];  	VND *vnd;	char **dir;	fprintf(stdout,"Open the VND file and initialize values to 0\n");	vnd=VNDop(2,9999,3,N,1,sizeof(long),"george",-1,dir,1);	VNDdump(vnd,stdout);	fprintf(stdout,"Write out data in first dimension slices\n");	fprintf(stdout,   		"Values = i+j*100+k*10000 where i,j,k are the keys\n");	fprintf(stdout,"in the first, second, and third dimensions\n");	for(k=0;k<N[2];k++) { 		key[2]=k;   		for(j=0;j<N[1];j++) {			key[1]=j;

⌨️ 快捷键说明

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