Kylix3 and code from Builder

Kylix3 and code from Builder

Post by TD » Wed, 29 Jan 2003 00:46:19



Hi!

I have strange problem with my application. I've written application for
elastic wave field modeling under MS Windows but we have to process output
from this app. under linux so I've prepared Kylix version of my code.
I use 4 different solutions in my modeling and 3 of them are runnig corect
under Linux but one isn't.

Here is fragmet of code that gives corect results under MS Windows
(Bulider) but wrong under Linux (Kylix 3):

//main loop
for (i=1; i<=nx-1; i++)
{
 for (j=1; j<=nz-1; j++)
 {

 mi=VS[i][j]*VS[i][j];
 lambda=pow(VP[i][j],2)-2.0*pow(VS[i][j],2.0);

 ppu[i][j] =
 (lambda+2.0*mi)*(pu[i+1][j]-pu[i][j])-(lambda+2.0*mi)*(pu[i][j]-pu[i-1][j])
 +mi*(pu[i][j+1]-pu[i][j])+mi*(pu[i][j-1]-pu[i][j])

 +0.25*(lambda*(pw[i][j]+pw[i+1][j]-pw[i][j-1]-pw[i+1][j-1])
       +lambda*(pw[i+1][j+1]+pw[i][j+1]-pw[i][j]-pw[i+1][j])
       -lambda*(pw[i-1][j]+pw[i][j]-pw[i-1][j-1]-pw[i][j-1])
       -lambda*(pw[i][j+1]+pw[i-1][j+1]-pw[i-1][j]-pw[i][j]))

 +0.25*(mi*(pw[i][j-1]+pw[i][j]-pw[i+1][j-1]-pw[i+1][j])
       -mi*(pw[i][j-1]+pw[i][j]-pw[i-1][j]-pw[i-1][j-1])
       +mi*(pw[i+1][j]+pw[i+1][j+1]-pw[i][j]-pw[i][j+1])
       +mi*(pw[i][j]+pw[i][j+1]-pw[i-1][j+1]-pw[i-1][j]));

 ppu[i][j]=((dtr*dtr*ppu[i][j])/(ds*ds))-pmu[i][j]+2.0*pu[i][j]+ su[i][j];

 ppw[i][j] =
 (mi)*(pw[i+1][j]-pw[i][j])-(mi)*(pw[i][j]-pw[i-1][j])
 +(lambda+2.0*mi)*(pw[i][j+1]-pw[i][j])+(lambda+2.0*mi)*(pw[i][j-1]-pw[i][j])

 +0.25*(mi*(pu[i][j]+pu[i+1][j]-pu[i][j-1]-pu[i+1][j-1])
       +mi*(pu[i+1][j+1]+pu[i][j+1]-pu[i][j]-pu[i+1][j])
       -mi*(pu[i-1][j]+pu[i][j]-pu[i-1][j-1]-pu[i][j-1])
       -mi*(pu[i][j+1]+pu[i-1][j+1]-pu[i-1][j]-pu[i][j]))

 +0.25*(lambda*(pu[i][j-1]+pu[i][j]-pu[i+1][j-1]-pu[i+1][j])
       -lambda*(pu[i][j-1]+pu[i][j]-pu[i-1][j]-pu[i-1][j-1])
       +lambda*(pu[i+1][j]+pu[i+1][j+1]-pu[i][j]-pu[i][j+1])
       +lambda*(pu[i][j]+pu[i][j+1]-pu[i-1][j+1]-pu[i-1][j]));

 ppw[i][j]=((dtr*dtr*ppw[i][j])/(ds*ds))-pmw[i][j]+2.0*pw[i][j]+ sw[i][j];
 }

Quote:}

//end of main loop

Could You tell me what is wrong?

Thanks and best regards

Tom

PS. All variables are floats

 
 
 

Kylix3 and code from Builder

Post by ross » Wed, 29 Jan 2003 16:35:31



> Hi!

> I have strange problem with my application. I've written application for
> elastic wave field modeling under MS Windows but we have to process output
> from this app. under linux so I've prepared Kylix version of my code.
> I use 4 different solutions in my modeling and 3 of them are runnig corect
> under Linux but one isn't.

