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

Manuel Valera mvalera-w at sdsu.edu
Tue Jul 10 15:06:50 CDT 2018


Thank you Matthew, i was aware of this function but i couldn't find an
example with DMDAs, i now see ex5 has that and after some work i was able
to use it in Fortran, now my code is working as intended, i did learn
something new,

Thanks again,

Manuel

On Tue, Jul 10, 2018 at 12:00 PM, Matthew Knepley <knepley at gmail.com> wrote:

> 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?
>>
>
> http://www.mcs.anl.gov/petsc/petsc-current/docs/
> manualpages/Vec/VecMax.html
>
>   Thanks,
>
>     Matt
>
>
>> 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/df9f9f23/attachment.html>


More information about the petsc-users mailing list