parallel-io/heat-restart/c/io.c
void write_field(field *temperature, int iter, parallel_data *parallel)
{
    char filename[64];

    /* The actual write routine takes only the actual data
     * (without ghost layers) so we need array for that. */
    int height, width;
    double **full_data;
    double **tmp_data;          // array for MPI sends and receives

    int i, p;

    height = temperature->nx * parallel->size;
    width = temperature->ny;

    tmp_data = malloc_2d(temperature->nx, temperature->ny);

    if (parallel->rank == 0) {
        /* Copy the inner data */
        full_data = malloc_2d(height, width);
        for (i = 0; i < temperature->nx; i++)
            memcpy(full_data[i], &temperature->data[i + 1][1],
                   temperature->ny * sizeof(double));
        /* Receive data from other ranks */
        for (p = 1; p < parallel->size; p++) {
            MPI_Recv(&tmp_data[0][0], temperature->nx * temperature->ny,
                     MPI_DOUBLE, p, 22, MPI_COMM_WORLD, MPI_STATUS_IGNORE);
            /* Copy data to full array */
            memcpy(&full_data[p * temperature->nx][0], tmp_data[0],
                   temperature->nx * temperature->ny * sizeof(double));
        }
        /* Write out the data to a png file */
        sprintf(filename, "%s_%04d.png", "heat", iter);
        save_png(full_data[0], height, width, filename, 'c');
        free_2d(full_data);
    } else {
        /* Send data */
        for (i = 0; i < temperature->nx; i++)
            memcpy(tmp_data[i], &temperature->data[i + 1][1],
                   temperature->ny * sizeof(double));
        MPI_Send(&tmp_data[0][0], temperature->nx * temperature->ny,
                 MPI_DOUBLE, 0, 22, MPI_COMM_WORLD);
    }

    free_2d(tmp_data);

}
/* Output routine that prints out a picture of the temperature
 * distribution. */
Output routine that prints out a picture of the temperature
distribution.
Output routine that prints out a picture of the temperature distribution .
void write_field(field *temperature, int iter, parallel_data *parallel)
{
    char filename[64];
    int height, width;
    double **full_data;
    double **tmp_data;          
    int i, p;
    height = temperature->nx * parallel->size;
    width = temperature->ny;
    tmp_data = malloc_2d(temperature->nx, temperature->ny);
    if (parallel->rank == 0) {
        full_data = malloc_2d(height, width);
        for (i = 0; i < temperature->nx; i++)
            memcpy(full_data[i], &temperature->data[i + 1][1],
                   temperature->ny * sizeof(double));
        for (p = 1; p < parallel->size; p++) {
            MPI_Recv(&tmp_data[0][0], temperature->nx * temperature->ny,
                     MPI_DOUBLE, p, 22, MPI_COMM_WORLD, MPI_STATUS_IGNORE);
            memcpy(&full_data[p * temperature->nx][0], tmp_data[0],
                   temperature->nx * temperature->ny * sizeof(double));
        }
        sprintf(filename, "%s_%04d.png", "heat", iter);
        save_png(full_data[0], height, width, filename, 'c');
        free_2d(full_data);
    } else {
        for (i = 0; i < temperature->nx; i++)
            memcpy(tmp_data[i], &temperature->data[i + 1][1],
                   temperature->ny * sizeof(double));
        MPI_Send(&tmp_data[0][0], temperature->nx * temperature->ny,
                 MPI_DOUBLE, 0, 22, MPI_COMM_WORLD);
    }
    free_2d(tmp_data);
}
void write_field ( field * temperature , int iter , parallel_data * parallel ) { char filename [ 64 ] ; int height , width ; double * * full_data ; double * * tmp_data ; int i , p ; height = temperature -> nx * parallel -> size ; width = temperature -> ny ; tmp_data = malloc_2d ( temperature -> nx , temperature -> ny ) ; if ( parallel -> rank == 0 ) { full_data = malloc_2d ( height , width ) ; for ( i = 0 ; i < temperature -> nx ; i ++ ) memcpy ( full_data [ i ] , & temperature -> data [ i + 1 ] [ 1 ] , temperature -> ny * sizeof ( double ) ) ; for ( p = 1 ; p < parallel -> size ; p ++ ) { MPI_Recv ( & tmp_data [ 0 ] [ 0 ] , temperature -> nx * temperature -> ny , MPI_DOUBLE , p , 22 , MPI_COMM_WORLD , MPI_STATUS_IGNORE ) ; memcpy ( & full_data [ p * temperature -> nx ] [ 0 ] , tmp_data [ 0 ] , temperature -> nx * temperature -> ny * sizeof ( double ) ) ; } sprintf ( filename , " " , " " , iter ) ; save_png ( full_data [ 0 ] , height , width , filename , ' ' ) ; free_2d ( full_data ) ; } else { for ( i = 0 ; i < temperature -> nx ; i ++ ) memcpy ( tmp_data [ i ] , & temperature -> data [ i + 1 ] [ 1 ] , temperature -> ny * sizeof ( double ) ) ; MPI_Send ( & tmp_data [ 0 ] [ 0 ] , temperature -> nx * temperature -> ny , MPI_DOUBLE , 0 , 22 , MPI_COMM_WORLD ) ; } free_2d ( tmp_data ) ; }
Output routine that prints out a picture of the temperature
 distribution.
Output routine that prints out a picture of the temperature distribution .
/* The actual write routine takes only the actual data
     * (without ghost layers) so we need array for that. */ // array for MPI sends and receives /* Copy the inner data */ /* Receive data from other ranks */ /* Copy data to full array */ /* Write out the data to a png file */ /* Send data */