Skip to content

Commit

Permalink
mixed precision mosaic2 (#1074)
Browse files Browse the repository at this point in the history
  • Loading branch information
mlee03 authored Sep 8, 2023
1 parent afdc9df commit bf76280
Show file tree
Hide file tree
Showing 20 changed files with 1,618 additions and 3,110 deletions.
3 changes: 3 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -315,6 +315,7 @@ foreach(kind ${kinds})
constants4
topography/include
axis_utils/include
mosaic2/include
constants
astronomy/include
field_manager/include
Expand Down Expand Up @@ -365,6 +366,7 @@ foreach(kind ${kinds})
$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/sat_vapor_pres/include>
$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/field_manager/include>
$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/horiz_interp/include>
$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/mosaic2/include>
$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/string_utils/include>
$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/mpp/include>
$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/string_utils/include>
Expand All @@ -376,6 +378,7 @@ foreach(kind ${kinds})
$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/tracer_manager/include>
$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/interpolator/include>
$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/coupler/include>
$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/mosaic2/include>
$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/data_override/include>)

target_include_directories(${libTgt} INTERFACE
Expand Down
7 changes: 7 additions & 0 deletions configure.ac
Original file line number Diff line number Diff line change
Expand Up @@ -296,6 +296,13 @@ else
AM_CONDITIONAL([SKIP_DEPRECATED_IO_TESTS], false)
fi

# disable mosaic unit tests if FMS is compiled in r4
if test $enable_mixed_mode = yes ; then
AM_CONDITIONAL([SKIP_MOSAIC_TESTS], true)
else
AM_CONDITIONAL([SKIP_MOSAIC_TESTS], false)
fi

# Set any required compile flags. This will not be done if the user wants to
# define all their own flags.
if test $enable_setting_flags = yes; then
Expand Down
6 changes: 3 additions & 3 deletions mosaic/Makefile.am
Original file line number Diff line number Diff line change
Expand Up @@ -51,9 +51,9 @@ grid_mod.$(FC_MODEXT): mosaic_mod.$(FC_MODEXT)

# Mod files are built and then installed as headers.
MODFILES = \
mosaic_mod.$(FC_MODEXT) \
grid_mod.$(FC_MODEXT) \
gradient_mod.$(FC_MODEXT)
mosaic_mod.$(FC_MODEXT) \
grid_mod.$(FC_MODEXT) \
gradient_mod.$(FC_MODEXT)
nodist_include_HEADERS = $(MODFILES)
BUILT_SOURCES = $(MODFILES)

Expand Down
81 changes: 12 additions & 69 deletions mosaic/read_mosaic.c
Original file line number Diff line number Diff line change
Expand Up @@ -258,11 +258,7 @@ void get_var_data(const char *file, const char *name, void *data)

switch (vartype) {
case NC_DOUBLE:case NC_FLOAT:
#ifdef OVERLOAD_R4
status = nc_get_var_float(ncid, varid, (float *)data);
#else
status = nc_get_var_double(ncid, varid, (double *)data);
#endif
break;
case NC_INT:
status = nc_get_var_int(ncid, varid, (int *)data);
Expand Down Expand Up @@ -318,11 +314,7 @@ void get_var_data_region(const char *file, const char *name, const size_t *start

switch (vartype) {
case NC_DOUBLE:case NC_FLOAT:
#ifdef OVERLOAD_R4
status = nc_get_vara_float(ncid, varid, start, nread, (float *)data);
#else
status = nc_get_vara_double(ncid, varid, start, nread, (double *)data);
#endif
break;
case NC_INT:
status = nc_get_vara_int(ncid, varid, start, nread, (int *)data);
Expand Down Expand Up @@ -400,59 +392,35 @@ int read_mosaic_xgrid_size( const char *xgrid_file )
return ncells;
}

#ifdef OVERLOAD_R4
float get_global_area(void)
{
float garea;
#else
double get_global_area(void)
{
double garea;
#endif
garea = 4*M_PI*RADIUS*RADIUS;

return garea;
}

#ifdef OVERLOAD_R4
float get_global_area_(void)
double get_global_area_(void)
{
float garea;
#else
double get_global_area_(void)
{
double garea;
#endif
garea = 4*M_PI*RADIUS*RADIUS;
double garea;
garea = 4*M_PI*RADIUS*RADIUS;

return garea;
}
return garea;
}


/****************************************************************************/
#ifdef OVERLOAD_R4
void read_mosaic_xgrid_order1_(const char *xgrid_file, int *i1, int *j1, int *i2, int *j2, float *area )
#else
void read_mosaic_xgrid_order1_(const char *xgrid_file, int *i1, int *j1, int *i2, int *j2, double *area )
#endif
void read_mosaic_xgrid_order1_(const char *xgrid_file, int *i1, int *j1, int *i2, int *j2, double *area )
{
read_mosaic_xgrid_order1(xgrid_file, i1, j1, i2, j2, area);

}

#ifdef OVERLOAD_R4
void read_mosaic_xgrid_order1(const char *xgrid_file, int *i1, int *j1, int *i2, int *j2, float *area )
#else
void read_mosaic_xgrid_order1(const char *xgrid_file, int *i1, int *j1, int *i2, int *j2, double *area )
#endif
void read_mosaic_xgrid_order1(const char *xgrid_file, int *i1, int *j1, int *i2, int *j2, double *area )
{
int ncells, n;
int *tile1_cell, *tile2_cell;
#ifdef OVERLOAD_R4
float garea;
#else
double garea;
#endif

ncells = get_dimlen(xgrid_file, "ncells");

Expand All @@ -479,30 +447,18 @@ float get_global_area(void)
} /* read_mosaic_xgrid_order1 */


#ifdef OVERLOAD_R4
void read_mosaic_xgrid_order1_region_(const char *xgrid_file, int *i1, int *j1, int *i2, int *j2, float *area, int *isc, int *iec )
#else
void read_mosaic_xgrid_order1_region_(const char *xgrid_file, int *i1, int *j1, int *i2, int *j2, double *area, int *isc, int *iec )
#endif
void read_mosaic_xgrid_order1_region_(const char *xgrid_file, int *i1, int *j1, int *i2, int *j2, double *area, int *isc, int *iec )
{
read_mosaic_xgrid_order1_region(xgrid_file, i1, j1, i2, j2, area, isc, iec);

}

#ifdef OVERLOAD_R4
void read_mosaic_xgrid_order1_region(const char *xgrid_file, int *i1, int *j1, int *i2, int *j2, float *area, int *isc, int *iec )
#else
void read_mosaic_xgrid_order1_region(const char *xgrid_file, int *i1, int *j1, int *i2, int *j2, double *area, int *isc, int *iec )
#endif
void read_mosaic_xgrid_order1_region(const char *xgrid_file, int *i1, int *j1, int *i2, int *j2, double *area, int *isc, int *iec )
{
int ncells, n, i;
int *tile1_cell, *tile2_cell;
size_t start[4], nread[4];
#ifdef OVERLOAD_R4
float garea;
#else
double garea;
#endif

ncells = *iec-*isc+1;

Expand Down Expand Up @@ -540,30 +496,17 @@ float get_global_area(void)

/* NOTE: di, dj is for tile1, */
/****************************************************************************/
#ifdef OVERLOAD_R4
void read_mosaic_xgrid_order2_(const char *xgrid_file, int *i1, int *j1, int *i2, int *j2, float *area, float *di, float *dj )
#else
void read_mosaic_xgrid_order2_(const char *xgrid_file, int *i1, int *j1, int *i2, int *j2, double *area, double *di, double *dj )
#endif
{
void read_mosaic_xgrid_order2_(const char *xgrid_file, int *i1, int *j1, int *i2, int *j2, double *area, double *di, double *dj )
{
read_mosaic_xgrid_order2(xgrid_file, i1, j1, i2, j2, area, di, dj);

}
#ifdef OVERLOAD_R4
void read_mosaic_xgrid_order2(const char *xgrid_file, int *i1, int *j1, int *i2, int *j2, float *area, float *di, float *dj )
#else
void read_mosaic_xgrid_order2(const char *xgrid_file, int *i1, int *j1, int *i2, int *j2, double *area, double *di, double *dj )
#endif

void read_mosaic_xgrid_order2(const char *xgrid_file, int *i1, int *j1, int *i2, int *j2, double *area, double *di, double *dj )
{
int ncells, n;
int *tile1_cell, *tile2_cell;
double *tile1_distance;
#ifdef OVERLOAD_R4
float garea;
#else
double garea;
#endif
ncells = get_dimlen(xgrid_file, "ncells");

tile1_cell = (int *)malloc(ncells*2*sizeof(int ));
Expand Down
27 changes: 0 additions & 27 deletions mosaic/read_mosaic.h
Original file line number Diff line number Diff line change
Expand Up @@ -44,19 +44,6 @@ void get_var_text_att(const char *file, const char *name, const char *attname, c

int read_mosaic_xgrid_size( const char *xgrid_file );

#ifdef OVERLOAD_R4

void read_mosaic_xgrid_order1(const char *xgrid_file, int *i1, int *j1, int *i2, int *j2, float *area );

void read_mosaic_xgrid_order1_region(const char *xgrid_file, int *i1, int *j1, int *i2, int *j2, float *area, int *isc, int *iec );

void read_mosaic_xgrid_order2(const char *xgrid_file, int *i1, int *j1, int *i2, int *j2,
float *area, float *di, float *dj );

float get_global_area(void);

#else

void read_mosaic_xgrid_order1(const char *xgrid_file, int *i1, int *j1, int *i2, int *j2, double *area );

void read_mosaic_xgrid_order1_region(const char *xgrid_file, int *i1, int *j1, int *i2, int *j2, double *area, int *isc, int *iec );
Expand All @@ -66,7 +53,6 @@ void read_mosaic_xgrid_order2(const char *xgrid_file, int *i1, int *j1, int *i2,

double get_global_area(void);

#endif

int read_mosaic_ntiles(const char *mosaic_file);

Expand Down Expand Up @@ -94,17 +80,6 @@ int read_mosaic_ncontacts_(const char *mosaic_file);

void read_mosaic_grid_sizes_(const char *mosaic_file, int *nx, int *ny);

#ifdef OVERLOAD_R4

float get_global_area_(void);

void read_mosaic_xgrid_order1_(const char *xgrid_file, int *i1, int *j1, int *i2, int *j2, float *area );

void read_mosaic_xgrid_order1_region_(const char *xgrid_file, int *i1, int *j1, int *i2, int *j2, float *area, int *isc, int *iec );

void read_mosaic_xgrid_order2_(const char *xgrid_file, int *i1, int *j1, int *i2, int *j2, float *area, float *di, float *dj );

#else

double get_global_area_(void);

Expand All @@ -114,6 +89,4 @@ void read_mosaic_xgrid_order1_region_(const char *xgrid_file, int *i1, int *j1,

void read_mosaic_xgrid_order2_(const char *xgrid_file, int *i1, int *j1, int *i2, int *j2, double *area, double *di, double *dj );

#endif /* OVERLOAD_R4 */

#endif
13 changes: 8 additions & 5 deletions mosaic2/Makefile.am
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
# Ed Hartnett 2/22/19

# Include .h and .mod files.
AM_CPPFLAGS = -I$(top_srcdir)/include -I$(top_srcdir)/mosaic
AM_CPPFLAGS = -I$(top_srcdir)/include -I$(top_srcdir)/mosaic -I$(top_srcdir)/mosaic2/include
AM_FCFLAGS = $(FC_MODINC). $(FC_MODOUT)$(MODDIR)

# Build these uninstalled convenience libraries.
Expand All @@ -32,14 +32,17 @@ noinst_LTLIBRARIES = libmosaic2.la

libmosaic2_la_SOURCES = \
mosaic2.F90 \
grid2.F90
grid2.F90 \
include/mosaic2_r4.fh include/mosaic2_r8.fh include/mosaic2.inc \
include/grid2_r4.fh include/grid2_r8.fh include/grid2.inc

# Some mods are dependant on other mods in this dir.
grid2_mod.$(FC_MODEXT): mosaic2_mod.$(FC_MODEXT)
grid2_mod.$(FC_MODEXT): mosaic2_mod.$(FC_MODEXT) include/grid2_r4.fh include/grid2_r8.fh include/grid2.inc
mosaic2_mod.$(FC_MODEXT): include/mosaic2_r4.fh include/mosaic2_r8.fh include/mosaic2.inc

MODFILES = \
mosaic2_mod.$(FC_MODEXT) \
grid2_mod.$(FC_MODEXT)
mosaic2_mod.$(FC_MODEXT) \
grid2_mod.$(FC_MODEXT)
nodist_include_HEADERS = $(MODFILES)
BUILT_SOURCES = $(MODFILES)

Expand Down
Loading

0 comments on commit bf76280

Please sign in to comment.