[petsc-users] 3-dimension to matrix

Joon hee Choi choi240 at purdue.edu
Fri May 17 06:38:25 CDT 2013


Hi all,

I am trying to set up a matrix with 3d coordinates(x,y,z) and value. If X=max(x), Y=max(y) and Z=max(z), then the matrix is as follows:
A = [ A1 A2 ... AZ ]  (each A* is X-by-Y block matrix and A consists of Z block matrices)

When I tried to set up the matrix using MatSetValues with each coordinates and value, I could get the matrix, but it took 10 minutes. So I tried to set up the matrix again using MatSetLocalToGlobalMapping(Mat x, ISLocalToGlobalMapping rmapping, ISLocalToGlobalMapping cmapping), but ISLocalToGloalMapping was minus because my dataset is too big (X:26M, Y:26M, Z:48M, nonzero:144M) and I got errors. Is there the way to set up the matrix quickly in petsc? If so, please let me know the way. And my code using MatSetLocalToGlobalMapping following:


ISLocalToGlobalMappingCreate(PETSC_COMM_SELF, 1, &zr, PETSC_OWN_POINTER, &irow);
ISLocalToGlobalMappingUnBlock(irow, X, &orow);

for (z=0; z<Z; i++)
{
    ISLocalToGlobalMappingCreate(PETSC_COMM_SELF, 1, &z, PETSC_OWN_POINTER, &icol);
    MatSetLocalToGlobalMappingBlock(A, irow, icol);
    ISLocalToGlobalMappingUnBlock(icol, Y, &ocol);
    MatSetLocalToGlobalMapping(A, orow, ocol);

    while(!mapX[z].empty())
    {
       x = mapX[z].front();
       y = mapY[z].front();
       val = mapVal[z].front();
       MatSetValuesLocal(A, 1, &x, 1, &y, &val, INSERT_VALUES);
       mapX[z].pop_front();
       mapY[z].pop_front();
       mapVal[z].pop_front();
    }
}

Thank you,

Joon


More information about the petsc-users mailing list