<html><head></head><body><div style="color:#000; background-color:#fff; font-family:HelveticaNeue-Light, Helvetica Neue Light, Helvetica Neue, Helvetica, Arial, Lucida Grande, sans-serif;font-size:16px"><div id="yui_3_16_0_ym19_1_1466606883184_111622" dir="ltr"><span id="yui_3_16_0_ym19_1_1466606883184_111623">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. <br></span></div><div id="yui_3_16_0_ym19_1_1466606883184_111700" dir="ltr"><span id="yui_3_16_0_ym19_1_1466606883184_111623"><br></span></div><div id="yui_3_16_0_ym19_1_1466606883184_111701" dir="ltr"><span id="yui_3_16_0_ym19_1_1466606883184_111623">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:</span></div><div id="yui_3_16_0_ym19_1_1466606883184_111624" dir="ltr"><span id="yui_3_16_0_ym19_1_1466606883184_111625"><br id="yui_3_16_0_ym19_1_1466606883184_111626"></span></div><div id="yui_3_16_0_ym19_1_1466606883184_111627" dir="ltr"><span id="yui_3_16_0_ym19_1_1466606883184_111628">if (  ! rank ) {<br id="yui_3_16_0_ym19_1_1466606883184_111629">run_app();<br id="yui_3_16_0_ym19_1_1466606883184_111630"></span></div><div id="yui_3_16_0_ym19_1_1466606883184_111631"><div id="yui_3_16_0_ym19_1_1466606883184_111632">}</div><div id="yui_3_16_0_ym19_1_1466606883184_111633"><br id="yui_3_16_0_ym19_1_1466606883184_111634"></div><div id="yui_3_16_0_ym19_1_1466606883184_111635">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?<br id="yui_3_16_0_ym19_1_1466606883184_111636"></div><div id="yui_3_16_0_ym19_1_1466606883184_111704"><br id="yui_3_16_0_ym19_1_1466606883184_111637"></div><br id="yui_3_16_0_ym19_1_1466606883184_111638"></div><div id="yui_3_16_0_ym19_1_1466606883184_111639">  <div id="yui_3_16_0_ym19_1_1466606883184_111640" style="font-family: HelveticaNeue-Light, Helvetica Neue Light, Helvetica Neue, Helvetica, Arial, Lucida Grande, sans-serif; font-size: 16px;"> <div id="yui_3_16_0_ym19_1_1466606883184_111641" style="font-family: HelveticaNeue, Helvetica Neue, Helvetica, Arial, Lucida Grande, sans-serif; font-size: 16px;"> <div id="yui_3_16_0_ym19_1_1466606883184_111642" dir="ltr"> <font id="yui_3_16_0_ym19_1_1466606883184_111643" face="Arial" size="2"> <hr id="yui_3_16_0_ym19_1_1466606883184_111644" size="1"> <b id="yui_3_16_0_ym19_1_1466606883184_111645"><span id="yui_3_16_0_ym19_1_1466606883184_111646" style="font-weight:bold;">From:</span></b> Faraz Hussain <faraz_hussain@yahoo.com><br id="yui_3_16_0_ym19_1_1466606883184_111647"> <b id="yui_3_16_0_ym19_1_1466606883184_111648"><span id="yui_3_16_0_ym19_1_1466606883184_111649" style="font-weight: bold;">To:</span></b> "petsc-users@mcs.anl.gov" <petsc-users@mcs.anl.gov> <br id="yui_3_16_0_ym19_1_1466606883184_111650"> <b id="yui_3_16_0_ym19_1_1466606883184_111651"><span id="yui_3_16_0_ym19_1_1466606883184_111652" style="font-weight: bold;">Sent:</span></b> Wednesday, June 22, 2016 9:35 AM<br id="yui_3_16_0_ym19_1_1466606883184_111653"> <b id="yui_3_16_0_ym19_1_1466606883184_111654"><span id="yui_3_16_0_ym19_1_1466606883184_111655" style="font-weight: bold;">Subject:</span></b> Example on using VecGetValues?<br id="yui_3_16_0_ym19_1_1466606883184_111656"> </font> </div> <div id="yui_3_16_0_ym19_1_1466606883184_111657"><br id="yui_3_16_0_ym19_1_1466606883184_111658">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:<br id="yui_3_16_0_ym19_1_1466606883184_111659"><br id="yui_3_16_0_ym19_1_1466606883184_111660"><br id="yui_3_16_0_ym19_1_1466606883184_111661">VecScatter ctx;<br id="yui_3_16_0_ym19_1_1466606883184_111662">VecScatterCreateToZero(petsc_x,&ctx,&petsc_b);<br id="yui_3_16_0_ym19_1_1466606883184_111663">VecScatterBegin(ctx,petsc_x,petsc_b,INSERT_VALUES,SCATTER_FORWARD);<br id="yui_3_16_0_ym19_1_1466606883184_111664">VecScatterEnd(ctx,petsc_x,petsc_b,INSERT_VALUES,SCATTER_FORWARD);<br id="yui_3_16_0_ym19_1_1466606883184_111665">VecScatterDestroy(&ctx);<br id="yui_3_16_0_ym19_1_1466606883184_111666"><br id="yui_3_16_0_ym19_1_1466606883184_111667">VecView( petsc_b,PETSC_VIEWER_STDOUT_WORLD);<br id="yui_3_16_0_ym19_1_1466606883184_111668"><br id="yui_3_16_0_ym19_1_1466606883184_111669"><br id="yui_3_16_0_ym19_1_1466606883184_111670">PetscScalar   value;<br id="yui_3_16_0_ym19_1_1466606883184_111671">  for ( row=0; row < size ; row++ ) {<br id="yui_3_16_0_ym19_1_1466606883184_111672">        ierr = VecGetValues( petsc_b, 0, row, &value );CHKERRQ(ierr);<br id="yui_3_16_0_ym19_1_1466606883184_111673">        b[row] = value;<br id="yui_3_16_0_ym19_1_1466606883184_111674">        printf ( "Value is %.17g\n", b[row]);<br id="yui_3_16_0_ym19_1_1466606883184_111675">                                        }<br id="yui_3_16_0_ym19_1_1466606883184_111676"><br id="yui_3_16_0_ym19_1_1466606883184_111677">It keeps printing this out, but the values should be real numbers, not 0:<br id="yui_3_16_0_ym19_1_1466606883184_111678"><br id="yui_3_16_0_ym19_1_1466606883184_111679">Value is 0<br id="yui_3_16_0_ym19_1_1466606883184_111680">Value is 0<br id="yui_3_16_0_ym19_1_1466606883184_111681">Value is 0<br id="yui_3_16_0_ym19_1_1466606883184_111682">....<br id="yui_3_16_0_ym19_1_1466606883184_111683"><br id="yui_3_16_0_ym19_1_1466606883184_111684"><br id="yui_3_16_0_ym19_1_1466606883184_111685"></div> </div> </div>  </div></div></body></html>