examples/omp/benchmarks/kastors-1.1/jacobi/src/jacobi-block-task-dep.c
void sweep (int nx, int ny, double dx, double dy, double *f_,
        int itold, int itnew, double *u_, double *unew_, int block_size)
{
#ifdef _OPENMP
    double (*f)[nx][ny] = (double (*)[nx][ny])f_;
    double (*u)[nx][ny] = (double (*)[nx][ny])u_;
    double (*unew)[nx][ny] = (double (*)[nx][ny])unew_;
#endif

    if (block_size == 0)
        block_size = nx;

    int max_blocks_x = (nx / block_size);
    int max_blocks_y = (ny / block_size);

#pragma omp parallel
#pragma omp single
    {
        int it;
        int block_x, block_y;
        for (it = itold + 1; it <= itnew; it++) {
            /*
            for (block_x = 0; block_x < max_blocks_x; block_x++) {
                for (block_y = 0; block_y < max_blocks_y; block_y++) {
#pragma omp task shared(u_, unew_, block_size, nx, ny) firstprivate(block_x, block_y) \
                    depend(in: unew[block_x * block_size: block_size][block_y * block_size: block_size]) \
                    depend(out: u[block_x * block_size: block_size][block_y * block_size: block_size])
                    copy_block(nx, ny, block_x, block_y, u_, unew_, block_size);
                }
            }
            */
            // Compute a new estimate.
            for (block_x = 0; block_x < max_blocks_x; block_x++) {
                for (block_y = 0; block_y < max_blocks_y; block_y++) {
                    int xdm1 = block_x == 0 ? 0 : 1;
                    int xdp1 = block_x == max_blocks_x-1 ? 0 : +1;
                    int ydp1 = block_y == max_blocks_y-1 ? 0 : +1;
                    int ydm1 = block_y == 0 ? 0 : 1;
#pragma omp task shared(u_, unew_, f_, dx, dy, nx, ny, block_size) \
                 firstprivate(block_x, block_y, xdm1, xdp1, ydp1, ydm1) \
                 depend(inout: unew[ block_x         * block_size][ block_y         * block_size], \
                                  u[ block_x         * block_size][ block_y         * block_size]) \
                 depend(in   :    f[ block_x         * block_size][ block_y         * block_size], \
                                  u[(block_x - xdm1) * block_size][ block_y         * block_size], \
                                  u[ block_x         * block_size][(block_y + ydp1) * block_size], \
                                  u[ block_x         * block_size][(block_y - ydm1) * block_size], \
                                  u[(block_x + xdp1) * block_size][ block_y         * block_size])  
                    { //compute_estimate(block_x, block_y, u_, unew_, f_, dx, dy, nx, ny, block_size);
                        copy_block(nx, ny, block_x, block_y, u_, unew_, block_size);
                        int i, j;
                        int start_i = block_x * block_size;
                        int start_j = block_y * block_size;
                        for (i = start_i; i < start_i + block_size; i++) {
                            for (j = start_j; j < start_j + block_size; j++) {
                                if (i == 0 || j == 0 || i == nx - 1 || j == ny - 1) {
                                    (*unew)[i][j] = (*f)[i][j];
                                } else {
                                    (*unew)[i][j] = 0.25 * ( (*u)[i-1][j] + (*u)[i][j+1]
                                                           + (*u)[i][j-1] + (*u)[i+1][j]
                                                           + (*f)[i][j] * dx * dy       );
                                }
                            }
                        }
                    }
                }
            }
        }
    }
}
/* #pragma omp task/taskwait version of SWEEP. */
pragma omp task/taskwait version of SWEEP.
pragma omp task / taskwait version of SWEEP .
void sweep (int nx, int ny, double dx, double dy, double *f_,
        int itold, int itnew, double *u_, double *unew_, int block_size)
{
#ifdef _OPENMP
    double (*f)[nx][ny] = (double (*)[nx][ny])f_;
    double (*u)[nx][ny] = (double (*)[nx][ny])u_;
    double (*unew)[nx][ny] = (double (*)[nx][ny])unew_;
#endif
    if (block_size == 0)
        block_size = nx;
    int max_blocks_x = (nx / block_size);
    int max_blocks_y = (ny / block_size);
#pragma omp parallel
#pragma omp single
    {
        int it;
        int block_x, block_y;
        for (it = itold + 1; it <= itnew; it++) {
            for (block_x = 0; block_x < max_blocks_x; block_x++) {
                for (block_y = 0; block_y < max_blocks_y; block_y++) {
                    int xdm1 = block_x == 0 ? 0 : 1;
                    int xdp1 = block_x == max_blocks_x-1 ? 0 : +1;
                    int ydp1 = block_y == max_blocks_y-1 ? 0 : +1;
                    int ydm1 = block_y == 0 ? 0 : 1;
#pragma omp task shared(u_, unew_, f_, dx, dy, nx, ny, block_size) \
                 firstprivate(block_x, block_y, xdm1, xdp1, ydp1, ydm1) \
                 depend(inout: unew[ block_x         * block_size][ block_y         * block_size], \
                                  u[ block_x         * block_size][ block_y         * block_size]) \
                 depend(in   :    f[ block_x         * block_size][ block_y         * block_size], \
                                  u[(block_x - xdm1) * block_size][ block_y         * block_size], \
                                  u[ block_x         * block_size][(block_y + ydp1) * block_size], \
                                  u[ block_x         * block_size][(block_y - ydm1) * block_size], \
                                  u[(block_x + xdp1) * block_size][ block_y         * block_size])  
                    { 
                        copy_block(nx, ny, block_x, block_y, u_, unew_, block_size);
                        int i, j;
                        int start_i = block_x * block_size;
                        int start_j = block_y * block_size;
                        for (i = start_i; i < start_i + block_size; i++) {
                            for (j = start_j; j < start_j + block_size; j++) {
                                if (i == 0 || j == 0 || i == nx - 1 || j == ny - 1) {
                                    (*unew)[i][j] = (*f)[i][j];
                                } else {
                                    (*unew)[i][j] = 0.25 * ( (*u)[i-1][j] + (*u)[i][j+1]
                                                           + (*u)[i][j-1] + (*u)[i+1][j]
                                                           + (*f)[i][j] * dx * dy       );
                                }
                            }
                        }
                    }
                }
            }
        }
    }
}
void sweep ( int nx , int ny , double dx , double dy , double * f_ , int itold , int itnew , double * u_ , double * unew_ , int block_size ) { #ifdef _OPENMP double ( * f ) [ nx ] [ ny ] = ( double ( * ) [ nx ] [ ny ] ) f_ ; double ( * u ) [ nx ] [ ny ] = ( double ( * ) [ nx ] [ ny ] ) u_ ; double ( * unew ) [ nx ] [ ny ] = ( double ( * ) [ nx ] [ ny ] ) unew_ ; #endif if ( block_size == 0 ) block_size = nx ; int max_blocks_x = ( nx / block_size ) ; int max_blocks_y = ( ny / block_size ) ; #pragma  omp parallel #pragma  omp single { int it ; int block_x , block_y ; for ( it = itold + 1 ; it <= itnew ; it ++ ) { for ( block_x = 0 ; block_x < max_blocks_x ; block_x ++ ) { for ( block_y = 0 ; block_y < max_blocks_y ; block_y ++ ) { int xdm1 = block_x == 0 ? 0 : 1 ; int xdp1 = block_x == max_blocks_x - 1 ? 0 : +1 ; int ydp1 = block_y == max_blocks_y - 1 ? 0 : +1 ; int ydm1 = block_y == 0 ? 0 : 1 ; #pragma  omp task shared(u_, unew_, f_, dx, dy, nx, ny, block_size) \
                 firstprivate(block_x, block_y, xdm1, xdp1, ydp1, ydm1) \
                 depend(inout: unew[ block_x         * block_size][ block_y         * block_size], \
                                  u[ block_x         * block_size][ block_y         * block_size]) \
                 depend(in   :    f[ block_x         * block_size][ block_y         * block_size], \
                                  u[(block_x - xdm1) * block_size][ block_y         * block_size], \
                                  u[ block_x         * block_size][(block_y + ydp1) * block_size], \
                                  u[ block_x         * block_size][(block_y - ydm1) * block_size], \
                                  u[(block_x + xdp1) * block_size][ block_y         * block_size])   { copy_block ( nx , ny , block_x , block_y , u_ , unew_ , block_size ) ; int i , j ; int start_i = block_x * block_size ; int start_j = block_y * block_size ; for ( i = start_i ; i < start_i + block_size ; i ++ ) { for ( j = start_j ; j < start_j + block_size ; j ++ ) { if ( i == 0 || j == 0 || i == nx - 1 || j == ny - 1 ) { ( * unew ) [ i ] [ j ] = ( * f ) [ i ] [ j ] ; } else { ( * unew ) [ i ] [ j ] = 0.25 * ( ( * u ) [ i - 1 ] [ j ] + ( * u ) [ i ] [ j + 1 ] + ( * u ) [ i ] [ j - 1 ] + ( * u ) [ i + 1 ] [ j ] + ( * f ) [ i ] [ j ] * dx * dy ) ; } } } } } } } } }
pragma omp task/taskwait version of SWEEP.
pragma omp task / taskwait version of SWEEP .
/*
            for (block_x = 0; block_x < max_blocks_x; block_x++) {
                for (block_y = 0; block_y < max_blocks_y; block_y++) {
#pragma omp task shared(u_, unew_, block_size, nx, ny) firstprivate(block_x, block_y) \
                    depend(in: unew[block_x * block_size: block_size][block_y * block_size: block_size]) \
                    depend(out: u[block_x * block_size: block_size][block_y * block_size: block_size])
                    copy_block(nx, ny, block_x, block_y, u_, unew_, block_size);
                }
            }
            */ // Compute a new estimate. //compute_estimate(block_x, block_y, u_, unew_, f_, dx, dy, nx, ny, block_size);