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

Vector-ordered Rosenbrock Solver #172

Merged
merged 33 commits into from
Jul 15, 2024
Merged
Show file tree
Hide file tree
Changes from 24 commits
Commits
Show all changes
33 commits
Select commit Hold shift + click to select a range
4ac0fab
update cmake options
boulderdaze Jun 24, 2024
e27634b
set vector matrix dimension
boulderdaze Jun 24, 2024
d114885
compilation flag for grid cells, vector matrix dimension
boulderdaze Jul 3, 2024
6d2bc7d
c api for vector ordered matrix
boulderdaze Jul 3, 2024
bf57538
add vector matrix test
boulderdaze Jul 3, 2024
090b620
update fortran api
boulderdaze Jul 3, 2024
062c748
merge main
boulderdaze Jul 3, 2024
4546e4a
chage the build type
boulderdaze Jul 3, 2024
fa82486
update python wrapper
boulderdaze Jul 5, 2024
54ec3e7
resolve memory leak
boulderdaze Jul 5, 2024
b362330
fix intel docker
boulderdaze Jul 5, 2024
30bfafc
tuvx on
boulderdaze Jul 5, 2024
4c10839
micm git tag
boulderdaze Jul 5, 2024
b484cfe
edit erorr
boulderdaze Jul 5, 2024
2d50377
opdate the option name for open mp
boulderdaze Jul 5, 2024
f4f6526
remove open mp fortran in c tests
boulderdaze Jul 5, 2024
b8481f6
edit comment
boulderdaze Jul 5, 2024
5a67815
replace unique ptr T to T
boulderdaze Jul 8, 2024
983a510
replace tempalte with auto
boulderdaze Jul 8, 2024
997038b
add map header
boulderdaze Jul 9, 2024
8b08448
Merge branch 'main' into 55-vector-ordered-rosenbrock
boulderdaze Jul 9, 2024
80a0f66
expose solver type enum to python
boulderdaze Jul 9, 2024
23889c3
back to template
boulderdaze Jul 9, 2024
276bc8f
back to template
boulderdaze Jul 9, 2024
2812b21
enum for solver type
boulderdaze Jul 10, 2024
09bf9b8
enum solver type for fortran
boulderdaze Jul 10, 2024
680a2cb
add fortran 2023 feature comment
boulderdaze Jul 10, 2024
61c87df
pass num grid cells to constructor
boulderdaze Jul 10, 2024
63bf319
code clean up
boulderdaze Jul 10, 2024
15ae988
specify enabled languages in top level cmake
boulderdaze Jul 11, 2024
e53faf2
comment out the tuvx openmp tests
boulderdaze Jul 11, 2024
1f548de
revert back
boulderdaze Jul 11, 2024
830b426
revert back
boulderdaze Jul 11, 2024
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
9 changes: 9 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,15 @@ option(MUSICA_BUILD_DOCS "Build the documentation" OFF)
option(MUSICA_ENABLE_MICM "Enable MICM" ON)
option(MUSICA_ENABLE_TUVX "Enable TUV-x" ON)

set(MUSICA_SET_MICM_NUM_GRID_CELLS "1" CACHE STRING "Set the number of grid cells for MICM Solver")
mattldawson marked this conversation as resolved.
Show resolved Hide resolved
set(MUSICA_SET_MICM_VECTOR_MATRIX_SIZE "2" CACHE STRING "Set MICM vector-ordered matrix dimension")

if(${MUSICA_SET_MICM_NUM_GRID_CELLS} LESS ${MUSICA_SET_MICM_VECTOR_MATRIX_SIZE})
set(MUSICA_SET_MICM_VECTOR_MATRIX_SIZE ${MUSICA_SET_MICM_NUM_GRID_CELLS})
message(STATUS "MICM vector matrix dimension must be less than or equal to the number of grid cells")
message(STATUS "MICM vector matrix dimension: " ${MUSICA_SET_MICM_VECTOR_MATRIX_SIZE})
endif()

cmake_dependent_option(
MUSICA_ENABLE_PYTHON_LIBRARY "Adds pybind11, a lightweight header-only library that exposes C++ types in Python and vice versa" OFF "MUSICA_BUILD_C_CXX_INTERFACE" OFF)

