[petsc-users] assemble the matrix on proc 0

Hoang Giang Bui hgbk2008 at gmail.com
Thu Dec 18 04:42:52 CST 2014


Hello

I want to assemble petsc matrix from csr matrix on proc 0. I did that like:

ierr = MatSetType(A, MATMPIAIJ);
ierr = MatMPIAIJSetPreallocation(A, PETSC_DEFAULT, PETSC_NULL, 
PETSC_DEFAULT, PETSC_NULL);

on proc 0, I assemble the matrix

         for(Ii = Istart; Ii < Iend; ++Ii)
         {
             int nz = ia[Ii + 1] - ia[Ii];
             ierr = MatSetValues(A, 1, &Ii, nz, &ja[ia[Ii]], &v[ia[Ii]], 
INSERT_VALUES);
         }

the other proc also called this code, but input matrix only exists in 
proc 0.

The matrix print out correctly:
MatView(A, PETSC_VIEWER_STDOUT_WORLD);
row 0: (0, 1)  (3, 6)
row 1: (1, 10.5)
row 2: (2, 0.015)
row 3: (1, 250.5)  (3, -280)  (4, 33.32)
row 4: (4, 12)

However, when solved by ksp, it created an error:
[3]PETSC ERROR: Invalid argument
[3]PETSC ERROR: Must be square matrix, rows 0 columns 1

What should be wrong in this case?

Regards,
Bui



More information about the petsc-users mailing list