コード例 #1
0
PetscErrorCode readProfileSurfaceScalarDataRecord(char *fileName, PetscScalar *arr, PetscInt numValsPerProfile, PetscInt iRec)
{
/* Random access version of readProfileSurfaceScalarData */
/* This version takes 1 additional argument:  */
/*   iRec: the record to read (iRec=1 is the first record) */
  PetscErrorCode ierr;
  off_t  off, offset;  
  PetscViewer fd;
  PetscInt fp;
  PetscInt iShift;
  PetscMPIInt numProcessors, myId;

  ierr = MPI_Comm_rank(PETSC_COMM_WORLD,&myId);CHKERRQ(ierr);  
  ierr = MPI_Comm_size(PETSC_COMM_WORLD,&numProcessors);CHKERRQ(ierr);
  

/* Shift file pointer to start of data owned by local process */
  iShift = (iRec-1)*numValsPerProfile*totalNumProfiles + numValsPerProfile*numPrevProfiles;
  off = PETSC_BINARY_SCALAR_SIZE*iShift;
  ierr = PetscViewerBinaryOpen(PETSC_COMM_SELF,fileName,FILE_MODE_READ,&fd);CHKERRQ(ierr);
  ierr = PetscViewerBinaryGetDescriptor(fd,&fp);CHKERRQ(ierr);
  ierr = PetscBinarySeek(fp,off,PETSC_BINARY_SEEK_SET,&offset);CHKERRQ(ierr);
  ierr = PetscBinaryRead(fp,arr,numValsPerProfile*lNumProfiles,PETSC_SCALAR);CHKERRQ(ierr);
  ierr = PetscViewerDestroy(fd);CHKERRQ(ierr);
  
  return 0;
}
コード例 #2
0
ファイル: sysio.c プロジェクト: petsc/petsc
/*@C
   PetscBinarySynchronizedSeek - Moves the file pointer on a PETSc binary file.


   Input Parameters:
+  fd - the file
.  whence - if PETSC_BINARY_SEEK_SET then size is an absolute location in the file
            if PETSC_BINARY_SEEK_CUR then size is offset from current location
            if PETSC_BINARY_SEEK_END then size is offset from end of file
-  off    - number of bytes to move. Use PETSC_BINARY_INT_SIZE, PETSC_BINARY_SCALAR_SIZE,
            etc. in your calculation rather than sizeof() to compute byte lengths.

   Output Parameter:
.   offset - new offset in file

   Level: developer

   Notes:
   Integers are stored on the file as 32 long, regardless of whether
   they are stored in the machine as 32 or 64, this means the same
   binary file may be read on any machine. Hence you CANNOT use sizeof()
   to determine the offset or location.

   Concepts: binary files^seeking
   Concepts: files^seeking in binary

.seealso: PetscBinaryRead(), PetscBinaryWrite(), PetscBinaryOpen(), PetscBinarySynchronizedWrite(), PetscBinarySynchronizedRead(),
          PetscBinarySynchronizedSeek()
@*/
PetscErrorCode  PetscBinarySynchronizedSeek(MPI_Comm comm,int fd,off_t off,PetscBinarySeekType whence,off_t *offset)
{
  PetscErrorCode ierr;
  PetscMPIInt    rank;

  PetscFunctionBegin;
  ierr = MPI_Comm_rank(comm,&rank);CHKERRQ(ierr);
  if (!rank) {
    ierr = PetscBinarySeek(fd,off,whence,offset);CHKERRQ(ierr);
  }
  PetscFunctionReturn(0);
}
コード例 #3
0
PetscErrorCode readProfileSurfaceScalarData(char *fileName, PetscScalar *arr, PetscInt numValsPerProfile)
{
  PetscErrorCode ierr;
/*   PetscScalar *tmpArr; */
/*   PetscInt ip; */
/*   size_t m1, m2; */
  off_t  off, offset;  
  PetscViewer fd;
  PetscInt fp;
  PetscInt iShift;
  PetscMPIInt numProcessors, myId;

  ierr = MPI_Comm_rank(PETSC_COMM_WORLD,&myId);CHKERRQ(ierr);  
  ierr = MPI_Comm_size(PETSC_COMM_WORLD,&numProcessors);CHKERRQ(ierr);
  
/*   m1 = numValsPerProfile*totalNumProfiles*sizeof(PetscScalar); */
/*   m2 = numValsPerProfile*lNumProfiles*sizeof(PetscScalar); */

/*Read all data into temporary array */
/*   ierr = PetscMalloc(m1,&tmpArr);CHKERRQ(ierr); */
/*   ierr = PetscViewerBinaryOpen(PETSC_COMM_SELF,fileName,FILE_MODE_READ,&fd);CHKERRQ(ierr); */
/*   ierr = PetscViewerBinaryGetDescriptor(fd,&fp);CHKERRQ(ierr); */
/*   ierr = PetscBinaryRead(fp,tmpArr,numValsPerProfile*totalNumProfiles,PETSC_SCALAR);CHKERRQ(ierr); */
/*   ierr = PetscViewerDestroy(fd);CHKERRQ(ierr); */

/* Shift file pointer to start of data owned by local process */
  iShift = numValsPerProfile*numPrevProfiles;
/*   printf("ipro=%d,iShift=%d\n",myId,iShift); */
  off = PETSC_BINARY_SCALAR_SIZE*iShift;
  ierr = PetscViewerBinaryOpen(PETSC_COMM_SELF,fileName,FILE_MODE_READ,&fd);CHKERRQ(ierr);
  ierr = PetscViewerBinaryGetDescriptor(fd,&fp);CHKERRQ(ierr);
  ierr = PetscBinarySeek(fp,off,PETSC_BINARY_SEEK_SET,&offset);CHKERRQ(ierr);
  ierr = PetscBinaryRead(fp,arr,numValsPerProfile*lNumProfiles,PETSC_SCALAR);CHKERRQ(ierr);
  ierr = PetscViewerDestroy(fd);CHKERRQ(ierr);
  
/*   ierr = PetscMalloc(m2,&arr);CHKERRQ(ierr); */
/*   for (ip=1; ip<=lNumProfiles; ip++) {   */
/*     arr[ip-1]=tmpArr[numPrevProfiles+ip-1]; */
/*   } */

/*   ierr = PetscFree(tmpArr);CHKERRQ(ierr); */
    
  return 0;
}
コード例 #4
0
PetscErrorCode readProfileSurfaceIntData(char *fileName, PetscInt *arr, PetscInt numValsPerProfile)
{
  PetscErrorCode ierr;
/*   PetscInt *tmpArr; */
/*   PetscInt ip; */
/*   size_t m1, m2; */
  off_t  off, offset;  
  PetscViewer fd;
  PetscInt fp;
  PetscInt iShift;

/*   m1 = totalNumProfiles*sizeof(PetscInt); */
/*   m2 = lNumProfiles*sizeof(PetscInt); */

/*   ierr = PetscMalloc(m1,&tmpArr);CHKERRQ(ierr); */
/*   ierr = PetscViewerBinaryOpen(PETSC_COMM_SELF,fileName,FILE_MODE_READ,&fd);CHKERRQ(ierr); */
/*   ierr = PetscViewerBinaryGetDescriptor(fd,&fp);CHKERRQ(ierr); */
/*   ierr = PetscBinaryRead(fp,tmpArr,totalNumProfiles,PETSC_INT);CHKERRQ(ierr); */
/*   ierr = PetscViewerDestroy(fd);CHKERRQ(ierr); */

/* Shift file pointer to start of data owned by local process */
  iShift = numValsPerProfile*numPrevProfiles;
  off = PETSC_BINARY_INT_SIZE*iShift;
  ierr = PetscViewerBinaryOpen(PETSC_COMM_SELF,fileName,FILE_MODE_READ,&fd);CHKERRQ(ierr);
  ierr = PetscViewerBinaryGetDescriptor(fd,&fp);CHKERRQ(ierr);
  ierr = PetscBinarySeek(fp,off,PETSC_BINARY_SEEK_SET,&offset);CHKERRQ(ierr);
  ierr = PetscBinaryRead(fp,arr,numValsPerProfile*lNumProfiles,PETSC_INT);CHKERRQ(ierr);
  ierr = PetscViewerDestroy(fd);CHKERRQ(ierr);

/*   for (ip=0; ip<totalNumProfiles; ip++) { */
/*     ierr = PetscPrintf(PETSC_COMM_WORLD,"ip=%d,kc=%d\n",ip,tmpArr[ip]);CHKERRQ(ierr); */
/*   }  */
/*   ierr = PetscMalloc(m2,&arr);CHKERRQ(ierr); */
/*   for (ip=1; ip<=lNumProfiles; ip++) {   */
/*     arr[ip-1]=tmpArr[numPrevProfiles+ip-1]; */
/*     ierr = PetscPrintf(PETSC_COMM_WORLD,"ip=%d,kc=%d\n",ip,arr[ip-1]);CHKERRQ(ierr);     */
/*   } */

/*   ierr = PetscFree(tmpArr);CHKERRQ(ierr); */
    
  return 0;
}
コード例 #5
0
void PETSC_STDCALL   petscbinaryseek_(int *fd,off_t *off,PetscBinarySeekType *whence,off_t *offset, int *__ierr ){
*__ierr = PetscBinarySeek(*fd,*off,*whence,
	(off_t* )PetscToPointer((offset) ));
}