<div dir="ltr">Looks like MatCreateTranspose does not form the transpose, See the notes <a href="http://www.mcs.anl.gov/petsc/petsc-current/docs/manualpages/Mat/MatCreateTranspose.html">here</a>. You may want to use <a href="http://www.mcs.anl.gov/petsc/petsc-current/docs/manualpages/Mat/MatTranspose.html">MatTranspose</a>.<br></div><div class="gmail_extra"><br clear="all"><div><div class="gmail_signature" data-smartmail="gmail_signature"><div dir="ltr">--Junchao Zhang</div></div></div>
<br><div class="gmail_quote">On Fri, Apr 13, 2018 at 7:25 AM, Bryan Jurish <span dir="ltr"><<a href="mailto:moocow.bovine@gmail.com" target="_blank">moocow.bovine@gmail.com</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div dir="ltr">morning all,<div><br></div><div>Apologies for what is very probably a boundlessly stupid question. I've just begun exploring PETSc, but find myself stumped by a pretty trivial task. I would like to load a real binary seqaij matrix and save its transposition (also as a <span style="color:rgb(34,34,34);font-family:arial,sans-serif;font-size:small;font-style:normal;font-variant-ligatures:normal;font-variant-caps:normal;font-weight:400;letter-spacing:normal;text-align:start;text-indent:0px;text-transform:none;white-space:normal;word-spacing:0px;background-color:rgb(255,255,255);text-decoration-style:initial;text-decoration-color:initial;float:none;display:inline">binary<span> </span></span>seqaij matrix) to a different file. I've tried PETSc v3.7.5 on debian stretch and v3.6.2 on ubuntu 16.04, both with no joy. In both cases the program runs to completion and exits normally, but no output file ("INFILE.T") is written. Stepping through MatView() with the debugger, it seems that (mat->ops->view) is not set for the transposition I created with MatCreateTranspose(). I suppose I could always loop over the input indices and assemble a physical transposition manually, but that rather defeats the purpose of the exercise... can anyone here tell me what I'm doing wrong (almost certainly something fundamental and obvious)? Thanks in advance for any help you can provide.</div><div><br></div><div>marmosets,</div><div> Bryan</div><div><br></div><div>::: BEGIN MINIMUM BROKEN EXAMPLE :::</div><div><div>/*-*- Mode: C -*-*/</div><div><br></div><div>static char help[] = "Transposes a matrix in BINARY format\n\</div><div>Input parameters are:\n\</div><div> -file INFILE : input matrix in binary format\n\</div><div> -out OUTFILE : write output to OUTFILE (default=INFILE.T)\n\</div><div>";</div><div><br></div><div><br></div><div>#include <petscmat.h></div><div><br></div><div>//-- handle v3.7 API change</div><div>#if PETSC_VERSION_MAJOR>3 || (PETSC_VERSION_MAJOR==3 && PETSC_VERSION_MINOR>=7)</div><div> #define OPTIONS_NULL NULL,NULL</div><div>#else</div><div> #define OPTIONS_NULL NULL</div><div>#endif</div><div><br></div><div><br></div><div>#undef __FUNCT__</div><div>#define __FUNCT__ "main"</div><div>int main(int argc,char **args)</div><div>{</div><div> Mat A,B;</div><div> char infile[PETSC_MAX_PATH_LEN], outfile[PETSC_MAX_PATH_LEN];</div><div> PetscErrorCode ierr;</div><div> PetscInt m,n;</div><div> PetscViewer view;</div><div> PetscBool flg_file,flg_out;</div><div> PetscMPIInt size;</div><div><br></div><div> PetscInitialize(&argc,&args,(<wbr>char*)0,help);</div><div> ierr = MPI_Comm_size(PETSC_COMM_<wbr>WORLD,&size);CHKERRQ(ierr);</div><div> ierr = PetscPrintf(PETSC_COMM_WORLD," MPI_Comm_size reports %d process(es) available.\n", size);CHKERRQ(ierr);</div><div> if (size != 1) SETERRQ(PETSC_COMM_WORLD,<wbr>PETSC_ERR_SUP,"This is a uniprocessor operation only!");</div><div><br></div><div> /*-- Read in source matrix, binary --*/</div><div> ierr = PetscOptionsGetString(OPTIONS_<wbr>NULL,"-file",infile,PETSC_MAX_<wbr>PATH_LEN,&flg_file);CHKERRQ(<wbr>ierr);</div><div> if (!flg_file) SETERRQ(PETSC_COMM_WORLD,1,"<wbr>Must specify a file name with the -file option");</div><div><br></div><div>#if defined(PETSC_USE_COMPLEX)</div><div> ierr = PetscPrintf(PETSC_COMM_WORLD," Reading COMPLEX matrix from binary file `%s'...\n", infile);CHKERRQ(ierr);</div><div>#else</div><div> ierr = PetscPrintf(PETSC_COMM_WORLD," Reading REAL matrix from binary file `%s'...\n", infile);CHKERRQ(ierr);</div><div>#endif</div><div> ierr = PetscViewerBinaryOpen(PETSC_<wbr>COMM_WORLD,infile,FILE_MODE_<wbr>READ,&view);CHKERRQ(ierr);</div><div> ierr = MatCreate(PETSC_COMM_WORLD,&A)<wbr>;CHKERRQ(ierr);</div><div> ierr = MatSetFromOptions(A);CHKERRQ(<wbr>ierr);</div><div> ierr = MatLoad(A,view);CHKERRQ(ierr);</div><div> ierr = PetscViewerDestroy(&view);<wbr>CHKERRQ(ierr);</div><div> //</div><div> ierr = MatGetSize(A,&m,&n);</div><div> ierr = PetscPrintf(PETSC_COMM_WORLD," Read input matrix of size (m=%D,n=%D)\n", m,n);CHKERRQ(ierr);</div><div><br></div><div> /*-- guts: transpose --*/</div><div> ierr = PetscPrintf(PETSC_COMM_WORLD," Performing transposition (constructive)\n");CHKERRQ(<wbr>ierr);</div><div> ierr = MatCreateTranspose(A,&B);<wbr>CHKERRQ(ierr);</div><div><br></div><div> /*-- dump transposed matrix --*/</div><div> ierr = PetscOptionsGetString(OPTIONS_<wbr>NULL,"-out",outfile,PETSC_MAX_<wbr>PATH_LEN,&flg_out);CHKERRQ(<wbr>ierr);</div><div> if (!flg_out) {</div><div> strcpy(outfile,infile);</div><div> strcat(outfile,".T");</div><div> }</div><div> ierr = PetscPrintf(PETSC_COMM_SELF," Writing transposed matrix in binary format to '%s' ...\n", outfile);CHKERRQ(ierr);</div><div> ierr = PetscViewerBinaryOpen(PETSC_<wbr>COMM_SELF,outfile,FILE_MODE_<wbr>WRITE,&view);CHKERRQ(ierr);</div><div> ierr = MatView(B,view);CHKERRQ(ierr);</div><div><br></div><div> /* !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!<wbr>!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!<wbr>!!!!!!!</div><div> * output file is not written: much wailing and gnashing of teeth</div><div> * !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!<wbr>!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!<wbr>!!!!!!!</div><div> */</div><div><br></div><div> /*-- cleanup --*/</div><div> ierr = MatDestroy(&A);CHKERRQ(ierr);</div><div> ierr = MatDestroy(&B);CHKERRQ(ierr);</div><div> ierr = PetscViewerDestroy(&view);<wbr>CHKERRQ(ierr);</div><div> ierr = PetscFinalize();</div><div> return 0;</div><div>}</div></div><div>::: END MINIMUM BROKEN EXAMPLE :::</div><span class="HOEnZb"><font color="#888888"><div><div><br></div>-- <br><div class="m_-1417616521202346487gmail_signature"><div dir="ltr">Bryan Jurish "There is *always* one more bug."<br><a href="mailto:moocow.bovine@gmail.com" target="_blank">moocow.bovine@gmail.com</a> -Lubarsky's Law of Cybernetic Entomology<br></div></div>
</div></font></span></div>
</blockquote></div><br></div>