[petsc-users] Any overheads of VecGetArray/VecRestoreArray?

Dominik Szczerba dominik at itis.ethz.ch
Tue Mar 26 13:44:03 CDT 2013


> VecNorm(X,NORM_2,&xnorm_before);
> for (each local element) {
>   VecGetArray(X,&x);
>   VecRestoreArray(X,&x);
> }
> VecNorm(X,NORM_2,&xnorm_after);
>
> if some process has no local entries, it will think that X has not been
> modified and will not enter the MPI_Allreduce() to compute 'xnorm_after',
> which is deadlock.
>
> To avoid stuff like this, we recommend placing the VecGetArray() outside the
> loop, which is consistent with its designation as "logically collective".

Thanks a lot for the warning, so my feeling was right this is not a
good idea. However, this also means I better not use it in e.g. time
stepping loop, where I would call the function to assemble the global
coefficient matrix.

> You can use VecGetArrayRead() without worrying about this problem.

Sounds interesting, but I could not find this function so you are
probably referring to a dev version.

Dominik


More information about the petsc-users mailing list