sw/benchmarks/src/ocean.c
// go to next finest grid by interpolation and addition
go to next finest grid by interpolation and addition
go to next finest grid by interpolation and addition
void interpolation(double **finer, double **q, int lastrow, int lastcol,
    int i_off, int j_off, int nk)
{
    int i, j;
    double coeff_k1 = 1.0 / ((1 << (nk + 1)) + 1);
    int imx =                (1 << (nk    )) + 1;
    for(i=1; i<=lastrow; i++) {
        double ci1 = (imx-(i+i_off)) * coeff_k1;
        double ci2 = (i+i_off) * coeff_k1;
        for(j=1; j<=lastcol; j++) {
    	    double cj1 = (imx-(j+j_off)) * coeff_k1;
    	    double cj2 = (j+j_off) * coeff_k1;
    	    double d1 = cj1*q[i  ][j-1] + (1.0-cj1)*q[i  ][j];
    	    double d2 = cj1*q[i-1][j-1] + (1.0-cj1)*q[i-1][j];
    	    double d3 = cj1*q[i+1][j-1] + (1.0-cj1)*q[i+1][j];
    	    double d4 = cj2*q[i  ][j+1] + (1.0-cj2)*q[i  ][j];
    	    double d5 = cj2*q[i-1][j+1] + (1.0-cj2)*q[i-1][j];
    	    double d6 = cj2*q[i+1][j+1] + (1.0-cj2)*q[i+1][j];
    	    finer[2*i-1][2*j-1] += ci1*d2 + (1.0-ci1)*d1;
    	    finer[2*i  ][2*j-1] += ci2*d3 + (1.0-ci2)*d1;
    	    finer[2*i-1][2*j]   += ci1*d5 + (1.0-ci1)*d4;
    	    finer[2*i  ][2*j]   += ci2*d6 + (1.0-ci2)*d4;
        }
    }
}
void interpolation ( double * * finer , double * * q , int lastrow , int lastcol , int i_off , int j_off , int nk ) { int i , j ; double coeff_k1 = 1.0 / ( ( 1 << ( nk + 1 ) ) + 1 ) ; int imx = ( 1 << ( nk ) ) + 1 ; for ( i = 1 ; i <= lastrow ; i ++ ) { double ci1 = ( imx - ( i + i_off ) ) * coeff_k1 ; double ci2 = ( i + i_off ) * coeff_k1 ; for ( j = 1 ; j <= lastcol ; j ++ ) { double cj1 = ( imx - ( j + j_off ) ) * coeff_k1 ; double cj2 = ( j + j_off ) * coeff_k1 ; double d1 = cj1 * q [ i ] [ j - 1 ] + ( 1.0 - cj1 ) * q [ i ] [ j ] ; double d2 = cj1 * q [ i - 1 ] [ j - 1 ] + ( 1.0 - cj1 ) * q [ i - 1 ] [ j ] ; double d3 = cj1 * q [ i + 1 ] [ j - 1 ] + ( 1.0 - cj1 ) * q [ i + 1 ] [ j ] ; double d4 = cj2 * q [ i ] [ j + 1 ] + ( 1.0 - cj2 ) * q [ i ] [ j ] ; double d5 = cj2 * q [ i - 1 ] [ j + 1 ] + ( 1.0 - cj2 ) * q [ i - 1 ] [ j ] ; double d6 = cj2 * q [ i + 1 ] [ j + 1 ] + ( 1.0 - cj2 ) * q [ i + 1 ] [ j ] ; finer [ 2 * i - 1 ] [ 2 * j - 1 ] += ci1 * d2 + ( 1.0 - ci1 ) * d1 ; finer [ 2 * i ] [ 2 * j - 1 ] += ci2 * d3 + ( 1.0 - ci2 ) * d1 ; finer [ 2 * i - 1 ] [ 2 * j ] += ci1 * d5 + ( 1.0 - ci1 ) * d4 ; finer [ 2 * i ] [ 2 * j ] += ci2 * d6 + ( 1.0 - ci2 ) * d4 ; } } }
go to next finest grid by interpolation and addition
go to next finest grid by interpolation and addition