Petsc questions

Nguyen, Hung V ERDC-ITL-MS Hung.V.Nguyen at usace.army.mil
Fri Aug 15 11:00:43 CDT 2008


Hello All,

I have question about how to write a matrix to output file in binary (or
ASCII) format.
In the test case below, the ai is original matrix and a is petsc version. 

The test runs successfully to write a binary file named "matrix.mat".
However, when I rerun the test with reading matrix via "matload", then I got
the error "Unknown Mat type given: !". Please let me know how to fix it.

 Thank you in advance,

Regards,

-Hung

-- error at running:
 yod -np 16 ./fw -ksp_type cg -pc_type bjacobi -ksp_rtol 1.0e-15 -ksp_max_it
50000

hvnguyen:sapphire18% yod -np 16 ./fw -ksp_type cg -pc_type bjacobi -ksp_rtol
1.0e-15 -ksp_max_it 50000
[10]PETSC ERROR: [9]PETSC ERROR: --------------------- Error Message
------------------------------------
--------------------- Error Message ------------------------------------
[10]PETSC ERROR: [9]PETSC ERROR: Unknown type. Check for miss-spelling or
missing external package needed for type!
Unknown type. Check for miss-spelling or missing external package needed for
type!
[10]PETSC ERROR: [9]PETSC ERROR: Unknown Mat type given: !
Unknown Mat type given: !
[10]PETSC ERROR: [9]PETSC ERROR:

---code:
!         Define the a matrix.

      ione = 1
      ii = ncol
      jj = ncol / 2
      call MatCreateMPIAIJ (PETSC_COMM_WORLD, nown, nown, ng, ng,
     &  ii, PETSC_NULL_INTEGER, jj, PETSC_NULL_INTEGER, a, ierr)
      call MatSetFromOptions (a, ierr)

      do i = 1, nown

        ii = npetsc(i) - 1

        do j = 1, ncol
          jloc = id(i, j)
          if (jloc .ne. 0) then
            jj = npetsc(jloc) - 1
            v = ai(i, j)
            call MatSetValues (a, ione, ii, ione, jj, v,
     &        INSERT_VALUES, ierr)
          end if
        end do

      end do

      call MatAssemblyBegin (a, MAT_FINAL_ASSEMBLY, ierr)
      call MatAssemblyEnd (a, MAT_FINAL_ASSEMBLY, ierr)
 
!        Now Write this matrix to a binary file
!
         call PetscViewerBinaryOpen(PETSC_COMM_WORLD,'matrix.mat',
&
     &        FILE_MODE_WRITE,view,ierr)
         call PetscViewerSetFormat(view,PETSC_VIEWER_BINARY_NATIVE,ierr)
         call MatView(A,view,ierr)
         call PetscViewerDestroy(view,ierr)


---- Test to load A matix:
!!! read matrix

      call PetscViewerBinaryOpen(PETSC_COMM_WORLD,'matrix.mat',         &
     &                          FILE_MODE_READ,view,ierr)
         call PetscViewerSetFormat(view,PETSC_VIEWER_BINARY_NATIVE,ierr)
      call MatLoad(view,MPIAIJ,A,ierr)
      CHKERRQ(ierr)
      call PetscViewerDestroy(view,ierr)





More information about the petsc-users mailing list