Make several subroutines callable in shared library

This commit is contained in:
Paul Romano 2017-06-08 20:17:07 -05:00
parent 0d71494b3e
commit e75e91dcb5
7 changed files with 49 additions and 28 deletions

View file

@ -98,6 +98,8 @@ endif()
# endif()
#endif()
set(CMAKE_POSITION_INDEPENDENT_CODE ON)
if(CMAKE_Fortran_COMPILER_ID STREQUAL GNU)
# Make sure version is sufficient
execute_process(COMMAND ${CMAKE_Fortran_COMPILER} -dumpversion
@ -107,7 +109,7 @@ if(CMAKE_Fortran_COMPILER_ID STREQUAL GNU)
endif()
# GCC compiler options
list(APPEND f90flags -cpp -std=f2008 -fbacktrace -O2)
list(APPEND f90flags -cpp -std=f2008ts -fbacktrace -O2)
list(APPEND cflags -cpp -std=c99 -O2)
if(debug)
list(REMOVE_ITEM f90flags -O2)
@ -344,7 +346,7 @@ set(LIBOPENMC_FORTRAN_SRC
src/volume_calc.F90
src/volume_header.F90
src/xml_interface.F90)
add_library(libopenmc STATIC ${LIBOPENMC_FORTRAN_SRC})
add_library(libopenmc SHARED ${LIBOPENMC_FORTRAN_SRC})
set_target_properties(libopenmc PROPERTIES OUTPUT_NAME openmc)
add_executable(${program} src/main.F90)
set_property(TARGET ${program} libopenmc pugixml_fortran

View file

@ -1,5 +1,7 @@
module finalize
use, intrinsic :: ISO_C_BINDING
use hdf5, only: h5tclose_f, h5close_f
use global
@ -15,7 +17,7 @@ contains
! statistics and writing out tallies
!===============================================================================
subroutine openmc_finalize()
subroutine openmc_finalize() bind(C)
integer :: hdf5_err

View file

@ -46,11 +46,19 @@ contains
! setting up timers, etc.
!===============================================================================
subroutine openmc_init(intracomm)
#ifdef MPIF08
type(MPI_Comm), intent(in) :: intracomm ! MPI intracommunicator
#else
subroutine openmc_init(intracomm) bind(C)
integer, intent(in), optional :: intracomm ! MPI intracommunicator
! Copy the communicator to a new variable. This is done to avoid changing
! the signature of this subroutine.
#ifdef MPI
#ifdef MPIF08
type(MPI_Comm), intent(in) :: comm ! MPI intracommunicator
comm % MPI_VAL = intracomm
#else
integer :: comm
comm = intracomm
#endif
#endif
! Start total and initialization timer
@ -59,7 +67,7 @@ contains
#ifdef MPI
! Setup MPI
call initialize_mpi(intracomm)
call initialize_mpi(comm)
#endif
! Initialize HDF5 interface

View file

@ -6,15 +6,19 @@ program main
use initialize, only: openmc_init
use message_passing
use particle_restart, only: run_particle_restart
use plot, only: run_plot
use simulation, only: run_simulation
use volume_calc, only: run_volume_calculations
use plot, only: openmc_plot_geometry
use simulation, only: openmc_run
use volume_calc, only: openmc_calculate_volumes
implicit none
! Initialize run -- when run with MPI, pass communicator
#ifdef MPI
#ifdef MPIF08
call openmc_init(MPI_COMM_WORLD % MPI_VAL)
#else
call openmc_init(MPI_COMM_WORLD)
#endif
#else
call openmc_init()
#endif
@ -22,13 +26,13 @@ program main
! start problem based on mode
select case (run_mode)
case (MODE_FIXEDSOURCE, MODE_EIGENVALUE)
call run_simulation()
call openmc_run()
case (MODE_PLOTTING)
call run_plot()
call openmc_plot_geometry()
case (MODE_PARTICLE)
if (master) call run_particle_restart()
case (MODE_VOLUME)
call run_volume_calculations()
call openmc_calculate_volumes()
end select
! finalize run

View file

@ -1,5 +1,9 @@
module plot
use, intrinsic :: ISO_C_BINDING
use hdf5
use constants
use error, only: fatal_error
use geometry, only: find_cell, check_cell_overlap
@ -14,12 +18,10 @@ module plot
use progress_header, only: ProgressBar
use string, only: to_str
use hdf5
implicit none
private
public :: run_plot
public :: openmc_plot_geometry
integer, parameter :: RED = 1
integer, parameter :: GREEN = 2
@ -31,7 +33,7 @@ contains
! RUN_PLOT controls the logic for making one or many plots
!===============================================================================
subroutine run_plot()
subroutine openmc_plot_geometry() bind(C)
integer :: i ! loop index for plots
@ -51,7 +53,7 @@ contains
end associate
end do
end subroutine run_plot
end subroutine openmc_plot_geometry
!===============================================================================
! POSITION_RGB computes the red/green/blue values for a given plot with the

View file

@ -1,5 +1,7 @@
module simulation
use, intrinsic :: ISO_C_BINDING
use cmfd_execute, only: cmfd_init_batch, execute_cmfd
use constants, only: ZERO
use eigenvalue, only: count_source_for_ufs, calculate_average_keff, &
@ -22,21 +24,20 @@ module simulation
tally_statistics
use trigger, only: check_triggers
use tracking, only: transport
use volume_calc, only: run_volume_calculations
implicit none
private
public :: run_simulation
public :: openmc_run
contains
!===============================================================================
! RUN_SIMULATION encompasses all the main logic where iterations are performed
! OPENMC_RUN encompasses all the main logic where iterations are performed
! over the batches, generations, and histories in a fixed source or k-eigenvalue
! calculation.
!===============================================================================
subroutine run_simulation()
subroutine openmc_run() bind(C)
type(Particle) :: p
integer(8) :: i_work
@ -115,7 +116,7 @@ contains
! Clear particle
call p % clear()
end subroutine run_simulation
end subroutine openmc_run
!===============================================================================
! INITIALIZE_HISTORY

View file

@ -1,5 +1,7 @@
module volume_calc
use, intrinsic :: ISO_C_BINDING
use hdf5, only: HID_T
#ifdef _OPENMP
use omp_lib
@ -21,16 +23,16 @@ module volume_calc
implicit none
private
public :: run_volume_calculations
public :: openmc_calculate_volumes
contains
!===============================================================================
! RUN_VOLUME_CALCULATIONS runs each of the stochastic volume calculations that
! OPENMC_CALCULATE_VOLUMES runs each of the stochastic volume calculations that
! the user has specified and writes results to HDF5 files
!===============================================================================
subroutine run_volume_calculations()
subroutine openmc_calculate_volumes() bind(C)
integer :: i, j
integer :: n
real(8), allocatable :: volume(:,:) ! volume mean/stdev in each domain
@ -93,7 +95,7 @@ contains
call write_message("Elapsed time: " // trim(to_str(time_volume % &
get_value())) // " s", 6)
end if
end subroutine run_volume_calculations
end subroutine openmc_calculate_volumes
!===============================================================================
! GET_VOLUME stochastically determines the volume of a set of domains along with