Skip to content

Commit

Permalink
Merge pull request #17 from kgerheiser/feature/cmake-tests
Browse files Browse the repository at this point in the history
Build tests with CMake
  • Loading branch information
kgerheiser authored Oct 19, 2020
2 parents 0510d58 + c1fcfb8 commit 72b9f57
Show file tree
Hide file tree
Showing 96 changed files with 932 additions and 6,424 deletions.
25 changes: 1 addition & 24 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,29 +10,6 @@ jobs:

steps:

- name: checkout-pfunit
uses: actions/checkout@v2
with:
repository: Goddard-Fortran-Ecosystem/pFUnit
path: pfunit

- name: cache-pfunit
id: cache-pfunit
uses: actions/cache@v2
with:
path: ~/pfunit
key: pfunit-${{ runner.os }}-${{ hashFiles('pfunit/VERSION') }}

- name: build-pfunit
if: steps.cache-pfunit.outputs.cache-hit != 'true'
run: |
cd pfunit
mkdir build
cd build
cmake .. -DSKIP_MPI=YES -DSKIP_ESMF=YES -DSKIP_FHAMCREST=YES -DCMAKE_INSTALL_PREFIX=~/pfunit
make -j2
make install
- name: checkout-sp
uses: actions/checkout@v2
with:
Expand Down Expand Up @@ -60,7 +37,7 @@ jobs:
cd ip2
mkdir build
cd build
cmake .. -DENABLE_TESTS=ON -DOPENMP=ON -DCMAKE_PREFIX_PATH="~/pfunit;~/"
cmake .. -DOPENMP=ON -DCMAKE_PREFIX_PATH="~/"
make -j2
- name: test
Expand Down
9 changes: 4 additions & 5 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ file(STRINGS "VERSION" pVersion)
project(
ip2
VERSION ${pVersion}
LANGUAGES Fortran)
LANGUAGES C Fortran)

option(OPENMP "use OpenMP threading" OFF)
option(ENABLE_TESTS "Build pfunit tests?" OFF)
Expand All @@ -28,8 +28,7 @@ find_package(sp REQUIRED)

add_subdirectory(src)

if (ENABLE_TESTS)
find_package(PFUNIT REQUIRED)
enable_testing()
add_subdirectory(tests)
include(CTest)
if(BUILD_TESTING)
add_subdirectory(tests)
endif()
1 change: 1 addition & 0 deletions src/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ set(kinds "4" "8" "d")
foreach(kind ${kinds})
set(lib_name ${PROJECT_NAME}_${kind})
set(module_dir "${CMAKE_CURRENT_BINARY_DIR}/include_${kind}")
configure_file(ip2lib_${kind}.h ${CMAKE_CURRENT_BINARY_DIR}/include_${kind}/ip2lib.h COPYONLY)

# Compiled with preprocessor definition LSIZE=D, not d
string(TOUPPER ${kind} kind_definition)
Expand Down
49 changes: 40 additions & 9 deletions tests/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,12 +1,43 @@
#list(APPEND CMAKE_CTEST_ARGUMENTS "--output-on-failure")

execute_process(COMMAND cmake -E create_symlink
"${CMAKE_SOURCE_DIR}/tests/data"
"${CMAKE_CURRENT_BINARY_DIR}/data" # New name
)


add_pfunit_ctest (ip2_test
TEST_SOURCES test_mod.pf
LINK_LIBRARIES ip2::ip2_d sp::sp_d
)
"${CMAKE_CURRENT_SOURCE_DIR}/data"
"${CMAKE_CURRENT_BINARY_DIR}/data" # New name
)

if(CMAKE_Fortran_COMPILER_ID MATCHES "^(Intel)$")
set(CMAKE_Fortran_FLAGS "-r8 -g -traceback -assume byterecl")
set(CMAKE_C_FLAGS "-std=c99")
elseif(CMAKE_Fortran_COMPILER_ID MATCHES "^(GNU)$")
set(CMAKE_Fortran_FLAGS "-fdefault-real-8 -fno-range-check -g -fbacktrace -fcheck=bounds")
endif()

# Contains common routines used for testing such as reading and interpolating data
add_library(test_library input_data_mod.f90 interp_mod.f90)
target_link_libraries(test_library PUBLIC ip2::ip2_d)

link_libraries(test_library)

add_executable(test_gdswzd test_gdswzd.c)
add_executable(test_scalar test_scalar.f90)
add_executable(test_vector test_vector.f90)

add_test(test_gdswzd_c test_gdswzd)

