diff --git a/src/ALL_fortran.cpp b/src/ALL_fortran.cpp index f3c179cc548965f8a01d058cb045fe0add3095e1..62fc6e0a898e09af9665faaf2379d2b19fea24a9 100644 --- a/src/ALL_fortran.cpp +++ b/src/ALL_fortran.cpp @@ -249,6 +249,21 @@ void all_get_work_array_c(ALL_t *all_obj, double *work, int length) { ALL_catch } +void all_get_number_of_neighbors_c(ALL_t *all_obj, int *count) { + ALL_try + std::vector<int> neighbors = all_obj->getNeighbors(); + *count = neighbors.size(); + ALL_catch +} + +void all_get_neighbors_c(ALL_t *all_obj, int *neighbors, int count) { + ALL_try + std::vector<int> all_neighbors = all_obj->getNeighbors(); + assert((int)all_neighbors.size() == count); + memcpy(neighbors,&all_neighbors[0],count*sizeof(*neighbors)); + ALL_catch +} + #ifdef ALL_VTK_OUTPUT // print VTK outlines void all_print_vtk_outlines_c(ALL_t * all_obj known_unused, int known_unused step) { diff --git a/src/ALL_module.F90 b/src/ALL_module.F90 index 0092c46520878a72dea0fa0b0e3b10710ac14436..d76af38fc8a0c19dee71b0ae77e65e465e883bbf 100644 --- a/src/ALL_module.F90 +++ b/src/ALL_module.F90 @@ -181,6 +181,17 @@ module ALL_module integer(c_int), value :: length real(c_double), dimension(length) :: work end subroutine + subroutine all_get_number_of_neighbors_c(obj, count) bind(C) + use iso_c_binding + type(c_ptr), value :: obj + integer(c_int) :: count + end subroutine + subroutine all_get_neighbors_c(obj, neighbors, count) bind(C) + use iso_c_binding + type(c_ptr), value :: obj + integer(c_int), value :: count + integer(c_int), dimension(count) :: neighbors + end subroutine #ifdef ALL_VTK_OUTPUT subroutine all_print_vtk_outlines_c(obj, step) bind(C) use iso_c_binding @@ -238,6 +249,8 @@ module ALL_module procedure :: get_length_of_work => ALL_get_length_of_work procedure :: get_work => ALL_get_work procedure :: get_work_array => ALL_get_work_array + procedure :: get_number_of_neighbors => ALL_get_number_of_neighbors + procedure :: get_neighbors => ALL_get_neighbors #ifdef ALL_VTK_OUTPUT procedure :: print_vtk_outlines => ALL_print_vtk_outlines procedure :: print_vtk_vertices => ALL_print_vtk_vertices @@ -268,6 +281,8 @@ module ALL_module public :: ALL_get_length_of_work public :: ALL_get_work public :: ALL_get_work_array + public :: ALL_get_number_of_neighbors + public :: ALL_get_neighbors #ifdef ALL_VTK_OUTPUT public :: ALL_print_vtk_outlines public :: ALL_print_vtk_vertices @@ -480,6 +495,25 @@ contains endif call all_get_work_array_c(this%object, work, size(work)) end subroutine + !> Retrieve number of neighbors (i.e. length of neighbors list) + subroutine ALL_get_number_of_neighbors(this, count) + class(ALL_t), intent(in) :: this + integer(c_int), intent(out) :: count + call all_get_number_of_vertices_c(this%object, count) + end subroutine + !> Retrieve list of neighboring ranks (must be correct size already) + subroutine ALL_get_neighbors(this, neighbors) + class(ALL_t), intent(in) :: this + integer(c_int), dimension(:), intent(out) :: neighbors + integer :: count + call ALL_get_number_of_neighbors(this, count) + if(size(neighbors) /= count) then + write(error_unit,'(a)') "ALL_get_neighbors: neighbors has wrong length!" + stop + endif + call all_get_neighbors_c(this%object, neighbors, size(neighbors)) + end subroutine + #ifdef ALL_VTK_OUTPUT !> Print VTK outlines (must be enabled in build step) subroutine ALL_print_vtk_outlines(this, step)