openmp/heat/c/solution/setup.c
void generate_field(field *temperature)
{
    int i, j;
    double radius;
    int dx, dy;

    /* Allocate the temperature array, note that
     * we have to allocate also the ghost layers */
#pragma omp single
    {
    temperature->data =
        malloc_2d(temperature->nx + 2, temperature->ny + 2);
    }

    /* Radius of the source disc */
    radius = temperature->nx / 6.0;
#pragma omp for private(i, j, dx, dy)
    for (i = 0; i < temperature->nx + 2; i++) {
        for (j = 0; j < temperature->ny + 2; j++) {
            /* Distances of point i, j from the origin */
            dx = i - temperature->nx / 2 + 1;
            dy = j - temperature->ny / 2 + 1;
            if (dx * dx + dy * dy < radius * radius) {
                temperature->data[i][j] = 5.0;
            } else {
                temperature->data[i][j] = 65.0;
            }
        }
    }

    /* Boundary conditions */
#pragma omp for private(i)
    for (i = 0; i < temperature->nx + 2; i++) {
        temperature->data[i][0] = 20.0;
        temperature->data[i][temperature->ny + 1] = 70.0;
    }

#pragma omp for private(j)
    for (j = 0; j < temperature->ny + 2; j++) {
        temperature->data[0][j] = 85.0;
        temperature->data[temperature->nx + 1][j] = 5.0;
    }

}
/* Generate initial temperature field.  Pattern is disc with a radius
 * of nx_full / 6 in the center of the grid.
 * Boundary conditions are (different) constant temperatures outside the grid */
Generate initial temperature field.  Pattern is disc with a radius
of nx_full / 6 in the center of the grid.
Boundary conditions are (different) constant temperatures outside the grid
Generate initial temperature field . Pattern is disc with a radius of nx_full / 6 in the center of the grid . Boundary conditions are ( different ) constant temperatures outside the grid
void generate_field(field *temperature)
{
    int i, j;
    double radius;
    int dx, dy;
#pragma omp single
    {
    temperature->data =
        malloc_2d(temperature->nx + 2, temperature->ny + 2);
    }
    radius = temperature->nx / 6.0;
#pragma omp for private(i, j, dx, dy)
    for (i = 0; i < temperature->nx + 2; i++) {
        for (j = 0; j < temperature->ny + 2; j++) {
            dx = i - temperature->nx / 2 + 1;
            dy = j - temperature->ny / 2 + 1;
            if (dx * dx + dy * dy < radius * radius) {
                temperature->data[i][j] = 5.0;
            } else {
                temperature->data[i][j] = 65.0;
            }
        }
    }
#pragma omp for private(i)
    for (i = 0; i < temperature->nx + 2; i++) {
        temperature->data[i][0] = 20.0;
        temperature->data[i][temperature->ny + 1] = 70.0;
    }
#pragma omp for private(j)
    for (j = 0; j < temperature->ny + 2; j++) {
        temperature->data[0][j] = 85.0;
        temperature->data[temperature->nx + 1][j] = 5.0;
    }
}
void generate_field ( field * temperature ) { int i , j ; double radius ; int dx , dy ; #pragma  omp single { temperature -> data = malloc_2d ( temperature -> nx + 2 , temperature -> ny + 2 ) ; } radius = temperature -> nx / 6.0 ; #pragma  omp for private(i, j, dx, dy) for ( i = 0 ; i < temperature -> nx + 2 ; i ++ ) { for ( j = 0 ; j < temperature -> ny + 2 ; j ++ ) { dx = i - temperature -> nx / 2 + 1 ; dy = j - temperature -> ny / 2 + 1 ; if ( dx * dx + dy * dy < radius * radius ) { temperature -> data [ i ] [ j ] = 5.0 ; } else { temperature -> data [ i ] [ j ] = 65.0 ; } } } #pragma  omp for private(i) for ( i = 0 ; i < temperature -> nx + 2 ; i ++ ) { temperature -> data [ i ] [ 0 ] = 20.0 ; temperature -> data [ i ] [ temperature -> ny + 1 ] = 70.0 ; } #pragma  omp for private(j) for ( j = 0 ; j < temperature -> ny + 2 ; j ++ ) { temperature -> data [ 0 ] [ j ] = 85.0 ; temperature -> data [ temperature -> nx + 1 ] [ j ] = 5.0 ; } }
Generate initial temperature field.
Generate initial temperature field .
/* Allocate the temperature array, note that
     * we have to allocate also the ghost layers */ /* Radius of the source disc */ /* Distances of point i, j from the origin */ /* Boundary conditions */