Skip to content

Commit

Permalink
change minmaxavlists to minmaxavg_lists
Browse files Browse the repository at this point in the history
  • Loading branch information
mlee03 authored and mlee03 committed Oct 18, 2023
1 parent ccede60 commit b3b01a5
Show file tree
Hide file tree
Showing 6 changed files with 63 additions and 63 deletions.
30 changes: 15 additions & 15 deletions tools/fregrid/conserve_interp.c
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ void setup_conserve_interp(int ntiles_in, const Grid_config *grid_in, int ntiles
//START NTILES_OUT
for(n=0; n<ntiles_out; n++) {

Minmaxavglists out_minmaxavglists;
Minmaxavg_lists out_minmaxavg_lists;

nx_out = grid_out[n].nxc;
ny_out = grid_out[n].nyc;
Expand All @@ -95,22 +95,22 @@ void setup_conserve_interp(int ntiles_in, const Grid_config *grid_in, int ntiles


//allocate memory for the lists
malloc_minmaxavg_lists(nx_out*ny_out, &out_minmaxavglists);
malloc_minmaxavg_lists(nx_out*ny_out, &out_minmaxavg_lists);

#define MAX_V 8
#pragma acc enter data create(out_minmaxavglists)
#pragma acc enter data create(out_minmaxavglists.lon_list[0:MAX_V*nx_out*ny_out], \
out_minmaxavglists.lat_list[0:MAX_V*nx_out*ny_out], \
out_minmaxavglists.lon_min_list[0:nx_out*ny_out], \
out_minmaxavglists.lon_max_list[0:nx_out*ny_out], \
out_minmaxavglists.lat_min_list[0:nx_out*ny_out], \
out_minmaxavglists.lat_max_list[0:nx_out*ny_out], \
out_minmaxavglists.n_list[0:nx_out*ny_out], \
out_minmaxavglists.lon_avg[0:nx_out*ny_out] )
#pragma acc enter data create(out_minmaxavg_lists)
#pragma acc enter data create(out_minmaxavg_lists.lon_list[0:MAX_V*nx_out*ny_out], \
out_minmaxavg_lists.lat_list[0:MAX_V*nx_out*ny_out], \
out_minmaxavg_lists.lon_min_list[0:nx_out*ny_out], \
out_minmaxavg_lists.lon_max_list[0:nx_out*ny_out], \
out_minmaxavg_lists.lat_min_list[0:nx_out*ny_out], \
out_minmaxavg_lists.lat_max_list[0:nx_out*ny_out], \
out_minmaxavg_lists.n_list[0:nx_out*ny_out], \
out_minmaxavg_lists.lon_avg[0:nx_out*ny_out] )


//compute the list values
get_minmaxavg_lists(nx_out, ny_out, grid_out[n].lonc, grid_out[n].latc, &out_minmaxavglists);
get_minmaxavg_lists(nx_out, ny_out, grid_out[n].lonc, grid_out[n].latc, &out_minmaxavg_lists);

//START NTILES_IN
for(m=0; m<ntiles_in; m++) {
Expand Down Expand Up @@ -178,7 +178,7 @@ void setup_conserve_interp(int ntiles_in, const Grid_config *grid_in, int ntiles
#ifdef _OPENACC
nxgrid = create_xgrid_2dx2d_order2_acc(&nx_in, &ny_now, &nx_out, &ny_out, grid_in[m].lonc+jstart*(nx_in+1),
grid_in[m].latc+jstart*(nx_in+1), grid_out[n].lonc, grid_out[n].latc,
&out_minmaxavglists, mask, i_in, j_in, i_out, j_out,
&out_minmaxavg_lists, mask, i_in, j_in, i_out, j_out,
xgrid_area, xgrid_clon, xgrid_clat);
#else
nxgrid = create_xgrid_2dx2d_order2(&nx_in, &ny_now, &nx_out, &ny_out, grid_in[m].lonc+jstart*(nx_in+1),
Expand Down Expand Up @@ -280,8 +280,8 @@ void setup_conserve_interp(int ntiles_in, const Grid_config *grid_in, int ntiles
malloc_xgrid_arrays(zero, &i_in, &j_in, &i_out, &j_out, &xgrid_area, &xgrid_clon , &xgrid_clat);
#pragma acc exit data delete(grid_in[m].latc, grid_in[m].lonc)
} // ntiles_in
malloc_minmaxavg_lists(zero, &out_minmaxavglists);
#pragma acc exit data delete(out_minmaxavglists)
malloc_minmaxavg_lists(zero, &out_minmaxavg_lists);
#pragma acc exit data delete(out_minmaxavg_lists)
#pragma acc exit data delete(grid_out[n].latc, grid_out[n].lonc)
} // ntimes_out

Expand Down
2 changes: 1 addition & 1 deletion tools/fregrid/globals.h
Original file line number Diff line number Diff line change
Expand Up @@ -245,6 +245,6 @@ typedef struct{
double *lon_list;
double *lat_list;
int *n_list;
} Minmaxavglists;
} Minmaxavg_lists;

#endif
25 changes: 13 additions & 12 deletions tools/libfrencutils/create_xgrid_acc.c
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,8 @@
*******************************************************************************/
int create_xgrid_2dx2d_order2_acc(const int *nlon_in, const int *nlat_in, const int *nlon_out, const int *nlat_out,
const double *lon_in, const double *lat_in, const double *lon_out, const double *lat_out,
Minmaxavglists *out_minmaxavglists, const double *mask_in, int *i_in, int *j_in, int *i_out, int *j_out,
Minmaxavg_lists *out_minmaxavg_lists, const double *mask_in,
int *i_in, int *j_in, int *i_out, int *j_out,
double *xgrid_area, double *xgrid_clon, double *xgrid_clat)
{

Expand Down Expand Up @@ -66,10 +67,10 @@ int create_xgrid_2dx2d_order2_acc(const int *nlon_in, const int *nlat_in, const

#pragma acc data present(lon_out[0:(nx2+1)*(ny2+1)], lat_out[0:(nx2+1)*(ny2+1)])
#pragma acc data present(lon_in[0:(nx1+1)*(ny1+1)], lat_in[0:(nx1+1)*(ny1+1)], mask_in[0:nx1*ny1])
#pragma acc data present(out_minmaxavglists->lon_list[0:MAX_V*nx2*ny2], out_minmaxavglists->lat_list[0:MAX_V*nx2*ny2])
#pragma acc data present(out_minmaxavglists->n_list[0:nx2*ny2], out_minmaxavglists->lon_avg[0:nx2*ny2])
#pragma acc data present(out_minmaxavglists->lat_min_list[0:nx2*ny2], out_minmaxavglists->lat_max_list[0:nx2*ny2])
#pragma acc data present(out_minmaxavglists->lon_min_list[0:nx2*ny2], out_minmaxavglists->lon_max_list[0:nx2*ny2])
#pragma acc data present(out_minmaxavg_lists->lon_list[0:MAX_V*nx2*ny2], out_minmaxavg_lists->lat_list[0:MAX_V*nx2*ny2])
#pragma acc data present(out_minmaxavg_lists->n_list[0:nx2*ny2], out_minmaxavg_lists->lon_avg[0:nx2*ny2])
#pragma acc data present(out_minmaxavg_lists->lat_min_list[0:nx2*ny2], out_minmaxavg_lists->lat_max_list[0:nx2*ny2])
#pragma acc data present(out_minmaxavg_lists->lon_min_list[0:nx2*ny2], out_minmaxavg_lists->lon_max_list[0:nx2*ny2])
#pragma acc data present(xgrid_area[0:mxxgrid], xgrid_clon[0:mxxgrid], xgrid_clat[0:mxxgrid], \
i_in[0:mxxgrid], j_in[0:mxxgrid], i_out[0:mxxgrid],j_out[0:mxxgrid])
#pragma acc data copyin(area_in[0:nx1*ny1], area_out[0:nx2*ny2])
Expand Down Expand Up @@ -102,17 +103,17 @@ int create_xgrid_2dx2d_order2_acc(const int *nlon_in, const int *nlat_in, const
i2 = ij%nx2;
j2 = ij/nx2;

if(out_minmaxavglists->lat_min_list[ij] >= lat_in_max || out_minmaxavglists->lat_max_list[ij] <= lat_in_min ) continue;
if(out_minmaxavg_lists->lat_min_list[ij] >= lat_in_max || out_minmaxavg_lists->lat_max_list[ij] <= lat_in_min ) continue;
/* adjust x2_in according to lon_in_avg*/
n2_in = out_minmaxavglists->n_list[ij];
n2_in = out_minmaxavg_lists->n_list[ij];
#pragma acc loop seq
for(l=0; l<n2_in; l++) {
x2_in[l] = out_minmaxavglists->lon_list[ij*MAX_V+l];
y2_in[l] = out_minmaxavglists->lat_list[ij*MAX_V+l];
x2_in[l] = out_minmaxavg_lists->lon_list[ij*MAX_V+l];
y2_in[l] = out_minmaxavg_lists->lat_list[ij*MAX_V+l];
}
lon_out_min = out_minmaxavglists->lon_min_list[ij];
lon_out_max = out_minmaxavglists->lon_max_list[ij];
dx = out_minmaxavglists->lon_avg[ij] - lon_in_avg;
lon_out_min = out_minmaxavg_lists->lon_min_list[ij];
lon_out_max = out_minmaxavg_lists->lon_max_list[ij];
dx = out_minmaxavg_lists->lon_avg[ij] - lon_in_avg;
if(dx < -M_PI ) {
lon_out_min += TPI;
lon_out_max += TPI;
Expand Down
3 changes: 2 additions & 1 deletion tools/libfrencutils/create_xgrid_acc.h
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@

int create_xgrid_2dx2d_order2_acc(const int *nlon_in, const int *nlat_in, const int *nlon_out, const int *nlat_out,
const double *lon_in, const double *lat_in, const double *lon_out, const double *lat_out,
Minmaxavglists *out_minmaxavglists, const double *mask_in, int *i_in, int *j_in, int *i_out, int *j_out,
Minmaxavg_lists *out_minmaxavg_lists, const double *mask_in,
int *i_in, int *j_in, int *i_out, int *j_out,
double *xgrid_area, double *xgrid_clon, double *xgrid_clat);
#endif
62 changes: 30 additions & 32 deletions tools/libfrencutils/create_xgrid_util.c
Original file line number Diff line number Diff line change
Expand Up @@ -44,39 +44,37 @@ int line_intersect_2D_3D(double *a1, double *a2, double *q1, double *q2, double
void malloc_minmaxavg_lists
allocates lists to hold min, max, avg values of lat/lon coordinates
*******************************************************************************/
void malloc_minmaxavg_lists(const int n, Minmaxavglists *minmaxavglists)
void malloc_minmaxavg_lists(const int n, Minmaxavg_lists *minmaxavg_lists)
{

if( !minmaxavglists->lon_min_list ) free(minmaxavglists->lon_min_list);
if( !minmaxavglists->lon_max_list ) free(minmaxavglists->lon_max_list);
if( !minmaxavglists->lat_min_list ) free(minmaxavglists->lat_min_list);
if( !minmaxavglists->lat_max_list ) free(minmaxavglists->lat_max_list);
if( !minmaxavglists->n_list) free(minmaxavglists->n_list);
if( !minmaxavglists->lon_avg) free(minmaxavglists->lon_avg);
if( !minmaxavglists->lon_list) free(minmaxavglists->lon_list);
if( !minmaxavglists->lat_list) free(minmaxavglists->lat_list);
if( !minmaxavg_lists->lon_min_list ) free(minmaxavg_lists->lon_min_list);
if( !minmaxavg_lists->lon_max_list ) free(minmaxavg_lists->lon_max_list);
if( !minmaxavg_lists->lat_min_list ) free(minmaxavg_lists->lat_min_list);
if( !minmaxavg_lists->lat_max_list ) free(minmaxavg_lists->lat_max_list);
if( !minmaxavg_lists->n_list) free(minmaxavg_lists->n_list);
if( !minmaxavg_lists->lon_avg) free(minmaxavg_lists->lon_avg);
if( !minmaxavg_lists->lon_list) free(minmaxavg_lists->lon_list);
if( !minmaxavg_lists->lat_list) free(minmaxavg_lists->lat_list);

if(n>0){
minmaxavglists->lon_min_list=(double *)malloc(n*sizeof(double));
minmaxavglists->lon_max_list=(double *)malloc(n*sizeof(double));
minmaxavglists->lat_min_list=(double *)malloc(n*sizeof(double));
minmaxavglists->lat_max_list=(double *)malloc(n*sizeof(double));
minmaxavglists->n_list=(int *)malloc(n*sizeof(int));
minmaxavglists->lon_avg=(double *)malloc(n*sizeof(double));
minmaxavglists->lon_list=(double *)malloc(MAX_V*n*sizeof(double));
minmaxavglists->lat_list=(double *)malloc(MAX_V*n*sizeof(double));
minmaxavg_lists->lon_min_list=(double *)malloc(n*sizeof(double));
minmaxavg_lists->lon_max_list=(double *)malloc(n*sizeof(double));
minmaxavg_lists->lat_min_list=(double *)malloc(n*sizeof(double));
minmaxavg_lists->lat_max_list=(double *)malloc(n*sizeof(double));
minmaxavg_lists->n_list=(int *)malloc(n*sizeof(int));
minmaxavg_lists->lon_avg=(double *)malloc(n*sizeof(double));
minmaxavg_lists->lon_list=(double *)malloc(MAX_V*n*sizeof(double));
minmaxavg_lists->lat_list=(double *)malloc(MAX_V*n*sizeof(double));
}

return *minmaxavglists;

}//malloc_minmaxavg_lists

/*******************************************************************************
void get_minmaxavg_lists
computes lists to hold min, max, avg values of lat/lon coordinates
*******************************************************************************/
void get_minmaxavg_lists(const int nx, const int ny, const double *lon, const double *lat,
Minmaxavglists *minmaxavglists)
Minmaxavg_lists *minmaxavg_lists)
{

int nxp, nyp;
Expand All @@ -85,10 +83,10 @@ void get_minmaxavg_lists(const int nx, const int ny, const double *lon, const do
nyp = ny+1;

#pragma acc data present(lon[0:nxp*nyp], lat[0:nxp*nyp])
#pragma acc data present(minmaxavglists->lon_list[0:MAX_V*nx*ny], minmaxavglists->lat_list[0:MAX_V*nx*ny])
#pragma acc data present(minmaxavglists->n_list[0:nx*ny], minmaxavglists->lon_avg[0:nx*ny])
#pragma acc data present(minmaxavglists->lat_min_list[0:nx*ny], minmaxavglists->lat_max_list[0:nx*ny])
#pragma acc data present(minmaxavglists->lon_min_list[0:nx*ny], minmaxavglists->lon_max_list[0:nx*ny])
#pragma acc data present(minmaxavg_lists->lon_list[0:MAX_V*nx*ny], minmaxavg_lists->lat_list[0:MAX_V*nx*ny])
#pragma acc data present(minmaxavg_lists->n_list[0:nx*ny], minmaxavg_lists->lon_avg[0:nx*ny])
#pragma acc data present(minmaxavg_lists->lat_min_list[0:nx*ny], minmaxavg_lists->lat_max_list[0:nx*ny])
#pragma acc data present(minmaxavg_lists->lon_min_list[0:nx*ny], minmaxavg_lists->lon_max_list[0:nx*ny])

#pragma acc parallel loop independent
for(int ij=0; ij<nx*ny; ij++){
Expand All @@ -106,19 +104,19 @@ void get_minmaxavg_lists(const int nx, const int ny, const double *lon, const do
x_in[2] = lon[n2]; y_in[2] = lat[n2];
x_in[3] = lon[n3]; y_in[3] = lat[n3];

minmaxavglists->lat_min_list[n] = minval_double(4, y_in);
minmaxavglists->lat_max_list[n] = maxval_double(4, y_in);
minmaxavg_lists->lat_min_list[n] = minval_double(4, y_in);
minmaxavg_lists->lat_max_list[n] = maxval_double(4, y_in);
n_in = fix_lon(x_in, y_in, 4, M_PI);
//Commented out for now. OpenACC does not like error_handler
//if(n2_in > MAX_V) error_handler("create_xgrid.c: n_in is greater than MAX_V");
minmaxavglists->lon_min_list[n] = minval_double(n_in, x_in);
minmaxavglists->lon_max_list[n] = maxval_double(n_in, x_in);
minmaxavglists->lon_avg[n] = avgval_double(n_in, x_in);
minmaxavglists->n_list[n] = n_in;
minmaxavg_lists->lon_min_list[n] = minval_double(n_in, x_in);
minmaxavg_lists->lon_max_list[n] = maxval_double(n_in, x_in);
minmaxavg_lists->lon_avg[n] = avgval_double(n_in, x_in);
minmaxavg_lists->n_list[n] = n_in;
#pragma acc loop independent
for(l=0; l<n_in; l++) {
minmaxavglists->lon_list[n*MAX_V+l] = x_in[l];
minmaxavglists->lat_list[n*MAX_V+l] = y_in[l];
minmaxavg_lists->lon_list[n*MAX_V+l] = x_in[l];
minmaxavg_lists->lat_list[n*MAX_V+l] = y_in[l];
}
}

Expand Down
4 changes: 2 additions & 2 deletions tools/libfrencutils/create_xgrid_util.h
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,8 @@
#define MV 50
/* this value is small compare to earth area */

void malloc_minmaxavg_lists(const int n, Minmaxavglists *minmaxavglists);
void get_minmaxavg_lists(const int nx, const int ny, const double *lon, const double *lat, Minmaxavglists *minmaxavglists);
void malloc_minmaxavg_lists(const int n, Minmaxavg_lists *minmaxavg_lists);
void get_minmaxavg_lists(const int nx, const int ny, const double *lon, const double *lat, Minmaxavg_lists *minmaxavg_lists);
#pragma acc routine seq
double poly_ctrlon(const double lon[], const double lat[], int n, double clon);
#pragma acc routine seq
Expand Down

0 comments on commit b3b01a5

Please sign in to comment.