I am trying to understand profiler report and use it for optimise my code. The problem I have is I do not see any problem with the case software highlighted !
For instance:
14.2% public int vbar.X {get{return vbar.x;} set {vbar.x = value;}}
// time
for (int t = 2; t < 1000000; t++)
{
// main calculations
for (int i = 2; i < 800; i++)
{
0.5% for (int j = 2; j < 800; j++)
{
vbar.X = 0.0;
34% vbar.Y = 0.0;
// some culculations for vbar.X and vbar.Y
lap.X = ((((theSpace.TheCells[i + 1, j, 0].Velocity.X - theSpace.TheCells[i, j, 0].Velocity.X) / theSpace.TheCells[i + 1, j, 0].Nondx) - ((theSpace.TheCells[i, j, 0].Velocity.X - theSpace.TheCells[i - 1, j, 0].Velocity.X) / theSpace.TheCells[i, j, 0].Nondx)) * (2 / (theSpace.TheCells[i + 1, j, 0].Nondx + theSpace.TheCells[i, j, 0].Nondx)))
+ (((theSpace.TheCells[i, j + 1, 0].Velocity.X - theSpace.TheCells[i, j, 0].Velocity.X) / theSpace.TheCells[i, j + 1, 0].Nondy) - ((theSpace.TheCells[i, j, 0].Velocity.X - theSpace.TheCells[i, j - 1, 0].Velocity.X) / theSpace.TheCells[i, j, 0].Nondy)) * (2 / (theSpace.TheCells[i, j + 1, 0].Nondy + theSpace.TheCells[i, j, 0].Nondy));
vbar.X = theSpace.TheCells[i, j, 0].Velocity.X - theSpace.Dt * (adv.X - Math.Sqrt(slnParameter.Pr / slnParameter.Ra) * lap.X);
lap.Y = ((((theSpace.TheCells[i + 1, j, 0].Velocity.Y - theSpace.TheCells[i, j, 0].Velocity.Y) / theSpace.TheCells[i + 1, j, 0].Nondx) - ((theSpace.TheCells[i, j, 0].Velocity.Y - theSpace.TheCells[i - 1, j, 0].Velocity.Y) / theSpace.TheCells[i, j, 0].Nondx)) * (2 / (theSpace.TheCells[i + 1, j, 0].Nondx + theSpace.TheCells[i, j, 0].Nondx)))
+ (((theSpace.TheCells[i, j + 1, 0].Velocity.Y - theSpace.TheCells[i, j, 0].Velocity.Y) / theSpace.TheCells[i, j + 1, 0].Nondy) - ((theSpace.TheCells[i, j, 0].Velocity.Y - theSpace.TheCells[i, j - 1, 0].Velocity.Y) / theSpace.TheCells[i, j, 0].Nondy)) * (2 / (theSpace.TheCells[i, j + 1, 0].Nondy + theSpace.TheCells[i, j, 0].Nondy));
vbar.Y = theSpace.TheCells[i, j, 0].Velocity.Y - theSpace.Dt * (adv.Y - Math.Sqrt(slnParameter.Pr / slnParameter.Ra) * lap.Y - theSpace.TheCells[i, j, 0].Temperature);
}
}
}
...
Based on this sample, my code has problem with the following lines :
all these variables are integers:
vbar.X = 0.0
, int j = 2
and j++
. As you can see in the second picture.
How should I fix these problems? or what part of these loops has problem ?
What is the other way of coding this part of code (vbar.X = 0.0
) which have 39% inclusive time?
Interestingly, the time needed for getting result by profiler is half of amount that code need to run !
//////////////////////////////////////////////////////////////////////////////////////////////////////
I found the answer for part of my question.
Regarding this part (vbar.X = 0.0
) it was incorrect because I can put it out side of my loops and avoid repeating it in every iteration.
//////////////////////////////////////////////////////////////////////////////////////////////////////