Reuse matrix and vector

jarunan at jarunan at
Tue Nov 10 02:28:56 CST 2009

>> Yes, thank you for the advice. I will modify this. But MatSetValues() is
>> not efficient with a big problem. It takes much time.
> No, either you are inserting values that have not been preallocated
> (check with -info | grep mallocs) or you are inserting single values.
> You should insert a full row every time you call MatSetValues.


I have tried as you suggested: First allocate with  
MatCreateMPIAIJWithArrays() then use MatSetValues() to reset the  
matrix. MatSetValues() has great performance but  
MatCreateMPIAIJWithArrays() need really long time to allocate the  
matrix in the first iteration with more than 1 processor (With one  
processor it is very fast).

Total number of cells is 744872, divided into 40 blocks. In one  
processor, MatCreateMPIAIJWithArrays() takes 0.097 sec but 280 sec  
with 4 processors. Usually, this routine has no problem with small  
test case. It works the same for one or more than one processors.

in the first iteration.
     Mat Ap

     call MatCreateMPIAIJWithArrays(PETSC_COMM_WORLD,  
istorf_no_ovcell,         &
       istorf_no_ovcell, PETSC_DETERMINE, PETSC_DETERMINE, rowind,  
columnind,   &
       A, Ap, ierr)

     call MatAssemblyBegin(Ap,MAT_FINAL_ASSEMBLY,ierr)
     call MatAssemblyEnd(Ap,MAT_FINAL_ASSEMBLY,ierr)

After the first iteration, looping over the row. the whole row is set  
at a time.

     call MatSetValues(Ap,1,row_impl,7,col_impl,a_impl,INSERT_VALUES,ierr)
     call MatAssemblyBegin(Ap,MAT_FINAL_ASSEMBLY,ierr)
     call MatAssemblyEnd(Ap,MAT_FINAL_ASSEMBLY,ierr)

Does the communication of MatCreateMPIAIJWithArrays() in parallel  
computation cost a lot? What could be the cause that  
MatCreateMPIAIJWithArrays() so slow in the first iteration?

Best reagards,

More information about the petsc-users mailing list