<html><head><meta http-equiv="Content-Type" content="text/html charset=utf-8"><meta http-equiv="Content-Type" content="text/html charset=utf-8"></head><body style="word-wrap: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space;" class=""><meta http-equiv="Content-Type" content="text/html charset=utf-8" class=""><meta http-equiv="Content-Type" content="text/html charset=utf-8" class=""><div style="word-wrap: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space;" class=""><div class="">Hi Hong,</div><div class=""><br class=""></div><div class="">I tested the fix and it works perfectly.</div><div class=""><br class=""></div><div class="">Thanks for this rapid feedback.</div><div class=""><br class=""></div><div class="">Best regards,</div><div class="">Bernard.</div><div class=""><br class=""></div><div class=""><br class=""></div><div class=""><br class=""></div><br class=""><div class=""><blockquote type="cite" class=""><div class="">On 29 Sep 2016, at 17:57, Hong <<a href="mailto:hzhang@mcs.anl.gov" class="">hzhang@mcs.anl.gov</a>> wrote:</div><br class="Apple-interchange-newline"><div class=""><div dir="ltr" class=""><span style="color:rgb(80,0,80)" class="">Bernard,</span><div class=""><font color="#500050" class="">The bug is fixed in branch hzhang/fix-elementalSetOption.</font></div><div class=""><font color="#500050" class=""><a href="https://bitbucket.org/petsc/petsc/commits/891a05710665f381fc66132810d0b09973b0e049" class="">https://bitbucket.org/petsc/petsc/commits/891a05710665f381fc66132810d0b09973b0e049</a><br class=""></font></div><div class=""><font color="#500050" class=""><br class=""></font></div><div class=""><font color="#500050" class="">It will be merged to petsc-release after night tests.</font></div><div class=""><font color="#500050" class="">Thanks for reporting it!</font></div><div class=""><font color="#500050" class=""><br class=""></font></div><div class=""><font color="#500050" class="">Hong</font></div><div class=""><div class="gmail_extra"><br class=""><div class="gmail_quote">On Wed, Sep 28, 2016 at 8:04 PM, Hong <span dir="ltr" class=""><<a href="mailto:hzhang@mcs.anl.gov" target="_blank" class="">hzhang@mcs.anl.gov</a>></span> wrote:<br class=""><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex"><div dir="ltr" class=""><div class="gmail_extra"><div class="gmail_quote">Bernard:</div><div class="gmail_quote">With your code, I reproduced error and found that the default </div><div class="gmail_quote">MAT_ROW_ORIENTED for MatSetValues() is changed to MAT_COLUMN_ORIENTED. This is a bug in our library. I'll fix it.</div><div class="gmail_quote"><br class=""></div><div class="gmail_quote">You can add</div><div class="gmail_quote">MatSetOption(C,MAT_ROW_<wbr class="">ORIENTED,PETSC_TRUE); </div><div class="gmail_quote">before 2nd call of matrixC(C,t).</div><div class="gmail_quote"><br class=""></div><div class="gmail_quote">Thanks for reporting the bug.</div><span class="gmail-HOEnZb"><font color="#888888" class=""><div class="gmail_quote"><br class=""></div><div class="gmail_quote">Hong</div></font></span><div class=""><div class="gmail-h5"><div class="gmail_quote"><br class=""><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex"><div style="word-wrap:break-word" class="">Hello,<div class=""><br class=""></div><div class="">Here is a trimmed down piece of code that illustrates a strange behaviour that I am desperately trying to understand.</div><div class=""><br class=""></div><div class="">The problem is that I would expect successive calls to MatView(C,…) to display the same numbers. However, the numbers displayed are different, even though the content of the matrix C should be the same.</div><div class=""><br class=""></div><div class="">Any help to resolve this would be appreciated.</div><div class=""><br class=""></div><div class="">Cheers,</div><div class="">Bernard.</div><div class=""><br class=""></div><div class="">Code:</div><div class="">******</div><div class=""><br class=""></div><div class=""><div class="">static char help[] = "Elemental test\n\n";</div><div class=""><br class=""></div><div class="">/*T</div><div class="">   </div><div class="">T*/</div><div class=""><br class=""></div><div class="">#include <petscmat.h></div><div class=""><br class=""></div><div class="">PetscScalar pi=3.141592653589793;</div><div class=""><br class=""></div><div class="">/* Prototypes */</div><div class="">PetscErrorCode matrixC(Mat C, PetscScalar t);</div><div class=""><br class=""></div><div class="">#undef __FUNCT__</div><div class="">#define __FUNCT__ "main"</div><div class="">int main(int argc, char **args){</div><div class=""><br class=""></div><div class="">   Mat C;</div><div class=""> </div><div class="">   PetscInt N = 8;</div><div class="">   PetscScalar t=0.1, dt=0.0001;</div><div class="">   PetscErrorCode ierr;</div><div class=""><br class=""></div><div class="">   /* parameters */</div><div class="">   ierr = PetscInitialize(&argc, &args, (char*) 0, help) ;CHKERRQ(ierr);</div><div class="">  </div><div class="">   ierr = MatCreate(PETSC_COMM_WORLD, &C); CHKERRQ(ierr);</div><div class="">   ierr = MatSetSizes(C, PETSC_DECIDE, PETSC_DECIDE, N, N); CHKERRQ(ierr);</div><div class="">   ierr = MatSetType(C, MATELEMENTAL); CHKERRQ(ierr);</div><div class="">   ierr = MatSetFromOptions(C); CHKERRQ(ierr);</div><div class="">   ierr = MatSetUp(C); CHKERRQ(ierr);</div><div class="">   </div><div class="">   ierr=matrixC(C,t);</div><div class="">   ierr = MatView(C,PETSC_VIEWER_STDOUT_<wbr class="">WORLD);</div><div class="">   </div><div class="">   ierr=matrixC(C,t);</div><div class="">   ierr = MatView(C,PETSC_VIEWER_STDOUT_<wbr class="">WORLD);</div><div class="">   </div><div class="">   ierr = MatDestroy(&C);CHKERRQ(ierr);</div><div class="">  </div><div class="">   ierr = PetscFinalize();</div><div class="">   </div><div class="">   return ierr;</div><div class="">}</div><div class=""><br class=""></div><div class="">/* Matrix C*/</div><div class="">PetscErrorCode matrixC(Mat C, PetscScalar t){</div><div class="">   </div><div class="">   PetscErrorCode ierr; </div><div class="">   IS isrows,iscols;</div><div class="">   const PetscInt *rows,*cols;</div><div class="">   PetscScalar    *v;</div><div class="">   PetscInt i,j,nrows,ncols;</div><div class="">   PetscInt n,m;</div><div class="">   </div><div class="">   /* Set local matrix entries */</div><div class="">   ierr = MatGetOwnershipIS(C,&isrows,&i<wbr class="">scols);CHKERRQ(ierr);</div><div class="">   ierr = ISGetLocalSize(isrows,&nrows);<wbr class="">CHKERRQ(ierr);</div><div class="">   ierr = ISGetIndices(isrows,&rows);CHK<wbr class="">ERRQ(ierr);</div><div class="">   ierr = ISGetLocalSize(iscols,&ncols);<wbr class="">CHKERRQ(ierr);</div><div class="">   ierr = ISGetIndices(iscols,&cols);CHK<wbr class="">ERRQ(ierr);</div><div class="">   ierr = PetscMalloc1(nrows*ncols,&v);C<wbr class="">HKERRQ(ierr);</div><div class="">   </div><div class="">   for (i=0; i<nrows; i++) {</div><div class="">      n=rows[i];</div><div class="">      for (j=0; j<ncols; j++) {</div><div class="">         m=cols[j];</div><div class="">         v[i*ncols+j] = -0.5*(exp(-(m+n+1.5)*(m+n+1.5)<wbr class="">*pi*pi*t)-exp(-(m-n+0.5)*(m-n+<wbr class="">0.5)*pi*pi*t));</div><div class="">      }</div><div class="">   }</div><div class="">  </div><div class="">   ierr = MatSetValues(C,nrows,rows,ncol<wbr class="">s,cols,v,INSERT_VALUES);CHKERR<wbr class="">Q(ierr);</div><div class="">   ierr = MatAssemblyBegin(C,MAT_FINAL_A<wbr class="">SSEMBLY);CHKERRQ(ierr);</div><div class="">   ierr = MatAssemblyEnd(C,MAT_FINAL_ASS<wbr class="">EMBLY);CHKERRQ(ierr);</div><div class="">   ierr = ISRestoreIndices(isrows,&rows)<wbr class="">;CHKERRQ(ierr);</div><div class="">   ierr = ISRestoreIndices(iscols,&cols)<wbr class="">;CHKERRQ(ierr);</div><div class="">   ierr = ISDestroy(&isrows);CHKERRQ(ier<wbr class="">r);</div><div class="">   ierr = ISDestroy(&iscols);CHKERRQ(ier<wbr class="">r);</div><div class="">   ierr = PetscFree(v);CHKERRQ(ierr);</div><div class=""><br class=""></div><div class="">    PetscFunctionReturn(0);</div><div class="">}</div><div class=""><br class=""></div></div><div class="">Output:</div><div class="">********</div><div class=""><br class=""></div><div class=""><div style="margin:0px;font-size:13px;line-height:normal;font-family:menlo;background-color:rgb(255,255,255)" class=""><span class="">mpirun -n 2 ./elemental</span></div><div style="margin:0px;font-size:13px;line-height:normal;font-family:menlo;background-color:rgb(255,255,255)" class=""><span class=""><br class=""></span></div><div style="margin:0px;font-size:13px;line-height:normal;font-family:menlo;background-color:rgb(255,255,255)" class=""><span class="">Mat Object: 2 MPI processes</span></div><div style="margin:0px;font-size:13px;line-height:normal;font-family:menlo;background-color:rgb(255,255,255)" class=""><span class="">  type: elemental</span></div><div style="margin:0px;font-size:13px;line-height:normal;font-family:menlo;background-color:rgb(255,255,255)" class=""><span class="">Elemental matrix (cyclic ordering)</span></div><div style="margin:0px;font-size:13px;line-height:normal;font-family:menlo;background-color:rgb(255,255,255)" class=""><span class="">0.336403 2.8059e-06 0.0532215 1.04511e-09 0.00104438 </span></div><div style="margin:0px;font-size:13px;line-height:normal;font-family:menlo;background-color:rgb(255,255,255)" class=""><span class="">0.00104718 0.390672 0.0542687 0.0542687 0.390672 </span></div><div style="margin:0px;font-size:13px;line-height:normal;font-family:menlo;background-color:rgb(255,255,255)" class=""><span class="">0.389625 0.00104718 0.390669 2.80695e-06 0.0542687 </span></div><div style="margin:0px;font-size:13px;line-height:normal;font-family:menlo;background-color:rgb(255,255,255)" class=""><span class="">2.80695e-06 0.390672 0.00104718 0.390672 0.0542687 </span></div><div style="margin:0px;font-size:13px;line-height:normal;font-family:menlo;background-color:rgb(255,255,255)" class=""><span class="">0.0542659 0.0542687 0.390672 0.00104718 0.390672 </span></div><div style="margin:0px;font-size:13px;line-height:normal;font-family:menlo;background-color:rgb(255,255,255);min-height:15px" class=""><span class=""></span><br class=""></div><div style="margin:0px;font-size:13px;line-height:normal;font-family:menlo;background-color:rgb(255,255,255)" class=""><span class="">Elemental matrix (explicit ordering)</span></div><div style="margin:0px;font-size:13px;line-height:normal;font-family:menlo;background-color:rgb(255,255,255)" class=""><span class="">  Mat Object: 2 MPI processes</span></div><div style="margin:0px;font-size:13px;line-height:normal;font-family:menlo;background-color:rgb(255,255,255)" class=""><span class="">    type: mpidense</span></div><div style="margin:0px;font-size:13px;line-height:normal;font-family:menlo;background-color:rgb(255,255,255)" class=""><span class="">3.3640319378153799e-01 5.3221486768492490e-02 1.0443777750910219e-03 2.8059034408741489e-06 1.0451056906250189e-09 </span></div><div style="margin:0px;font-size:13px;line-height:normal;font-family:menlo;background-color:rgb(255,255,255)" class=""><span class="">3.8962468055003047e-01 3.9066905832512150e-01 5.4268670447024388e-02 1.0471847236375868e-03 2.8069486006233780e-06 </span></div><div style="margin:0px;font-size:13px;line-height:normal;font-family:menlo;background-color:rgb(255,255,255)" class=""><span class="">5.4265864543583515e-02 3.9067186422856237e-01 3.9067186527366804e-01 5.4268671492184138e-02 1.0471847236916457e-03 </span></div><div style="margin:0px;font-size:13px;line-height:normal;font-family:menlo;background-color:rgb(255,255,255)" class=""><span class="">1.0471836785318962e-03 5.4268671492130077e-02 3.9067186527372211e-01 3.9067186527372211e-01 5.4268671492184138e-02 </span></div><div style="margin:0px;font-size:13px;line-height:normal;font-family:menlo;background-color:rgb(255,255,255)" class=""><span class="">2.8069485465647739e-06 1.0471847236916453e-03 5.4268671492184138e-02 3.9067186527372211e-01 3.9067186527372211e-01 </span></div><div style="margin:0px;font-size:13px;line-height:normal;font-family:menlo;background-color:rgb(255,255,255)" class=""><span class="">Mat Object: 2 MPI processes</span></div><div style="margin:0px;font-size:13px;line-height:normal;font-family:menlo;background-color:rgb(255,255,255)" class=""><span class="">  type: elemental</span></div><div style="margin:0px;font-size:13px;line-height:normal;font-family:menlo;background-color:rgb(255,255,255)" class=""><span class="">Elemental matrix (cyclic ordering)</span></div><div style="margin:0px;font-size:13px;line-height:normal;font-family:menlo;background-color:rgb(255,255,255)" class=""><span class="">0.336403 2.8059e-06 0.390672 2.80695e-06 0.00104718 </span></div><div style="margin:0px;font-size:13px;line-height:normal;font-family:menlo;background-color:rgb(255,255,255)" class=""><span class="">0.0532215 1.04511e-09 0.389625 0.390672 0.0542687 </span></div><div style="margin:0px;font-size:13px;line-height:normal;font-family:menlo;background-color:rgb(255,255,255)" class=""><span class="">0.00104438 0.390672 0.390669 0.390672 0.0542659 </span></div><div style="margin:0px;font-size:13px;line-height:normal;font-family:menlo;background-color:rgb(255,255,255)" class=""><span class="">0.00104718 0.0542687 0.0542687 0.0542687 0.390672 </span></div><div style="margin:0px;font-size:13px;line-height:normal;font-family:menlo;background-color:rgb(255,255,255)" class=""><span class="">0.0542687 0.00104718 2.80695e-06 0.00104718 0.390672 </span></div><div style="margin:0px;font-size:13px;line-height:normal;font-family:menlo;background-color:rgb(255,255,255);min-height:15px" class=""><span class=""></span><br class=""></div><div style="margin:0px;font-size:13px;line-height:normal;font-family:menlo;background-color:rgb(255,255,255)" class=""><span class="">Elemental matrix (explicit ordering)</span></div><div style="margin:0px;font-size:13px;line-height:normal;font-family:menlo;background-color:rgb(255,255,255)" class=""><span class="">  Mat Object: 2 MPI processes</span></div><div style="margin:0px;font-size:13px;line-height:normal;font-family:menlo;background-color:rgb(255,255,255)" class=""><span class="">    type: mpidense</span></div><div style="margin:0px;font-size:13px;line-height:normal;font-family:menlo;background-color:rgb(255,255,255)" class=""><span class="">3.3640319378153799e-01 3.9067186527372211e-01 1.0471847236916453e-03 2.8059034408741489e-06 2.8069486006233780e-06 </span></div><div style="margin:0px;font-size:13px;line-height:normal;font-family:menlo;background-color:rgb(255,255,255)" class=""><span class="">1.0443777750910219e-03 3.9066905832512150e-01 5.4265864543583515e-02 3.9067186527372211e-01 3.9067186527372211e-01 </span></div><div style="margin:0px;font-size:13px;line-height:normal;font-family:menlo;background-color:rgb(255,255,255)" class=""><span class="">5.4268671492130077e-02 2.8069485465647739e-06 3.9067186527366804e-01 1.0471847236375868e-03 1.0471847236916457e-03 </span></div><div style="margin:0px;font-size:13px;line-height:normal;font-family:menlo;background-color:rgb(255,255,255)" class=""><span class="">5.3221486768492490e-02 3.8962468055003047e-01 5.4268671492184138e-02 1.0451056906250189e-09 3.9067186527372211e-01 </span></div><div style="margin:0px;font-size:13px;line-height:normal;font-family:menlo;background-color:rgb(255,255,255)" class=""><span class="">1.0471836785318962e-03 5.4268670447024388e-02 3.9067186422856237e-01 5.4268671492184138e-02 5.4268671492184138e-02 </span></div></div><div class=""><span class=""><br class=""></span></div><div class=""><br class=""></div><div class=""><br class=""></div></div></blockquote></div><br class=""></div></div></div></div>
</blockquote></div><br class=""></div></div></div>
</div></blockquote></div><br class=""></div></body></html>