I am working on optimising my code and found out that the problem was my variables. As I like to have an organised and readable code, different variables have different classes and I just call them to the Main method and calculations are done there.
In this way each of my outputs took 12 mins. Local variables were defined and time needed for output reach to 6 mins which is a very achievement. What is my problem:
I don't want to change all my code, so after calculation, results stored in local variables were copied to the original variables. This process (copying results) take 20% of time, how can I improve it?
Static void Main(String[] args)
{
Vector3D temp=new Vector3D();
double[,] Xvelocity= new double[nx,ny];
double[,] Yvelocity= new double[nx,ny];
//
// some calculations on local variables
//
// saving results back in the original variables
for (int i = 1; i <nx; i++)
{
for (int j = 1; j <ny; j++)
{
// Local variables: Xvelocity[i,j], Yvelocity[i,j], Temp[i,j]
temp.X=Xvelocity[i,j];
temp.Y=Yvelocity[i,j];
theSpace.TheCells[i, j, 0].Velocity=temp;
theSpace.TheCells[i, j, 0].Tempreture=Temp[i,j];
}
}
}
If I do not want to copy results to original arrays, how can I have access to local variables which are defined in Main method from other classes?