Expand Down
1 change: 1 addition & 0 deletions cmake/dependencies.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,7 @@ if (MUSICA_ENABLE_MICM AND MUSICA_BUILD_C_CXX_INTERFACE)
)
set(MICM_ENABLE_TESTS OFF)
set(MICM_ENABLE_EXAMPLES OFF)
set(MICM_DEFAULT_VECTOR_MATRIX_SIZE ${MUSICA_SET_MICM_VECTOR_MATRIX_SIZE})

FetchContent_MakeAvailable(micm)
endif()
Expand Down
2 changes: 1 addition & 1 deletion cmake/test_util.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ function(create_standard_test_cxx)
add_executable(test_${TEST_NAME} ${TEST_SOURCES})
target_link_libraries(test_${TEST_NAME} PUBLIC musica::musica GTest::gtest_main)
if(MUSICA_ENABLE_OPENMP)
target_link_libraries(test_${TEST_NAME} PUBLIC OpenMP::OpenMP_CXX OpenMP::OpenMP_Fortran)
target_link_libraries(test_${TEST_NAME} PUBLIC OpenMP::OpenMP_CXX)
endif()
Comment on lines 45 to 47
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hi @mattldawson and @K20shores, what do you think about this change? Matt and I briefly discussed about this. The issue is that OpenMP::OpenMP_Fortran is not found when test_micm_c_api is built. I removed it because this line belongs to function(create_standard_test_cxx) and I assumed that it shouldn't need OpenMp_Fortran for c++ tests.
Matt mentioned we could specify fortran as one of the languages in the top-level CMakeLists.txt and update find_package in cmake/dependencies.cmake

project(musica-distribution VERSION 0.7.0 LANGUAGES C CXX Fortran)
find_package(OpenMP REQUIRED COMPONENTS C CXX Fortran)

I think that makes sense although I think it is useful to separate the fortran stuff from MUSICA-C as it is since we eventually pursue fortran-free. I'd like to hear what you all think.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would like to keep fortran separated, but with the inclusion of tuvx into the musica-c library that line is blurred. Because of that I think we should go with Matt's suggestion. The other option is to check if TUVX is enabled before we check for OpenMP. If it is, enable the fortran language so that the fortran part of OpenMP is found, if that's possible

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I created a separate issue to tackle this.

if(NOT DEFINED TEST_WORKING_DIRECTORY)
set(TEST_WORKING_DIRECTORY "${CMAKE_BINARY_DIR}")
Expand Down
2 changes: 1 addition & 1 deletion docker/Dockerfile.fortran-gcc
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
FROM fedora:35

ARG BUILD_TYPE=release
ARG BUILD_TYPE=Release

RUN dnf -y update \
&& dnf -y install \
Expand Down
6 changes: 2 additions & 4 deletions docker/Dockerfile.fortran-intel
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ COPY . musica
RUN cd musica \
&& cmake -S . \
-B build \
-D CMAKE_BUILD_TYPE=Release \
-D CMAKE_BUILD_TYPE=${BUILD_TYPE} \
&& cd build \
&& make install -j

Expand All @@ -69,6 +69,4 @@ RUN cd musica/fortran/test/fetch_content_integration \
-D MUSICA_ENABLE_MEMCHECK=ON \
&& make -j

WORKDIR musica/fortran/test/fetch_content_integration/build
RUN cp -r /musica/build/_deps/tuvx-src/examples/ .
RUN cp -r /musica/build/_deps/tuvx-src/data/ .
WORKDIR musica/fortran/test/fetch_content_integration/build
4 changes: 3 additions & 1 deletion docker/Dockerfile.memcheck
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
FROM fedora:35

ARG BUILD_TYPE=Debug

RUN dnf -y update \
&& dnf -y install \
cmake \
Expand All @@ -22,7 +24,7 @@ COPY . musica
RUN cd musica \
&& cmake -S . \
-B build \
-D CMAKE_BUILD_TYPE=Debug \
-D CMAKE_BUILD_TYPE=${BUILD_TYPE} \
-D MUSICA_ENABLE_MEMCHECK=ON \
&& cd build \
&& make install -j 8
Expand Down
8 changes: 5 additions & 3 deletions docker/Dockerfile.mpi
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
FROM fedora:35

ARG BUILD_TYPE=Debug