# scalar tests
add_test(test_lambert_biliner_scalar test_scalar 218 0)
add_test(test_gaussian_neighbor_scalar test_scalar 127 2)
add_test(test_latlon_bilinear_scalar test_scalar 3 0)
add_test(test_mercator_bicubic_scalar test_scalar 8 1)
add_test(test_polar-stereo_neighbor-budget_scalar test_scalar 212 6)
add_test(test_rotatedB_spectral_scalar test_scalar 205 4)
add_test(test_rotatedE_budget_scalar test_scalar 203 3)

# vector tests
add_test(test_lambert_biliner_vector test_vector 218 0)
add_test(test_gaussian_neighbor_vector test_vector 127 2)
add_test(test_latlon_bilinear_vector test_vector 3 0)
add_test(test_mercator_bicubic_vector test_vector 8 1)
add_test(test_polar-stereo_neighbor-budget_vector test_vector 212 6)
add_test(test_rotatedB_spectral_vector test_vector 205 4)
add_test(test_rotatedE_budget_vector test_vector 203 3)
185 changes: 29 additions & 156 deletions tests/README.md
Original file line number Diff line number Diff line change
@@ -1,22 +1,15 @@
## Description

Unit test for the NCEP IPOLATES library (IPLIB).

Please refer to README.md in the main directory for how to run tests using PFUnit.

This file is kept temporarily for historical purposes until all unit tests are converted to use pfunit.

## ABSTRACT:
---------

This test invokes IPOLATES to interpolate scalar and
vector data to several grids of various map projections
using all IPOLATES interpolation options. The output
is compared to baseline data and a summary of differences is
sent to standard output.


## HOW THE TEST WORKS:
-------------------
## How the Test Works

There are two separate programs to test the scalar and vector interpolation.
The scalar program calls routine 'ipolates' to interpolate a global field
Expand All @@ -43,162 +36,42 @@ the baseline data are computed and sent to standard output. For this
unit test to pass the differences should be "small".


## DIRECTORY LAYOUT:
-----------------

./sorc - Contains the files and scripts needed to build the
unit test programs. And the programs themselves.

./sorc/scalar -
Contains a Fortran program to call routine 'ipolates'
to interpolate a global field of albedo data to
several grids and using all interpolation options.

./sorc/vector -
Contains a Fortran program to call routine 'ipolatev'
to interpolate a global field of u/v wind data to
several grids and using all interpolation options.

./exec - Contains the unit test executables. There is one executable
for the single ("4"), double ("8") and mixed ("d") precision
versions of the IPOLATES library:

scalar_4.exe scalar_8.exe scalar_d.exe
vector_4.exe vector_8.exe vector_d.exe

./work - The working directory for program execution.
## Data

./lib - The location of the IPOLATES libraries and module files as
expected by the unit test programs.
### Input Data
Contains the input scalar and vector data. The
data are in binary little endian format:

./scripts - Contains scripts to run this unit test.
- data/scalar/global_snoalb.bin (global snow albedo)
- data/vector/global_uv_wind.bin (global 500mb u/v wind)

./input_data - Contains the input scalar and vector data. The
data are in binary little endian format:
### Baseline Data
Contains the baseline set of scalar and vector data
interpolated to each target grid. Binary, little endian
format. Output from each call to routine ipolates and
ipolatev is compared to its baseline counterpart. There
are sub-directories for the scalar and vector data.
And under these sub-directories, there are sub-directories
for the single (4_byte_bin) and mixed/double (8_byte_bin)
versions of the IPOLATES library. The file names
contain the grid number and IPOLATES interpolation
option (defined below); i.e.:

./scalar/global_snoalb.bin (global snow albedo)
./vector/global_uv_wind.bin (global 500mb u/v wind)
- grid${gridnum}.opt${ip_option}.bin_4/8

./baseline_data - Contains the baseline set of scalar and vector data
interpolated to each target grid. Binary, little endian
format. Output from each call to routine ipolates and
ipolatev is compared to its baseline counterpart. There
are sub-directories for the scalar and vector data.
And under these sub-directories, there are sub-directories
for the single (4_byte_bin) and mixed/double (8_byte_bin)
versions of the IPOLATES library. The file names
contain the grid number and IPOLATES interpolation
option (defined below); i.e.:

grid${gridnum}.opt${ip_option}.bin_4/8

Grads control files to view each file are located in the
./grads subdirectory. These files do not account
for map projection. Rather, they display the data
as a 2-D field with no interpolation. So when
viewing, do a "set mproj off" during your grads session.
Grads control files to view each file are located in the
grads subdirectory. These files do not account
for map projection. Rather, they display the data
as a 2-D field with no interpolation. So when
viewing, do a "set mproj off" during your grads session.


## How to Run

