From d8d9343862e6000ea4bfbb62be8eac0f38a36b14 Mon Sep 17 00:00:00 2001 From: Chiara Hergl Date: Wed, 24 Jul 2024 08:07:53 +0200 Subject: [PATCH 01/42] Change Makefile for fortran_interface.f90 --- api/Makefile.am | 18 +++++++++++++++++- 1 file changed, 17 insertions(+), 1 deletion(-) diff --git a/api/Makefile.am b/api/Makefile.am index e5991dd619..ed2d0b0a3a 100644 --- a/api/Makefile.am +++ b/api/Makefile.am @@ -10,5 +10,21 @@ libt8_installed_headers_fortran_interface = \ dist_fortraninterfaceinclude_HEADERS = $(libt8_installed_headers_fortran_interface) -AM_CPPFLAGS += -I@top_srcdir@/api +t8_fortran_module_sources = src/t8_fortran_interface/t8_mo_fortran_interface.f90 \ +src/t8_messy/t8_mo_messy_coupler_interface.f90 + +# Add the Fortran sources to the lib +libt8_compiled_sources += $(t8_fortran_module_sources) +# Save the module sources in a different variable for later use +AM_FCFLAGS = +AM_CPPFLAGS = -I@top_srcdir@/api +MODSOURCES = $(t8_fortran_module_sources) + +src_libt8_la_FCFLAGS = $(AM_FCFLAGS) +src_libt8_la_FFLAGS = $(FFLAGS) + +# Include the Fortran specific variables and rules +include t8_fortran_specific.mk + + endif From adbef22a729056573f1f0d5145eaa6bbdb3fb673 Mon Sep 17 00:00:00 2001 From: Chiara Hergl Date: Wed, 24 Jul 2024 08:08:23 +0200 Subject: [PATCH 02/42] add t8_mo_fortran_interface.f90 --- .../t8_mo_fortran_interface.f90 | 250 ++++++++++++++++++ 1 file changed, 250 insertions(+) create mode 100644 api/t8_fortran_interface/t8_mo_fortran_interface.f90 diff --git a/api/t8_fortran_interface/t8_mo_fortran_interface.f90 b/api/t8_fortran_interface/t8_mo_fortran_interface.f90 new file mode 100644 index 0000000000..17aaebff11 --- /dev/null +++ b/api/t8_fortran_interface/t8_mo_fortran_interface.f90 @@ -0,0 +1,250 @@ +module t8_mo_fortran_interface + + use, intrinsic :: ISO_C_BINDING + + + !!! Interface for t8_fortran_MPI_Comm_new + !!! Given a fortran MPI Communicator, converts it into C and + !!! returns a pointer to the C MPI communicator. + !!! This function allocates memory that needs to be freed with + !!! t8_fortran_mpi_comm_delete_f + !!! + !!! Code modified from: https://stackoverflow.com/questions/42530620/how-to-pass-mpi-communicator-handle-from-fortran-to-c-using-iso-c-binding + INTERFACE + type (C_PTR) FUNCTION t8_fortran_mpi_comm_new_f (FCOMM) & + BIND(C, NAME='t8_fortran_MPI_Comm_new') + use, intrinsic :: ISO_C_BINDING, only: c_int, c_ptr + IMPLICIT NONE + INTEGER (C_INT), VALUE :: Fcomm + END FUNCTION t8_fortran_mpi_comm_new_f + END INTERFACE + + !!! Free memory of a C MPI communicator pointer that was + !!! allocated using t8_fortran_mpi_comm_new_f + INTERFACE + subroutine t8_fortran_mpi_comm_delete_f (Ccomm) & + BIND(C, NAME='t8_fortran_MPI_Comm_delete') + use, intrinsic :: ISO_C_BINDING, only: c_ptr + IMPLICIT NONE + type (c_ptr), value :: Ccomm + END subroutine t8_fortran_mpi_comm_delete_f + END INTERFACE + + !!! Initialize sc and t8code with a given C MPI Communicator + Interface + subroutine t8_fortran_init_all_f (Ccomm) & + BIND(C, NAME='t8_fortran_init_all') + use, intrinsic :: ISO_C_BINDING, only: c_ptr + IMPLICIT NONE + type (c_ptr), value :: Ccomm + END subroutine t8_fortran_init_all_f + end Interface + + !!! Initialize sc and t8code with a given C MPI Communicator + Interface + subroutine t8_fortran_init_all_noMPI_f () & + BIND(C, NAME='t8_fortran_init_all_noMPI') + END subroutine t8_fortran_init_all_noMPI_f + end Interface + + Interface + type (c_ptr) function t8_cmesh_new_periodic_tri_f (Ccomm) & + bind (c, name = 't8_cmesh_new_periodic_tri_wrap') + use, intrinsic :: ISO_C_BINDING, only: c_ptr + IMPLICIT NONE + type (c_ptr), value :: Ccomm + end function t8_cmesh_new_periodic_tri_f + end Interface + + Interface + integer (c_int) function t8_cmesh_vtk_write_file_f (cmesh, fileprefix, scale) & + bind (c, name = 't8_cmesh_vtk_write_file') + use, intrinsic :: ISO_C_BINDING, only: c_ptr, c_int, c_char, c_double + IMPLICIT NONE + type (c_ptr), value :: cmesh + character (c_char) :: fileprefix + real (c_double), value :: scale + end function t8_cmesh_vtk_write_file_f + end Interface + + Interface + subroutine t8_cmesh_destroy_f (cmesh) & + bind (c, name = 't8_cmesh_destroy') + use, intrinsic :: ISO_C_BINDING, only: c_ptr + IMPLICIT NONE + type (c_ptr) :: cmesh + end subroutine t8_cmesh_destroy_f + end Interface + + Interface + subroutine t8_fortran_cmesh_init_f (cmesh) & + bind (c, name = 't8_cmesh_init') + use, intrinsic :: ISO_C_BINDING, only: c_ptr + IMPLICIT NONE + type (c_ptr) :: cmesh + end subroutine t8_fortran_cmesh_init_f + end Interface + + Interface + type (c_ptr) function t8_fortran_geometry_linear_new_f (dimension) & + bind (c, name = 't8_geometry_linear_new') + use, intrinsic :: ISO_C_BINDING, only: c_int, c_ptr + IMPLICIT NONE + integer (c_int), value :: dimension + end function t8_fortran_geometry_linear_new_f + end Interface + + Interface + subroutine t8_fortran_cmesh_register_geometry_f (cmesh, geometry) & + bind (c, name = 't8_cmesh_register_geometry') + use, intrinsic :: ISO_C_BINDING, only: c_ptr + IMPLICIT NONE + type (c_ptr), value :: cmesh + type (c_ptr), value :: geometry + end subroutine t8_fortran_cmesh_register_geometry_f + end Interface + + Interface + subroutine t8_fortran_cmesh_set_tree_class_f (cmesh, gtree_id, tree_class) & + bind (c, name = 't8_cmesh_set_tree_class') + use, intrinsic :: ISO_C_BINDING, only: c_ptr, c_int64_t, c_int + IMPLICIT NONE + type (c_ptr), value :: cmesh + integer (c_int64_t), value :: gtree_id + integer (c_int), value :: tree_class + end subroutine t8_fortran_cmesh_set_tree_class_f + end Interface + + Interface + subroutine t8_fortran_cmesh_set_tree_vertices_f (cmesh, ltree_id, vertices, num_vertices) & + bind (c, name = 't8_cmesh_set_tree_vertices') + use, intrinsic :: ISO_C_BINDING, only: c_ptr, c_int, c_int64_t + IMPLICIT NONE + type (c_ptr), value :: cmesh + integer (c_int64_t), value :: ltree_id + type(c_ptr),value :: vertices + integer (c_int), value :: num_vertices + end subroutine t8_fortran_cmesh_set_tree_vertices_f + end Interface + + Interface + subroutine t8_fortran_cmesh_set_join_f (cmesh, gtree1, gtree2, face1, face2, orientation) & + bind (c, name = 't8_cmesh_set_join') + use, intrinsic :: ISO_C_BINDING, only: c_ptr, c_int, c_int64_t + IMPLICIT NONE + type (c_ptr), value :: cmesh + integer (c_int64_t), value :: gtree1 + integer (c_int64_t), value :: gtree2 + integer (c_int), value :: face1 + integer (c_int), value :: face2 + integer (c_int), value :: orientation + end subroutine t8_fortran_cmesh_set_join_f + end Interface + + Interface + subroutine t8_fortran_cmesh_set_join_by_vertices_noConn_f (cmesh, ntrees, eclasses, vertices, do_both_directions) & + bind (c, name = 't8_fortran_cmesh_set_join_by_vertices_noConn') + use, intrinsic :: ISO_C_BINDING, only: c_ptr, c_int + IMPLICIT NONE + type (c_ptr), value :: cmesh + integer (c_int), value :: ntrees + type (c_ptr), value :: eclasses + type (c_ptr), value :: vertices + integer (c_int), value :: do_both_directions + end subroutine t8_fortran_cmesh_set_join_by_vertices_noConn_f + end Interface + + Interface + subroutine t8_fortran_cmesh_commit_f (cmesh, Ccom) & + bind (c, name = 't8_fortran_cmesh_commit') + use, intrinsic :: ISO_C_BINDING, only: c_ptr + IMPLICIT NONE + type (c_ptr), value :: cmesh + type (c_ptr), value :: Ccom + end subroutine t8_fortran_cmesh_commit_f + end Interface + + Interface + type (c_ptr) function t8_forest_new_uniform_default_f (cmesh, level, do_face_ghost, Ccomm) & + bind (c, name = 't8_forest_new_uniform_default') + use, intrinsic :: ISO_C_BINDING, only: c_ptr, c_int + IMPLICIT NONE + type (c_ptr), value :: cmesh + integer (c_int), value :: level + integer (c_int), value :: do_face_ghost + type (c_ptr), value :: Ccomm + end function t8_forest_new_uniform_default_f + end Interface + + + Interface + subroutine t8_forest_unref_f (forest) & + bind (c, name = 't8_forest_unref') + use, intrinsic :: ISO_C_BINDING, only: c_ptr + IMPLICIT NONE + type (c_ptr) :: forest + end subroutine t8_forest_unref_f + end Interface + + + Interface + integer (c_int) function t8_forest_write_vtk_f (forest, fileprefix) & + bind (c, name = 't8_forest_write_vtk') + use, intrinsic :: ISO_C_BINDING, only: c_ptr, c_int, c_char, c_double + IMPLICIT NONE + type (c_ptr), value :: forest + character (c_char) :: fileprefix + end function t8_forest_write_vtk_f + end Interface + + Interface + subroutine t8_forest_iterate_replace_f (forest_new, forest_old, replace_fn) & + bind (c, name = 't8_forest_iterate_replace') + use, intrinsic :: ISO_C_BINDING, only: c_ptr + IMPLICIT NONE + type (c_ptr), value :: forest_new + type (c_ptr), value :: forest_old + type (c_ptr), value :: replace_fn + end subroutine t8_forest_iterate_replace_f + end Interface + + Interface + subroutine t8_global_productionf_noargs_f (string) & + bind (c, name = 't8_global_productionf_noargs') + use, intrinsic :: ISO_C_BINDING, only: c_char + IMPLICIT NONE + character (c_char) :: string + end subroutine t8_global_productionf_noargs_f + end Interface + + Interface + subroutine t8_fortran_finalize_f () & + bind (c, name = 't8_fortran_finalize') + IMPLICIT NONE + end subroutine t8_fortran_finalize_f + end Interface + + ! Interface + ! type (c_ptr) function t8_fortran_adapt_by_coordinates_f (forest, forest_from, recursive, callback) & + ! bind (c, name = 't8_fortran_adapt_by_coordinates') + ! use, intrinsic :: ICO_C_BINDING, only : c_ptr, c_int + ! IMPLICIT NONE + ! type (c_ptr), value :: forest + ! type (c_ptr), value :: forest_from + ! integer (c_int), value :: recursive + ! type (c_ptr), value :: callback + ! end function t8_fortran_adapt_by_coordinates_f + ! end Interface + + Interface + subroutine t8_fortran_element_volume_f () & + bind (c, name = 't8_forest_element_volume') + use, intrinsic :: ISO_C_BINDING, only: c_ptr + IMPLICIT NONE + type (c_ptr), value :: forest + integer (c_int64_t), value :: ltreeid + type (c_ptr), value :: element + end subroutine t8_fortran_element_volume_f + end Interface + +End module t8_mo_fortran_interface From 1eb7cea88b0dbb04546e36ee093c08a76c9ae0a4 Mon Sep 17 00:00:00 2001 From: Chiara Hergl Date: Wed, 24 Jul 2024 08:08:51 +0200 Subject: [PATCH 03/42] Add t8_fortran_specific.mk --- t8_fortran_specific.mk | 45 ++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 45 insertions(+) create mode 100644 t8_fortran_specific.mk diff --git a/t8_fortran_specific.mk b/t8_fortran_specific.mk new file mode 100644 index 0000000000..2b4c35e457 --- /dev/null +++ b/t8_fortran_specific.mk @@ -0,0 +1,45 @@ +if T8_ENABLE_FORTRAN +# Clean up modules files in the root directory (if no module directory has been specified) +CLEANFILES += *.$(FC_MODEXT) + +# Get the supplied FCFLAGS +AM_FCFLAGS += @FCFLAGS@ + +# Define a variable holding the module directory (for a rule below) +t8_current_moddir = + +if T8_WITH_MODDIR +# Updates for the module output and include path (if a seperate module directory has been specified) +AM_FCFLAGS += $(FC_MODOUT)@T8_FORTRAN_MODULE_DIR@ $(FC_MODINC)@T8_FORTRAN_MODULE_DIR@ +AM_CPPFLAGS += -I@T8_FORTRAN_MODULE_DIR@ + +# Clean the module files in this directory +CLEANFILES += @T8_FORTRAN_MODULE_DIR@/*.$(FC_MODEXT) + +# Add the creation of the module directory as an order only prerequisite to the Fortran module files +$(MODSOURCES): %.f90 : | create-moddir + +# Rule to create the module directory +create-moddir: + @$(MKDIR_P) @T8_FORTRAN_MODULE_DIR@ + +# Save the module directory +t8_current_moddir += @T8_FORTRAN_MODULE_DIR@/ + +endif + +# If the install target is made, we will copy the module files into the include directory (after the installation of the header files) +install-data-hook: + @cp -fp $(t8_current_moddir)*.$(FC_MODEXT) $(includedir) + +# Define dependencies of the Fortran modules (in case they depend on other modules) +# This needs to be done in order to ensure the correct build process in any case + +# Define dependencies for all Fortran programs of the Fortran modules +# This needs to be done in order to ensure the correct build process in any case +# ... + +# TODO: Implement t8_fortran_test depends on the modules: t8_mo_fortran_interface +#example/Fortran/t8_fortran_test.o : api/t8_fortran_interface/t8_mo_fortran_interface.o + +endif From d8a13003743705c103590b27173b861683514067 Mon Sep 17 00:00:00 2001 From: Chiara Hergl Date: Wed, 24 Jul 2024 11:54:06 +0200 Subject: [PATCH 04/42] Add first fortran interface file --- .../t8_mo_fortran_interface.f90 | 249 ++++++++++++++++++ 1 file changed, 249 insertions(+) create mode 100644 api/t8_fortran_interface/t8_mo_fortran_interface.f90 diff --git a/api/t8_fortran_interface/t8_mo_fortran_interface.f90 b/api/t8_fortran_interface/t8_mo_fortran_interface.f90 new file mode 100644 index 0000000000..48a3aea7fb --- /dev/null +++ b/api/t8_fortran_interface/t8_mo_fortran_interface.f90 @@ -0,0 +1,249 @@ +module t8_mo_fortran_interface + + use, intrinsic :: ISO_C_BINDING + + + !!! Interface for t8_fortran_MPI_Comm_new + !!! Given a fortran MPI Communicator, converts it into C and + !!! returns a pointer to the C MPI communicator. + !!! This function allocates memory that needs to be freed with + !!! t8_fortran_mpi_comm_delete_f + !!! + !!! Code modified from: https://stackoverflow.com/questions/42530620/how-to-pass-mpi-communicator-handle-from-fortran-to-c-using-iso-c-binding + INTERFACE + type (C_PTR) FUNCTION t8_fortran_mpi_comm_new_f (FCOMM) & + BIND(C, NAME='t8_fortran_MPI_Comm_new') + use, intrinsic :: ISO_C_BINDING, only: c_int, c_ptr + IMPLICIT NONE + INTEGER (C_INT), VALUE :: Fcomm + END FUNCTION t8_fortran_mpi_comm_new_f + END INTERFACE + + !!! Free memory of a C MPI communicator pointer that was + !!! allocated using t8_fortran_mpi_comm_new_f + INTERFACE + subroutine t8_fortran_mpi_comm_delete_f (Ccomm) & + BIND(C, NAME='t8_fortran_MPI_Comm_delete') + use, intrinsic :: ISO_C_BINDING, only: c_ptr + IMPLICIT NONE + type (c_ptr), value :: Ccomm + END subroutine t8_fortran_mpi_comm_delete_f + END INTERFACE + + !!! Initialize sc and t8code with a given C MPI Communicator + Interface + subroutine t8_fortran_init_all_f (Ccomm) & + BIND(C, NAME='t8_fortran_init_all') + use, intrinsic :: ISO_C_BINDING, only: c_ptr + IMPLICIT NONE + type (c_ptr), value :: Ccomm + END subroutine t8_fortran_init_all_f + end Interface + + !!! Initialize sc and t8code with a given C MPI Communicator + Interface + subroutine t8_fortran_init_all_noMPI_f () & + BIND(C, NAME='t8_fortran_init_all_noMPI') + END subroutine t8_fortran_init_all_noMPI_f + end Interface + + Interface + type (c_ptr) function t8_cmesh_new_periodic_tri_f (Ccomm) & + bind (c, name = 't8_cmesh_new_periodic_tri_wrap') + use, intrinsic :: ISO_C_BINDING, only: c_ptr + IMPLICIT NONE + type (c_ptr), value :: Ccomm + end function t8_cmesh_new_periodic_tri_f + end Interface + + Interface + integer (c_int) function t8_cmesh_vtk_write_file_f (cmesh, fileprefix, scale) & + bind (c, name = 't8_cmesh_vtk_write_file') + use, intrinsic :: ISO_C_BINDING, only: c_ptr, c_int, c_char, c_double + IMPLICIT NONE + type (c_ptr), value :: cmesh + character (c_char) :: fileprefix + real (c_double), value :: scale + end function t8_cmesh_vtk_write_file_f + end Interface + + Interface + subroutine t8_cmesh_destroy_f (cmesh) & + bind (c, name = 't8_cmesh_destroy') + use, intrinsic :: ISO_C_BINDING, only: c_ptr + IMPLICIT NONE + type (c_ptr) :: cmesh + end subroutine t8_cmesh_destroy_f + end Interface + + Interface + subroutine t8_fortran_cmesh_init_f (cmesh) & + bind (c, name = 't8_cmesh_init') + use, intrinsic :: ISO_C_BINDING, only: c_ptr + IMPLICIT NONE + type (c_ptr) :: cmesh + end subroutine t8_fortran_cmesh_init_f + end Interface + + Interface + type (c_ptr) function t8_fortran_geometry_linear_new_f (dimension) & + bind (c, name = 't8_geometry_linear_new') + use, intrinsic :: ISO_C_BINDING, only: c_int, c_ptr + IMPLICIT NONE + integer (c_int), value :: dimension + end function t8_fortran_geometry_linear_new_f + end Interface + + Interface + subroutine t8_fortran_cmesh_register_geometry_f (cmesh, geometry) & + bind (c, name = 't8_cmesh_register_geometry') + use, intrinsic :: ISO_C_BINDING, only: c_ptr + IMPLICIT NONE + type (c_ptr), value :: cmesh + type (c_ptr), value :: geometry + end subroutine t8_fortran_cmesh_register_geometry_f + end Interface + + Interface + subroutine t8_fortran_cmesh_set_tree_class_f (cmesh, gtree_id, tree_class) & + bind (c, name = 't8_cmesh_set_tree_class') + use, intrinsic :: ISO_C_BINDING, only: c_ptr, c_int64_t, c_int + IMPLICIT NONE + type (c_ptr), value :: cmesh + integer (c_int64_t), value :: gtree_id + integer (c_int), value :: tree_class + end subroutine t8_fortran_cmesh_set_tree_class_f + end Interface + + Interface + subroutine t8_fortran_cmesh_set_tree_vertices_f (cmesh, ltree_id, vertices, num_vertices) & + bind (c, name = 't8_cmesh_set_tree_vertices') + use, intrinsic :: ISO_C_BINDING, only: c_ptr, c_int, c_int64_t + IMPLICIT NONE + type (c_ptr), value :: cmesh + integer (c_int64_t), value :: ltree_id + type(c_ptr),value :: vertices + integer (c_int), value :: num_vertices + end subroutine t8_fortran_cmesh_set_tree_vertices_f + end Interface + + Interface + subroutine t8_fortran_cmesh_set_join_f (cmesh, gtree1, gtree2, face1, face2, orientation) & + bind (c, name = 't8_cmesh_set_join') + use, intrinsic :: ISO_C_BINDING, only: c_ptr, c_int, c_int64_t + IMPLICIT NONE + type (c_ptr), value :: cmesh + integer (c_int64_t), value :: gtree1 + integer (c_int64_t), value :: gtree2 + integer (c_int), value :: face1 + integer (c_int), value :: face2 + integer (c_int), value :: orientation + end subroutine t8_fortran_cmesh_set_join_f + end Interface + + Interface + subroutine t8_fortran_cmesh_set_join_by_vertices_noConn_f (cmesh, ntrees, eclasses, vertices, do_both_directions) & + bind (c, name = 't8_fortran_cmesh_set_join_by_vertices_noConn') + use, intrinsic :: ISO_C_BINDING, only: c_ptr, c_int + IMPLICIT NONE + type (c_ptr), value :: cmesh + integer (c_int), value :: ntrees + type (c_ptr), value :: eclasses + type (c_ptr), value :: vertices + integer (c_int), value :: do_both_directions + end subroutine t8_fortran_cmesh_set_join_by_vertices_noConn_f + end Interface + + Interface + subroutine t8_fortran_cmesh_commit_f (cmesh, Ccom) & + bind (c, name = 't8_fortran_cmesh_commit') + use, intrinsic :: ISO_C_BINDING, only: c_ptr + IMPLICIT NONE + type (c_ptr), value :: cmesh + type (c_ptr), value :: Ccom + end subroutine t8_fortran_cmesh_commit_f + end Interface + + Interface + type (c_ptr) function t8_forest_new_uniform_default_f (cmesh, level, do_face_ghost, Ccomm) & + bind (c, name = 't8_forest_new_uniform_default') + use, intrinsic :: ISO_C_BINDING, only: c_ptr, c_int + IMPLICIT NONE + type (c_ptr), value :: cmesh + integer (c_int), value :: level + integer (c_int), value :: do_face_ghost + type (c_ptr), value :: Ccomm + end function t8_forest_new_uniform_default_f + end Interface + + + Interface + subroutine t8_forest_unref_f (forest) & + bind (c, name = 't8_forest_unref') + use, intrinsic :: ISO_C_BINDING, only: c_ptr + IMPLICIT NONE + type (c_ptr) :: forest + end subroutine t8_forest_unref_f + end Interface + + + Interface + integer (c_int) function t8_forest_write_vtk_f (forest, fileprefix) & + bind (c, name = 't8_forest_write_vtk') + use, intrinsic :: ISO_C_BINDING, only: c_ptr, c_int, c_char, c_double + IMPLICIT NONE + type (c_ptr), value :: forest + character (c_char) :: fileprefix + end function t8_forest_write_vtk_f + end Interface + + Interface + subroutine t8_forest_iterate_replace_f (forest_new, forest_old, replace_fn) & + bind (c, name = 't8_forest_iterate_replace') + use, intrinsic :: ISO_C_BINDING, only: c_ptr + IMPLICIT NONE + type (c_ptr), value :: forest_new + type (c_ptr), value :: forest_old + type (c_ptr), value :: replace_fn + end subroutine t8_forest_iterate_replace_f + end Interface + + Interface + subroutine t8_global_productionf_noargs_f (string) & + bind (c, name = 't8_global_productionf_noargs') + use, intrinsic :: ISO_C_BINDING, only: c_char + IMPLICIT NONE + character (c_char) :: string + end subroutine t8_global_productionf_noargs_f + end Interface + + Interface + subroutine t8_fortran_finalize_f () & + bind (c, name = 't8_fortran_finalize') + IMPLICIT NONE + end subroutine t8_fortran_finalize_f + end Interface + + Interface + type (c_ptr) function t8_fortran_adapt_by_coordinates_f (forest, recursive, callback) & + bind (c, name = 't8_fortran_adapt_by_coordinates') + use, intrinsic :: ISO_C_BINDING, only : c_ptr, c_int + IMPLICIT NONE + type (c_ptr), value :: forest + integer (c_int), value :: recursive + type (c_ptr), value :: callback + end function t8_fortran_adapt_by_coordinates_f + end Interface + + Interface + subroutine t8_fortran_element_volume_f (forest, ltreeid, element) & + bind (c, name = 't8_forest_element_volume') + use, intrinsic :: ISO_C_BINDING, only: c_ptr, c_int + IMPLICIT NONE + type (c_ptr), value :: forest + integer (c_int), value :: ltreeid + type (c_ptr), value :: element + end subroutine t8_fortran_element_volume_f + end Interface + +End module t8_mo_fortran_interface From f1f7e4c5d6d0d192ae7e1cce3a293dd2df33b66a Mon Sep 17 00:00:00 2001 From: Chiara Hergl Date: Wed, 24 Jul 2024 11:57:17 +0200 Subject: [PATCH 05/42] Add auto-build for fortran --- api/Makefile.am | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/api/Makefile.am b/api/Makefile.am index ed2d0b0a3a..90c3788bb5 100644 --- a/api/Makefile.am +++ b/api/Makefile.am @@ -10,21 +10,20 @@ libt8_installed_headers_fortran_interface = \ dist_fortraninterfaceinclude_HEADERS = $(libt8_installed_headers_fortran_interface) -t8_fortran_module_sources = src/t8_fortran_interface/t8_mo_fortran_interface.f90 \ -src/t8_messy/t8_mo_messy_coupler_interface.f90 +t8_fortran_module_sources = api/t8_fortran_interface/t8_mo_fortran_interface.f90 # Add the Fortran sources to the lib libt8_compiled_sources += $(t8_fortran_module_sources) # Save the module sources in a different variable for later use AM_FCFLAGS = -AM_CPPFLAGS = -I@top_srcdir@/api +AM_CPPFLAGS += -I@top_srcdir@/api MODSOURCES = $(t8_fortran_module_sources) src_libt8_la_FCFLAGS = $(AM_FCFLAGS) src_libt8_la_FFLAGS = $(FFLAGS) # Include the Fortran specific variables and rules -include t8_fortran_specific.mk +#include t8_fortran_specific.mk endif From f5128c702349fa215703951e7085fa3dc0993964 Mon Sep 17 00:00:00 2001 From: Chiara Hergl Date: Wed, 24 Jul 2024 11:57:38 +0200 Subject: [PATCH 06/42] Add empty fortran file --- .../t8_mo_fortran_interface.f90 | 250 ------------------ 1 file changed, 250 deletions(-) diff --git a/api/t8_fortran_interface/t8_mo_fortran_interface.f90 b/api/t8_fortran_interface/t8_mo_fortran_interface.f90 index 17aaebff11..e69de29bb2 100644 --- a/api/t8_fortran_interface/t8_mo_fortran_interface.f90 +++ b/api/t8_fortran_interface/t8_mo_fortran_interface.f90 @@ -1,250 +0,0 @@ -module t8_mo_fortran_interface - - use, intrinsic :: ISO_C_BINDING - - - !!! Interface for t8_fortran_MPI_Comm_new - !!! Given a fortran MPI Communicator, converts it into C and - !!! returns a pointer to the C MPI communicator. - !!! This function allocates memory that needs to be freed with - !!! t8_fortran_mpi_comm_delete_f - !!! - !!! Code modified from: https://stackoverflow.com/questions/42530620/how-to-pass-mpi-communicator-handle-from-fortran-to-c-using-iso-c-binding - INTERFACE - type (C_PTR) FUNCTION t8_fortran_mpi_comm_new_f (FCOMM) & - BIND(C, NAME='t8_fortran_MPI_Comm_new') - use, intrinsic :: ISO_C_BINDING, only: c_int, c_ptr - IMPLICIT NONE - INTEGER (C_INT), VALUE :: Fcomm - END FUNCTION t8_fortran_mpi_comm_new_f - END INTERFACE - - !!! Free memory of a C MPI communicator pointer that was - !!! allocated using t8_fortran_mpi_comm_new_f - INTERFACE - subroutine t8_fortran_mpi_comm_delete_f (Ccomm) & - BIND(C, NAME='t8_fortran_MPI_Comm_delete') - use, intrinsic :: ISO_C_BINDING, only: c_ptr - IMPLICIT NONE - type (c_ptr), value :: Ccomm - END subroutine t8_fortran_mpi_comm_delete_f - END INTERFACE - - !!! Initialize sc and t8code with a given C MPI Communicator - Interface - subroutine t8_fortran_init_all_f (Ccomm) & - BIND(C, NAME='t8_fortran_init_all') - use, intrinsic :: ISO_C_BINDING, only: c_ptr - IMPLICIT NONE - type (c_ptr), value :: Ccomm - END subroutine t8_fortran_init_all_f - end Interface - - !!! Initialize sc and t8code with a given C MPI Communicator - Interface - subroutine t8_fortran_init_all_noMPI_f () & - BIND(C, NAME='t8_fortran_init_all_noMPI') - END subroutine t8_fortran_init_all_noMPI_f - end Interface - - Interface - type (c_ptr) function t8_cmesh_new_periodic_tri_f (Ccomm) & - bind (c, name = 't8_cmesh_new_periodic_tri_wrap') - use, intrinsic :: ISO_C_BINDING, only: c_ptr - IMPLICIT NONE - type (c_ptr), value :: Ccomm - end function t8_cmesh_new_periodic_tri_f - end Interface - - Interface - integer (c_int) function t8_cmesh_vtk_write_file_f (cmesh, fileprefix, scale) & - bind (c, name = 't8_cmesh_vtk_write_file') - use, intrinsic :: ISO_C_BINDING, only: c_ptr, c_int, c_char, c_double - IMPLICIT NONE - type (c_ptr), value :: cmesh - character (c_char) :: fileprefix - real (c_double), value :: scale - end function t8_cmesh_vtk_write_file_f - end Interface - - Interface - subroutine t8_cmesh_destroy_f (cmesh) & - bind (c, name = 't8_cmesh_destroy') - use, intrinsic :: ISO_C_BINDING, only: c_ptr - IMPLICIT NONE - type (c_ptr) :: cmesh - end subroutine t8_cmesh_destroy_f - end Interface - - Interface - subroutine t8_fortran_cmesh_init_f (cmesh) & - bind (c, name = 't8_cmesh_init') - use, intrinsic :: ISO_C_BINDING, only: c_ptr - IMPLICIT NONE - type (c_ptr) :: cmesh - end subroutine t8_fortran_cmesh_init_f - end Interface - - Interface - type (c_ptr) function t8_fortran_geometry_linear_new_f (dimension) & - bind (c, name = 't8_geometry_linear_new') - use, intrinsic :: ISO_C_BINDING, only: c_int, c_ptr - IMPLICIT NONE - integer (c_int), value :: dimension - end function t8_fortran_geometry_linear_new_f - end Interface - - Interface - subroutine t8_fortran_cmesh_register_geometry_f (cmesh, geometry) & - bind (c, name = 't8_cmesh_register_geometry') - use, intrinsic :: ISO_C_BINDING, only: c_ptr - IMPLICIT NONE - type (c_ptr), value :: cmesh - type (c_ptr), value :: geometry - end subroutine t8_fortran_cmesh_register_geometry_f - end Interface - - Interface - subroutine t8_fortran_cmesh_set_tree_class_f (cmesh, gtree_id, tree_class) & - bind (c, name = 't8_cmesh_set_tree_class') - use, intrinsic :: ISO_C_BINDING, only: c_ptr, c_int64_t, c_int - IMPLICIT NONE - type (c_ptr), value :: cmesh - integer (c_int64_t), value :: gtree_id - integer (c_int), value :: tree_class - end subroutine t8_fortran_cmesh_set_tree_class_f - end Interface - - Interface - subroutine t8_fortran_cmesh_set_tree_vertices_f (cmesh, ltree_id, vertices, num_vertices) & - bind (c, name = 't8_cmesh_set_tree_vertices') - use, intrinsic :: ISO_C_BINDING, only: c_ptr, c_int, c_int64_t - IMPLICIT NONE - type (c_ptr), value :: cmesh - integer (c_int64_t), value :: ltree_id - type(c_ptr),value :: vertices - integer (c_int), value :: num_vertices - end subroutine t8_fortran_cmesh_set_tree_vertices_f - end Interface - - Interface - subroutine t8_fortran_cmesh_set_join_f (cmesh, gtree1, gtree2, face1, face2, orientation) & - bind (c, name = 't8_cmesh_set_join') - use, intrinsic :: ISO_C_BINDING, only: c_ptr, c_int, c_int64_t - IMPLICIT NONE - type (c_ptr), value :: cmesh - integer (c_int64_t), value :: gtree1 - integer (c_int64_t), value :: gtree2 - integer (c_int), value :: face1 - integer (c_int), value :: face2 - integer (c_int), value :: orientation - end subroutine t8_fortran_cmesh_set_join_f - end Interface - - Interface - subroutine t8_fortran_cmesh_set_join_by_vertices_noConn_f (cmesh, ntrees, eclasses, vertices, do_both_directions) & - bind (c, name = 't8_fortran_cmesh_set_join_by_vertices_noConn') - use, intrinsic :: ISO_C_BINDING, only: c_ptr, c_int - IMPLICIT NONE - type (c_ptr), value :: cmesh - integer (c_int), value :: ntrees - type (c_ptr), value :: eclasses - type (c_ptr), value :: vertices - integer (c_int), value :: do_both_directions - end subroutine t8_fortran_cmesh_set_join_by_vertices_noConn_f - end Interface - - Interface - subroutine t8_fortran_cmesh_commit_f (cmesh, Ccom) & - bind (c, name = 't8_fortran_cmesh_commit') - use, intrinsic :: ISO_C_BINDING, only: c_ptr - IMPLICIT NONE - type (c_ptr), value :: cmesh - type (c_ptr), value :: Ccom - end subroutine t8_fortran_cmesh_commit_f - end Interface - - Interface - type (c_ptr) function t8_forest_new_uniform_default_f (cmesh, level, do_face_ghost, Ccomm) & - bind (c, name = 't8_forest_new_uniform_default') - use, intrinsic :: ISO_C_BINDING, only: c_ptr, c_int - IMPLICIT NONE - type (c_ptr), value :: cmesh - integer (c_int), value :: level - integer (c_int), value :: do_face_ghost - type (c_ptr), value :: Ccomm - end function t8_forest_new_uniform_default_f - end Interface - - - Interface - subroutine t8_forest_unref_f (forest) & - bind (c, name = 't8_forest_unref') - use, intrinsic :: ISO_C_BINDING, only: c_ptr - IMPLICIT NONE - type (c_ptr) :: forest - end subroutine t8_forest_unref_f - end Interface - - - Interface - integer (c_int) function t8_forest_write_vtk_f (forest, fileprefix) & - bind (c, name = 't8_forest_write_vtk') - use, intrinsic :: ISO_C_BINDING, only: c_ptr, c_int, c_char, c_double - IMPLICIT NONE - type (c_ptr), value :: forest - character (c_char) :: fileprefix - end function t8_forest_write_vtk_f - end Interface - - Interface - subroutine t8_forest_iterate_replace_f (forest_new, forest_old, replace_fn) & - bind (c, name = 't8_forest_iterate_replace') - use, intrinsic :: ISO_C_BINDING, only: c_ptr - IMPLICIT NONE - type (c_ptr), value :: forest_new - type (c_ptr), value :: forest_old - type (c_ptr), value :: replace_fn - end subroutine t8_forest_iterate_replace_f - end Interface - - Interface - subroutine t8_global_productionf_noargs_f (string) & - bind (c, name = 't8_global_productionf_noargs') - use, intrinsic :: ISO_C_BINDING, only: c_char - IMPLICIT NONE - character (c_char) :: string - end subroutine t8_global_productionf_noargs_f - end Interface - - Interface - subroutine t8_fortran_finalize_f () & - bind (c, name = 't8_fortran_finalize') - IMPLICIT NONE - end subroutine t8_fortran_finalize_f - end Interface - - ! Interface - ! type (c_ptr) function t8_fortran_adapt_by_coordinates_f (forest, forest_from, recursive, callback) & - ! bind (c, name = 't8_fortran_adapt_by_coordinates') - ! use, intrinsic :: ICO_C_BINDING, only : c_ptr, c_int - ! IMPLICIT NONE - ! type (c_ptr), value :: forest - ! type (c_ptr), value :: forest_from - ! integer (c_int), value :: recursive - ! type (c_ptr), value :: callback - ! end function t8_fortran_adapt_by_coordinates_f - ! end Interface - - Interface - subroutine t8_fortran_element_volume_f () & - bind (c, name = 't8_forest_element_volume') - use, intrinsic :: ISO_C_BINDING, only: c_ptr - IMPLICIT NONE - type (c_ptr), value :: forest - integer (c_int64_t), value :: ltreeid - type (c_ptr), value :: element - end subroutine t8_fortran_element_volume_f - end Interface - -End module t8_mo_fortran_interface From e467b8adb3ce73056bc726cab4321fdc8416b072 Mon Sep 17 00:00:00 2001 From: Chiara Hergl Date: Wed, 24 Jul 2024 11:58:41 +0200 Subject: [PATCH 07/42] Add fortran configure file --- config/t8_fortran.m4 | 34 ++++++++++++++++++++++++++++++++++ 1 file changed, 34 insertions(+) create mode 100644 config/t8_fortran.m4 diff --git a/config/t8_fortran.m4 b/config/t8_fortran.m4 new file mode 100644 index 0000000000..b1e452376e --- /dev/null +++ b/config/t8_fortran.m4 @@ -0,0 +1,34 @@ +dnl T8_CHECK_FORTRAN +dnl This functions checks some properties of Fortran modules and +dnl whether specific directory for the Fortran module files has been specified or not. +dnl +dnl A directory may be specified by the option --with-moddir= +dnl This option is only of relevance if the option --enable-fortran has been chosen, +dnl since only in this case Fortran codes will be compiled +dnl +AC_DEFUN([T8_CHECK_FORTRAN], [ + +dnl Check if a directory has been specified which will hold the module files +T8_ARG_WITH([moddir], + [if Fortran modules will be built, this option specifies an explicit directory which should hold the module files (use --with-moddir=)], + [MODDIR]) + +dnl If Fortran is enabled +if test "x$T8_ENABLE_FORTRAN" != xno ; then + +dnl Check the properties of Fortran modules (after the Fortran Compiler has been found by MPI_ENGAGE) +AC_FC_MODULE_EXTENSION +AC_FC_MODULE_FLAG +AC_FC_MODULE_OUTPUT_FLAG + +if test "x$T8_WITH_MODDIR" = xyes ; then + dnl The option is given without a directory + AC_MSG_ERROR([missing directory path for the module directory]) +elif test "x$T8_WITH_MODDIR" != xno ; then + AC_MSG_NOTICE([we have set a module dir var]) + dnl Substitute the variable in the makefile + AC_SUBST(T8_FORTRAN_MODULE_DIR, $T8_WITH_MODDIR) +fi + +fi +]) From 0cf9128bb19e239450a2f8126f7f987a1595bee7 Mon Sep 17 00:00:00 2001 From: Chiara Hergl Date: Wed, 24 Jul 2024 11:59:43 +0200 Subject: [PATCH 08/42] Add missing header file --- api/t8_fortran_interface/t8_fortran_interface.h | 1 + 1 file changed, 1 insertion(+) diff --git a/api/t8_fortran_interface/t8_fortran_interface.h b/api/t8_fortran_interface/t8_fortran_interface.h index bdfcfeadf5..83de06c804 100644 --- a/api/t8_fortran_interface/t8_fortran_interface.h +++ b/api/t8_fortran_interface/t8_fortran_interface.h @@ -35,6 +35,7 @@ #include #include #include +#include typedef int (*t8_fortran_adapt_coordinate_callback) (double x, double y, double z, int is_family); From addf7fb6cdc7ffb88d32a9aa4ab450fdd94ca126 Mon Sep 17 00:00:00 2001 From: Chiara Hergl Date: Wed, 24 Jul 2024 12:00:18 +0200 Subject: [PATCH 09/42] config file not needed --- config/t8_fortran.m4 | 34 ---------------------------------- 1 file changed, 34 deletions(-) delete mode 100644 config/t8_fortran.m4 diff --git a/config/t8_fortran.m4 b/config/t8_fortran.m4 deleted file mode 100644 index b1e452376e..0000000000 --- a/config/t8_fortran.m4 +++ /dev/null @@ -1,34 +0,0 @@ -dnl T8_CHECK_FORTRAN -dnl This functions checks some properties of Fortran modules and -dnl whether specific directory for the Fortran module files has been specified or not. -dnl -dnl A directory may be specified by the option --with-moddir= -dnl This option is only of relevance if the option --enable-fortran has been chosen, -dnl since only in this case Fortran codes will be compiled -dnl -AC_DEFUN([T8_CHECK_FORTRAN], [ - -dnl Check if a directory has been specified which will hold the module files -T8_ARG_WITH([moddir], - [if Fortran modules will be built, this option specifies an explicit directory which should hold the module files (use --with-moddir=)], - [MODDIR]) - -dnl If Fortran is enabled -if test "x$T8_ENABLE_FORTRAN" != xno ; then - -dnl Check the properties of Fortran modules (after the Fortran Compiler has been found by MPI_ENGAGE) -AC_FC_MODULE_EXTENSION -AC_FC_MODULE_FLAG -AC_FC_MODULE_OUTPUT_FLAG - -if test "x$T8_WITH_MODDIR" = xyes ; then - dnl The option is given without a directory - AC_MSG_ERROR([missing directory path for the module directory]) -elif test "x$T8_WITH_MODDIR" != xno ; then - AC_MSG_NOTICE([we have set a module dir var]) - dnl Substitute the variable in the makefile - AC_SUBST(T8_FORTRAN_MODULE_DIR, $T8_WITH_MODDIR) -fi - -fi -]) From 709a71b5ffbf01b28c5bfc58b2d8f21c2b016720 Mon Sep 17 00:00:00 2001 From: Chiara Hergl Date: Wed, 24 Jul 2024 12:12:31 +0200 Subject: [PATCH 10/42] Correct typo --- t8_fortran_specific.mk | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/t8_fortran_specific.mk b/t8_fortran_specific.mk index 2b4c35e457..0392a631f3 100644 --- a/t8_fortran_specific.mk +++ b/t8_fortran_specific.mk @@ -9,7 +9,7 @@ AM_FCFLAGS += @FCFLAGS@ t8_current_moddir = if T8_WITH_MODDIR -# Updates for the module output and include path (if a seperate module directory has been specified) +# Updates for the module output and include path (if a separate module directory has been specified) AM_FCFLAGS += $(FC_MODOUT)@T8_FORTRAN_MODULE_DIR@ $(FC_MODINC)@T8_FORTRAN_MODULE_DIR@ AM_CPPFLAGS += -I@T8_FORTRAN_MODULE_DIR@ From 1bfa26753fa005c8dd1aacf885aff4adc32bed40 Mon Sep 17 00:00:00 2001 From: Chiara Hergl Date: Mon, 29 Jul 2024 08:03:26 +0200 Subject: [PATCH 11/42] Add functions in interface --- .../t8_mo_fortran_interface.f90 | 58 +++++++++++++++++++ 1 file changed, 58 insertions(+) diff --git a/api/t8_fortran_interface/t8_mo_fortran_interface.f90 b/api/t8_fortran_interface/t8_mo_fortran_interface.f90 index 48a3aea7fb..3f85edb6e9 100644 --- a/api/t8_fortran_interface/t8_mo_fortran_interface.f90 +++ b/api/t8_fortran_interface/t8_mo_fortran_interface.f90 @@ -208,6 +208,64 @@ subroutine t8_forest_iterate_replace_f (forest_new, forest_old, replace_fn) & end subroutine t8_forest_iterate_replace_f end Interface + Interface + integer (c_int) function t8_forest_get_local_num_elements (forest) & + bind (c, name = 't8_forest_get_local_num_elements') + use, intrinsic :: ISO_C_BINDING, only: c_ptr, c_int + IMPLICIT NONE + type (c_ptr), value :: forest + end function t8_forest_get_local_num_elements + end Interface + + Interface + integer (c_int) function t8_forest_get_global_num_elements (forest) & + bind (c, name = 't8_forest_get_global_num_elements') + use, intrinsic :: ISO_C_BINDING, only: c_ptr, c_int + IMPLICIT NONE + type (c_ptr), value :: forest + end function t8_forest_get_global_num_elements + end Interface + + Interface + integer (c_int) function t8_forest_get_num_local_trees (forest) & + bind (c, name = 't8_forest_get_num_local_trees') + use, intrinsic :: ISO_C_BINDING, only: c_ptr, c_int + IMPLICIT NONE + type (c_ptr), value :: forest + end function t8_forest_get_num_local_trees + end Interface + + Interface + integer (c_int) function t8_forest_get_tree_num_elements (forest, ltreeid) & + bind (c, name = 't8_forest_get_tree_num_elements') + use, intrinsic :: ISO_C_BINDING, only: c_ptr, c_int + IMPLICIT NONE + type (c_ptr), value :: forest + integer (c_int), value :: ltreeid + end function t8_forest_get_tree_num_elements + end Interface + + Interface + type (c_ptr) function t8_forest_get_element_in_tree (forest, ltreeid, leid_in_tree) & + bind (c, name = 't8_forest_get_element_in_tree') + use, intrinsic :: ISO_C_BINDING, only: c_ptr, c_int + IMPLICIT NONE + type (c_ptr), value :: forest + integer (c_int), value :: ltreeid, leid_in_tree + end function t8_forest_get_element_in_tree + end Interface + + Interface + subroutine t8_forest_element_from_ref_coords (forest, ltreeid, element, ref_coords, num_coords, coords_out) & + bind (c, name = 't8_forest_element_from_ref_coords') + use, intrinsic :: ISO_C_BINDING, only: c_ptr, c_int, c_double + IMPLICIT NONE + type (c_ptr), value :: forest, element + integer (c_int), value :: ltreeid, num_coords + real (c_double), dimension(3) :: ref_coords, coords_out + end subroutine t8_forest_element_from_ref_coords + end Interface + Interface subroutine t8_global_productionf_noargs_f (string) & bind (c, name = 't8_global_productionf_noargs') From 472bb8890d5e44c662ec8e416e99ca6850abb43c Mon Sep 17 00:00:00 2001 From: Sandro Elsweijer Date: Mon, 12 Aug 2024 10:47:51 +0200 Subject: [PATCH 12/42] add api testfile --- .github/workflows/tests_cmake_t8code_api.yml | 107 +++++++++++++++++++ 1 file changed, 107 insertions(+) create mode 100644 .github/workflows/tests_cmake_t8code_api.yml diff --git a/.github/workflows/tests_cmake_t8code_api.yml b/.github/workflows/tests_cmake_t8code_api.yml new file mode 100644 index 0000000000..ee3c75047d --- /dev/null +++ b/.github/workflows/tests_cmake_t8code_api.yml @@ -0,0 +1,107 @@ +name: CMake tests t8code api + + +# This file is part of t8code. +# t8code is a C library to manage a collection (a forest) of multiple +# connected adaptive space-trees of general element types in parallel. +# +# Copyright (C) 2024 the developers +# +# t8code is free software; you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation; either version 2 of the License, or +# (at your option) any later version. +# +# t8code is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with t8code; if not, write to the Free Software Foundation, Inc., +# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. + +on: + workflow_call: + inputs: + MAKEFLAGS: + required: true + type: string + MPI: + required: true + type: string + BUILD_TYPE: + required: true + type: string + LESS_TESTS: + required: true + type: boolean + +jobs: + t8code_cmake_tests: + timeout-minutes: 30 + runs-on: ubuntu-latest + container: dlramr/t8code-ubuntu:t8-dependencies + steps: +# +# Setup +# + - name: Download artifacts + uses: actions/download-artifact@v4 + with: + name: SC_P4EST_MPI_${{ inputs.MPI }} + - name: untar artifact + run: tar -xf artifact.tar && rm artifact.tar + - name: Update packages + run: apt-get update && apt-get upgrade -y + # This seems to be necessary because of the docker container + - name: disable ownership checks + run: git config --global --add safe.directory '*' + - name: Get input vars + run: export MAKEFLAGS="${{ inputs.MAKEFLAGS }}" + && export MPI="${{ inputs.MPI }}" + && export BUILD_TYPE="${{ inputs.BUILD_TYPE }}" + && export SC_PATH=$PWD/sc/build/$BUILD_TYPE + && export P4EST_PATH=$PWD/p4est/build/$BUILD_TYPE + && echo MAKEFLAGS="$MAKEFLAGS" >> $GITHUB_ENV + && echo MPI="$MPI" >> $GITHUB_ENV + && echo BUILD_TYPE="$BUILD_TYPE" >> $GITHUB_ENV + && echo SC_PATH="$SC_PATH" >> $GITHUB_ENV + && echo P4EST_PATH="$P4EST_PATH" >> $GITHUB_ENV +# +# T8CODE +# +# + # build config vars + - name: less-test option + if: ${{ inputs.LESS_TESTS }} + run: export LESS_TEST_OPTION="-DT8CODE_ENABLE_LESS_TESTS=ON" + && echo LESS_TEST_OPTION="$LESS_TEST_OPTION" >> $GITHUB_ENV + - name: build config variables + run: export CONFIG_OPTIONS="${LESS_TEST_OPTION} -GNinja -DT8CODE_USE_SYSTEM_SC=ON -DT8CODE_USE_SYSTEM_P4EST=ON -DT8CODE_BUILD_PEDANTIC=ON -DT8CODE_ENABLE_MPI=$MPI -DCMAKE_BUILD_TYPE=$BUILD_TYPE -DSC_DIR=$SC_PATH/install/cmake -DP4EST_DIR=$P4EST_PATH/install/cmake" + && echo CONFIG_OPTIONS="$CONFIG_OPTIONS" >> $GITHUB_ENV + # cmake and test with fortran + - name: check fortran + run: echo "Checking fortran" + - name: echo cmake line + run: echo cmake ../ $CONFIG_OPTIONS -DT8CODE_ENABLE_FORTRAN=ON + - name: cmake MPI fortran debug + run: mkdir build_fortran && cd build_fortran && cmake ../ $CONFIG_OPTIONS -DT8CODE_ENABLE_FORTRAN=ON + - name: OnFailUploadLog + if: failure() + uses: actions/upload-artifact@v4 + with: + name: cmake_${{ inputs.BUILD_TYPE }}_MPI_${{ inputs.MPI }}_fortran.log + path: build_fortran/CMakeFiles/CMakeOutput.log + - name: make + run: cd build_fortran && ninja $MAKEFLAGS + - name: ninja install + run: cd build_fortran && ninja install $MAKEFLAGS + - name: ninja test + run: cd build_fortran && ninja test $MAKEFLAGS + - name: OnFailUploadLog + if: failure() + uses: actions/upload-artifact@v4 + with: + name: test-suite_${{ inputs.BUILD_TYPE }}_MPI_${{ inputs.MPI }}_fortran.log + path: build_fortran/Testing/Temporary/LastTest.log From 80d806a6057a78e21516728c178706e5148711a9 Mon Sep 17 00:00:00 2001 From: Sandro Elsweijer Date: Mon, 12 Aug 2024 10:48:09 +0200 Subject: [PATCH 13/42] add api tests to workflow --- .github/workflows/tests_cmake_testsuite.yml | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/.github/workflows/tests_cmake_testsuite.yml b/.github/workflows/tests_cmake_testsuite.yml index ba3616153c..f6c7ca8d9d 100644 --- a/.github/workflows/tests_cmake_testsuite.yml +++ b/.github/workflows/tests_cmake_testsuite.yml @@ -114,3 +114,20 @@ jobs: BUILD_TYPE: ${{ matrix.BUILD_TYPE }} LESS_TESTS: ${{ github.event_name == 'pull_request' }} + # Run t8code linkage tests with and without MPI and in serial and debug mode + t8code_api_tests: + if: (github.event_name == 'schedule' && github.repository == 'DLR-AMR/t8code') || (github.event_name != 'schedule') && false + uses: ./.github/workflows/tests_cmake_t8code_api.yml + strategy: + fail-fast: false + matrix: + MPI: [OFF, ON] + BUILD_TYPE: [Debug, Release] + include: + - MAKEFLAGS: -j4 + needs: preparation + with: + MAKEFLAGS: ${{ matrix.MAKEFLAGS }} + MPI: ${{ matrix.MPI }} + BUILD_TYPE: ${{ matrix.BUILD_TYPE }} + LESS_TESTS: ${{ github.event_name == 'pull_request' }} From da5132d3c376f80be54172dd09ab4a3b8c0c8e6f Mon Sep 17 00:00:00 2001 From: Chiara Hergl Date: Mon, 12 Aug 2024 11:17:51 +0200 Subject: [PATCH 14/42] Indentation --- .../t8_fortran_interface.h | 136 +++++++++--------- 1 file changed, 68 insertions(+), 68 deletions(-) diff --git a/api/t8_fortran_interface/t8_fortran_interface.h b/api/t8_fortran_interface/t8_fortran_interface.h index d47001aa64..195205f280 100644 --- a/api/t8_fortran_interface/t8_fortran_interface.h +++ b/api/t8_fortran_interface/t8_fortran_interface.h @@ -18,8 +18,8 @@ You should have received a copy of the GNU General Public License along with t8code; if not, write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. -*/ - +*/ + /** \file t8_fortran_interface.h * In this file we provide a basic Fortran interface * for some functions of t8code. @@ -27,52 +27,52 @@ * t8code function. * We only export a minimum of the actual t8code functionality * to Fortran. - */ - -#ifndef T8_FORTRAN_INTERFACE_H -#define T8_FORTRAN_INTERFACE_H - -#include -#include -#include -#include - -typedef int (*t8_fortran_adapt_coordinate_callback) (double x, double y, double z, int is_family); - -/* A fallback type if t8code is not built with MPI */ -typedef -#ifdef T8_ENABLE_MPI - MPI_Fint -#else - int -#endif - MPI_T8_Fint; - -T8_EXTERN_C_BEGIN (); - + */ + +#ifndef T8_FORTRAN_INTERFACE_H +#define T8_FORTRAN_INTERFACE_H + +#include +#include +#include +#include + +typedef int (*t8_fortran_adapt_coordinate_callback) (double x, double y, double z, int is_family); + +/* A fallback type if t8code is not built with MPI */ +typedef +#ifdef T8_ENABLE_MPI + MPI_Fint +#else + int +#endif + MPI_T8_Fint; + +T8_EXTERN_C_BEGIN (); + /** Initialize sc and t8code with SC_MPI_COMM_WORLD communicator * and SC_LP_DEFAULT logging. * This call is equivalent to * sc_init (comm, 1, 1, NULL, SC_LP_ESSENTIAL); * t8_init (SC_LP_DEFAULT); * \param [in] comm The MPI communicator to use. - */ -void -t8_fortran_init_all (sc_MPI_Comm *comm); - + */ +void +t8_fortran_init_all (sc_MPI_Comm *comm); + /** Finalize sc. This wraps sc_finalize in order to have consistent * naming with t8_fortran_init_all. - */ -void -t8_fortran_finalize (); - + */ +void +t8_fortran_finalize (); + /** Commit cmesh. This wraps cmesh_commit in order to use the dereferenced communicator. * \param [in, out] cmesh Cmesh to commit * \param [in] Ccomm Pointer to a C MPI communicator. -*/ -void -t8_fortran_cmesh_commit (t8_cmesh_t cmesh, sc_MPI_Comm *comm); - +*/ +void +t8_fortran_cmesh_commit (t8_cmesh_t cmesh, sc_MPI_Comm *comm); + /** This function calls t8_cmesh_set_join_by_stash with connectivity = NULL. * \param[in,out] cmesh Pointer to a t8code cmesh object. If set to NULL this argument is ignored. * \param[in] do_both_directions Compute the connectivity from both neighboring sides. @@ -82,10 +82,10 @@ t8_fortran_cmesh_commit (t8_cmesh_t cmesh, sc_MPI_Comm *comm); * consider to use a fully featured mesh generator. * * \note This routine does not detect periodic boundaries. -*/ -void -t8_fortran_cmesh_set_join_by_stash_noConn (t8_cmesh_t cmesh, const int do_both_directions); - +*/ +void +t8_fortran_cmesh_set_join_by_stash_noConn (t8_cmesh_t cmesh, const int do_both_directions); + /** Translate a fortran MPI communicator into a C MPI communicator * and return a pointer to it. * \param [in] Fcomm Fortran MPI Communicator @@ -94,24 +94,24 @@ t8_fortran_cmesh_set_join_by_stash_noConn (t8_cmesh_t cmesh, const int do_both_d * Call \ref t8_fortran_MPI_Comm_delete to free this memory. * \note t8code needs to be configured with MPI support to be able to use * this function. - */ -sc_MPI_Comm * -t8_fortran_MPI_Comm_new (MPI_T8_Fint Fcomm); - + */ +sc_MPI_Comm * +t8_fortran_MPI_Comm_new (MPI_T8_Fint Fcomm); + /** Free the memory of a C MPI Communicator pointer that was created * with \ref t8_fortran_MPI_Comm_new. * \param [in] Ccomm Pointer to a C MPI communicator. - */ -void -t8_fortran_MPI_Comm_delete (sc_MPI_Comm *Ccomm); - + */ +void +t8_fortran_MPI_Comm_delete (sc_MPI_Comm *Ccomm); + /** Wraps t8_cmesh_new_periodic_tri, passing the MPI communicator as pointer instead of by value * \param [in] Ccomm Pointer to a C MPI communicator. * \param [out] Example cmesh - */ -t8_cmesh_t -t8_cmesh_new_periodic_tri_wrap (sc_MPI_Comm *Ccomm); - + */ +t8_cmesh_t +t8_cmesh_new_periodic_tri_wrap (sc_MPI_Comm *Ccomm); + /** Wraps \ref t8_forest_new_uniform with the default scheme as scheme * and passes MPI communicator as pointer instead of by value. * Build a uniformly refined forest on a coarse mesh. @@ -121,26 +121,26 @@ t8_cmesh_new_periodic_tri_wrap (sc_MPI_Comm *Ccomm); * \param [in] comm MPI communicator to use. * \return A uniform forest with coarse mesh \a cmesh, eclass_scheme * \a scheme and refinement level \a level. - */ -t8_forest_t -t8_forest_new_uniform_default (t8_cmesh_t cmesh, int level, int do_face_ghost, sc_MPI_Comm *comm); - + */ +t8_forest_t +t8_forest_new_uniform_default (t8_cmesh_t cmesh, int level, int do_face_ghost, sc_MPI_Comm *comm); + /** * \param [in, out] forest The forest * \param [in] recursive A flag specifying whether adaptation is to be done recursively * or not. If the value is zero, adaptation is not recursive * and it is recursive otherwise. * \param [in] callback A pointer to a user defined function. t8code will never touch the function. - */ -t8_forest_t -t8_forest_adapt_by_coordinates (t8_forest_t forest, int recursive, t8_fortran_adapt_coordinate_callback callback); - + */ +t8_forest_t +t8_forest_adapt_by_coordinates (t8_forest_t forest, int recursive, t8_fortran_adapt_coordinate_callback callback); + /** Log a message on the root rank with priority SC_LP_PRODUCTION. * \param [in] string String to log. - */ -void -t8_global_productionf_noargs (const char *string); - -T8_EXTERN_C_END (); - -#endif /* !T8_FORTRAN_INTERFACE_H */ + */ +void +t8_global_productionf_noargs (const char *string); + +T8_EXTERN_C_END (); + +#endif /* !T8_FORTRAN_INTERFACE_H */ From c49f9f3d4a322b8a792758b1b51fd925acc051f3 Mon Sep 17 00:00:00 2001 From: Johannes Holke Date: Tue, 13 Aug 2024 14:16:41 +0200 Subject: [PATCH 15/42] Add some comments --- api/Makefile.am | 3 ++- t8_fortran_specific.mk | 2 ++ 2 files changed, 4 insertions(+), 1 deletion(-) diff --git a/api/Makefile.am b/api/Makefile.am index 782d9b142a..0ff693b435 100644 --- a/api/Makefile.am +++ b/api/Makefile.am @@ -10,11 +10,12 @@ libt8_installed_headers_fortran_interface = \ dist_fortraninterfaceinclude_HEADERS = $(libt8_installed_headers_fortran_interface) +# Save the module sources in a different variable for later use t8_fortran_module_sources = api/t8_fortran_interface/t8_mo_fortran_interface.f90 # Add the Fortran sources to the lib libt8_compiled_sources += $(t8_fortran_module_sources) -# Save the module sources in a different variable for later use + AM_FCFLAGS = libt8_compiled_sources += \ api/t8_fortran_interface/t8_fortran_interface.c diff --git a/t8_fortran_specific.mk b/t8_fortran_specific.mk index 0392a631f3..c4ca56e9ac 100644 --- a/t8_fortran_specific.mk +++ b/t8_fortran_specific.mk @@ -26,6 +26,7 @@ create-moddir: # Save the module directory t8_current_moddir += @T8_FORTRAN_MODULE_DIR@/ +# End if T8_WITH_MODDIR endif # If the install target is made, we will copy the module files into the include directory (after the installation of the header files) @@ -42,4 +43,5 @@ install-data-hook: # TODO: Implement t8_fortran_test depends on the modules: t8_mo_fortran_interface #example/Fortran/t8_fortran_test.o : api/t8_fortran_interface/t8_mo_fortran_interface.o +# end if T8_ENABLE_FORTRAN endif From 8634236743472b7dd6860416de9d43a881850ea1 Mon Sep 17 00:00:00 2001 From: Chiara Hergl <124142713+chiaraMaHe@users.noreply.github.com> Date: Mon, 19 Aug 2024 08:49:38 +0200 Subject: [PATCH 16/42] Update api/Makefile.am Co-authored-by: Sandro Elsweijer <49643115+sandro-elsweijer@users.noreply.github.com> --- api/Makefile.am | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/api/Makefile.am b/api/Makefile.am index 0ff693b435..02fd34388e 100644 --- a/api/Makefile.am +++ b/api/Makefile.am @@ -30,4 +30,4 @@ src_libt8_la_FFLAGS = $(FFLAGS) #include t8_fortran_specific.mk -endif \ No newline at end of file +endif From 574ee3e11b03dfd5878d62c3a3ba36db692c50c7 Mon Sep 17 00:00:00 2001 From: Chiara Hergl Date: Mon, 19 Aug 2024 09:22:07 +0200 Subject: [PATCH 17/42] Remove # to add fortran_specific_mk --- api/Makefile.am | 65 ++++++++++++++++++++++++------------------------- 1 file changed, 32 insertions(+), 33 deletions(-) diff --git a/api/Makefile.am b/api/Makefile.am index 02fd34388e..a2b6662245 100644 --- a/api/Makefile.am +++ b/api/Makefile.am @@ -1,33 +1,32 @@ -# This file is part of t8code -# Non-recursive Makefile.am in api -# Included from toplevel directory - -if T8_ENABLE_FORTRAN -fortraninterfaceincludedir = $(includedir)/t8_fortran_interface - -libt8_installed_headers_fortran_interface = \ - api/t8_fortran_interface/t8_fortran_interface.h - -dist_fortraninterfaceinclude_HEADERS = $(libt8_installed_headers_fortran_interface) - -# Save the module sources in a different variable for later use -t8_fortran_module_sources = api/t8_fortran_interface/t8_mo_fortran_interface.f90 - -# Add the Fortran sources to the lib -libt8_compiled_sources += $(t8_fortran_module_sources) - -AM_FCFLAGS = -libt8_compiled_sources += \ - api/t8_fortran_interface/t8_fortran_interface.c - -AM_CPPFLAGS += -I@top_srcdir@/api -MODSOURCES = $(t8_fortran_module_sources) - -src_libt8_la_FCFLAGS = $(AM_FCFLAGS) -src_libt8_la_FFLAGS = $(FFLAGS) - -# Include the Fortran specific variables and rules -#include t8_fortran_specific.mk - - -endif +# This file is part of t8code +# Non-recursive Makefile.am in api +# Included from toplevel directory + +if T8_ENABLE_FORTRAN +fortraninterfaceincludedir = $(includedir)/t8_fortran_interface + +libt8_installed_headers_fortran_interface = \ + api/t8_fortran_interface/t8_fortran_interface.h + +dist_fortraninterfaceinclude_HEADERS = $(libt8_installed_headers_fortran_interface) + +# Save the module sources in a different variable for later use +t8_fortran_module_sources = api/t8_fortran_interface/t8_mo_fortran_interface.f90 + +# Add the Fortran sources to the lib +libt8_compiled_sources += $(t8_fortran_module_sources) + +AM_FCFLAGS = +libt8_compiled_sources += \ + api/t8_fortran_interface/t8_fortran_interface.c + +AM_CPPFLAGS += -I@top_srcdir@/api +MODSOURCES = $(t8_fortran_module_sources) + +src_libt8_la_FCFLAGS = $(AM_FCFLAGS) +src_libt8_la_FFLAGS = $(FFLAGS) + +# Include the Fortran specific variables and rules +include t8_fortran_specific.mk + +endif From 2a514b859de14a16851218784103ddf42c055dfd Mon Sep 17 00:00:00 2001 From: Chiara Hergl Date: Mon, 19 Aug 2024 09:25:25 +0200 Subject: [PATCH 18/42] Rename file --- api/Makefile.am | 2 +- .../{t8_mo_fortran_interface.f90 => t8_fortran_interface.f90} | 0 t8_fortran_specific.mk | 4 ++-- 3 files changed, 3 insertions(+), 3 deletions(-) rename api/t8_fortran_interface/{t8_mo_fortran_interface.f90 => t8_fortran_interface.f90} (100%) diff --git a/api/Makefile.am b/api/Makefile.am index a2b6662245..e50f8f326b 100644 --- a/api/Makefile.am +++ b/api/Makefile.am @@ -11,7 +11,7 @@ libt8_installed_headers_fortran_interface = \ dist_fortraninterfaceinclude_HEADERS = $(libt8_installed_headers_fortran_interface) # Save the module sources in a different variable for later use -t8_fortran_module_sources = api/t8_fortran_interface/t8_mo_fortran_interface.f90 +t8_fortran_module_sources = api/t8_fortran_interface/t8_fortran_interface.f90 # Add the Fortran sources to the lib libt8_compiled_sources += $(t8_fortran_module_sources) diff --git a/api/t8_fortran_interface/t8_mo_fortran_interface.f90 b/api/t8_fortran_interface/t8_fortran_interface.f90 similarity index 100% rename from api/t8_fortran_interface/t8_mo_fortran_interface.f90 rename to api/t8_fortran_interface/t8_fortran_interface.f90 diff --git a/t8_fortran_specific.mk b/t8_fortran_specific.mk index c4ca56e9ac..1dc0dd7c34 100644 --- a/t8_fortran_specific.mk +++ b/t8_fortran_specific.mk @@ -40,8 +40,8 @@ install-data-hook: # This needs to be done in order to ensure the correct build process in any case # ... -# TODO: Implement t8_fortran_test depends on the modules: t8_mo_fortran_interface -#example/Fortran/t8_fortran_test.o : api/t8_fortran_interface/t8_mo_fortran_interface.o +# TODO: Implement t8_fortran_test depends on the modules: t8_fortran_interface +#example/Fortran/t8_fortran_test.o : api/t8_fortran_interface/t8_fortran_interface.o # end if T8_ENABLE_FORTRAN endif From 3b187f12b1c6a47ba2180d1647961156f20caa8f Mon Sep 17 00:00:00 2001 From: Sandro Elsweijer Date: Tue, 20 Aug 2024 11:48:20 +0200 Subject: [PATCH 19/42] add input description for cmake ci t8code api tests --- .github/workflows/tests_cmake_t8code_api.yml | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/.github/workflows/tests_cmake_t8code_api.yml b/.github/workflows/tests_cmake_t8code_api.yml index ee3c75047d..f38659f2e0 100644 --- a/.github/workflows/tests_cmake_t8code_api.yml +++ b/.github/workflows/tests_cmake_t8code_api.yml @@ -27,15 +27,19 @@ on: MAKEFLAGS: required: true type: string + description: 'Make flags to use for compilation (like -j4)' MPI: required: true type: string + description: 'Use MPI for compilation (ON/OFF)' BUILD_TYPE: required: true type: string + description: 'Build type (Release/Debug)' LESS_TESTS: required: true type: boolean + description: 'Enable less tests option for configuring' jobs: t8code_cmake_tests: From a5799d7d9b337858a3de9562ffff504486edce35 Mon Sep 17 00:00:00 2001 From: Sandro Elsweijer Date: Tue, 20 Aug 2024 14:01:28 +0200 Subject: [PATCH 20/42] switch from ninja test to ctest for parallel test execution --- .github/workflows/tests_cmake_t8code_api.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/workflows/tests_cmake_t8code_api.yml b/.github/workflows/tests_cmake_t8code_api.yml index f38659f2e0..c078984f60 100644 --- a/.github/workflows/tests_cmake_t8code_api.yml +++ b/.github/workflows/tests_cmake_t8code_api.yml @@ -101,8 +101,8 @@ jobs: run: cd build_fortran && ninja $MAKEFLAGS - name: ninja install run: cd build_fortran && ninja install $MAKEFLAGS - - name: ninja test - run: cd build_fortran && ninja test $MAKEFLAGS + - name: ctest + run: cd build_fortran && ctest $MAKEFLAGS - name: OnFailUploadLog if: failure() uses: actions/upload-artifact@v4 From 2b7cb44e4103b05eeaef36cbdeff468b8620e237 Mon Sep 17 00:00:00 2001 From: Sandro Elsweijer Date: Fri, 23 Aug 2024 12:18:34 +0200 Subject: [PATCH 21/42] execute tests in serial bc its faster --- .github/workflows/tests_cmake_t8code_api.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/workflows/tests_cmake_t8code_api.yml b/.github/workflows/tests_cmake_t8code_api.yml index c078984f60..5c6d42e08c 100644 --- a/.github/workflows/tests_cmake_t8code_api.yml +++ b/.github/workflows/tests_cmake_t8code_api.yml @@ -101,8 +101,8 @@ jobs: run: cd build_fortran && ninja $MAKEFLAGS - name: ninja install run: cd build_fortran && ninja install $MAKEFLAGS - - name: ctest - run: cd build_fortran && ctest $MAKEFLAGS + - name: ninja test + run: cd build_fortran && ninja test - name: OnFailUploadLog if: failure() uses: actions/upload-artifact@v4 From 9cf9ec3e050e1504439563ed8d84ca7bd59048cd Mon Sep 17 00:00:00 2001 From: Chiara Hergl Date: Mon, 16 Sep 2024 15:44:07 +0200 Subject: [PATCH 22/42] Add t8_fortran.m4 to Makefile --- Makefile.am | 1 + 1 file changed, 1 insertion(+) diff --git a/Makefile.am b/Makefile.am index f0872791e7..e4c53198bb 100644 --- a/Makefile.am +++ b/Makefile.am @@ -47,6 +47,7 @@ dist_t8aclocal_DATA = config/t8_include.m4 \ config/t8_netcdf.m4 \ config/t8_vtk.m4 \ config/t8_occ.m4 \ + config/t8_fortran.m4 \ config/t8_mpi.m4 From 3cfce5686803d50aab7e318893fb32568d7c7246 Mon Sep 17 00:00:00 2001 From: Chiara Hergl Date: Mon, 16 Sep 2024 15:45:45 +0200 Subject: [PATCH 23/42] Change name of fortran file --- api/Makefile.am | 2 +- .../{t8_fortran_interface.f90 => t8_fortran_interface_f.f90} | 0 2 files changed, 1 insertion(+), 1 deletion(-) rename api/t8_fortran_interface/{t8_fortran_interface.f90 => t8_fortran_interface_f.f90} (100%) diff --git a/api/Makefile.am b/api/Makefile.am index e50f8f326b..2dd7ba7397 100644 --- a/api/Makefile.am +++ b/api/Makefile.am @@ -11,7 +11,7 @@ libt8_installed_headers_fortran_interface = \ dist_fortraninterfaceinclude_HEADERS = $(libt8_installed_headers_fortran_interface) # Save the module sources in a different variable for later use -t8_fortran_module_sources = api/t8_fortran_interface/t8_fortran_interface.f90 +t8_fortran_module_sources = api/t8_fortran_interface/t8_fortran_interface_f.f90 # Add the Fortran sources to the lib libt8_compiled_sources += $(t8_fortran_module_sources) diff --git a/api/t8_fortran_interface/t8_fortran_interface.f90 b/api/t8_fortran_interface/t8_fortran_interface_f.f90 similarity index 100% rename from api/t8_fortran_interface/t8_fortran_interface.f90 rename to api/t8_fortran_interface/t8_fortran_interface_f.f90 From c870226233890ec26ac589e10cc4f966ae4486f8 Mon Sep 17 00:00:00 2001 From: Chiara Hergl Date: Mon, 16 Sep 2024 15:46:18 +0200 Subject: [PATCH 24/42] Add t8_fortran.m4 --- config/t8_fortran.m4 | 34 ++++++++++++++++++++++++++++++++++ 1 file changed, 34 insertions(+) create mode 100644 config/t8_fortran.m4 diff --git a/config/t8_fortran.m4 b/config/t8_fortran.m4 new file mode 100644 index 0000000000..b1e452376e --- /dev/null +++ b/config/t8_fortran.m4 @@ -0,0 +1,34 @@ +dnl T8_CHECK_FORTRAN +dnl This functions checks some properties of Fortran modules and +dnl whether specific directory for the Fortran module files has been specified or not. +dnl +dnl A directory may be specified by the option --with-moddir= +dnl This option is only of relevance if the option --enable-fortran has been chosen, +dnl since only in this case Fortran codes will be compiled +dnl +AC_DEFUN([T8_CHECK_FORTRAN], [ + +dnl Check if a directory has been specified which will hold the module files +T8_ARG_WITH([moddir], + [if Fortran modules will be built, this option specifies an explicit directory which should hold the module files (use --with-moddir=)], + [MODDIR]) + +dnl If Fortran is enabled +if test "x$T8_ENABLE_FORTRAN" != xno ; then + +dnl Check the properties of Fortran modules (after the Fortran Compiler has been found by MPI_ENGAGE) +AC_FC_MODULE_EXTENSION +AC_FC_MODULE_FLAG +AC_FC_MODULE_OUTPUT_FLAG + +if test "x$T8_WITH_MODDIR" = xyes ; then + dnl The option is given without a directory + AC_MSG_ERROR([missing directory path for the module directory]) +elif test "x$T8_WITH_MODDIR" != xno ; then + AC_MSG_NOTICE([we have set a module dir var]) + dnl Substitute the variable in the makefile + AC_SUBST(T8_FORTRAN_MODULE_DIR, $T8_WITH_MODDIR) +fi + +fi +]) From ce35a779ae84b8fffa4431a17081ea50cc6d93e7 Mon Sep 17 00:00:00 2001 From: Johannes Markert Date: Tue, 24 Sep 2024 10:17:14 +0200 Subject: [PATCH 25/42] Renamed Fortran interface module. --- .../{t8_mo_fortran_interface.f90 => t8_fortran_interface.f90} | 4 ++-- api/t8_fortran_interface/t8_fortran_interface_f.f90 | 0 2 files changed, 2 insertions(+), 2 deletions(-) rename api/t8_fortran_interface/{t8_mo_fortran_interface.f90 => t8_fortran_interface.f90} (97%) delete mode 100644 api/t8_fortran_interface/t8_fortran_interface_f.f90 diff --git a/api/t8_fortran_interface/t8_mo_fortran_interface.f90 b/api/t8_fortran_interface/t8_fortran_interface.f90 similarity index 97% rename from api/t8_fortran_interface/t8_mo_fortran_interface.f90 rename to api/t8_fortran_interface/t8_fortran_interface.f90 index 3f85edb6e9..56b4281b9c 100644 --- a/api/t8_fortran_interface/t8_mo_fortran_interface.f90 +++ b/api/t8_fortran_interface/t8_fortran_interface.f90 @@ -1,4 +1,4 @@ -module t8_mo_fortran_interface +module t8_fortran_interface use, intrinsic :: ISO_C_BINDING @@ -304,4 +304,4 @@ subroutine t8_fortran_element_volume_f (forest, ltreeid, element) & end subroutine t8_fortran_element_volume_f end Interface -End module t8_mo_fortran_interface +End module t8_fortran_interface diff --git a/api/t8_fortran_interface/t8_fortran_interface_f.f90 b/api/t8_fortran_interface/t8_fortran_interface_f.f90 deleted file mode 100644 index e69de29bb2..0000000000 From d1477323cbe501665dda98b634c224e0b1c4b3db Mon Sep 17 00:00:00 2001 From: Johannes Markert Date: Tue, 24 Sep 2024 10:25:24 +0200 Subject: [PATCH 26/42] Updated makefile to new fortran interface module name. --- api/Makefile.am | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/api/Makefile.am b/api/Makefile.am index 2dd7ba7397..e50f8f326b 100644 --- a/api/Makefile.am +++ b/api/Makefile.am @@ -11,7 +11,7 @@ libt8_installed_headers_fortran_interface = \ dist_fortraninterfaceinclude_HEADERS = $(libt8_installed_headers_fortran_interface) # Save the module sources in a different variable for later use -t8_fortran_module_sources = api/t8_fortran_interface/t8_fortran_interface_f.f90 +t8_fortran_module_sources = api/t8_fortran_interface/t8_fortran_interface.f90 # Add the Fortran sources to the lib libt8_compiled_sources += $(t8_fortran_module_sources) From e48d01f79f73a46a77b8942044e6687b0e96a688 Mon Sep 17 00:00:00 2001 From: Johannes Markert Date: Tue, 24 Sep 2024 11:57:59 +0200 Subject: [PATCH 27/42] Added _mod suffix. --- api/Makefile.am | 2 +- ...{t8_fortran_interface.f90 => t8_fortran_interface_mod.f90} | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) rename api/t8_fortran_interface/{t8_fortran_interface.f90 => t8_fortran_interface_mod.f90} (97%) diff --git a/api/Makefile.am b/api/Makefile.am index e50f8f326b..42c29ff68d 100644 --- a/api/Makefile.am +++ b/api/Makefile.am @@ -11,7 +11,7 @@ libt8_installed_headers_fortran_interface = \ dist_fortraninterfaceinclude_HEADERS = $(libt8_installed_headers_fortran_interface) # Save the module sources in a different variable for later use -t8_fortran_module_sources = api/t8_fortran_interface/t8_fortran_interface.f90 +t8_fortran_module_sources = api/t8_fortran_interface/t8_fortran_interface_mod.f90 # Add the Fortran sources to the lib libt8_compiled_sources += $(t8_fortran_module_sources) diff --git a/api/t8_fortran_interface/t8_fortran_interface.f90 b/api/t8_fortran_interface/t8_fortran_interface_mod.f90 similarity index 97% rename from api/t8_fortran_interface/t8_fortran_interface.f90 rename to api/t8_fortran_interface/t8_fortran_interface_mod.f90 index 56b4281b9c..8dc2fea3c3 100644 --- a/api/t8_fortran_interface/t8_fortran_interface.f90 +++ b/api/t8_fortran_interface/t8_fortran_interface_mod.f90 @@ -1,4 +1,4 @@ -module t8_fortran_interface +module t8_fortran_interface_mod use, intrinsic :: ISO_C_BINDING @@ -304,4 +304,4 @@ subroutine t8_fortran_element_volume_f (forest, ltreeid, element) & end subroutine t8_fortran_element_volume_f end Interface -End module t8_fortran_interface +End module t8_fortran_interface_mod From 13fedd2c6ed79cd0cf7232ebaab1b4e83c36d61f Mon Sep 17 00:00:00 2001 From: Johannes Markert Date: Tue, 24 Sep 2024 16:24:14 +0200 Subject: [PATCH 28/42] CMake build for Fortran interface. --- CMakeCache.txt | 38 +++++++++++++++++++ CMakeFiles/cmake.check_cache | 1 + CMakeLists.txt | 13 ++++++- Makefile.am | 5 ++- api/t8_fortran_interface/CMakeLists.txt | 18 +++++++++ api/{ => t8_fortran_interface}/Makefile.am | 5 +-- .../t8_fortran_interface.c | 2 +- 7 files changed, 75 insertions(+), 7 deletions(-) create mode 100644 CMakeCache.txt create mode 100644 CMakeFiles/cmake.check_cache create mode 100644 api/t8_fortran_interface/CMakeLists.txt rename api/{ => t8_fortran_interface}/Makefile.am (93%) diff --git a/CMakeCache.txt b/CMakeCache.txt new file mode 100644 index 0000000000..f00179a4b6 --- /dev/null +++ b/CMakeCache.txt @@ -0,0 +1,38 @@ +# This is the CMakeCache file. +# For build in directory: /home/mark_jo/codes/t8code/main +# It was generated by CMake: /tools/modulesystem/spack-22.2/opt/spack/linux-ubuntu20.04-x86_64_v3/gcc-9.4.0/cmake-3.23.1-ndj7uex4iujfquklfcpl4i2vzeugdx2i/bin/cmake +# You can edit this file to change values found and used by cmake. +# If you do not want to change any of the values, simply exit the editor. +# If you do want to change a value, simply edit, save, and exit the editor. +# The syntax for the file is as follows: +# KEY:TYPE=VALUE +# KEY is the name of a variable in the cache. +# TYPE is a hint to GUIs for the type of VALUE, DO NOT EDIT TYPE!. +# VALUE is the current value for the KEY. + +######################## +# EXTERNAL cache entries +######################## + + +######################## +# INTERNAL cache entries +######################## + +//This is the directory where this CMakeCache.txt was created +CMAKE_CACHEFILE_DIR:INTERNAL=/home/mark_jo/codes/t8code/main +//Major version of cmake used to create the current loaded cache +CMAKE_CACHE_MAJOR_VERSION:INTERNAL=3 +//Minor version of cmake used to create the current loaded cache +CMAKE_CACHE_MINOR_VERSION:INTERNAL=23 +//Patch version of cmake used to create the current loaded cache +CMAKE_CACHE_PATCH_VERSION:INTERNAL=1 +//Path to CMake executable. +CMAKE_COMMAND:INTERNAL=/tools/modulesystem/spack-22.2/opt/spack/linux-ubuntu20.04-x86_64_v3/gcc-9.4.0/cmake-3.23.1-ndj7uex4iujfquklfcpl4i2vzeugdx2i/bin/cmake +//Path to cpack program executable. +CMAKE_CPACK_COMMAND:INTERNAL=/tools/modulesystem/spack-22.2/opt/spack/linux-ubuntu20.04-x86_64_v3/gcc-9.4.0/cmake-3.23.1-ndj7uex4iujfquklfcpl4i2vzeugdx2i/bin/cpack +//Path to ctest program executable. +CMAKE_CTEST_COMMAND:INTERNAL=/tools/modulesystem/spack-22.2/opt/spack/linux-ubuntu20.04-x86_64_v3/gcc-9.4.0/cmake-3.23.1-ndj7uex4iujfquklfcpl4i2vzeugdx2i/bin/ctest +//Path to CMake installation. +CMAKE_ROOT:INTERNAL=/tools/modulesystem/spack-22.2/opt/spack/linux-ubuntu20.04-x86_64_v3/gcc-9.4.0/cmake-3.23.1-ndj7uex4iujfquklfcpl4i2vzeugdx2i/share/cmake-3.23 + diff --git a/CMakeFiles/cmake.check_cache b/CMakeFiles/cmake.check_cache new file mode 100644 index 0000000000..3dccd73172 --- /dev/null +++ b/CMakeFiles/cmake.check_cache @@ -0,0 +1 @@ +# This file is generated by cmake for dependency checking of the CMakeCache.txt file diff --git a/CMakeLists.txt b/CMakeLists.txt index 90dd8cdcb2..6cf9c8d0c3 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -4,7 +4,7 @@ include(cmake/GitProjectVersion.cmake) project( T8CODE DESCRIPTION "Parallel algorithms and data structures for tree-based AMR with arbitrary element shapes." - LANGUAGES C CXX + LANGUAGES C CXX Fortran VERSION "${T8CODE_VERSION_MAJOR}.${T8CODE_VERSION_MINOR}.${T8CODE_VERSION_PATCH}" ) include( CTest ) @@ -15,6 +15,7 @@ option( T8CODE_BUILD_TESTS "Build t8code's automated tests" ON ) option( T8CODE_BUILD_TUTORIALS "Build t8code's tutorials" ON ) option( T8CODE_BUILD_EXAMPLES "Build t8code's examples" ON ) option( T8CODE_BUILD_BENCHMARKS "Build t8code's benchmarks" ON ) +option( T8CODE_BUILD_FORTRAN_INTERFACE "Build t8code's Fortran interface" OFF ) option( T8CODE_ENABLE_LESS_TESTS "Tests not as thoroughly to speed up the test suite. Tests the same functionality. (WARNING: Use with care.)" OFF ) option( T8CODE_ENABLE_MPI "Enable t8code's features which rely on MPI" ON ) @@ -136,3 +137,13 @@ endif() if ( T8CODE_BUILD_DOCUMENTATION ) add_subdirectory( ${CMAKE_CURRENT_LIST_DIR}/doc ) endif() + +if( T8CODE_BUILD_FORTRAN_INTERFACE ) + enable_language(Fortran) + + # set(FVERSION "-std=f95") + # set(CMAKE_Fortran_FLAGS "${CMAKE_Fortran_FLAGS} ${FVERSION}") + + add_subdirectory( ${CMAKE_CURRENT_LIST_DIR}/api/t8_fortran_interface ) + +endif( T8CODE_BUILD_FORTRAN_INTERFACE ) diff --git a/Makefile.am b/Makefile.am index e4c53198bb..83e1184228 100644 --- a/Makefile.am +++ b/Makefile.am @@ -79,7 +79,10 @@ include test/Makefile.am include example/Makefile.am include tutorials/Makefile.am include benchmarks/Makefile.am -include api/Makefile.am + +if T8_ENABLE_FORTRAN + include api/Makefile.am +endif # revision control and ChangeLog ChangeLog: diff --git a/api/t8_fortran_interface/CMakeLists.txt b/api/t8_fortran_interface/CMakeLists.txt new file mode 100644 index 0000000000..3072277cd3 --- /dev/null +++ b/api/t8_fortran_interface/CMakeLists.txt @@ -0,0 +1,18 @@ +# Link in C-Fortran interface file into libt8. +target_sources( T8 PRIVATE t8_fortran_interface.c ) +target_sources( T8 PRIVATE t8_fortran_interface_mod.f90 ) + +# Add this directory to header search path. +target_include_directories( T8 PRIVATE ${CMAKE_CURRENT_LIST_DIR} ) + +# Install header files. +install( + FILES ${CMAKE_CURRENT_LIST_DIR}/t8_fortran_interface.h + DESTINATION ${CMAKE_INSTALL_PREFIX}/include/t8_fortran_interface +) + +# Install module files. +install( + FILES ${CMAKE_BINARY_DIR}/src/t8_fortran_interface_mod.mod + DESTINATION ${CMAKE_INSTALL_PREFIX}/include/t8_fortran_interface +) diff --git a/api/Makefile.am b/api/t8_fortran_interface/Makefile.am similarity index 93% rename from api/Makefile.am rename to api/t8_fortran_interface/Makefile.am index 42c29ff68d..36eb9f96bc 100644 --- a/api/Makefile.am +++ b/api/t8_fortran_interface/Makefile.am @@ -2,7 +2,6 @@ # Non-recursive Makefile.am in api # Included from toplevel directory -if T8_ENABLE_FORTRAN fortraninterfaceincludedir = $(includedir)/t8_fortran_interface libt8_installed_headers_fortran_interface = \ @@ -20,7 +19,7 @@ AM_FCFLAGS = libt8_compiled_sources += \ api/t8_fortran_interface/t8_fortran_interface.c -AM_CPPFLAGS += -I@top_srcdir@/api +AM_CPPFLAGS += -I@top_srcdir@/api/t8_fortran_interface MODSOURCES = $(t8_fortran_module_sources) src_libt8_la_FCFLAGS = $(AM_FCFLAGS) @@ -28,5 +27,3 @@ src_libt8_la_FFLAGS = $(FFLAGS) # Include the Fortran specific variables and rules include t8_fortran_specific.mk - -endif diff --git a/api/t8_fortran_interface/t8_fortran_interface.c b/api/t8_fortran_interface/t8_fortran_interface.c index 92d0ab5a8e..487ca829fe 100644 --- a/api/t8_fortran_interface/t8_fortran_interface.c +++ b/api/t8_fortran_interface/t8_fortran_interface.c @@ -20,7 +20,7 @@ 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */ -#include +#include #include #include #include From cc743cade27dcb1cee07a5e7e30443430c1845c6 Mon Sep 17 00:00:00 2001 From: Johannes Markert Date: Tue, 24 Sep 2024 16:44:45 +0200 Subject: [PATCH 29/42] Fixed autotools. --- Makefile.am | 5 +---- api/{t8_fortran_interface => }/Makefile.am | 4 ++++ 2 files changed, 5 insertions(+), 4 deletions(-) rename api/{t8_fortran_interface => }/Makefile.am (95%) diff --git a/Makefile.am b/Makefile.am index 83e1184228..e4c53198bb 100644 --- a/Makefile.am +++ b/Makefile.am @@ -79,10 +79,7 @@ include test/Makefile.am include example/Makefile.am include tutorials/Makefile.am include benchmarks/Makefile.am - -if T8_ENABLE_FORTRAN - include api/Makefile.am -endif +include api/Makefile.am # revision control and ChangeLog ChangeLog: diff --git a/api/t8_fortran_interface/Makefile.am b/api/Makefile.am similarity index 95% rename from api/t8_fortran_interface/Makefile.am rename to api/Makefile.am index 36eb9f96bc..89684d0b26 100644 --- a/api/t8_fortran_interface/Makefile.am +++ b/api/Makefile.am @@ -2,6 +2,7 @@ # Non-recursive Makefile.am in api # Included from toplevel directory +if T8_ENABLE_FORTRAN fortraninterfaceincludedir = $(includedir)/t8_fortran_interface libt8_installed_headers_fortran_interface = \ @@ -27,3 +28,6 @@ src_libt8_la_FFLAGS = $(FFLAGS) # Include the Fortran specific variables and rules include t8_fortran_specific.mk + +# T8_ENABLE_FORTRAN +endif From 1523f92e01d42d149e1394534f28a56fbc5cd95e Mon Sep 17 00:00:00 2001 From: Johannes Markert Date: Tue, 24 Sep 2024 17:05:36 +0200 Subject: [PATCH 30/42] Reorganized autools Fortran interface. --- api/Makefile.am | 2 +- .../t8_fortran_interface/t8_fortran_specific.mk | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) rename t8_fortran_specific.mk => api/t8_fortran_interface/t8_fortran_specific.mk (95%) diff --git a/api/Makefile.am b/api/Makefile.am index 89684d0b26..b27d462ba9 100644 --- a/api/Makefile.am +++ b/api/Makefile.am @@ -27,7 +27,7 @@ src_libt8_la_FCFLAGS = $(AM_FCFLAGS) src_libt8_la_FFLAGS = $(FFLAGS) # Include the Fortran specific variables and rules -include t8_fortran_specific.mk +include api/t8_fortran_interface/t8_fortran_specific.mk # T8_ENABLE_FORTRAN endif diff --git a/t8_fortran_specific.mk b/api/t8_fortran_interface/t8_fortran_specific.mk similarity index 95% rename from t8_fortran_specific.mk rename to api/t8_fortran_interface/t8_fortran_specific.mk index 1dc0dd7c34..3bde84337f 100644 --- a/t8_fortran_specific.mk +++ b/api/t8_fortran_interface/t8_fortran_specific.mk @@ -31,7 +31,7 @@ endif # If the install target is made, we will copy the module files into the include directory (after the installation of the header files) install-data-hook: - @cp -fp $(t8_current_moddir)*.$(FC_MODEXT) $(includedir) + @cp -fp $(t8_current_moddir)*.$(FC_MODEXT) $(includedir)/t8_fortran_interface # Define dependencies of the Fortran modules (in case they depend on other modules) # This needs to be done in order to ensure the correct build process in any case From 361f16aed67c602e8ee7b424845fc021ce17b8ef Mon Sep 17 00:00:00 2001 From: Johannes Markert Date: Tue, 24 Sep 2024 18:45:19 +0200 Subject: [PATCH 31/42] Added MPI Fortran test. --- .github/workflows/tests_cmake_t8code.yml | 2 +- CMakeLists.txt | 14 +++++----- test/CMakeLists.txt | 15 ++++++++++- .../t8_fortran_interface/t8_test_mpi_init.f90 | 26 +++++++++++++++++++ 4 files changed, 47 insertions(+), 10 deletions(-) create mode 100644 test/api/t8_fortran_interface/t8_test_mpi_init.f90 diff --git a/.github/workflows/tests_cmake_t8code.yml b/.github/workflows/tests_cmake_t8code.yml index 1effcaba77..066ff46af2 100644 --- a/.github/workflows/tests_cmake_t8code.yml +++ b/.github/workflows/tests_cmake_t8code.yml @@ -81,7 +81,7 @@ jobs: run: export LESS_TEST_OPTION="-DT8CODE_ENABLE_LESS_TESTS=ON" && echo LESS_TEST_OPTION="$LESS_TEST_OPTION" >> $GITHUB_ENV - name: build config variables - run: export CONFIG_OPTIONS="${LESS_TEST_OPTION} -GNinja -DT8CODE_USE_SYSTEM_SC=ON -DT8CODE_USE_SYSTEM_P4EST=ON -DT8CODE_BUILD_PEDANTIC=ON -DT8CODE_ENABLE_MPI=$MPI -DCMAKE_BUILD_TYPE=$BUILD_TYPE -DSC_DIR=$SC_PATH/install/cmake -DP4EST_DIR=$P4EST_PATH/install/cmake" + run: export CONFIG_OPTIONS="${LESS_TEST_OPTION} -GNinja -DT8CODE_USE_SYSTEM_SC=ON -DT8CODE_USE_SYSTEM_P4EST=ON -DT8CODE_BUILD_PEDANTIC=ON -DT8CODE_BUILD_FORTRAN=$MPI -DT8CODE_ENABLE_MPI=$MPI -DCMAKE_BUILD_TYPE=$BUILD_TYPE -DSC_DIR=$SC_PATH/install/cmake -DP4EST_DIR=$P4EST_PATH/install/cmake" && echo CONFIG_OPTIONS="$CONFIG_OPTIONS" >> $GITHUB_ENV # cmake and test - name: Printing MPI compiler info diff --git a/CMakeLists.txt b/CMakeLists.txt index 6cf9c8d0c3..e8d71a712b 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -57,7 +57,9 @@ set( CMAKE_CXX_EXTENSIONS OFF ) set(CMAKE_MODULE_PATH "${PROJECT_SOURCE_DIR}/cmake" ${CMAKE_MODULE_PATH}) if( T8CODE_ENABLE_MPI ) - find_package( MPI COMPONENTS C REQUIRED ) + + # find_package( MPI COMPONENTS Fortran REQUIRED ) + find_package( MPI COMPONENTS C Fortran REQUIRED ) if( NOT MPIEXEC_EXECUTABLE ) message( FATAL_ERROR "MPIEXEC was not found" ) endif() @@ -139,11 +141,7 @@ if ( T8CODE_BUILD_DOCUMENTATION ) endif() if( T8CODE_BUILD_FORTRAN_INTERFACE ) - enable_language(Fortran) - - # set(FVERSION "-std=f95") - # set(CMAKE_Fortran_FLAGS "${CMAKE_Fortran_FLAGS} ${FVERSION}") - + enable_language( Fortran ) + # find_package( MPI COMPONENTS Fortran REQUIRED ) add_subdirectory( ${CMAKE_CURRENT_LIST_DIR}/api/t8_fortran_interface ) - -endif( T8CODE_BUILD_FORTRAN_INTERFACE ) +endif() diff --git a/test/CMakeLists.txt b/test/CMakeLists.txt index a6cd1f77af..b341ba4987 100644 --- a/test/CMakeLists.txt +++ b/test/CMakeLists.txt @@ -20,7 +20,16 @@ function( add_t8_test ) set(TEST_BUILD_DIR "${CMAKE_BINARY_DIR}/${TEST_RELATIVE_DIR}") add_executable( ${ADD_T8_TEST_NAME} ${ADD_T8_TEST_SOURCES} ) - target_link_libraries( ${ADD_T8_TEST_NAME} PRIVATE T8 gtest pthread) + + # Check if test is a Fortran file and if MPI is enabled. + string ( FIND ${ADD_T8_TEST_NAME} "fortran" is_fortran_file ) + if ( (${is_fortran_file} GREATER_EQUAL 0) AND T8CODE_ENABLE_MPI ) + target_include_directories( ${ADD_T8_TEST_NAME} PRIVATE ${CMAKE_BINARY_DIR}/src ) + target_link_libraries( ${ADD_T8_TEST_NAME} PRIVATE T8 gtest pthread MPI::MPI_Fortran ) + else() + # target_link_libraries( ${ADD_T8_TEST_NAME} PRIVATE T8 MPI::MPI_Fortran ) + target_link_libraries( ${ADD_T8_TEST_NAME} PRIVATE T8 gtest pthread ) + endif () set_target_properties(${ADD_T8_TEST_NAME} PROPERTIES RUNTIME_OUTPUT_DIRECTORY "${TEST_BUILD_DIR}" @@ -131,6 +140,10 @@ add_t8_test( NAME t8_gtest_pack_unpack_serial SOURCES t8_gtest_main.cx add_t8_test( NAME t8_gtest_root_serial SOURCES t8_gtest_main.cxx t8_schemes/t8_gtest_root.cxx ) add_t8_test( NAME t8_gtest_scheme_consistency_serial SOURCES t8_gtest_main.cxx t8_schemes/t8_gtest_scheme_consistency.cxx ) +if( T8CODE_BUILD_FORTRAN_INTERFACE AND T8CODE_ENABLE_MPI ) + add_t8_test( NAME t8_test_fortran_mpi_interface_init SOURCES api/t8_fortran_interface/t8_test_mpi_init.f90 ) +endif() + copy_test_file( test_cube_unstructured_1.inp ) copy_test_file( test_cube_unstructured_2.inp ) copy_test_file( test_vtk_tri.vtu ) diff --git a/test/api/t8_fortran_interface/t8_test_mpi_init.f90 b/test/api/t8_fortran_interface/t8_test_mpi_init.f90 new file mode 100644 index 0000000000..93cfc33ea2 --- /dev/null +++ b/test/api/t8_fortran_interface/t8_test_mpi_init.f90 @@ -0,0 +1,26 @@ +program t8_test_init + use mpi + use iso_c_binding, only: c_ptr, c_int + use t8_fortran_interface_mod + + implicit none + + integer :: ierror, fcomm + type(c_ptr) :: ccomm + + call MPI_Init (ierror) + + if (ierror /= 0) then + print *, 'MPI initialization failed.' + stop 1 + endif + + fcomm = MPI_COMM_WORLD + ccomm = t8_fortran_mpi_comm_new_f (fcomm) + + call t8_fortran_init_all_f (ccomm) + call t8_fortran_finalize_f () + + print *, 'All good!' + stop 0 +end program From e4df9dd21d1c81b9ba774a9c430ca71428b62664 Mon Sep 17 00:00:00 2001 From: Johannes Markert Date: Tue, 24 Sep 2024 18:49:41 +0200 Subject: [PATCH 32/42] Added comment and license. --- .../t8_fortran_interface/t8_test_mpi_init.f90 | 27 ++++++++++++++++++- 1 file changed, 26 insertions(+), 1 deletion(-) diff --git a/test/api/t8_fortran_interface/t8_test_mpi_init.f90 b/test/api/t8_fortran_interface/t8_test_mpi_init.f90 index 93cfc33ea2..665a6d0ec7 100644 --- a/test/api/t8_fortran_interface/t8_test_mpi_init.f90 +++ b/test/api/t8_fortran_interface/t8_test_mpi_init.f90 @@ -1,4 +1,29 @@ -program t8_test_init +!! This file is part of t8code. +!! t8code is a C library to manage a collection (a forest) of multiple +!! connected adaptive space-trees of general element classes in parallel. +!! +!! Copyright (C) 2024 the developers +!! +!! t8code is free software; you can redistribute it and/or modify +!! it under the terms of the GNU General Public License as published by +!! the Free Software Foundation; either version 2 of the License, or +!! (at your option) any later version. +!! +!! t8code is distributed in the hope that it will be useful, +!! but WITHOUT ANY WARRANTY; without even the implied warranty of +!! MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +!! GNU General Public License for more details. +!! +!! You should have received a copy of the GNU General Public License +!! along with t8code; if not, write to the Free Software Foundation, Inc., +!! 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. + +!! Description: +!! +!! This program tests if t8code can be initialized from Fortran +!! with given MPI communicator. Works only when MPI is enabled. + +program t8_test_mpi_init use mpi use iso_c_binding, only: c_ptr, c_int use t8_fortran_interface_mod From 41c337f9d387278b83ab2e7b99652674d87a24b1 Mon Sep 17 00:00:00 2001 From: Johannes Markert Date: Tue, 24 Sep 2024 18:55:17 +0200 Subject: [PATCH 33/42] Ignore CMake related cache files. --- .gitignore | 3 +++ CMakeCache.txt | 38 ------------------------------------ CMakeFiles/cmake.check_cache | 1 - 3 files changed, 3 insertions(+), 39 deletions(-) delete mode 100644 CMakeCache.txt delete mode 100644 CMakeFiles/cmake.check_cache diff --git a/.gitignore b/.gitignore index 03984a386e..da972a4f2d 100644 --- a/.gitignore +++ b/.gitignore @@ -22,6 +22,9 @@ config.status Doxyfile doxygen/ +CMakeCache.txt +CMakeFiles/ + src/stamp-h1 src/t8_config.h src/pre_config.h diff --git a/CMakeCache.txt b/CMakeCache.txt deleted file mode 100644 index f00179a4b6..0000000000 --- a/CMakeCache.txt +++ /dev/null @@ -1,38 +0,0 @@ -# This is the CMakeCache file. -# For build in directory: /home/mark_jo/codes/t8code/main -# It was generated by CMake: /tools/modulesystem/spack-22.2/opt/spack/linux-ubuntu20.04-x86_64_v3/gcc-9.4.0/cmake-3.23.1-ndj7uex4iujfquklfcpl4i2vzeugdx2i/bin/cmake -# You can edit this file to change values found and used by cmake. -# If you do not want to change any of the values, simply exit the editor. -# If you do want to change a value, simply edit, save, and exit the editor. -# The syntax for the file is as follows: -# KEY:TYPE=VALUE -# KEY is the name of a variable in the cache. -# TYPE is a hint to GUIs for the type of VALUE, DO NOT EDIT TYPE!. -# VALUE is the current value for the KEY. - -######################## -# EXTERNAL cache entries -######################## - - -######################## -# INTERNAL cache entries -######################## - -//This is the directory where this CMakeCache.txt was created -CMAKE_CACHEFILE_DIR:INTERNAL=/home/mark_jo/codes/t8code/main -//Major version of cmake used to create the current loaded cache -CMAKE_CACHE_MAJOR_VERSION:INTERNAL=3 -//Minor version of cmake used to create the current loaded cache -CMAKE_CACHE_MINOR_VERSION:INTERNAL=23 -//Patch version of cmake used to create the current loaded cache -CMAKE_CACHE_PATCH_VERSION:INTERNAL=1 -//Path to CMake executable. -CMAKE_COMMAND:INTERNAL=/tools/modulesystem/spack-22.2/opt/spack/linux-ubuntu20.04-x86_64_v3/gcc-9.4.0/cmake-3.23.1-ndj7uex4iujfquklfcpl4i2vzeugdx2i/bin/cmake -//Path to cpack program executable. -CMAKE_CPACK_COMMAND:INTERNAL=/tools/modulesystem/spack-22.2/opt/spack/linux-ubuntu20.04-x86_64_v3/gcc-9.4.0/cmake-3.23.1-ndj7uex4iujfquklfcpl4i2vzeugdx2i/bin/cpack -//Path to ctest program executable. -CMAKE_CTEST_COMMAND:INTERNAL=/tools/modulesystem/spack-22.2/opt/spack/linux-ubuntu20.04-x86_64_v3/gcc-9.4.0/cmake-3.23.1-ndj7uex4iujfquklfcpl4i2vzeugdx2i/bin/ctest -//Path to CMake installation. -CMAKE_ROOT:INTERNAL=/tools/modulesystem/spack-22.2/opt/spack/linux-ubuntu20.04-x86_64_v3/gcc-9.4.0/cmake-3.23.1-ndj7uex4iujfquklfcpl4i2vzeugdx2i/share/cmake-3.23 - diff --git a/CMakeFiles/cmake.check_cache b/CMakeFiles/cmake.check_cache deleted file mode 100644 index 3dccd73172..0000000000 --- a/CMakeFiles/cmake.check_cache +++ /dev/null @@ -1 +0,0 @@ -# This file is generated by cmake for dependency checking of the CMakeCache.txt file From 9667de5e41a3ca1e1b7cf4d995e84d7c0a1ef6e2 Mon Sep 17 00:00:00 2001 From: Johannes Markert Date: Tue, 24 Sep 2024 18:58:02 +0200 Subject: [PATCH 34/42] Refinement. --- CMakeLists.txt | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index e8d71a712b..559f20a73f 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -57,9 +57,12 @@ set( CMAKE_CXX_EXTENSIONS OFF ) set(CMAKE_MODULE_PATH "${PROJECT_SOURCE_DIR}/cmake" ${CMAKE_MODULE_PATH}) if( T8CODE_ENABLE_MPI ) + if( T8CODE_BUILD_FORTRAN_INTERFACE ) + find_package( MPI COMPONENTS C Fortran REQUIRED ) + else() + find_package( MPI COMPONENTS C REQUIRED ) + endif() - # find_package( MPI COMPONENTS Fortran REQUIRED ) - find_package( MPI COMPONENTS C Fortran REQUIRED ) if( NOT MPIEXEC_EXECUTABLE ) message( FATAL_ERROR "MPIEXEC was not found" ) endif() @@ -142,6 +145,5 @@ endif() if( T8CODE_BUILD_FORTRAN_INTERFACE ) enable_language( Fortran ) - # find_package( MPI COMPONENTS Fortran REQUIRED ) add_subdirectory( ${CMAKE_CURRENT_LIST_DIR}/api/t8_fortran_interface ) endif() From aa668207920a2132f2b6d28bdac8534871dca9be Mon Sep 17 00:00:00 2001 From: Johannes Markert Date: Tue, 24 Sep 2024 19:00:14 +0200 Subject: [PATCH 35/42] Added license. --- .../t8_fortran_interface_mod.f90 | 20 +++++++++++++++++++ 1 file changed, 20 insertions(+) diff --git a/api/t8_fortran_interface/t8_fortran_interface_mod.f90 b/api/t8_fortran_interface/t8_fortran_interface_mod.f90 index 8dc2fea3c3..5001bc70cf 100644 --- a/api/t8_fortran_interface/t8_fortran_interface_mod.f90 +++ b/api/t8_fortran_interface/t8_fortran_interface_mod.f90 @@ -1,3 +1,23 @@ +!! This file is part of t8code. +!! t8code is a C library to manage a collection (a forest) of multiple +!! connected adaptive space-trees of general element classes in parallel. +!! +!! Copyright (C) 2024 the developers +!! +!! t8code is free software; you can redistribute it and/or modify +!! it under the terms of the GNU General Public License as published by +!! the Free Software Foundation; either version 2 of the License, or +!! (at your option) any later version. +!! +!! t8code is distributed in the hope that it will be useful, +!! but WITHOUT ANY WARRANTY; without even the implied warranty of +!! MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +!! GNU General Public License for more details. +!! +!! You should have received a copy of the GNU General Public License +!! along with t8code; if not, write to the Free Software Foundation, Inc., +!! 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. + module t8_fortran_interface_mod use, intrinsic :: ISO_C_BINDING From e8f3deff3c8859dd69d92b42b92e608b3507e2b3 Mon Sep 17 00:00:00 2001 From: Johannes Markert Date: Tue, 24 Sep 2024 19:01:21 +0200 Subject: [PATCH 36/42] Code cleanup. --- test/CMakeLists.txt | 1 - 1 file changed, 1 deletion(-) diff --git a/test/CMakeLists.txt b/test/CMakeLists.txt index b341ba4987..e1f3e5eb39 100644 --- a/test/CMakeLists.txt +++ b/test/CMakeLists.txt @@ -27,7 +27,6 @@ function( add_t8_test ) target_include_directories( ${ADD_T8_TEST_NAME} PRIVATE ${CMAKE_BINARY_DIR}/src ) target_link_libraries( ${ADD_T8_TEST_NAME} PRIVATE T8 gtest pthread MPI::MPI_Fortran ) else() - # target_link_libraries( ${ADD_T8_TEST_NAME} PRIVATE T8 MPI::MPI_Fortran ) target_link_libraries( ${ADD_T8_TEST_NAME} PRIVATE T8 gtest pthread ) endif () From 7293849e0b7335b2c23ec24abc65819923ae1d9a Mon Sep 17 00:00:00 2001 From: Johannes Markert Date: Wed, 25 Sep 2024 10:38:28 +0200 Subject: [PATCH 37/42] Fixed typo. --- .github/workflows/tests_cmake_t8code.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/tests_cmake_t8code.yml b/.github/workflows/tests_cmake_t8code.yml index 066ff46af2..22e48b2730 100644 --- a/.github/workflows/tests_cmake_t8code.yml +++ b/.github/workflows/tests_cmake_t8code.yml @@ -81,7 +81,7 @@ jobs: run: export LESS_TEST_OPTION="-DT8CODE_ENABLE_LESS_TESTS=ON" && echo LESS_TEST_OPTION="$LESS_TEST_OPTION" >> $GITHUB_ENV - name: build config variables - run: export CONFIG_OPTIONS="${LESS_TEST_OPTION} -GNinja -DT8CODE_USE_SYSTEM_SC=ON -DT8CODE_USE_SYSTEM_P4EST=ON -DT8CODE_BUILD_PEDANTIC=ON -DT8CODE_BUILD_FORTRAN=$MPI -DT8CODE_ENABLE_MPI=$MPI -DCMAKE_BUILD_TYPE=$BUILD_TYPE -DSC_DIR=$SC_PATH/install/cmake -DP4EST_DIR=$P4EST_PATH/install/cmake" + run: export CONFIG_OPTIONS="${LESS_TEST_OPTION} -GNinja -DT8CODE_USE_SYSTEM_SC=ON -DT8CODE_USE_SYSTEM_P4EST=ON -DT8CODE_BUILD_PEDANTIC=ON -DT8CODE_BUILD_FORTRAN_INTERFACE=$MPI -DT8CODE_ENABLE_MPI=$MPI -DCMAKE_BUILD_TYPE=$BUILD_TYPE -DSC_DIR=$SC_PATH/install/cmake -DP4EST_DIR=$P4EST_PATH/install/cmake" && echo CONFIG_OPTIONS="$CONFIG_OPTIONS" >> $GITHUB_ENV # cmake and test - name: Printing MPI compiler info From 8a9305d639550cdf0b253eedc206bde1426e2296 Mon Sep 17 00:00:00 2001 From: Johannes Markert Date: Thu, 26 Sep 2024 09:51:39 +0200 Subject: [PATCH 38/42] Appended parallel suffix to Fortran linkage test. --- test/CMakeLists.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/CMakeLists.txt b/test/CMakeLists.txt index e1f3e5eb39..ef9f9ba71a 100644 --- a/test/CMakeLists.txt +++ b/test/CMakeLists.txt @@ -140,7 +140,7 @@ add_t8_test( NAME t8_gtest_root_serial SOURCES t8_gtest_main.cx add_t8_test( NAME t8_gtest_scheme_consistency_serial SOURCES t8_gtest_main.cxx t8_schemes/t8_gtest_scheme_consistency.cxx ) if( T8CODE_BUILD_FORTRAN_INTERFACE AND T8CODE_ENABLE_MPI ) - add_t8_test( NAME t8_test_fortran_mpi_interface_init SOURCES api/t8_fortran_interface/t8_test_mpi_init.f90 ) + add_t8_test( NAME t8_test_fortran_mpi_interface_init_parallel SOURCES api/t8_fortran_interface/t8_test_mpi_init.f90 ) endif() copy_test_file( test_cube_unstructured_1.inp ) From 7c56ce66895dde51190bc5c9e36c33c8c17cf8a1 Mon Sep 17 00:00:00 2001 From: Sandro Elsweijer Date: Fri, 27 Sep 2024 11:24:00 +0200 Subject: [PATCH 39/42] enforce MPI in api tests --- .github/workflows/tests_cmake_testsuite.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/tests_cmake_testsuite.yml b/.github/workflows/tests_cmake_testsuite.yml index b66ab540cc..0ab57b62a1 100644 --- a/.github/workflows/tests_cmake_testsuite.yml +++ b/.github/workflows/tests_cmake_testsuite.yml @@ -121,7 +121,7 @@ jobs: strategy: fail-fast: false matrix: - MPI: [OFF, ON] + MPI: [ON] # For now the fortran API only supports building with MPI BUILD_TYPE: [Debug, Release] include: - MAKEFLAGS: -j4 From 91433fa70668d667a8410d89f65da20fd370d6c7 Mon Sep 17 00:00:00 2001 From: Sandro Elsweijer Date: Fri, 27 Sep 2024 11:24:30 +0200 Subject: [PATCH 40/42] update fortran build flag in ci --- .github/workflows/tests_cmake_t8code_api.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/tests_cmake_t8code_api.yml b/.github/workflows/tests_cmake_t8code_api.yml index 5c6d42e08c..d96b5d0b33 100644 --- a/.github/workflows/tests_cmake_t8code_api.yml +++ b/.github/workflows/tests_cmake_t8code_api.yml @@ -88,7 +88,7 @@ jobs: - name: check fortran run: echo "Checking fortran" - name: echo cmake line - run: echo cmake ../ $CONFIG_OPTIONS -DT8CODE_ENABLE_FORTRAN=ON + run: echo cmake ../ $CONFIG_OPTIONS -DT8CODE_BUILD_FORTRAN_INTERFACE=ON - name: cmake MPI fortran debug run: mkdir build_fortran && cd build_fortran && cmake ../ $CONFIG_OPTIONS -DT8CODE_ENABLE_FORTRAN=ON - name: OnFailUploadLog From 8116ab9f5794efc3baf1685bb62259202f4980d4 Mon Sep 17 00:00:00 2001 From: Johannes Markert Date: Fri, 27 Sep 2024 13:29:29 +0200 Subject: [PATCH 41/42] Added warning and reverted parameter in GH action. --- .github/workflows/tests_cmake_t8code.yml | 2 +- CMakeLists.txt | 4 ++++ 2 files changed, 5 insertions(+), 1 deletion(-) diff --git a/.github/workflows/tests_cmake_t8code.yml b/.github/workflows/tests_cmake_t8code.yml index 22e48b2730..1effcaba77 100644 --- a/.github/workflows/tests_cmake_t8code.yml +++ b/.github/workflows/tests_cmake_t8code.yml @@ -81,7 +81,7 @@ jobs: run: export LESS_TEST_OPTION="-DT8CODE_ENABLE_LESS_TESTS=ON" && echo LESS_TEST_OPTION="$LESS_TEST_OPTION" >> $GITHUB_ENV - name: build config variables - run: export CONFIG_OPTIONS="${LESS_TEST_OPTION} -GNinja -DT8CODE_USE_SYSTEM_SC=ON -DT8CODE_USE_SYSTEM_P4EST=ON -DT8CODE_BUILD_PEDANTIC=ON -DT8CODE_BUILD_FORTRAN_INTERFACE=$MPI -DT8CODE_ENABLE_MPI=$MPI -DCMAKE_BUILD_TYPE=$BUILD_TYPE -DSC_DIR=$SC_PATH/install/cmake -DP4EST_DIR=$P4EST_PATH/install/cmake" + run: export CONFIG_OPTIONS="${LESS_TEST_OPTION} -GNinja -DT8CODE_USE_SYSTEM_SC=ON -DT8CODE_USE_SYSTEM_P4EST=ON -DT8CODE_BUILD_PEDANTIC=ON -DT8CODE_ENABLE_MPI=$MPI -DCMAKE_BUILD_TYPE=$BUILD_TYPE -DSC_DIR=$SC_PATH/install/cmake -DP4EST_DIR=$P4EST_PATH/install/cmake" && echo CONFIG_OPTIONS="$CONFIG_OPTIONS" >> $GITHUB_ENV # cmake and test - name: Printing MPI compiler info diff --git a/CMakeLists.txt b/CMakeLists.txt index 559f20a73f..90aa521073 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -146,4 +146,8 @@ endif() if( T8CODE_BUILD_FORTRAN_INTERFACE ) enable_language( Fortran ) add_subdirectory( ${CMAKE_CURRENT_LIST_DIR}/api/t8_fortran_interface ) + + if( NOT T8CODE_ENABLE_MPI ) + message( FATAL_ERROR "Fortran API only available when MPI is enabled." ) + endif() endif() From 1401af564f3ee92dec97d91de4750ba46f8be3a6 Mon Sep 17 00:00:00 2001 From: Sandro Elsweijer <49643115+sandro-elsweijer@users.noreply.github.com> Date: Mon, 30 Sep 2024 09:35:56 +0200 Subject: [PATCH 42/42] Enable api workflow --- .github/workflows/tests_cmake_testsuite.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/tests_cmake_testsuite.yml b/.github/workflows/tests_cmake_testsuite.yml index 0ab57b62a1..ac20231bc5 100644 --- a/.github/workflows/tests_cmake_testsuite.yml +++ b/.github/workflows/tests_cmake_testsuite.yml @@ -116,7 +116,7 @@ jobs: # Run t8code linkage tests with and without MPI and in serial and debug mode t8code_api_tests: - if: (github.event_name == 'schedule' && github.repository == 'DLR-AMR/t8code') || (github.event_name != 'schedule') && false + if: (github.event_name == 'schedule' && github.repository == 'DLR-AMR/t8code') || (github.event_name != 'schedule') uses: ./.github/workflows/tests_cmake_t8code_api.yml strategy: fail-fast: false