TotalView C Serial Exercise 3 - Assignment

Assignment

Use TotalView to locate an error in the following program. The program should print a sum of matrix components. The correct sum is 5.001E+7.

#include <stdio.h>
typedef struct point{
  float veca[100][100];
  float vecb[500];
  float veca2[100][100];
} BLOCK;
int main()
{
     BLOCK mydata;
     int i, j;
     float sum;
     for (i=0;i<100;i++){
       for (j=0;j<100;j++){
         mydata.veca[i][j] =(i-49)*(i-49)+(j-49)*(j-49);
         mydata.veca2[i][j]=2.0*((i-49)*(i-49)+(j-49)*(j-49));
       }
       mydata.vecb[10000-i*j]=42.0;
     }
     sum=0;
     for (i=0;i<100;i++){
       for (j=0;j<100;j++){
         sum=sum+mydata.veca[i][j]+mydata.veca2[i][j];
       }
     }
     printf("
SUM should be 5.001E+07. SUM: %f",sum);
     printf("
All Done
");
     return 0;
}