📄 vnd.c
字号:
fprintf(stderr,"VNDrw: incr (0 based for C, add 1 for Fortran) = %ld\n",incr); fprintf(stderr,"VNDrw: nvalues = %ld\n",nvalues); fprintf(stderr,"VNDrw: iopanel = %d idim = %d ipanel = %ld\n", iopanel,idim,ipanel); for(jj=0;jj<vnd->NumDim;jj++){ fprintf(stderr," Dimension = %d key = %ld \n", jj,key[jj]); } abort(); } ib = k/vnd->NNodesPerBlock[idim]; iw = k - ib*vnd->NNodesPerBlock[idim]; iw = ibyte + iw*vnd->ByteIncr[idim] + ib*vnd->NumBytesPerBlock; for(kk=0;kk<vnd->NumBytesPerNode;kk++){ vnd->w[iw]=values[iv]; iw++; iv++; } } } return; } fprintf(stderr,"VNDrw: Invalid option. Not r or w \n"); abort();}void VNDcl(VND *vnd, int mode)/*********************************************************************void VNDcl(VND *vnd, int mode) Close VND file structure. Flush I/O buffers. Free memory. VND *vnd Structure holding VND block matrix file information. int mode 0 means keep 1 means delete***********************************************************************/{ int iopanel; int ifile; for(iopanel=0;iopanel<vnd->NumOpenPanels;iopanel++){ if(vnd->Modified[iopanel]==1) { VNDrwslice(vnd,iopanel,'w', vnd->CurrentDimension[iopanel], vnd->CurrentBlock[iopanel], vnd->CurrentPanel[iopanel]); } } fclose(vnd->FileDescriptor); if(mode==1){ for(ifile=0;ifile<vnd->NumFiles;ifile++){ remove(vnd->FileNames[ifile]); VNDfree(vnd->FileNames[ifile],"VNDcl: freeing vnd->FileNames[ifile]"); } } VNDfree(vnd->CurrentPanel,"VNDcl: freeing vnd->CurrentPanel"); VNDfree(vnd->Modified,"VNDcl: freeing vnd->Modified"); VNDfree(vnd->CurrentDimension,"VNDcl: freeing vnd->CurrentDimension"); VNDfree(vnd->CurrentBlock,"VNDcl: freeing vnd->CurrentBlock"); VNDfree(vnd->N,"VNDcl: freeing vnd->N"); VNDfree(vnd->NNodesPerBlock,"VNDcl: freeing vnd->NNodesPerBlock"); VNDfree(vnd->NBlocks,"VNDcl: freeing vnd->NBlocks"); VNDfree(vnd->ByteIncr,"VNDcl: freeing vnd->ByteIncr"); VNDfree(vnd->BlockIncr,"VNDcl: freeing vnd->BlockIncr"); VNDfree(vnd->LenFileNames,"VNDcl: freeing vnd->LenFileNames"); VNDfree(vnd->FileNames,"VNDcl: freeing vnd->FileNames"); VNDfree(vnd->FirstDataByte,"VNDcl: freeing vnd->FirstDataByte"); VNDfree(vnd->LenFile,"VNDcl: freeing vnd->LenFile"); VNDfree(vnd->w,"VNDcl: freeing vnd->w"); VNDfree(vnd,"VNDcl: freeing vnd"); return;}void VNDdump(VND *vnd,FILE *fp)/*****************************************************************void VNDdump(VND *vnd,FILE *fp) Dump out values stored in VND structure to file. VND *vnd pointer to VND structure FILE *fp FILE pointer associated with output file******************************************************************/{ int j; fprintf(fp,"\nDump of VND structure\n"); fprintf(fp,"NumDim = %ld\n",vnd->NumDim); fprintf(fp,"NumBytesPerNode = %ld\n",vnd->NumBytesPerNode); fprintf(fp,"NumBlocksPerPanel = %ld\n",vnd->NumBlocksPerPanel); fprintf(fp,"NumFiles = %ld\n",vnd->NumFiles); fprintf(fp,"NumPanels = %ld\n",vnd->NumPanels); fprintf(fp,"NumOpenPanels = %ld\n",vnd->NumOpenPanels); fprintf(fp,"NumBytesMemBuf = %ld\n",vnd->NumBytesMemBuf); fprintf(fp,"NumBytesPerBlock = %ld\n",vnd->NumBytesPerBlock); fprintf(fp,"NumBytes1stDim = %ld\n",vnd->NumBytes1stDim); fprintf(fp,"NumNodesPerBlock = %ld\n",vnd->NumNodesPerBlock); fprintf(fp,"NumBlocksPerFile = %ld\n",vnd->NumBlocksPerFile); fprintf(fp,"CurrentFile = %d\n",vnd->CurrentFile); fprintf(fp,"Mode = %s\n",vnd->Mode); fprintf(fp,"FileDescriptor will not be dumped\n"); fprintf(fp,"\nFor each block matrix transpose dimension:\n"); for(j=0;j<vnd->NumDim;j++){ fprintf(fp,"Dimension = %d N = %ld NNodesPerBlock = %ld", j,vnd->N[j],vnd->NNodesPerBlock[j]); fprintf(fp," NBlocks = %ld ByteIncr = %ld BlockIncr = %ld\n", vnd->NBlocks[j],vnd->ByteIncr[j],vnd->BlockIncr[j]); } fprintf(fp,"\nFor each simultaneously open panel buffer:\n"); for(j=0;j<vnd->NumOpenPanels;j++){ fprintf(fp,"Open panel buffer = %d Current Panel = %ld", j,vnd->CurrentPanel[j]); fprintf(fp," CurrentDimension = %d CurrentBlock = %ld", vnd->CurrentDimension[j],vnd->CurrentBlock[j]); fprintf(fp," Modified = %d \n",vnd->Modified[j]); } fprintf(fp,"\nFor each VND file:\n"); for(j=0;j<vnd->NumFiles;j++){ fprintf(fp,"File name = %s\n",vnd->FileNames[j]); fprintf(fp," LenFileNames = %d FirstDataByte = %ld", vnd->LenFileNames[j],vnd->FirstDataByte[j]); fprintf(fp," LenFile = %ld \n",vnd->LenFile[j]); } fprintf(fp,"\n \n"); return;}void VNDlook(int *w, int lw){ int j; for(j=0;j<lw;j++){ fprintf(stdout," j=%d w[j]=%d \n",j,w[j]); } return;}void *VNDemalloc(size_t n, char *s){ void *p,*pp; long *j; n=1+(n-1)/sizeof(long); if((p = malloc((n+3)*sizeof(long)))==NULL) { fprintf(stderr,"Error allocating memory in VNDemalloc\n"); fprintf(stderr,"%s\n",s); abort(); /* return (NULL); */ } j=(long *)p; j[0]=6789; j[1]=(int) n; pp = &j[2]; j[n+2]=1234; total_VND_mem+=(n+3)*sizeof(long); return (pp);}void VNDmemchk( void *p , char * msg) { long *j; j = (long *)p; j = j-2; if(j[0]!=6789) { fprintf(stderr,"Beginning memory overrun detected by VNDmemchk\n"); fprintf(stderr,"%s\n",msg); abort(); } if(j[ j[1]+2 ]!=1234) { fprintf(stderr,"Ending memory overrun detected by VNDmemchk\n"); fprintf(stderr,"%s\n",msg); abort(); } }long VNDtotalmem(void){ return (total_VND_mem);}void VNDfree( void *p, char *msg){ void *pp; long *j; j = (long *)p; j=j-2; pp = (void *)j; VNDmemchk(p,msg); total_VND_mem= total_VND_mem-((int) ((j[1]+3)*sizeof(long)) ); free(pp);}void VNDerr(char *s){ fprintf(stderr,"VNDerr: fatal error\n"); fprintf(stderr,"%s\n",s); abort(); /* return; */}void VNDr2c(VND *vnd){ /* change vnd dimension 0 from real to complex */ vnd->NumBytesPerNode*=2; vnd->N[0]/=2; vnd->NNodesPerBlock[0]/=2; vnd->ByteIncr[0]*=2; return;}void VNDc2r(VND *vnd){ /* change vnd dimension 0 from complex to real */ vnd->NumBytesPerNode/=2; vnd->N[0]*=2; vnd->NNodesPerBlock[0]*=2; vnd->ByteIncr[0]/=2; return;}VND * V2Dop(int mode, long lwmax, long nbytes, char *file,long n0, long n1){ long N[2]; char **dir=NULL; N[0]=n0; N[1]=n1; return(VNDop(mode,lwmax,2,N,1,nbytes,file,0,dir,1)); }void V2Dr0(VND *vnd,long key,char *buf,int msgnum){ long k[2]; k[0]=0; k[1]=key; VNDrw('r',0,vnd,0,k,0,buf,0,1,vnd->N[0],msgnum,"v2dr0"); return;}void V2Dr1(VND *vnd,long key,char *buf,int msgnum){ long k[2]; k[1]=0; k[0]=key; VNDrw('r',0,vnd,1,k,0,buf,0,1,vnd->N[1],msgnum,"v2dr1"); return;}void V2Dw0(VND *vnd,long key,char *buf,int msgnum){ long k[2]; k[0]=0; k[1]=key; VNDrw('w',0,vnd,0,k,0,buf,0,1,vnd->N[0],msgnum,"v2dw0"); return;}void V2Dw1(VND *vnd,long key,char *buf,int msgnum){ long k[2]; k[1]=0; k[0]=key; VNDrw('w',0,vnd,1,k,0,buf,0,1,vnd->N[1],msgnum,"v2dw1"); return;}/*This is the Fortran user interface to the VND routines.VNDOP(vnd, mode, lwmax, ndim, N, npanels, nbytes, file, ndir, noppanels) Open block matrix file structure. int vnd returns as pointer to filled out I/O control structure integer 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 integer lwmax Maximum memory buffer size in nodes to use integer ndim Number of block matrix transpose dimensions integer N[ndim] List of number of nodes for each dimension integer npanels Number of panels of block matrix structure integer nbytes Number of bytes per node character*80 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. integer ndir Number of file directories available for holding data. Set ndir=0 to use one file in current directory. 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. int noppanels Max number of panels to be open at one timeVNDRW(iop, iopanel, vnd, idim, key, ipanel, values, start, incr, nvalues, msgnum) Read or write a vector for dimension "idim" character*1 iop "r" for read; "w" for write integer iopanel Index of current open panel buffer (Ranges from 1 to noppanels. Used to allow access to multiple panels simultaneously. For most applications, noppanels = 1 and iopanel will always equal 1.) integer vnd Structure holding block matrix file information. integer idim Current dimension for read or write (idim=1 for first dimension.) integer key[] List of node positions for each dimension (Value for dimension "idim" needs to be there but it's value is irrelevant.) integer ipanel Panel number for read or write. (First panel is panel 1.) integer values[]Returns as values read or input as values to be written. integer start starting node (data starts at 1, usually equals 1) integer incr node increment (usually 1) integer nvalues number of values to read or write (usually same as number of values in the specified dimension) integer msgnum A message number to be written out if error occurs.VNDCL(vnd, mode) Close VND file structure. integer vnd Structure holding VND block matrix file information. integer mode 0 means keep 1 means deleteVNDFLUSH(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. integer vnd VND control structure*/#ifdef CRAYvoid vndop_( VND **vnd, FORTINT *fort_mode, FORTINT *fort_lwmax, FORTINT *fort_ndim, FORTINT *fort_N, FORTINT *fort_npanels, FORTINT *fort_nbytes, char *fort_file, FORTINT *fort_ndir, char *fort_dir, FORTINT *fort_noppanels)#elsevoid vndop_( VND **vnd, FORTINT *fort_mode, FORTINT *fort_lwmax, FORTINT *fort_ndim, FORTINT *fort_N, FORTINT *fort_npanels, FORTINT *fort_nbytes, char *fort_file, FORTINT *fort_ndir, char *fort_dir, FORTINT *fort_noppanels, int lfile, int ldir)#endif{#ifdef CRAY int j;#else int j = (int) (ldir+lfile);#endif int k; int mode; long lwmax; int ndim; long *N; long npanels; long nbytes; char file[81]; int ndir; char **dir=NULL; int noppanels; mode=(int) fort_mode[0]; lwmax=(long) fort_lwmax[0]; ndim=(int) fort_ndim[0]; npanels=(long) fort_npanels[0]; nbytes=(long) fort_nbytes[0]; ndir=(int) fort_ndir[0]; noppanels=(int) fort_noppanels[0]; N = (long *)VNDemalloc(ndim*sizeof(long),"vndop_ allocating N"); for(j=0;j<ndim;j++) { N[j]=fort_N[j]; } for(j=0;j<80;j++) { if(isgraph(fort_file[j])==0) break; file[j]=fort_file[j]; } file[j]='\0'; if(ndir>0) { dir=(char **)VNDemalloc(ndir*sizeof(char *), "vndopen_
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -