39 USE iso_c_binding,
ONLY: c_int, c_ptr, c_funptr, c_f_procpointer, c_null_char, &
40 & c_associated, c_null_ptr, c_loc, c_char, c_double, c_f_pointer
56 SUBROUTINE comin_plugin_init_fct(state_ptr, host_version, host_wp)
BIND(C)
60 TYPE(C_PTR),
VALUE,
INTENT(IN) :: state_ptr
62 TYPE(C_PTR),
INTENT(IN) :: state_ptr
65 TYPE(t_comin_setup_version_info),
INTENT(IN) :: host_version
66 INTEGER(C_INT),
INTENT(IN) :: host_wp
67 END SUBROUTINE comin_plugin_init_fct
69 SUBROUTINE comin_primaryconstructor_fct() &
71 END SUBROUTINE comin_primaryconstructor_fct
75 INTEGER(c_int),
PARAMETER :: rtld_now = 2
79 FUNCTION dlopen_ptr(filename,mode)
BIND(c,name="dlopen")
83 TYPE(c_ptr) :: dlopen_ptr
84 TYPE(c_ptr),
VALUE,
INTENT(in) :: filename
85 INTEGER(c_int),
VALUE :: mode
86 END FUNCTION dlopen_ptr
88 FUNCTION dlsym(handle,name)
BIND(c,name="dlsym")
92 TYPE(c_funptr) :: dlsym
93 TYPE(c_ptr),
VALUE :: handle
94 CHARACTER(c_char),
INTENT(in) :: name(*)
105 FUNCTION dlerror()
RESULT(error)
BIND(C,NAME="dlerror")
114 TYPE :: comin_primaryconstructor_ptr
115 PROCEDURE(comin_primaryconstructor_fct),
POINTER,
NOPASS :: fct_ptr
116 END TYPE comin_primaryconstructor_ptr
121#include "comin_version.inc"
125 FUNCTION dlopen(filename, mode)
126 CHARACTER(LEN=*),
INTENT(in) :: filename
127 INTEGER(c_int),
VALUE :: mode
129 TYPE(c_ptr) :: dlopen
130 CHARACTER(len=1, kind=c_char),
TARGET :: c_filename(len(filename)+1)
132 dlopen = dlopen_ptr(c_loc(c_filename), mode)
141 INTEGER :: i, last_sep_idx
142 TYPE(c_funptr) :: setup_fct_c, plugin_init_fct_c
143 PROCEDURE(comin_primaryconstructor_fct),
BIND(C),
POINTER :: setup_fct
144 PROCEDURE(comin_plugin_init_fct),
BIND(C),
POINTER :: plugin_init_fct
151 state%num_plugins =
SIZE(plugin_list)
153 ALLOCATE(
state%plugin_info(
state%num_plugins))
154 DO i=1,
state%num_plugins
156 IF (trim(plugin_list(i)%plugin_library) .EQ.
"")
THEN
157 dl_handles(i) = dlopen_ptr(c_null_ptr, rtld_now)
159 dl_handles(i) = dlopen(plugin_list(i)%plugin_library, rtld_now)
166 plugin_init_fct_c = dlsym(
dl_handles(i),
"comin_plugin_init"//c_null_char)
167 IF (.NOT. c_associated(plugin_init_fct_c)) &
169 &
"Cannot load 'comin_plugin_init' from plugin: " //
convert_c_string(dlerror()))
170 CALL c_f_procpointer( plugin_init_fct_c, plugin_init_fct )
173 setup_fct_c = dlsym(
dl_handles(i), trim(plugin_list(i)%primary_constructor)//c_null_char)
174 IF (.NOT. c_associated(setup_fct_c)) &
176 &
"Cannot load primary constructor from plugin: " //
convert_c_string(dlerror()))
178 CALL c_f_procpointer( setup_fct_c, setup_fct )
180 state%current_plugin%id = i
181 IF (len_trim(plugin_list(i)%name) > 0)
THEN
182 state%current_plugin%name = trim(plugin_list(i)%name)
184 last_sep_idx = scan(plugin_list(i)%plugin_library,
"/", .true.)
185 state%current_plugin%name = trim(plugin_list(i)%plugin_library(last_sep_idx+1:)) // &
186 &
"(" // trim(plugin_list(i)%primary_constructor) //
")"
188 state%current_plugin%options = trim(plugin_list(i)%options)
189 state%current_plugin%comm = trim(plugin_list(i)%comm)
190 state%current_plugin%log_debug = plugin_list(i)%log_debug
191 state%current_plugin%log_info = plugin_list(i)%log_info
192 state%current_plugin%log_warning = plugin_list(i)%log_warning
194 NULLIFY(
state%current_plugin)
201 state%l_primary_done = .true.
207 CHARACTER(LEN=*),
INTENT(IN) :: plugin_str
208 INTEGER,
INTENT(IN) :: wp_check
211 IF (.NOT.
ASSOCIATED(
state%comin_host_finish))
THEN
216 IF (
wp /= wp_check)
THEN
219 CALL comin_message(
" " // plugin_str //
": working precision test successful.", 0)
229 comin_current_plugin =
state%current_plugin
234 INTEGER(C_INT) FUNCTION comin_current_get_plugin_id() &
235 &
BIND(C, NAME="comin_current_get_plugin_id")
236 comin_current_get_plugin_id = int(
state%current_plugin%id, c_int)
237 END FUNCTION comin_current_get_plugin_id
240 SUBROUTINE comin_current_get_plugin_name(val, len) &
241 &
BIND(C, NAME="comin_current_get_plugin_name")
242 TYPE(c_ptr),
INTENT(OUT) :: val
243 INTEGER(kind=c_int),
INTENT(OUT) :: len
245 val = c_loc(
state%current_plugin%name)
246 len = len_trim(
state%current_plugin%name)
247 END SUBROUTINE comin_current_get_plugin_name
250 SUBROUTINE comin_current_get_plugin_options(val, len) &
251 &
BIND(C, NAME="comin_current_get_plugin_options")
252 TYPE(c_ptr),
INTENT(OUT) :: val
253 INTEGER(kind=c_int),
INTENT(OUT) :: len
255 val = c_loc(
state%current_plugin%options)
256 len = len_trim(
state%current_plugin%options)
257 END SUBROUTINE comin_current_get_plugin_options
260 SUBROUTINE comin_current_get_plugin_comm(val, len) &
261 &
BIND(C, NAME="comin_current_get_plugin_comm")
262 TYPE(c_ptr),
INTENT(OUT) :: val
263 INTEGER(kind=c_int),
INTENT(OUT) :: len
265 val = c_loc(
state%current_plugin%comm)
266 len = len_trim(
state%current_plugin%comm)
267 END SUBROUTINE comin_current_get_plugin_comm
274 LOGICAL,
INTENT(IN) :: lstdout
275 INTEGER,
INTENT(IN),
OPTIONAL :: output_unit
276 IF (
ASSOCIATED(
state))
THEN
281 state%lstdout = lstdout
282 IF(
PRESENT(output_unit))
THEN
283 state%output_unit = output_unit
327 TYPE(c_ptr),
VALUE,
INTENT(IN) :: state_ptr
329 INTEGER(C_INT),
INTENT(IN) :: host_wp
343 IF( host_wp /= c_double )
THEN
347 CALL c_f_pointer(state_ptr, host_state)
349 IF(
ASSOCIATED(
state) .AND. .NOT.
ASSOCIATED(
state, host_state))
THEN
361 state%comin_descrdata_fct_glb2loc_cell => fct
362 IF (.NOT.
ASSOCIATED(
state%comin_descrdata_fct_glb2loc_cell))
THEN
377 state%comin_host_finish => error_handler
378 IF (.NOT.
ASSOCIATED(
state%comin_host_finish))
THEN
integer, parameter, public wp
working precision
type(t_comin_setup_version_info) function, public comin_setup_get_version()
Returns version info.
subroutine, public comin_setup_check(plugin_str, wp_check)
Performs basic compatibility checks.
subroutine, public comin_plugin_primaryconstructor(plugin_list)
Execute primary constructors.
subroutine, public comin_descrdata_set_fct_glb2loc_cell(fct)
Sets the "global-to-local" index lookup function.
subroutine, public comin_setup_init(lstdout, output_unit)
Initialize the comin stateThis routine needs to be called by the host before any other comin call.
subroutine, public comin_setup_finalize()
Destructor.
subroutine, public comin_setup_errhandler(error_handler)
Sets the global error handler procedure pointer.
subroutine, public comin_plugin_finish(routine, text)
Wrapper function for callback to ICON's "finish" routine.
subroutine, public comin_current_get_plugin_info(comin_current_plugin)
Returns the structure current_plugin. It can for example be used to access the id of the current plug...
In order to be compatible with ICON, the interface contains OPTIONAL arguments which are probably not...
subroutine, public convert_f_string(string, arr)
Convert Fortran string into C-style character array.
subroutine, public comin_callback_complete()
@ comin_error_plugin_init_state_initialized
@ comin_error_setup_precision_test_failed
@ comin_error_setup_comin_already_initialized
@ comin_error_descrdata_set_fct_glb2loc
@ comin_error_setup_errhandler_not_associated
@ comin_error_setup_finalize
@ comin_error_plugin_init_comin_version
@ comin_error_plugin_init_precision
@ comin_error_setup_errhandler_not_set
subroutine, public comin_error_set(errcode)
subroutine, public comin_message(message, lvl)
Prints a message on rank 0 if the global verbosity level larger than lvl.
subroutine, public comin_parallel_free_mpi_comms()
logical function, public comin_setup_version_compatible(setupa, setupb)
subroutine, public comin_plugin_init(state_ptr, host_version, host_wp)
Initialize the plugin state.
type(c_ptr), dimension(:), allocatable dl_handles
list of primary constructors
type(t_comin_state), pointer, public state
subroutine, public comin_var_complete()
Data type, describing the dynamic libraries.
The elements of this derived data type describe a 3rd party plugin.
The elements of this derived data type describe the current community interface.