Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 19 additions & 3 deletions lib/raster/vrt.c
Original file line number Diff line number Diff line change
Expand Up @@ -170,23 +170,39 @@ void Rast_close_vrt(struct R_vrt *vrt)
* move to get_row.c as read_data_vrt() ? */
int Rast_get_vrt_row(int fd, void *buf, int row, RASTER_MAP_TYPE data_type)
{
struct fileinfo *fcb = &R__.fileinfo[fd];
struct R_vrt *vrt = fcb->vrt;
struct tileinfo *ti = vrt->tileinfo;
struct R_vrt *vrt;
struct tileinfo *ti;
struct Cell_head *rd_window = &R__.rd_window;
double rown, rows;
int i, j;
int have_tile;
void *tmpbuf;
size_t size = Rast_cell_size(data_type);

// R__.fileinfo can be reallocated by concurrent open/close calls,
// so we extract the vrt pointer under the same lock that protects the I/O
// below. This expects callers to open the raster once per thread before
// entering any parallel code.
#pragma omp critical(raster_vrt_read)
{
vrt = R__.fileinfo[fd].vrt;
}
ti = vrt->tileinfo;

rown = rd_window->north - rd_window->ns_res * row;
rows = rd_window->north - rd_window->ns_res * (row + 1);

Rast_set_null_value(buf, rd_window->cols, data_type);
tmpbuf = Rast_allocate_input_buf(data_type);
have_tile = 0;

/* parallelised reading of the real raster maps
* constituting a GRASS virtual raster
* causes IO read errors and segmentation faults:
* enforce reading of the different rasters in only one thread
* Serialize the entire open/read/close cycle for each tile
* because they all access the non-thread-safe global R__.fileinfo array. */
#pragma omp critical(raster_vrt_read)
for (i = 0; i < vrt->tlist->n_values; i++) {
struct tileinfo *p = &ti[vrt->tlist->value[i]];

Expand Down
Loading