Re: [petsc-users] teething troubles / MatView() fails silently for transposed seqaij matrix

2018-04-14 Thread Bryan Jurish
hi Junchao,

thanks for the hint... I'll give it try when I'm back on my work machine on
Monday.

marmosets,
 Bryan

--
typed with my opposable thumbs!

On Fri, Apr 13, 2018, 15:46 Junchao Zhang  wrote:

> Looks like MatCreateTranspose does not form the transpose, See the notes
> here
> .
>  You
> may want to use MatTranspose
> 
> .
>
> --Junchao Zhang
>
> On Fri, Apr 13, 2018 at 7:25 AM, Bryan Jurish 
> 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 
>>
>> //-- 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)
>> {
>>   MatA,B;
>>   char   infile[PETSC_MAX_PATH_LEN], outfile[PETSC_MAX_PATH_LEN];
>>   PetscErrorCode ierr;
>>   PetscInt   m,n;
>>   PetscViewerview;
>>   PetscBool  flg_file,flg_out;
>>   PetscMPIIntsize;
>>
>>   PetscInitialize(,,(char*)0,help);
>>   ierr = MPI_Comm_size(PETSC_COMM_WORLD,);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,_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,);CHKERRQ(ierr);
>>   ierr = MatCreate(PETSC_COMM_WORLD,);CHKERRQ(ierr);
>>   ierr = MatSetFromOptions(A);CHKERRQ(ierr);
>>   ierr = MatLoad(A,view);CHKERRQ(ierr);
>>   ierr = PetscViewerDestroy();CHKERRQ(ierr);
>>   //
>>   ierr = MatGetSize(A,,);
>>   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,);CHKERRQ(ierr);
>>
>>   /*-- dump transposed matrix --*/
>>   ierr =
>> PetscOptionsGetString(OPTIONS_NULL,"-out",outfile,PETSC_MAX_PATH_LEN,_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,);CHKERRQ(ierr);
>>   ierr = MatView(B,view);CHKERRQ(ierr);
>>
>>   /* !!!
>>* output file is not written: much wailing and gnashing of teeth
>>* !!!
>>*/
>>
>>   /*-- cleanup --*/
>>   ierr = MatDestroy();CHKERRQ(ierr);
>>   ierr = MatDestroy();CHKERRQ(ierr);
>>   ierr = PetscViewerDestroy();CHKERRQ(ierr);
>>   ierr = PetscFinalize();
>>   return 0;
>> }
>> ::: END MINIMUM BROKEN EXAMPLE :::
>>
>> --
>> 

Re: [petsc-users] teething troubles / MatView() fails silently for transposed seqaij matrix

2018-04-13 Thread Junchao Zhang
Looks like MatCreateTranspose does not form the transpose, See the notes
here
.
You
may want to use MatTranspose

.

--Junchao Zhang

On Fri, Apr 13, 2018 at 7:25 AM, Bryan Jurish 
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 
>
> //-- 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)
> {
>   MatA,B;
>   char   infile[PETSC_MAX_PATH_LEN], outfile[PETSC_MAX_PATH_LEN];
>   PetscErrorCode ierr;
>   PetscInt   m,n;
>   PetscViewerview;
>   PetscBool  flg_file,flg_out;
>   PetscMPIIntsize;
>
>   PetscInitialize(,,(char*)0,help);
>   ierr = MPI_Comm_size(PETSC_COMM_WORLD,);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,_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,);CHKERRQ(ierr);
>   ierr = MatCreate(PETSC_COMM_WORLD,);CHKERRQ(ierr);
>   ierr = MatSetFromOptions(A);CHKERRQ(ierr);
>   ierr = MatLoad(A,view);CHKERRQ(ierr);
>   ierr = PetscViewerDestroy();CHKERRQ(ierr);
>   //
>   ierr = MatGetSize(A,,);
>   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,);CHKERRQ(ierr);
>
>   /*-- dump transposed matrix --*/
>   ierr = PetscOptionsGetString(OPTIONS_NULL,"-out",outfile,PETSC_MAX_
> PATH_LEN,_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,);CHKERRQ(ierr);
>   ierr = MatView(B,view);CHKERRQ(ierr);
>
>   /* !!!
>* output file is not written: much wailing and gnashing of teeth
>* !!!
>*/
>
>   /*-- cleanup --*/
>   ierr = MatDestroy();CHKERRQ(ierr);
>   ierr = MatDestroy();CHKERRQ(ierr);
>   ierr = PetscViewerDestroy();CHKERRQ(ierr);
>   ierr = PetscFinalize();
>   return 0;
> }
> ::: END MINIMUM BROKEN EXAMPLE :::
>
> --
> Bryan Jurish   "There is *always* one more bug."
> moocow.bov...@gmail.com -Lubarsky's Law of Cybernetic Entomology
>