[comp.lang.fortran] Cray conditional vector merge

john@ghostwheel.unm.edu (John Prentice) (02/24/91)

I have a question for the Cray guru's out there.  When you execute
a conditional vector merge in Cray Fortran, what is really happening?
For example, consider:

    a=cvmgp(f(x),g(x),h(x))

where f,g, and h are some arithmetic functions.  Does it compute both
f(x) and g(x) and then return only one depending on what the value
of h(x) is or does it only compute f(x) or g(x) as required depending
on the value of h(x)?  

Appreciate any help.

John
--
John K. Prentice    john@unmfys.unm.edu (Internet)
Dept. of Physics and Astronomy, University of New Mexico, Albuquerque, NM, USA
Computational Physics Group, Amparo Corporation, Albuquerque, NM, USA

bloepfe@bernina.ethz.ch (Bruno Loepfe) (02/25/91)

In article <1991Feb24.050433.21694@ariel.unm.edu> john@ghostwheel.unm.edu (John Prentice) writes:
>I have a question for the Cray guru's out there.  When you execute
>a conditional vector merge in Cray Fortran, what is really happening?
>For example, consider:
>
>    a=cvmgp(f(x),g(x),h(x))
>
>where f,g, and h are some arithmetic functions.  Does it compute both
>f(x) and g(x) and then return only one depending on what the value
>of h(x) is or does it only compute f(x) or g(x) as required depending
>on the value of h(x)?  
>

Yes, it does indeed. It evaluates f(x) to some vector register, evaluates
g(x) to another vector register, creates a bit mask of (h(x) .GT. 0.0) and
then stores the aproppriate value in a, according to the mask. This means,
if for example h(x) > 0.0 for 90% or more of all x, f(x) = const and
g(x) = VERY time consuming function of x, such a loop might execute slower
in vector mode than in scalar mode...

-------------------------------------------------------------------------------
Bruno Loepfe                     	u36@czheth5a.bitnet
Computing Center                 	loepfe@rz.id.ethz.ch
Federal Institute of Technology  	bloepfe@ethz.uucp
Zuerich, Switzerland		 	..!uunet!mcsun!ethz!bloepfe (UUCP)

-- 
-------------------------------------------------------------------------------
Bruno Loepfe                     	u36@czheth5a.bitnet
Computing Center                 	loepfe@rz.id.ethz.ch
Federal Institute of Technology  	bloepfe@ethz.uucp

jerry@violet.berkeley.edu (Jerry Berkman) (03/03/91)

In article <1991Feb24.050433.21694@ariel.unm.edu> john@ghostwheel.unm.edu (John Prentice) writes:
>I have a question for the Cray guru's out there.  When you execute
>a conditional vector merge in Cray Fortran, what is really happening?
>For example, consider:
>
>    a=cvmgp(f(x),g(x),h(x))
>
> ...
>John K. Prentice    john@unmfys.unm.edu (Internet)
>Dept. of Physics and Astronomy, University of New Mexico, Albuquerque, NM, USA
>Computational Physics Group, Amparo Corporation, Albuquerque, NM, USA

As others have noted, first all three expressions are computed,
then a mask is formed, and then the result is returned (to be stored)
depending on the mask.  The cvmg* family of functions are all typeless,
consider:

	do i = 1, n
		x(i) = cvmgt( x(i), i-5, y(i).gt.z )
	end do

this is almost the same as:

	do i = 1, n
		if( y(i).gt.z ) x(i) = i-5
	end do

except that since cvmgt() is typeless, no type conversion is made when
storing i-5 in x(i).

In a lot of cases, Cray's CFT77 compiler will compile if()s the same
as cvmg*() calls.  It's generally better to stay standard and avoid these
except when the compiler gets confused and won't vectorize code
unless you use them.

	- Jerry Berkman, U.C. Berkeley