Why are you loading the vector twice? Shouldn't you just use VecLoadIntoVector()?
Matt On Wed, Mar 10, 2010 at 9:50 AM, (Rebecca) Xuefei YUAN <xy2102 at columbia.edu>wrote: > Dear Barry and Matt, > > Thanks very much for the reply. > > I am a little bit confused about binary write and read as an input and > output method. > > For example, I have code1 and code2, where code1 will take code2's output > as an input. > > In code2, the following routine is used to save the solution as a binary > file: > > > #undef __FUNCT__ > #define __FUNCT__ "DumpSolutionToMatlab" > PetscErrorCode DumpSolutionToMatlab (DMMG*dmmg, char * fn) > { > DALocalInfo info; > PetscViewer viewer; > PetscFunctionBegin; > > ierr = DAGetLocalInfo (DMMGGetDA(dmmg),&info);CHKERRQ(ierr); > sprintf(fileName, > "ff_atwqt2ff_tx%i_ty%i_x%i_y%i_nl%i_gt%i_ot%i_s%i.dat",info.mx > ,info.my,parameters->mxfield,parameters->myfield,parameters->numberOfLevels,(PetscInt)(parameters->currentTime*10000),parameters->timeAccuracyOrder,(PetscInt)(parameters->smoothFactor*100)); > ierr = > PetscViewerBinaryOpen(PETSC_COMM_WORLD,fileName,FILE_MODE_WRITE,&viewer);CHKERRQ(ierr); > ierr = > PetscObjectSetName((PetscObject)dmmg[DMMGGetLevels(dmmg)-1]->x,"ff"); > ierr = VecView(dmmg[DMMGGetLevels(dmmg)-1]->x,viewer);CHKERRQ(ierr); > ierr = PetscViewerDestroy (viewer); CHKERRQ (ierr); > > PetscFunctionReturn(0); > } > > > In code1, the following routine is used to read the solution to a Vec named > FIELD: > > #undef __FUNCT__ > #define __FUNCT__ "FormInitialGuess_physical" > PetscErrorCode FormInitialGuess_physical(DMMG dmmg, Vec X) > { > Vec FIELD; > Field **field; > DA da,da2_4; > PetscViewer viewer; > DALocalInfo info,info2; > > PetscFunctionBegin; > > ierr = > DMCompositeGetEntries((DMComposite)(dmmg->dm),&da,PETSC_IGNORE);CHKERRQ(ierr); > ierr = DAGetLocalInfo(da,&info);CHKERRQ(ierr); > ierr = DACreate2d(PETSC_COMM_WORLD,DA_NONPERIODIC,DA_STENCIL_BOX, > (info.mx-1-parameters->abandonNumber), > (info.my-1-parameters->abandonNumber), PETSC_DECIDE, PETSC_DECIDE, 4, 2, > PETSC_NULL, PETSC_NULL, &da2_4);CHKERRQ(ierr); > ierr = DAGetLocalInfo(da2_4,&info2);CHKERRQ(ierr); > sprintf(fileName, "ff_twqt2ff_tx%i_ty%i_x%i_y%i_nl%i_gt%i_ot%i_s%i.dat", > info2.mx > ,info2.my,parameters->mxgrid-1,parameters->mygrid-1,parameters->numberOfLevels,(PetscInt)(parameters->timeToGenerateGrid*10000),parameters->timeAccuracyOrder,(PetscInt)(parameters->smoothFactor*100)); > > PetscViewerBinaryOpen(PETSC_COMM_WORLD,fileName,FILE_MODE_READ,&viewer); > VecLoad(viewer,PETSC_NULL,&FIELD); > VecLoadIntoVector(viewer,FIELD); > ierr = DAVecGetArray(da2_4,FIELD,&field);CHKERRQ(ierr); > > ierr = DAVecRestoreArray(da2_4,FIELD,&field);CHKERRQ(ierr); > ierr = VecDestroy(FIELD);CHKERRQ(ierr); > ierr = DADestroy(da2_4);CHKERRQ(ierr); > ierr = PetscViewerDestroy(viewer);CHKERRQ(ierr); > > PetscFunctionReturn(0); > } > > When I call > VecLoad(viewer,PETSC_NULL,&FIELD); > VecLoadIntoVector(viewer,FIELD); > > there is an error in proc0: > [0]PETSC ERROR: PetscBinaryRead() line 251 in src/sys/fileio/sysio.c Read > past end of file > > In gdb, it shows that > > Program received signal SIGABRT, Aborted. > [Switching to Thread 0xb7c7c6b0 (LWP 598)] > 0xb7f4c410 in __kernel_vsyscall () > (gdb) where > #0 0xb7f4c410 in __kernel_vsyscall () > #1 0xb7ccc085 in raise () from /lib/tls/i686/cmov/libc.so.6 > #2 0xb7ccda01 in abort () from /lib/tls/i686/cmov/libc.so.6 > #3 0x08733fe9 in PetscAbortErrorHandler (line=251, > fun=0x886a9c9 "PetscBinaryRead", file=0x886a942 "sysio.c", > dir=0x886a94a "src/sys/fileio/", n=66, p=1, > mess=0xbffdbe64 "Read past end of file", ctx=0x0) at errabort.c:62 > #4 0x086a8f5a in PetscError (line=251, func=0x886a9c9 "PetscBinaryRead", > file=0x886a942 "sysio.c", dir=0x886a94a "src/sys/fileio/", n=66, p=1, > mess=0x886a9e6 "Read past end of file") at err.c:482 > #5 0x086b73a2 in PetscBinaryRead (fd=9, p=0xbffdc764, n=1, type=PETSC_INT) > at sysio.c:251 > #6 0x085d8dee in VecLoadIntoVector_Binary (viewer=0x89f2870, > vec=0x89f4a00) > at vecio.c:445 > #7 0x085d9e76 in VecLoadIntoVector_Default (viewer=0x89f2870, > vec=0x89f4a00) > at vecio.c:514 > #8 0x085e9d2c in VecLoadIntoVector (viewer=0x89f2870, vec=0x89f4a00) > at vector.c:1031 > #9 0x0804f158 in FormInitialGuess_physical (dmmg=0x8999b30, X=0x898b3c0) > at vecviewload_out.c:391 > #10 0x08052d05 in DMMGSolve (dmmg=0x89999e0) at damg.c:307 > #11 0x0804d479 in main (argc=Cannot access memory at address 0x256 > ) at vecviewload_out.c:186 > > When I call > VecLoad(viewer,PETSC_NULL,&FIELD); > // VecLoadIntoVector(viewer,FIELD); > [0]PETSC ERROR: [1]PETSC ERROR: DAVecGetArray() line 53 in > src/dm/da/src/dagetarray.c Vector local size 32 is not compatible with DA > local sizes 36 100 > > [2]PETSC ERROR: [3]PETSC ERROR: DAVecGetArray() line 53 in > src/dm/da/src/dagetarray.c Vector local size 28 is not compatible with DA > local sizes 24 80 > > DAVecGetArray() line 53 in src/dm/da/src/dagetarray.c Vector local size 32 > is not compatible with DA local sizes 36 100 > > DAVecGetArray() line 53 in src/dm/da/src/dagetarray.c Vector local size 28 > is not compatible with DA local sizes 24 80 > > in gdb: > > Program received signal SIGABRT, Aborted. > [Switching to Thread 0xb7c4f6b0 (LWP 840)] > 0xb7f1f410 in __kernel_vsyscall () > (gdb) where > #0 0xb7f1f410 in __kernel_vsyscall () > #1 0xb7c9f085 in raise () from /lib/tls/i686/cmov/libc.so.6 > #2 0xb7ca0a01 in abort () from /lib/tls/i686/cmov/libc.so.6 > #3 0x08733fd1 in PetscAbortErrorHandler (line=53, > fun=0x883be60 "DAVecGetArray", file=0x883be6e "dagetarray.c", > dir=0x883be7b "src/dm/da/src/", n=75, p=1, > mess=0xbffcbd54 "Vector local size 32 is not compatible with DA local > sizes 36 100\n", ctx=0x0) at errabort.c:62 > #4 0x086a8f42 in PetscError (line=53, func=0x883be60 "DAVecGetArray", > file=0x883be6e "dagetarray.c", dir=0x883be7b "src/dm/da/src/", n=75, > p=1, > mess=0x883be8c "Vector local size %D is not compatible with DA local > sizes %D %D\n") at err.c:482 > #5 0x0820d20a in DAVecGetArray (da=0x89f1870, vec=0x89f4770, > array=0xbffcc770) > at dagetarray.c:53 > #6 0x0804f162 in FormInitialGuess_physical (dmmg=0x898a560, X=0x899b070) > at vecviewload_out.c:392 > #7 0x08052ced in DMMGSolve (dmmg=0x898a400) at damg.c:307 > #8 0x0804d479 in main (argc=Cannot access memory at address 0x348 > ) at vecviewload_out.c:186 > > If I call > // VecLoad(viewer,PETSC_NULL,&FIELD); > VecLoadIntoVector(viewer,FIELD); > [1]PETSC ERROR: VecLoadIntoVector() line 1016 in > src/vec/vec/interface/vector.c Null Object: Parameter # 2 > [0]PETSC ERROR: VecLoadIntoVector() line 1016 in > src/vec/vec/interface/vector.c Null Object: Parameter # 2 > [2]PETSC ERROR: VecLoadIntoVector() line 1016 in > src/vec/vec/interface/vector.c Null Object: Parameter # 2 > [3]PETSC ERROR: VecLoadIntoVector() line 1016 in > src/vec/vec/interface/vector.c Null Object: Parameter # 2 > Program received signal SIGABRT, Aborted. > [Switching to Thread 0xb7c256b0 (LWP 1111)] > 0xb7ef5410 in __kernel_vsyscall () > (gdb) where > #0 0xb7ef5410 in __kernel_vsyscall () > #1 0xb7c75085 in raise () from /lib/tls/i686/cmov/libc.so.6 > #2 0xb7c76a01 in abort () from /lib/tls/i686/cmov/libc.so.6 > #3 0x08733fc9 in PetscAbortErrorHandler (line=1016, > fun=0x885dc12 "VecLoadIntoVector", file=0x885d6b0 "vector.c", > dir=0x885d6b9 "src/vec/vec/interface/", n=85, p=1, > mess=0xbfc7f9d4 "Null Object: Parameter # 2", ctx=0x0) at errabort.c:62 > #4 0x086a8f3a in PetscError (line=1016, func=0x885dc12 > "VecLoadIntoVector", > file=0x885d6b0 "vector.c", dir=0x885d6b9 "src/vec/vec/interface/", n=85, > p=1, mess=0x885d6ed "Null Object: Parameter # %d") at err.c:482 > #5 0x085e985a in VecLoadIntoVector (viewer=0x8a08d10, vec=0x0) > at vector.c:1016 > #6 0x0804f138 in FormInitialGuess_physical (dmmg=0x89a2880, X=0x89b34f0) > at vecviewload_out.c:391 > #7 0x08052ce5 in DMMGSolve (dmmg=0x89a2720) at damg.c:307 > #8 0x0804d479 in main (argc=Cannot access memory at address 0x457 > ) at vecviewload_out.c:186 > > > So I am not sure how this binary write and read working? > > Did I miss sth? > > Thanks a lot! > > Rebecca > > > > -- What most experimenters take for granted before they begin their experiments is infinitely more interesting than any results to which their experiments lead. -- Norbert Wiener -------------- next part -------------- An HTML attachment was scrubbed... URL: <http://lists.mcs.anl.gov/pipermail/petsc-users/attachments/20100310/5c7bb649/attachment.htm>