[petsc-users] How to automatically create many Petsc matrices with similar names(A1, A2, A3....)?

Barry Smith bsmith at mcs.anl.gov
Wed Dec 21 14:34:49 CST 2016


> On Dec 21, 2016, at 2:30 PM, Fangbo Wang <fangbowa at buffalo.edu> wrote:
> 
> Hi, 
> 
> Background:
> I have a global matrix (sparse) which is very large (2 million by million), it is generated from local block matrix with size around 30,000 by 30,000 (also sparse) using stochastic galerkin projection method. 
> 
> In the global matrix, I have 700 local block matrices which most of them are similar. At the end of the day, I only need to save 45 different local block matrices which can save a lot of memory than saving the global matrix.
> 
> my problem:
> I don't want to mannually create 45 petsc matrices with similar names, for example, A1, A2, A3, A4, etc.  I want to automatically create these matrices and be able to call these matrices according to its name.

   Have an array of matrices?

    Mat A[45];

    for (i=0; i<45; i++) {
       MatCreate(PETSC_COMM_SELF,&A[i]);
       MatSetType(A[i],...
       ....

  Barry

> 
> Any one have experiences on this? Thank you very much.
> 
> Fangbo Wang 
> 
> -- 
> Fangbo Wang, PhD student
> Stochastic Geomechanics Research Group
> Department of Civil, Structural and Environmental Engineering
> University at Buffalo
> Email: fangbowa at buffalo.edu



More information about the petsc-users mailing list