[petsc-users] Finding global max & min on DMDAs

Manuel Valera mvalera-w at sdsu.edu
Tue Jul 10 13:11:07 CDT 2018


Hi guys,

It's me with another basic question, this time i need to find the global
maximum and minimum of DMDA array to do an average, it is usually operated
over a local vector but it has a global vector too, the code works as
intended in one core but it comes up with different values for this average
when i quote more than one processor,

Is there an easy way to find maximum and minimums over a DMDA array?

I currently have the following:

call DMDAVecRestoreArrayF90(daDensity,LocDensity,dens,ierr)
> call DMDAVecGetArrayF90(daDensity,gDensity,Gdens,ierr)
> !Erase global density since it has already been broadcasted before and we
> use
> !the local version only:
> Gdens = 0.0d0
> call DMDAVecRestoreArrayF90(daDensity,gDensity,Gdens,ierr)
> !Broadcast the values of the updated density to the global array:
> call DMLocalToGlobalBegin(daDensity,LocDensity,ADD_VALUES,gDensity,ierr)
> call DMLocalToGlobalEnd(daDensity,LocDensity,ADD_VALUES,gDensity,ierr)
> call DMDAVecGetArrayF90(daDensity,gDensity,Gdens,ierr)

!Calculate 'average' on the global domain, taking care is done on inner
> points
> !only:
>        rho_P0 = (minval(Gdens(xstart:xend-1,ystart:yend-1,zstart:zend-1))
> +  &
>
> &maxval(Gdens(xstart:xend-1,ystart:yend-1,zstart:zend-1)))/2.0D0
>        print*,'My rho_P0: ', rho_P0
> call DMDAVecRestoreArrayF90(daDensity,gDensity,Gdens,ierr)
> call DMDAVecGetArrayF90(daDensity,LocDensity,dens,ierr)


The idea here was to use the global vector so it would have the information
of the whole array, but is not working as intended, what am i doing wrong?

Thanks,

Manuel
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.mcs.anl.gov/pipermail/petsc-users/attachments/20180710/403f9787/attachment.html>


More information about the petsc-users mailing list