<html>
<head>
<style><!--
.hmmessage P
{
margin:0px;
padding:0px
}
body.hmmessage
{
font-size: 12pt;
font-family:Calibri
}
--></style></head>
<body class='hmmessage'><div dir='ltr'>Thanks a lot. It works. Following is the code that reads:<div><br></div><div><div> ierr = DMCreate(PETSC_COMM_WORLD,&da);CHKERRQ(ierr);</div><div><span style="font-size: 12pt; "> ierr = DMLoad(da,viewer);CHKERRQ(ierr);</span></div><div> ierr = DMCreateGlobalVector(da,&uu);CHKERRQ(ierr);</div><div> ierr = VecSetOptionsPrefix(uu,"solution_");CHKERRQ(ierr);</div><div> ierr = VecLoad(uu,viewer);CHKERRQ(ierr);</div><div><br></div><div><span style="font-size: 12pt; "> ierr = DMCreate(PETSC_COMM_WORLD,&cda);CHKERRQ(ierr);</span></div><div> ierr = DMLoad(cda,viewer);CHKERRQ(ierr);</div><div> ierr = DMCreateGlobalVector(cda,&gc);CHKERRQ(ierr);</div><div> ierr = VecSetOptionsPrefix(gc,"coord_");CHKERRQ(ierr);</div><div> ierr = VecLoad(gc,viewer);CHKERRQ(ierr);</div><div><br></div><br><div>> From: jedbrown@mcs.anl.gov<br>> To: pengxwang@hotmail.com; petsc-users@mcs.anl.gov<br>> Subject: RE: [petsc-users] DMDACoor3d and VecView<br>> Date: Thu, 23 May 2013 21:31:44 -0500<br>> <br>> Roc Wang <pengxwang@hotmail.com> writes:<br>> <br>> > Thanks, I followed the src/dm/examples/tests/ex14.c and ex13.c. There is still<br>> > error. Please take a look at the followings:<br>> <br>> > //The portion of writing vector in Solver program<br>> > /* write da, solution Vec Coordinate Da and Vec cda in binary format */<br>> > ierr = PetscLogEventRegister("Generate Vector",VEC_CLASSID,&VECTOR_WRITE);<br>> > CHKERRQ(ierr);<br>> > ierr = PetscLogEventBegin(VECTOR_WRITE,0,0,0,0);CHKERRQ(ierr);<br>> > ierr = PetscPrintf(PETSC_COMM_WORLD,"writing vector in binary to vector.bin<br>> > ...\n");CHKERRQ(ierr);<br>> > ierr = PetscViewerBinaryOpen(PETSC_COMM_WORLD,"vector.bin",FILE_MODE_WRITE,&<br>> > viewer);CHKERRQ(ierr);<br>> <br>> > ierr = DMView(da,viewer);CHKERRQ(ierr);<br>> > ierr = VecView(x,viewer);CHKERRQ(ierr);<br>> <br>> > ierr = PetscViewerDestroy(&viewer);CHKERRQ(ierr);<br>> > ierr = PetscLogEventEnd(VECTOR_WRITE,0,0,0,0);CHKERRQ(ierr); <br>> <br>> > //The portion of reading vector in the post-processing program<br>> > /* Read new vector in binary format */<br>> > DM da;<br>> > Vec uu;<br>> <br>> > ierr = PetscLogEventRegister("Read Vector",VEC_CLASSID,&VECTOR_READ);CHKERRQ<br>> > (ierr);<br>> > ierr = PetscLogEventBegin(VECTOR_READ,0,0,0,0);CHKERRQ(ierr);<br>> > ierr = PetscPrintf(PETSC_COMM_WORLD,"reading vector in binary from vector.bin<br>> > ...\n");CHKERRQ(ierr);<br>> > ierr = PetscViewerBinaryOpen(PETSC_COMM_WORLD,"vector.bin",FILE_MODE_READ,&<br>> > viewer);CHKERRQ(ierr);<br>> <br>> > //ierr = DMCreate(PETSC_COMM_WORLD,&da);CHKERRQ(ierr); //NOTE A<br>> <br>> > ierr = DMLoad(da,viewer);CHKERRQ(ierr);<br>> > ierr = DMCreateGlobalVector(da,&uu);CHKERRQ(ierr);<br>> <br>> > ierr = PetscViewerDestroy(&viewer);CHKERRQ(ierr);<br>> > ierr = PetscLogEventEnd(VECTOR_READ,0,0,0,0);CHKERRQ(ierr);<br>> <br>> > If the line of ierr = DMCreate(PETSC_COMM_WORLD,&da);CHKERRQ(ierr); //NOTE A<br>> > is commented out, the error is like:<br>> > [2]PETSC ERROR: --------------------- Error Message<br>> > ------------------------------------<br>> > [2]PETSC ERROR: Invalid argument!<br>> > [2]PETSC ERROR: Wrong type of object: Parameter # 1!<br>> > [2]PETSC ERROR:<br>> > ------------------------------------------------------------------------<br>> <br>> 1. ALWAYS paste the entire error message.<br>> <br>> 2. This is a memory error.<br>> <br>> > If with ierr = DMCreate(PETSC_COMM_WORLD,&da);CHKERRQ(ierr); //NOTE A, the<br>> > error is like:<br>> > [0]PETSC ERROR: --------------------- Error Message<br>> > ------------------------------------<br>> > [0]PETSC ERROR: Arguments are incompatible!<br>> > [0]PETSC ERROR: Cannot change block size 3 to 1!<br>> > [0]PETSC ERROR:<br>> > ------------------------------------------------------------------------<br>> <br>> Use VecSetOptionsPrefix(gc,"coord_") in both the code that writes and<br>> the code that reads, before VecView and VecLoad respectively.<br>> <br>> <br>> The simple PETSc binary format cannot distinguish the options unless you<br>> set different prefixes.<br></div></div> </div></body>
</html>