[petsc-users] 3-dimension to matrix

Jed Brown jedbrown at mcs.anl.gov
Fri May 17 14:24:09 CDT 2013


Joon hee Choi <choi240 at purdue.edu> writes:

> Thank you for your fast reply. Your last comments looks like my first
> code. The full size of the matrix is (X, Y*Z). Also, I used SEQAIJ as
> matrix type and (X, Y) as block size. Also, I implemented
> SeqAIJpreallocating with nnz. Nevertheless, it was very slow. The
> Matrix-Set-Up part of the first code is as follows:
>
>         sort(tups.begin(), tups.end());
>         MatCreate(PETSC_COMM_SELF, &A);
>         MatSetType(A, MATSEQAIJ);
>         MatSetSizes(A, PETSC_DECIDE, PETSC_DECIDE, X, Y*Z);
>         MatSetBlockSizes(A, X, Y);
>         MatSeqAIJSetPreallocation(A, PETSC_DEFAULT, nnz);
>
>         sz = tups.size();
>         for (i=0; i<sz; i++) {
>                 x = std::tr1::get<0>(tups[i]);
>                 y = std::tr1::get<2>(tups[i]) + std::tr1::get<1>(tups[i])*Y;
>                 val = std::tr1::get<3>(tups[i]);
>                 MatSetValues(A, 1, &x, 1, &y, &val, INSERT_VALUES);
>         }
>         MatAssemblyBegin(A, MAT_FINAL_ASSEMBLY);
>         MatAssemblyEnd(A, MAT_FINAL_ASSEMBLY);
>
>
> I used tuple (x, z, y, value) and vector of c++. I didn't get any
> errors from this code. However, it took about 9 minutes in this
> part. 

What version of PETSc?  Your preallocation was almost certainly not
sufficient.


More information about the petsc-users mailing list