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