Further to my posting of this afternoon, the solution to my current issue is 
the function:
VecGetArray.

thanks.
Sanjay


________________________________________
From: Kharche, Sanjay
Sent: 24 January 2013 16:03
To: PETSc users list
Subject: RE: [petsc-users] output

Hi Barry, All

I am still taking the first few steps towards getting started.

Yesterday, I was trying to output a vector in a specific format, essentially a 
row of 10 numbers only rather than a column of numbers+metadata. The suggestion 
for that was to output the vector as a binary, and then read it in using 
VecLoad from another standalone program and do whatever I wanted. Both my 
programs are serial, so there is no issue of parallel. In my standalone, I do 
something like:

PetscViewer viewer;
PetscViewerBinaryOpen(PETSC_COMM_WORLD,"ubu.bin",FILE_MODE_READ,&viewer);
VecLoad(u, viewer);
PetscViewerDestroy(&viewer);

// check that u has the values you think it should have.
VecView(u, PETSC_VIEWER_STDOUT_WORLD); // yes it does.

// Now test if u now visible to printf so I can do this:
for(i=0;i<10;i++)
fprintf(my_non_petscfile,"%f ",u[i]);
fprintf(my_non_petscfile,"\n");
// but this does not work - the values of u are not as shown by VecView!

And I still cannot output the vector u as a row into the non_petscfile. Can you 
help?

thanks
Sanjay


________________________________________
From: petsc-users-bounces at mcs.anl.gov [petsc-users-bounces at mcs.anl.gov] 
on behalf of Barry Smith [[email protected]]
Sent: 23 January 2013 20:53
To: PETSc users list
Subject: Re: [petsc-users] output

   Sanjay,

     Since you are wanting ASCII output you don't need to worry about absolute 
scalability. Thus what I would do is in your parallel PETSc application code 
save the vectors with VecView() to binary format. Then write a stand-alone 
sequential program in C, Matlab, Python that reads in the binary vectors with 
VecLoad() and outputs them in any way you want.  Trying to do fancy ASCII 
output in parallel is not worth spending time.

    Barry

On Jan 23, 2013, at 2:18 PM, "Kharche, Sanjay" <Sanjay.Kharche at 
liverpool.ac.uk> wrote:

>
> Dear All
>
> I am an absolute beginner to PetSc. I am trying to output PetSc vectors in a 
> specific format. This may have been discussed before, but I have so far not 
> found a solution.
>
> For 2 or 3 vectors, I do this:
>
> /*
> now write it to file.
> I would like row 1 to be u, row 2 to be b, and row 3 to be u. that way I can 
> use
> gnuplots surf, and also all my existin matlab code for plotting/analysis.
> */
> PetscViewer viewer; // a Petsc file pointer.
> PetscViewerASCIIOpen(PETSC_COMM_WORLD,"ubx.dat",&viewer);
> VecView(u,viewer); // this comes out with information that I dont want, and 
> in a column - I need to put it as a row.
> VecView(b,viewer);
> VecView(x,viewer);
> PetscViewerDestroy( &viewer );
>
> However, I have not been able to get rid of the information about procs, and 
> also the vectors u, b, and u need to be in row format as:
> 1 2 1 1 1
> 0 0 0 1 0
> -1 2 -1 0
>
> rather than what I have now:
>
> Vector Object: 1 MPI processes
>  type: seq
> 1
> 2
> 1
> 1
> 1
> etc....
>
>
> Any suggestions on how to do this will be appreciated.
>
> thanks
> Sanjay

Reply via email to