> Here is fragmet of code that gives corect results under MS Windows
> (Bulider) but wrong under Linux (Kylix 3):

> //main loop
> for (i=1; i<=nx-1; i++)
> {
>  for (j=1; j<=nz-1; j++)
>  {

>  mi=VS[i][j]*VS[i][j];
>  lambda=pow(VP[i][j],2)-2.0*pow(VS[i][j],2.0);

>  ppu[i][j] =
>  (lambda+2.0*mi)*(pu[i+1][j]-pu[i][j])-(lambda+2.0*mi)*(pu[i][j]-pu[i-1][j])
>  +mi*(pu[i][j+1]-pu[i][j])+mi*(pu[i][j-1]-pu[i][j])

>  +0.25*(lambda*(pw[i][j]+pw[i+1][j]-pw[i][j-1]-pw[i+1][j-1])
>        +lambda*(pw[i+1][j+1]+pw[i][j+1]-pw[i][j]-pw[i+1][j])
>        -lambda*(pw[i-1][j]+pw[i][j]-pw[i-1][j-1]-pw[i][j-1])
>        -lambda*(pw[i][j+1]+pw[i-1][j+1]-pw[i-1][j]-pw[i][j]))

>  +0.25*(mi*(pw[i][j-1]+pw[i][j]-pw[i+1][j-1]-pw[i+1][j])
>        -mi*(pw[i][j-1]+pw[i][j]-pw[i-1][j]-pw[i-1][j-1])
>        +mi*(pw[i+1][j]+pw[i+1][j+1]-pw[i][j]-pw[i][j+1])
>        +mi*(pw[i][j]+pw[i][j+1]-pw[i-1][j+1]-pw[i-1][j]));

>  ppu[i][j]=((dtr*dtr*ppu[i][j])/(ds*ds))-pmu[i][j]+2.0*pu[i][j]+ su[i][j];

>  ppw[i][j] =
>  (mi)*(pw[i+1][j]-pw[i][j])-(mi)*(pw[i][j]-pw[i-1][j])
>  +(lambda+2.0*mi)*(pw[i][j+1]-pw[i][j])+(lambda+2.0*mi)*(pw[i][j-1]-pw[i][j])

>  +0.25*(mi*(pu[i][j]+pu[i+1][j]-pu[i][j-1]-pu[i+1][j-1])
>        +mi*(pu[i+1][j+1]+pu[i][j+1]-pu[i][j]-pu[i+1][j])
>        -mi*(pu[i-1][j]+pu[i][j]-pu[i-1][j-1]-pu[i][j-1])
>        -mi*(pu[i][j+1]+pu[i-1][j+1]-pu[i-1][j]-pu[i][j]))

>  +0.25*(lambda*(pu[i][j-1]+pu[i][j]-pu[i+1][j-1]-pu[i+1][j])
>        -lambda*(pu[i][j-1]+pu[i][j]-pu[i-1][j]-pu[i-1][j-1])
>        +lambda*(pu[i+1][j]+pu[i+1][j+1]-pu[i][j]-pu[i][j+1])
>        +lambda*(pu[i][j]+pu[i][j+1]-pu[i-1][j+1]-pu[i-1][j]));

>  ppw[i][j]=((dtr*dtr*ppw[i][j])/(ds*ds))-pmw[i][j]+2.0*pw[i][j]+ sw[i][j];
>  }
> }
> //end of main loop

> Could You tell me what is wrong?

> Thanks and best regards

> Tom

> PS. All variables are floats

Without doing a deep analysis, it would appear that you are doing
quite a few difference operations. These can get flaky if you are
nearing the limits of floating point resolution. Perhaps the Windows
compiler is using intermediate doubles and hence not suffering from
the same problem.

This question might be better directed at a C programming group.

Brenton

 
 
 

Kylix3 and code from Builder

Post by tj bandrows » Fri, 31 Jan 2003 13:34:53


Quote:

> PS. All variables are floats

Lots of subtractions of close numbers can wreak havoc with floating
point numbers but some compilers / floating point libraries do better
with it than others.  Maybe consider Intel compiler?