RUN dnf -y update \
&& dnf install -y sudo \
&& adduser test_user \
Expand Down Expand Up @@ -38,9 +40,9 @@ RUN sudo chown -R test_user.test_user musica
RUN cd musica \
&& cmake -S . \
-B build \
-D CMAKE_BUILD_TYPE=debug \
-D ENABLE_TESTS=ON \
-D ENABLE_MPI=ON \
-D CMAKE_BUILD_TYPE=${BUILD_TYPE} \
-D MUSICA_ENABLE_TESTS=ON \
-D MUSICA_ENABLE_MPI=ON \
-D CMAKE_Fortran_COMPILER=/usr/lib64/openmpi/bin/mpif90 \
-D CMAKE_C_COMPILER=/usr/lib64/openmpi/bin/mpicc \
-D CMAKE_CXX_COMPILER=/usr/lib64/openmpi/bin/mpicxx \
Expand Down
10 changes: 6 additions & 4 deletions docker/Dockerfile.mpi_openmp
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
FROM fedora:35

ARG BUILD_TYPE=Debug

RUN dnf -y update \
&& dnf install -y sudo \
&& adduser test_user \
Expand Down Expand Up @@ -38,10 +40,10 @@ RUN sudo chown -R test_user.test_user musica
RUN cd musica \
&& cmake -S . \
-B build \
-D CMAKE_BUILD_TYPE=debug \
-D ENABLE_MPI=ON \
-D ENABLE_OPENMP=ON \
-D ENABLE_TESTS=ON \
-D CMAKE_BUILD_TYPE=${BUILD_TYPE} \
-D MUSICA_ENABLE_MPI=ON \
-D MUSICA_ENABLE_OPENMP=ON \
-D MUSICA_ENABLE_TESTS=ON \
-D CMAKE_Fortran_COMPILER=/usr/lib64/openmpi/bin/mpif90 \
-D CMAKE_C_COMPILER=/usr/lib64/openmpi/bin/mpicc \
-D CMAKE_CXX_COMPILER=/usr/lib64/openmpi/bin/mpicxx \
Expand Down
8 changes: 5 additions & 3 deletions docker/Dockerfile.openmp
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
FROM fedora:35

ARG BUILD_TYPE=Debug

RUN dnf -y update \
&& dnf install -y sudo \
&& adduser test_user \
Expand Down Expand Up @@ -37,9 +39,9 @@ RUN sudo chown -R test_user.test_user musica
RUN cd musica \
&& cmake -S . \
-B build \
-D CMAKE_BUILD_TYPE=debug \
-D ENABLE_OPENMP:BOOL=TRUE \
-D ENABLE_TESTS=ON \
-D CMAKE_BUILD_TYPE=${BUILD_TYPE} \
-D MUSICA_ENABLE_OPENMP=ON \
-D MUSICA_ENABLE_TESTS=ON \
-D CMAKE_Fortran_COMPILER=/usr/lib64/openmpi/bin/mpif90 \
-D CMAKE_C_COMPILER=/usr/lib64/openmpi/bin/mpicc \
-D CMAKE_CXX_COMPILER=/usr/lib64/openmpi/bin/mpic++ \
Expand Down
4 changes: 3 additions & 1 deletion docker/Dockerfile.python
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
FROM fedora:latest

ARG BUILD_TYPE=Release

RUN dnf -y update \
&& dnf -y install \
cmake \
Expand Down Expand Up @@ -45,7 +47,7 @@ RUN pip install -r requirements.txt
RUN cd musica \
&& cmake -S . \
-B build \
-D CMAKE_BUILD_TYPE=Release \
-D CMAKE_BUILD_TYPE=${BUILD_TYPE} \
-D MUSICA_ENABLE_PYTHON_LIBRARY=ON \
-D MUSICA_ENABLE_TUVX=OFF \
&& cd build \
Expand Down
14 changes: 8 additions & 6 deletions fortran/micm.F90
Original file line number Diff line number Diff line change
Expand Up @@ -26,12 +26,13 @@ module musica_micm
end type solver_stats_t_c

interface
function create_micm_c(config_path, error) bind(C, name="CreateMicm")
function create_micm_c(config_path, solver_type, error) bind(C, name="CreateMicm")
use musica_util, only: error_t_c
import c_ptr, c_int, c_char
character(kind=c_char), intent(in) :: config_path(*)
type(error_t_c), intent(inout) :: error
type(c_ptr) :: create_micm_c
character(kind=c_char), intent(in) :: config_path(*)
integer(kind=c_int), value, intent(in) :: solver_type
type(error_t_c), intent(inout) :: error
type(c_ptr) :: create_micm_c
end function create_micm_c

