[petsc-users] Tips on integrating petsc into my application?

Faraz Hussain faraz_hussain at yahoo.com
Thu Jun 23 08:06:19 CDT 2016


I have successfully integrated petsc into my application . However, when I do mpiexec -np x, then each process reads my input deck and consumes a lot of memory allocating all the data for the arrays. 

I believe I need to have only rank 0 do all the processing? What I have tried to do is put a giant if statement in my main function as follows:
if (  ! rank ) {
run_app();
}
However, when I run with more than np > 1, the code just hangs when it gets to the petsc.c code. I moved   PetscInitializeNoArguments() into my main function. Does it need to be in both main and my petsc.c code? Do I need to pass PETSC_COMM_WORLD to my petsc.c code?


      From: Faraz Hussain <faraz_hussain at yahoo.com>
 To: "petsc-users at mcs.anl.gov" <petsc-users at mcs.anl.gov> 
 Sent: Wednesday, June 22, 2016 9:35 AM
 Subject: Example on using VecGetValues?
   
I am trying to get my petsc vector of values into my c array of doubles. I tried this but it keeps giving value of 0:


VecScatter ctx;
VecScatterCreateToZero(petsc_x,&ctx,&petsc_b);
VecScatterBegin(ctx,petsc_x,petsc_b,INSERT_VALUES,SCATTER_FORWARD);
VecScatterEnd(ctx,petsc_x,petsc_b,INSERT_VALUES,SCATTER_FORWARD);
VecScatterDestroy(&ctx);

VecView( petsc_b,PETSC_VIEWER_STDOUT_WORLD);


PetscScalar  value;
  for ( row=0; row < size ; row++ ) {
        ierr = VecGetValues( petsc_b, 0, row, &value );CHKERRQ(ierr);
        b[row] = value;
        printf ( "Value is %.17g\n", b[row]);
                                        }

It keeps printing this out, but the values should be real numbers, not 0:

Value is 0
Value is 0
Value is 0
....


  
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.mcs.anl.gov/pipermail/petsc-users/attachments/20160623/e093ae57/attachment-0001.html>


More information about the petsc-users mailing list