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