subroutine delete_micm_c(micm, error) bind(C, name="DeleteMicm")
Expand Down Expand Up @@ -182,10 +183,11 @@ function get_micm_version() result(value)
value = string_t(string_c)
end function get_micm_version

function constructor(config_path, error) result( this )
function constructor(config_path, solver_type, error) result( this )
use musica_util, only: error_t_c, error_t, copy_mappings
type(micm_t), pointer :: this
character(len=*), intent(in) :: config_path
integer(c_int), intent(in) :: solver_type
type(error_t), intent(inout) :: error
character(len=1, kind=c_char) :: c_config_path(len_trim(config_path)+1)
integer :: n, i
Expand All @@ -201,7 +203,7 @@ function constructor(config_path, error) result( this )
end do
c_config_path(n+1) = c_null_char

this%ptr = create_micm_c(c_config_path, error_c)
this%ptr = create_micm_c(c_config_path, solver_type, error_c)
error = error_t(error_c)
if (.not. error%is_success()) then
deallocate(this)
Expand Down
8 changes: 5 additions & 3 deletions fortran/test/fetch_content_integration/test_micm_api.F90
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ subroutine test_api()
real(c_double), dimension(5) :: concentrations
real(c_double), dimension(3) :: user_defined_reaction_rates
character(len=256) :: config_path
integer(c_int) :: solver_type
character(len=:), allocatable :: string_value
real(c_double) :: double_value
integer(c_int) :: int_value
Expand All @@ -42,21 +43,22 @@ subroutine test_api()
real(c_double), parameter :: GAS_CONSTANT = 8.31446261815324_c_double ! J mol-1 K-1
integer :: i

config_path = "configs/chapman"
solver_type = 1
mattldawson marked this conversation as resolved.
Show resolved Hide resolved
time_step = 200
temperature = 272.5
pressure = 101253.4
air_density = pressure / ( GAS_CONSTANT * temperature )
num_concentrations = 5
concentrations = (/ 0.75, 0.4, 0.8, 0.01, 0.02 /)
config_path = "configs/chapman"
num_user_defined_reaction_rates = 3
user_defined_reaction_rates = (/ 0.1, 0.2, 0.3 /)

micm_version = get_micm_version()
print *, "[test micm fort api] MICM version ", micm_version%get_char_array()

write(*,*) "[test micm fort api] Creating MICM solver..."
micm => micm_t(config_path, error)
micm => micm_t(config_path, solver_type, error)
ASSERT( error%is_success() )

do i = 1, size( micm%species_ordering )
Expand Down Expand Up @@ -116,7 +118,7 @@ subroutine test_api()
ASSERT( error%is_error( MICM_ERROR_CATEGORY_SPECIES, \
MICM_SPECIES_ERROR_CODE_PROPERTY_NOT_FOUND ) )
deallocate( micm )
micm => micm_t( "configs/invalid", error )
micm => micm_t( "configs/invalid", solver_type, error )
ASSERT( error%is_error( MICM_ERROR_CATEGORY_CONFIGURATION, \
MICM_CONFIGURATION_ERROR_CODE_INVALID_FILE_PATH ) )
ASSERT( .not. associated( micm ) )
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ program test_micm_box_model
subroutine box_model()

character(len=256) :: config_path
integer(c_int) :: solver_type

real(c_double), parameter :: GAS_CONSTANT = 8.31446261815324_c_double ! J mol-1 K-1

Expand All @@ -38,6 +39,7 @@ subroutine box_model()
integer :: i

config_path = "configs/analytical"
solver_type = 2

time_step = 200
temperature = 273.0
Expand All @@ -47,7 +49,7 @@ subroutine box_model()
concentrations = (/ 1.0, 1.0, 1.0 /)

write(*,*) "Creating MICM solver..."
micm => micm_t(config_path, error)
micm => micm_t(config_path, solver_type, error)

do i = 1, size( micm%species_ordering )
associate(the_mapping => micm%species_ordering(i))
Expand Down
Loading
Loading