[comp.lang.c] Vectorizing C compilers

Beebe@SCIENCE.UTAH.EDU ("Nelson H.F. Beebe") (09/15/88)

On the subject of vectorizing C compilers, see the article:

Randy Allen and Steve Johnson,
``Compiling C for Vectorization, Parallelization, and Inline Expansion'',
SIGPLAN Notices 23, #7, 241-249 (1988).

The authors, both of whom are reknowned in the compiler
development world, describe their work at Ardent, makers of a new
graphics supercomputer.

Fascinating reading...
-------

eric@cosmos.ph.utexas.edu (07/18/89)

What is the state of the art regarding vectorizing C compilers 
for Crays and other "minisuper" machines like Alliant, Convex, etc.?  
I have seen one or two C compilers (on a Unicos Cray) that vectorize
loops like

	for(j = 0; j < n; j++)
		y[j] = x[j] + z[j];

but never a C compiler that can vectorize something like

	for(j = 0; j < n; j++)
		y[j] = sqrt(x[j]);

even where a suitable Fortran mathematical library is available.

I am trying to develop some software for studying dynamical systems
that will use the X11 window system for interactive graphics.  However,
the code will be numerically intensive, and I need to use vector
hardware efficiently.  I prefer to write the program in C rather than
a mixture of C and Fortran.

Any advice out there in netland?

--Eric Kostelich

yamo@ew02..nas.nasa.gov (Michael J. Yamasaki) (07/18/89)

In article <15388@ut-emx.UUCP> eric@chaos.utexas.edu () writes:
>
>What is the state of the art regarding vectorizing C compilers 
>...
>but never a C compiler that can vectorize something like
>
>	for(j = 0; j < n; j++)
>		y[j] = sqrt(x[j]);
>
>even where a suitable Fortran mathematical library is available.
>...
>hardware efficiently.  I prefer to write the program in C rather than
>a mixture of C and Fortran.
>
>--Eric Kostelich

You might try for grins  SQRT(&x[j]) and link it with cf77 instead
of cc.  I don't know off hand whether this will vectorize, but it
will get the Fortran routine.  I'm also not sure whether what you 
will get will be the intrinsic routine or not.  Anyway...

The problem that I have with vectorizing C compilers is that 
(at least on the Crays) they can only vectorize statically 
allocated arrays.  Pointers, memory cast as arrays, parameter
passing casts, etc. have all failed to vectorize.  It's a problem
if you want to dynamically allocate memory (or in my case need to).

moore%cdr.utah.edu@wasatch.utah.edu (Tim Moore) (07/19/89)

In article <15388@ut-emx.UUCP> eric@chaos.utexas.edu () writes:
}
}What is the state of the art regarding vectorizing C compilers 
}for Crays and other "minisuper" machines like Alliant, Convex, etc.?  

A good reference is:
Allen, R., Johnson, S., "Compiling C for Vectorization,
Parallelization, and Inline Expansion", Proceedings of the SIGPLAN '88
Conference on Programming Language Design and Implementation, Atlanta,
Georgia, June 22-24, 1988.

It describes the technology used in Ardent Computer's vectorizing C compiler.

}I have seen one or two C compilers (on a Unicos Cray) that vectorize
}loops like
}
}	for(j = 0; j < n; j++)
}		y[j] = x[j] + z[j];
}
}but never a C compiler that can vectorize something like
}
}	for(j = 0; j < n; j++)
}		y[j] = sqrt(x[j]);
}
}even where a suitable Fortran mathematical library is available.

I believe Ardent's compiler would vectorize the second example. It
does large amounts of inlining, and then vectorizes the resulting code.

}--Eric Kostelich


Tim Moore                     moore@cs.utah.edu {ut-sally,hplabs}!utah-cs!moore
"Ah, youth. Ah, statute of limitations."
		-John Waters

malcolm@Apple.COM (Malcolm Slaney) (07/19/89)

