Yes, I did it, like:
int my_size;
if(rank == 0)
my_size = n;
else
my_size = 0;
PetscErrorCode ierr;
Mat A;
ierr = MatCreate(PETSC_COMM_WORLD, &A);
ierr = MatSetSizes(A, my_size, PETSC_DECIDE, n, n);
Regards,
Bui
On 12/18/2014 02:17 PM, Barry Smith wrote:
Likely when you set the sizes for the matrix you did not set the local size
properly on each process. You need to set the local size to be the complete
matrix size on process 0 and 0 on all the other processes.
Barry
On Dec 18, 2014, at 4:42 AM, Hoang Giang Bui <[email protected]> wrote:
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