<div dir="ltr">On Mon, Jun 17, 2013 at 10:59 AM, Frederik Treue <span dir="ltr"><<a href="mailto:frtr@fysik.dtu.dk" target="_blank">frtr@fysik.dtu.dk</a>></span> wrote:<br><div class="gmail_extra"><div class="gmail_quote">
<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">Hi guys,<br>
<br>
is petscviewerbinaryread working? The examples given at the webpage<br>
either fails with out of memory error issues (ex65 and ex65dm) or<br>
doesn't compile (ex61) for me?<br>
<br>
Oddly I have problems only when trying to use mpi. My code:<br>
<br>
ierr=DMDACreate1d(PETSC_COMM_WORLD,DMDA_BOUNDARY_GHOSTED,156,1,1,PETSC_NULL,&da);CHKERRQ(ierr);<br>
<br>
ierr=DMCreateGlobalVector(da,&ReRead);CHKERRQ(ierr);<br>
<br>
ierr=VecAssemblyBegin(ReRead);CHKERRQ(ierr);<br>
ierr=VecAssemblyEnd(ReRead);CHKERRQ(ierr);<br>
<br>
double *workarray=(double*)malloc(156*sizeof(double));<br>
<br>
ierr = VecGetArray(ReRead,&workarray); CHKERRQ(ierr);<br></blockquote><div><br></div><div style>1) This does not make sense. You allocate an array, but then overwrite that</div><div style>array with the one inside the vector ReRead.</div>
<div> </div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
ierr=PetscViewerBinaryOpen(PETSC_COMM_WORLD,"./testvector",FILE_MODE_READ,&fileview);CHKERRQ(ierr);<br>
<br>
ierr=PetscViewerBinaryRead(fileview,&dummy,1,PETSC_SCALAR);CHKERRQ(ierr);<br>
<br>
ierr=PetscViewerBinaryRead(fileview,(void*)workarray,156,PETSC_SCALAR);CHKERRQ(ierr);<br>
printf("TEST: %g\n",workarray[144]);<br>
ierr=VecRestoreArray(ReRead,&workarray);<br></blockquote><div><br></div><div style>2) In parallel, the local array in your vector ReRead will be smaller than the global size 156. Thus this read also</div><div style> does not makes sense.</div>
<div style><br></div><div style> Matt</div><div> </div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
VecView(ReRead,PETSC_VIEWER_DRAW_WORLD);<br>
<br>
This works fine as long as I'm on a single processor. The file read also<br>
works on mpi with 2 processors, as evidenced by the result of the printf<br>
statement (which gives the right result from both processors). However<br>
the VecView statement fails with "Vector not generated from a DMDA!".<br>
Why?<br>
<br>
And second question: How do I generalize to 2d? Can I give a 2d array to<br>
PetscViewerBinaryRead and expect it to work? And how should it be<br>
malloc'ed? Or does one give a 1d array to PetscViewerBinaryRead and let<br>
VecRestoreArray do the rest? Or what?<br>
<span class="HOEnZb"><font color="#888888"><br>
/Frederik Treue<br>
<br>
</font></span></blockquote></div><br><br clear="all"><div><br></div>-- <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
</div></div>