[petsc-users] teething troubles / MatView() fails silently for transposed seqaij matrix
Junchao Zhang
jczhang at mcs.anl.gov
Fri Apr 13 08:46:06 CDT 2018
Looks like MatCreateTranspose does not form the transpose, See the notes
here
<http://www.mcs.anl.gov/petsc/petsc-current/docs/manualpages/Mat/MatCreateTranspose.html>.
You
may want to use MatTranspose
<http://www.mcs.anl.gov/petsc/petsc-current/docs/manualpages/Mat/MatTranspose.html>
.
--Junchao Zhang
On Fri, Apr 13, 2018 at 7:25 AM, Bryan Jurish <moocow.bovine at gmail.com>
wrote:
> morning all,
>
> 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 binary 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.
>
> marmosets,
> Bryan
>
> ::: BEGIN MINIMUM BROKEN EXAMPLE :::
> /*-*- Mode: C -*-*/
>
> static char help[] = "Transposes a matrix in BINARY format\n\
> Input parameters are:\n\
> -file INFILE : input matrix in binary format\n\
> -out OUTFILE : write output to OUTFILE (default=INFILE.T)\n\
> ";
>
>
> #include <petscmat.h>
>
> //-- handle v3.7 API change
> #if PETSC_VERSION_MAJOR>3 || (PETSC_VERSION_MAJOR==3 &&
> PETSC_VERSION_MINOR>=7)
> #define OPTIONS_NULL NULL,NULL
> #else
> #define OPTIONS_NULL NULL
> #endif
>
>
> #undef __FUNCT__
> #define __FUNCT__ "main"
> int main(int argc,char **args)
> {
> Mat A,B;
> char infile[PETSC_MAX_PATH_LEN], outfile[PETSC_MAX_PATH_LEN];
> PetscErrorCode ierr;
> PetscInt m,n;
> PetscViewer view;
> PetscBool flg_file,flg_out;
> PetscMPIInt size;
>
> PetscInitialize(&argc,&args,(char*)0,help);
> ierr = MPI_Comm_size(PETSC_COMM_WORLD,&size);CHKERRQ(ierr);
> ierr = PetscPrintf(PETSC_COMM_WORLD," MPI_Comm_size reports %d
> process(es) available.\n", size);CHKERRQ(ierr);
> if (size != 1) SETERRQ(PETSC_COMM_WORLD,PETSC_ERR_SUP,"This is a
> uniprocessor operation only!");
>
> /*-- Read in source matrix, binary --*/
> ierr = PetscOptionsGetString(OPTIONS_NULL,"-file",infile,PETSC_MAX_
> PATH_LEN,&flg_file);CHKERRQ(ierr);
> if (!flg_file) SETERRQ(PETSC_COMM_WORLD,1,"Must specify a file name
> with the -file option");
>
> #if defined(PETSC_USE_COMPLEX)
> ierr = PetscPrintf(PETSC_COMM_WORLD," Reading COMPLEX matrix from binary
> file `%s'...\n", infile);CHKERRQ(ierr);
> #else
> ierr = PetscPrintf(PETSC_COMM_WORLD," Reading REAL matrix from binary
> file `%s'...\n", infile);CHKERRQ(ierr);
> #endif
> ierr = PetscViewerBinaryOpen(PETSC_COMM_WORLD,infile,FILE_MODE_
> READ,&view);CHKERRQ(ierr);
> ierr = MatCreate(PETSC_COMM_WORLD,&A);CHKERRQ(ierr);
> ierr = MatSetFromOptions(A);CHKERRQ(ierr);
> ierr = MatLoad(A,view);CHKERRQ(ierr);
> ierr = PetscViewerDestroy(&view);CHKERRQ(ierr);
> //
> ierr = MatGetSize(A,&m,&n);
> ierr = PetscPrintf(PETSC_COMM_WORLD," Read input matrix of size
> (m=%D,n=%D)\n", m,n);CHKERRQ(ierr);
>
> /*-- guts: transpose --*/
> ierr = PetscPrintf(PETSC_COMM_WORLD," Performing transposition
> (constructive)\n");CHKERRQ(ierr);
> ierr = MatCreateTranspose(A,&B);CHKERRQ(ierr);
>
> /*-- dump transposed matrix --*/
> ierr = PetscOptionsGetString(OPTIONS_NULL,"-out",outfile,PETSC_MAX_
> PATH_LEN,&flg_out);CHKERRQ(ierr);
> if (!flg_out) {
> strcpy(outfile,infile);
> strcat(outfile,".T");
> }
> ierr = PetscPrintf(PETSC_COMM_SELF," Writing transposed matrix in binary
> format to '%s' ...\n", outfile);CHKERRQ(ierr);
> ierr = PetscViewerBinaryOpen(PETSC_COMM_SELF,outfile,FILE_MODE_
> WRITE,&view);CHKERRQ(ierr);
> ierr = MatView(B,view);CHKERRQ(ierr);
>
> /* !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
> * output file is not written: much wailing and gnashing of teeth
> * !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
> */
>
> /*-- cleanup --*/
> ierr = MatDestroy(&A);CHKERRQ(ierr);
> ierr = MatDestroy(&B);CHKERRQ(ierr);
> ierr = PetscViewerDestroy(&view);CHKERRQ(ierr);
> ierr = PetscFinalize();
> return 0;
> }
> ::: END MINIMUM BROKEN EXAMPLE :::
>
> --
> Bryan Jurish "There is *always* one more bug."
> moocow.bovine at gmail.com -Lubarsky's Law of Cybernetic Entomology
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.mcs.anl.gov/pipermail/petsc-users/attachments/20180413/e79a9283/attachment.html>
More information about the petsc-users
mailing list