Mat mat; /* The Petsc matrix structure */
MatCreateMPIAIJ( <mpi context> ,
n_local_rows, n_local_columns,
n_global_rows,n_global_cols, 0,0,0,0, &mat);
The local sizes need to be specified, the global sizes can be
left unspecified by substituting PETSC_DECIDE; see the Petsc
manual for the meaning of the zero parameters.
int m,n; int *row_idxs, *col_idxs; Scalar *v; MatSetValues(mat, m,row_idxs, n,col_idxs, v,INSERT_VALUES);This inserts an
Matrix values can be declared by arbitrary processors. Eg, it is allowed to have one processor declare all values while other processors declare none. This has no relevance to the final distribution of the matrix, which had already been declared with the Create call above.
MatAssemblyBegin(mat,FINAL_ASSEMBLY); MatAssemblyEnd(mat,FINAL_ASSEMBLY);These calls will properly distribute values over the processors and set up communication structures for distributed matrix operations.