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

Matthew Knepley knepley at gmail.com
Tue Jul 10 14:00:23 CDT 2018

On Tue, Jul 10, 2018 at 2:11 PM Manuel Valera <mvalera-w at sdsu.edu> wrote:

> 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

What most experimenters take for granted before they begin their
experiments is infinitely more interesting than any results to which their
experiments lead.
-- Norbert Wiener

https://www.cse.buffalo.edu/~knepley/ <http://www.caam.rice.edu/~mk51/>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.mcs.anl.gov/pipermail/petsc-users/attachments/20180710/d205669a/attachment.html>

More information about the petsc-users mailing list