Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fregrid_acc - convert 2d lon/lat_vertices arrays to 1d arrays #308

Merged
merged 1 commit into from
Sep 10, 2024
Merged
Show file tree
Hide file tree
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
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