[petsc-users] petscviewerbinaryread

Frederik Treue frtr at fysik.dtu.dk
Mon Jun 17 03:59:49 CDT 2013


Hi guys,

is petscviewerbinaryread working? The examples given at the webpage
either fails with out of memory error issues (ex65 and ex65dm) or
doesn't compile (ex61) for me?

Oddly I have problems only when trying to use mpi. My code:

ierr=DMDACreate1d(PETSC_COMM_WORLD,DMDA_BOUNDARY_GHOSTED,156,1,1,PETSC_NULL,&da);CHKERRQ(ierr);

ierr=DMCreateGlobalVector(da,&ReRead);CHKERRQ(ierr);

ierr=VecAssemblyBegin(ReRead);CHKERRQ(ierr);
ierr=VecAssemblyEnd(ReRead);CHKERRQ(ierr);

double *workarray=(double*)malloc(156*sizeof(double));

ierr = VecGetArray(ReRead,&workarray); CHKERRQ(ierr);

ierr=PetscViewerBinaryOpen(PETSC_COMM_WORLD,"./testvector",FILE_MODE_READ,&fileview);CHKERRQ(ierr);

ierr=PetscViewerBinaryRead(fileview,&dummy,1,PETSC_SCALAR);CHKERRQ(ierr);

ierr=PetscViewerBinaryRead(fileview,(void*)workarray,156,PETSC_SCALAR);CHKERRQ(ierr);
printf("TEST: %g\n",workarray[144]);
ierr=VecRestoreArray(ReRead,&workarray);

VecView(ReRead,PETSC_VIEWER_DRAW_WORLD);

This works fine as long as I'm on a single processor. The file read also
works on mpi with 2 processors, as evidenced by the result of the printf
statement (which gives the right result from both processors). However
the VecView statement fails with "Vector not generated from a DMDA!".
Why?

And second question: How do I generalize to 2d? Can I give a 2d array to
PetscViewerBinaryRead and expect it to work? And how should it be
malloc'ed? Or does one give a 1d array to PetscViewerBinaryRead and let
VecRestoreArray do the rest? Or what?

/Frederik Treue



More information about the petsc-users mailing list