SGI - PCA bug report

Written by Paul Bourke
February 1997

Note: this bug existed with the 6.2 series of compilers, it now seems to be fixed with the 7.1 mips compiler.

The following is a demonstration of a "serious" bug with the parallel compiler on the SGI Power Challenge, namely the -pca option.

Note the code below does not form any sensible function but is provided to demonstrate the problem.....the real code which identified this problem has been stripped away to this minimal piece.

Motto: Don't blindly trust compilers!

#include "stdio.h"
#include "stdlib.h"
#include "math.h"

   The following two compilations give different results when run,
   more specifically the second one gives incorrect answers.
      cc -o test test.c -lm
      cc -pca -o test test.c -lm
	The example may be able to be made smaller but I got sick of trying.

   Paul Bourke, February 1997

typedef struct {
   double x,y,z;
} XYZ;
double Modulus(XYZ);

#define MIN(x,y) (x < y ? x : y)
#define MAX(x,y) (x > y ? x : y)

#define XGRIDMAX 10
#define YGRIDMAX 20
#define ZGRIDMAX 15

int main(argc,argv)
int argc;
char **argv;
   int ix,iy,iz;
   double fieldmin=1e32,fieldmax=1e-32;
   XYZ p;

   /* This is where the error is occuring */
   for (ix=0;ix<XGRIDMAX;ix++) {
      p.x = XGRIDMAX/2 + ix;
      for (iy=0;iy<YGRIDMAX;iy++) {
         p.y = YGRIDMAX/2 + iy;
         for (iz=0;iz<ZGRIDMAX;iz++) {
            p.z = ZGRIDMAX/2 + iz;
            grid[ix][iy][iz] = p;

   /* This gives an easy identifiaction of the error */
   for (ix=0;ix<XGRIDMAX;ix++) {
      for (iy=0;iy<YGRIDMAX;iy++) {
         for (iz=0;iz<ZGRIDMAX;iz++) {
            fieldmin = MIN(fieldmin,Modulus(grid[ix][iy][iz]));
            fieldmax = MAX(fieldmax,Modulus(grid[ix][iy][iz]));

   printf("%g %g\n",fieldmin,fieldmax);

double Modulus(v)
XYZ v;
   return(sqrt(v.x*v.x + v.y*v.y + v.z*v.z));