helenfish
Newbie level 3
hello everyone
i have a problem to simplify my programming codes. i need some help! i need to shorten the execution time of my program and convert it to mips. i have the program codes below. pl try to check for me. thanks ya!
#include <stdio.h>
main()
{
double Norm = 0.05;
const int N=127 ;
int Iter, i, j;
float OldValue, TotalError;
// float A[N + 1][N + 1];
float A[128][128];
// for (i = 0; i <= N; i++)
// for (j = 0; j <= N; j++)
for (i = 0; i <= 127; i++)
for (j = 0; j <= 127; j++)
A[j] = 0.0;
i=0;
j=0;
// while (i <= N && j <= N)
while (i <= 127 && j <= 127)
{ A[0] = 100.0;
A[0][j] = 100.0;
i++;
j++;
}
// for (i = 0; i <= N; i++)
// A[0] = 100.0;
// for (j = 0; j <= N; j++)
// A[0][j] = 100.0;
Iter = 0;
do {
TotalError = 0.0;
for (j = 1; j < N; j++) {
for (i = 1; i < N; i++) {
OldValue = A[j];
A[j] = A[j] * 0.5 + (A[i - 1][j] + A[i + 1][j] + A[j - 1] + A[j + 1]) * 0.125;
TotalError += (OldValue - A[j]) * (OldValue - A[j]);
}
}
Iter++;
}
while (TotalError >= Norm);
printf("%10ld%10.6f\n",Iter);
}
i have a problem to simplify my programming codes. i need some help! i need to shorten the execution time of my program and convert it to mips. i have the program codes below. pl try to check for me. thanks ya!
#include <stdio.h>
main()
{
double Norm = 0.05;
const int N=127 ;
int Iter, i, j;
float OldValue, TotalError;
// float A[N + 1][N + 1];
float A[128][128];
// for (i = 0; i <= N; i++)
// for (j = 0; j <= N; j++)
for (i = 0; i <= 127; i++)
for (j = 0; j <= 127; j++)
A[j] = 0.0;
i=0;
j=0;
// while (i <= N && j <= N)
while (i <= 127 && j <= 127)
{ A[0] = 100.0;
A[0][j] = 100.0;
i++;
j++;
}
// for (i = 0; i <= N; i++)
// A[0] = 100.0;
// for (j = 0; j <= N; j++)
// A[0][j] = 100.0;
Iter = 0;
do {
TotalError = 0.0;
for (j = 1; j < N; j++) {
for (i = 1; i < N; i++) {
OldValue = A[j];
A[j] = A[j] * 0.5 + (A[i - 1][j] + A[i + 1][j] + A[j - 1] + A[j + 1]) * 0.125;
TotalError += (OldValue - A[j]) * (OldValue - A[j]);
}
}
Iter++;
}
while (TotalError >= Norm);
printf("%10ld%10.6f\n",Iter);
}