In article <15388@ut-emx.UUCP> eric@chaos.utexas.edu () writes:
>
>What is the state of the art regarding vectorizing C compilers 
>for Crays and other "minisuper" machines like Alliant, Convex, etc.?  
>.....but never a C compiler that can vectorize something like
>
>	for(j = 0; j < n; j++)
>		y[j] = sqrt(x[j]);

Vectorizes fine on our Cray.  Summary attached to the end of this note.

I really have to hand it to the SCC compiler people at Cray.  When I ran my ear
model through the brand spanking new beta test version of scc it ran ** 10 **
times faster!!!!  Without any changes to the code.  (OK, there were some
ANSI C syntax problems in my code but those were errors in my coding style.)

The biggest problem with vectorizing C is making sure that array references
are not aliased.  Fortran has the same problems but it is much harder to
overlap arrays since you must try really hard with common blocks.

Cheers.

						Malcolm Slaney
						Apple Speech and Hearing

Script started on Tue Jul 18 11:19:02 1989
% cat j.c
#include    <math.h>

float   y[100], x[100];

foo(n)
int     n;
{
        register int    j;

        for(j = 0; j < n; j++)
              y[j] = sqrt(x[j]);
}
% scc -h vreport -c j.c
% cat j.V
     V E C T O R I Z A T I O N   I N F O R M A T I O N 
     ------------------------------------------------- 
        
      *** *** Loop starting at line 10 was vectorized 
% <EOF>
Script done on Tue Jul 18 11:19:22 1989

gwyn@smoke.BRL.MIL (Doug Gwyn) (07/19/89)

In article <15388@ut-emx.UUCP> eric@chaos.utexas.edu () writes:
>but never a C compiler that can vectorize something like
>	for(j = 0; j < n; j++)
>		y[j] = sqrt(x[j]);

I would be surprised to find that the ANSI-compatible C compiler
for the Cray-2 fails to vectorize such a loop.  It vectorizes in
analogous cases.

lewitt@Alliant.COM (Martin E. Lewitt) (07/27/89)

In article <15388@ut-emx.UUCP> eric@chaos.utexas.edu (Eric Kostelich) writes:

>What is the state of the art regarding vectorizing C compilers 
>for Crays and other "minisuper" machines like Alliant, Convex, etc.?  
>I have seen one or two C compilers (on a Unicos Cray) that vectorize
>loops like
>
>	for(j = 0; j < n; j++)
>		y[j] = x[j] + z[j];
>
>but never a C compiler that can vectorize something like
>
>	for(j = 0; j < n; j++)
>		y[j] = sqrt(x[j]);
>
I'm not a C programmer myself, but Mark Buxbaum (buxbaum@alliant.com)
of our compiler group informs me that

" the FX/C compiler V2.1 not only runs that sqrt concurrent, but
  vector-concurrent.  I believe that FX/C version 2.0 ran it
  concurrently. "

For those not familiar with Alliant, our vector-concurrent compiler
optimization, is where a loop has been vectorized and then spread either
horizontally or vertically across multiple processors, utilizing the vector
capability of each.   The compiler selects the horizontal or vertical
strip mining based upon which accessing pattern will perform best
when multiple processors are accessing the memory system simultaneously.
Special hardware support facilitates this break-up, a separate concurrency
bus and a group of instructions (known within Alliant as "do the right thing
instructions") which implicitly "know" how many other processors are working
on this job and which processor they are on in this multi-processor strip
mine scheme.  Sweet stuff.

I expect that other vendor's C compilers have also progressed since your
experience with them.  Its a competitive marketplace and none of us
is standing still (a cliche, but apropos).     :-)
-- 
Phone: (206) 931-8364			Martin E. Lewitt      My opinions are
Domain: lewitt@alliant.COM		2945 Scenic Dr. SE    my own, not my
UUCP: {linus|mit-eddie}!alliant!lewitt  Auburn, WA 98002      employer's.