On Tue, Jul 10, 2018 at 2:11 PM Manuel Valera <[email protected]> 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/>
