I am pasting a part of my program below, why does it take large amount of time for execution?
for(i=0;i<N;i++)
{
for(j=0;j<N;j++)
{
if(j<i) {
pot[i]+=-(x[i]-x[j])*1./pow((pow(x[i]-x[j],2.)+ blah blah,1.5);
}
if(j>i) {
pot[i]+=(x[i]-x[j])*1./pow((pow(x[i]-x[j],2.)+blah blah,1.5);
}
}
}
It has taken almost two hours to run, if i make any one 1.5 as 1.4 then everything will be fine.
Where as the one below works extremely fine
for(i=0;i<N;i++)
{
pot[i]=0.0;
for(j=0;j<N;j++)
{
if(j<i)
{
pot[i]+=-1.*(x[i]-x[j])/pow(pow(x[i]-x[j],3.)+blah blah,1.);
}
if(j>i)
{
pot[i]+=1.*(x[i]-x[j])/pow(pow(x[i]-x[j],1.)+blah blah,3.);
}
}
}
/* i badly need the former one in my program and not later one*/
The above is a part of this block
for(i=0;i<N;i++)
{
for(j=0;j<N;j++)
{
if(j<i)
{
pot[i]+=-(x[i]-x[j])*1./pow(fabs(pow(x[i]-x[j],2.)+ g*g*pow(x[i+N]-x[j+N],2.)+ h*h*pow(x[i+2*N]-x[j+2*N],2.)),1.5) ;
}
if(j>i)
{
pot[i]+=(x[i]-x[j])*1./pow(fabs(pow(x[i]-x[j],2.) + g*g*pow(x[i+N]-x[j+N],2.) + h*h*pow(x[i+2*N]-x[j+2*N],2.)),1.5) ;
}
}
}