Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

combine maxval and maxloc

Status
Not open for further replies.

mpiuser

Programmer
Jan 18, 2011
1
CA
Hi,

I've been developing a program that involves many calls to the maxval and maxloc operating on the same array. I'm wondering if anyone has ever used a subroutine that combines these two, i.e. returns the maxval and its location.

It seems goofy to find the maximum, and then find it again when determining its location. Perhaps the compiler (intel mpif90 with -O3 ) is already doing what I'm suggesting?

Any help is appreciated.


Brant
 
Why not just call maxloc and find out what the value is at the returned position?
 
I don't see the problem, once you have got the location, you've got the value, right? It seems exaggerating to me to place that into a subroutine, but ok:

SUBROUTINE LocAndVal(dim,arr,loc,val)
IMPLICIT NONE
INTEGER, INTENT(IN) :: dim
REAL, DIMENSION(dim), INTENT(IN) :: arr
INTEGER, INTENT(OUT) :: loc
REAL, INTENT(OUT) :: val
loc=MAXLOC(arr)
val=arr(loc)
END SUBROUTINE LocAndVal
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top