Skip to content

Commit

Permalink
Merge pull request #308 from mlee03/cellstruct1d
Browse files Browse the repository at this point in the history
fregrid_acc - convert 2d lon/lat_vertices arrays to 1d arrays
  • Loading branch information
rem1776 authored Sep 10, 2024
2 parents e92dc37 + 9349e35 commit db1355b
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 30 deletions.
8 changes: 4 additions & 4 deletions tools/libfrencutils_acc/create_xgrid_acc.c
Original file line number Diff line number Diff line change
Expand Up @@ -230,8 +230,8 @@ int create_xgrid_2dx2d_order1_acc(const int nlon_input_cells, const int nlat_in
output_cell_lon_min += rotate;
output_cell_lon_max += rotate;
for (int l=0; l<nvertices2; l++) {
output_cell_lon_vertices[l] = output_grid_cells->lon_vertices[ij2][l] + rotate;
output_cell_lat_vertices[l] = output_grid_cells->lat_vertices[ij2][l];
output_cell_lon_vertices[l] = output_grid_cells->lon_vertices[ij2*MAX_V+l] + rotate;
output_cell_lat_vertices[l] = output_grid_cells->lat_vertices[ij2*MAX_V+l];
}

//output_cell_lon should in the same range as input_cell_lon after lon_fix,
Expand Down Expand Up @@ -391,8 +391,8 @@ int create_xgrid_2dx2d_order2_acc(const int nlon_input_cells, const int nlat_in
output_cell_area = output_grid_cells->area[ij2];

for (int l=0; l<nvertices2; l++) {
output_cell_lon_vertices[l] = output_grid_cells->lon_vertices[ij2][l] + rotate;
output_cell_lat_vertices[l] = output_grid_cells->lat_vertices[ij2][l];
output_cell_lon_vertices[l] = output_grid_cells->lon_vertices[ij2*MAX_V+l] + rotate;
output_cell_lat_vertices[l] = output_grid_cells->lat_vertices[ij2*MAX_V+l];
}

//output_cell_lon should in the same range as input_cell_lon after lon_fix,
Expand Down
32 changes: 8 additions & 24 deletions tools/libfrencutils_acc/create_xgrid_utils_acc.c
Original file line number Diff line number Diff line change
Expand Up @@ -660,20 +660,16 @@ void get_grid_cell_struct_acc( const int nlon, const int nlat, const Grid_config
grid_cells->lon_cent = (double *)malloc(ncells*sizeof(double));
grid_cells->area = (double *)malloc(ncells*sizeof(double));
grid_cells->nvertices = (int *)malloc(ncells*sizeof(int));
grid_cells->lon_vertices = (double **)malloc(ncells*sizeof(double));
grid_cells->lat_vertices = (double **)malloc(ncells*sizeof(double));
for(int icell=0 ; icell<ncells ; icell++) {
grid_cells->lat_vertices[icell] = (double *)malloc(MAX_V*sizeof(double));
grid_cells->lon_vertices[icell] = (double *)malloc(MAX_V*sizeof(double));
}
grid_cells->lon_vertices = (double *)malloc(MAX_V*ncells*sizeof(double));
grid_cells->lat_vertices = (double *)malloc(MAX_V*ncells*sizeof(double));

#pragma acc enter data create(grid_cells[:1])
#pragma acc enter data create(grid_cells->lon_min[:ncells], grid_cells->lon_max[:ncells], \
grid_cells->lat_min[:ncells], grid_cells->lat_max[:ncells], \
grid_cells->lon_cent[:ncells], grid_cells->nvertices[:ncells],\
grid_cells->area[:ncells])
#pragma acc enter data create(grid_cells->lon_vertices[:ncells][:MAX_V], \
grid_cells->lat_vertices[:ncells][:MAX_V])
#pragma acc enter data create(grid_cells->lon_vertices[:MAX_V*ncells], \
grid_cells->lat_vertices[:MAX_V*ncells])

#pragma acc data present(grid_cells[:1], lon[:npts], lat[:npts])
#pragma acc parallel loop independent
Expand All @@ -697,8 +693,8 @@ void get_grid_cell_struct_acc( const int nlon, const int nlat, const Grid_config
grid_cells->area[icell] = poly_area_acc(lon_vertices, lat_vertices, nvertices);

for(int ivertex=0 ; ivertex<nvertices ; ivertex++) {
grid_cells->lon_vertices[icell][ivertex] = lon_vertices[ivertex];
grid_cells->lat_vertices[icell][ivertex] = lat_vertices[ivertex];
grid_cells->lon_vertices[MAX_V*icell+ivertex] = lon_vertices[ivertex];
grid_cells->lat_vertices[MAX_V*icell+ivertex] = lat_vertices[ivertex];
}
}

Expand All @@ -707,14 +703,6 @@ void get_grid_cell_struct_acc( const int nlon, const int nlat, const Grid_config
void free_grid_cell_struct_acc( const int ncells, Grid_cells_struct_config *grid_cells)
{

for(int icell=0 ; icell<MAX_V ; icell++) {
#pragma acc exit data delete( grid_cells->lon_vertices[icell])
}

for(int icell=0 ; icell<MAX_V ; icell++) {
#pragma acc exit data delete( grid_cells->lat_vertices[icell])
}

#pragma acc exit data delete( grid_cells->lon_vertices, \
grid_cells->lat_vertices, \
grid_cells->lon_min, \
Expand All @@ -726,19 +714,15 @@ void free_grid_cell_struct_acc( const int ncells, Grid_cells_struct_config *grid
grid_cells->area)
#pragma acc exit data delete(grid_cells)

for(int icell=0 ; icell<MAX_V ; icell++) {
free(grid_cells->lon_vertices[icell]);
free(grid_cells->lat_vertices[icell]);
}
free(grid_cells->lon_min); grid_cells->lon_min = NULL;
free(grid_cells->lon_max); grid_cells->lon_max = NULL;
free(grid_cells->lon_cent); grid_cells->lon_cent = NULL;
free(grid_cells->lat_min); grid_cells->lat_min = NULL;
free(grid_cells->lat_max); grid_cells->lat_max = NULL;
free(grid_cells->area); grid_cells->area = NULL;
free(grid_cells->nvertices); grid_cells->nvertices=NULL;
//grid_cells->lon_vertices = NULL;
//grid_cells->lat_vertices = NULL;
free(grid_cells->lon_vertices); grid_cells->lon_vertices = NULL;
free(grid_cells->lat_vertices); grid_cells->lat_vertices = NULL;
}


Expand Down
4 changes: 2 additions & 2 deletions tools/libfrencutils_acc/globals_acc.h
Original file line number Diff line number Diff line change
Expand Up @@ -57,8 +57,8 @@ typedef struct {
double *lon_cent;
double *area;
int *nvertices;
double **lon_vertices;
double **lat_vertices;
double *lon_vertices;
double *lat_vertices;
double *recomputed_area;
double *centroid_lon;
double *centroid_lat;
Expand Down

0 comments on commit db1355b

Please sign in to comment.