## HOW TO RUN THE TEST:
--------------------

1) Build the IPOLATES library. Go to $root and read the
README.build file for details.


2) Ensure the ./lib directory contains (or links to) the IPOLATES libraries and
its module files. The ./lib directory already contains links that point to the
libraries and module files as they would exist when using the "nco" install
option from step (1). I.e:

module file directories:
incmod_4 -> $root/ip/vX.Y.Z/include/ip_vX.Y.Z_4 (single precision)
incmod_d -> $root/ip/vX.Y.Z/include/ip_vX.Y.Z_d (mixed precision)
incmod_8 -> $root/ip/vX.Y.Z/include/ip_vX.Y.Z_8 (double precistion)

libraries:
libip_4.a -> $root/ip/vX.Y.Z/libip_vX.Y.Z_4.a (single precision)
libip_d.a -> $root/ip/vX.Y.Z/libip_vX.Y.Z_d.a (mixed precision)
libip_8.a -> $root/ip/vX.Y.Z/libip_vX.Y.Z_8.a (double precistion)

So if that is how IPOLATES was built in step (1), there is
nothing more to do.

However, if you want to build with another version of the library,
or if you built them in step (1) using the "gnu" or "nco_cray" install option,
you will need to adjust these links. Example: Suppose you want to
test with the OPS version of IPOLATES on WCOSS Phase 2. You would set the
links as follows:

incmod_4 -> /nwprod2/lib/ip/vX.Y.Z/include/ip_vX.Y.Z_4
incmod_d -> /nwprod2/lib/ip/vX.Y.Z/include/ip_vX.Y.Z_d
incmod_8 -> /nwprod2/lib/ip/vX.Y.Z/include/ip_vX.Y.Z_8

libip_4.a -> /nwprod2/lib/ip/vX.Y.Z/libip_vX.Y.Z_4.a
libip_d.a -> /nwprod2/lib/ip/vX.Y.Z/libip_vX.Y.Z_d.a
libip_8.a -> /nwprod2/lib/ip/vX.Y.Z/libip_vX.Y.Z_8.a


3) Build the "scalar" and "vector" unit test programs
by running the "make_unit_test.ksh" build script. (Use the
"make_unit_test_wcoss-cray.ksh" build script on WCOSS-Cray.)

The IPOLATES library is dependant on the NCEP SP
(spectral) library (SPLIB). Intel compiled versions of SPLIB
exist on Theia and WCOSS Phase 1/2. When running "make_unit_test.ksh"
on these machines, these SP libraries are automatically located
by module loads and stored in these environment variables:

SP_LIB4 (single precision)
SP_LIBd (mixed precision)
SP_LIB8 (double precistion)

On WCOSS-Cray, Intel and Cray compiled versions of SPLIB exist.
And the "make_unit_test_wcoss-cray.ksh" script will locate
them by module loads.

If you are testing on a machine other than WCOSS or Theia,
or you have compiled IPOLATES with a compiler other than Intel or Cray,
you will need to locate (or build) SPLIB and set these environment
varibles by editing the build script, or by exporting these
variables on the command line before invoking it.
Example (when using bash):

$ export SP_LIB4=$directory/libsp_4.a

Once the SP libraries have been located, run "make_unit_test.ksh"
(or make_unit_test_wcoss-cray.ksh) from the command line. The script
takes one argument: the "config-setup" file that was used to compile
IPOLATES. So, if you built IPOLATES with the Intel-optimized option,
you would invoke as follows:

$ make_unit_test.ksh ifort.setup

On WCOSS-Cray, you would do the following:

$ make_unit_test_wcoss-cray.ksh ifort.setup


4) Run the unit test. Go to ./scripts. To run interactively, type:

$ run_unit_test.ksh

You may want to pipe the output to a log fle. Check output for any
"large" differences between the computed and baseline data.

To run "run_unit_test.ksh" on the WCOSS or Theia compute nodes,
invoke these driver scripts as follows:

$ run_wcoss.ksh (WCOSS Phase 1/2)
$ run_wcoss-cray.ksh (WCOSS-Cray)
$ run_wcoss-dell.ksh (WCOSS-Phase 3/Dell)
$ sbatch run_theia.ksh (Theia)
From the build directory simply run `make test`

In this case, output is sent to "unit_test.log".
Alternatively, to run all tests and show stdout run `ctest --verbose`

The individual test executables can be run from `<build_directory>/tests`. `test_scalar` and `test_vector` take two command-line arguments for the grid type and interpolation scheme.

## QUESTIONS:
----------

Contact: [email protected]
Loading

0 comments on commit 72b9f57

Please sign in to comment.