Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature Enhancements and Performance Improvements #13

Merged
merged 14 commits into from
May 19, 2024
Prev Previous commit
Next Next commit
Parallelize calculation of distances with OpenMP.
Signed-off-by: Seyed Ali Ghasemi <info@gha3mi.com>
  • Loading branch information
gha3mi committed May 15, 2024
commit 0a8be7b714b35fd0ad62a7a942ec3b1b42062641
39 changes: 35 additions & 4 deletions src/forcad_nurbs_curve.f90
Original file line number Diff line number Diff line change
@@ -1498,12 +1498,19 @@ pure subroutine nearest_point(this, point_Xg, nearest_Xg, nearest_Xt, id)
integer, intent(out), optional :: id
integer :: id_
real(rk), allocatable :: distances(:)
integer :: i

interface
pure function nearest_point_help_1d(f_ng, f_Xg, f_point_Xg) result(f_distances)
import :: rk
integer, intent(in) :: f_ng
real(rk), intent(in), contiguous :: f_Xg(:,:)
real(rk), intent(in), contiguous :: f_point_Xg(:)
real(rk), allocatable :: f_distances(:)
end function
end interface

allocate(distances(this%ng))
do concurrent (i = 1: this%ng)
distances(i) = norm2(this%Xg(i,:) - point_Xg)
end do
distances = nearest_point_help_1d(this%ng, this%Xg, point_Xg)

id_ = minloc(distances, dim=1)
if (present(id)) id = id_
@@ -1678,3 +1685,27 @@ impure function compute_Tgc_bspline_1d(Xt, knot, degree, nc, ng) result(Tgc)
!$OMP END PARALLEL DO
end function
!===============================================================================


!===============================================================================
!> author: Seyed Ali Ghasemi
!> license: BSD 3-Clause
impure function nearest_point_help_1d(ng, Xg, point_Xg) result(distances)
use forcad_utils, only: rk

implicit none
integer, intent(in) :: ng
real(rk), intent(in), contiguous :: Xg(:,:)
real(rk), intent(in), contiguous :: point_Xg(:)
real(rk), allocatable :: distances(:)
integer :: i

allocate(distances(ng))
!$OMP PARALLEL DO
do i = 1, ng
distances(i) = norm2(Xg(i,:) - point_Xg)
end do
!$OMP END PARALLEL DO

end function
!===============================================================================
41 changes: 36 additions & 5 deletions src/forcad_nurbs_surface.f90
Original file line number Diff line number Diff line change
@@ -2098,12 +2098,19 @@ pure subroutine nearest_point(this, point_Xg, nearest_Xg, nearest_Xt, id)
integer, intent(out), optional :: id
integer :: id_
real(rk), allocatable :: distances(:)
integer :: i

interface
pure function nearest_point_help_2d(f_ng, f_Xg, f_point_Xg) result(f_distances)
import :: rk
integer, intent(in) :: f_ng(2)
real(rk), intent(in), contiguous :: f_Xg(:,:)
real(rk), intent(in), contiguous :: f_point_Xg(:)
real(rk), allocatable :: f_distances(:)
end function
end interface

allocate(distances(this%ng(1)*this%ng(2)))
do concurrent (i = 1: this%ng(1)*this%ng(2))
distances(i) = norm2(this%Xg(i,:) - point_Xg)
end do
distances = nearest_point_help_2d(this%ng, this%Xg, point_Xg)

id_ = minloc(distances, dim=1)
if (present(id)) id = id_
@@ -2291,4 +2298,28 @@ impure function compute_Tgc_bspline_2d(Xt, knot1, knot2, degree, nc, ng) result(
end do
!$OMP END PARALLEL DO
end function
!===============================================================================
!===============================================================================


!===============================================================================
!> author: Seyed Ali Ghasemi
!> license: BSD 3-Clause
impure function nearest_point_help_2d(ng, Xg, point_Xg) result(distances)
use forcad_utils, only: rk

implicit none
integer, intent(in) :: ng(2)
real(rk), intent(in), contiguous :: Xg(:,:)
real(rk), intent(in), contiguous :: point_Xg(:)
real(rk), allocatable :: distances(:)
integer :: i

allocate(distances(ng(1)*ng(2)))
!$OMP PARALLEL DO
do i = 1, ng(1)*ng(2)
distances(i) = norm2(Xg(i,:) - point_Xg)
end do
!$OMP END PARALLEL DO

end function
!===============================================================================
39 changes: 35 additions & 4 deletions src/forcad_nurbs_volume.f90
Original file line number Diff line number Diff line change
@@ -2589,12 +2589,19 @@ pure subroutine nearest_point(this, point_Xg, nearest_Xg, nearest_Xt, id)
integer, intent(out), optional :: id
integer :: id_
real(rk), allocatable :: distances(:)
integer :: i

interface
pure function nearest_point_help_3d(f_ng, f_Xg, f_point_Xg) result(f_distances)
import :: rk
integer, intent(in) :: f_ng(3)
real(rk), intent(in), contiguous :: f_Xg(:,:)
real(rk), intent(in), contiguous :: f_point_Xg(:)
real(rk), allocatable :: f_distances(:)
end function
end interface

allocate(distances(this%ng(1)*this%ng(2)*this%ng(3)))
do concurrent (i = 1: this%ng(1)*this%ng(2)*this%ng(3))
distances(i) = norm2(this%Xg(i,:) - point_Xg)
end do
distances = nearest_point_help_3d(this%ng, this%Xg, point_Xg)

id_ = minloc(distances, dim=1)
if (present(id)) id = id_
@@ -2784,3 +2791,27 @@ impure function compute_Tgc_bspline_3d(Xt, knot1, knot2, knot3, degree, nc, ng)
!$OMP END PARALLEL DO
end function
!===============================================================================


!===============================================================================
!> author: Seyed Ali Ghasemi
!> license: BSD 3-Clause
impure function nearest_point_help_3d(ng, Xg, point_Xg) result(distances)
use forcad_utils, only: rk

implicit none
integer, intent(in) :: ng(3)
real(rk), intent(in), contiguous :: Xg(:,:)
real(rk), intent(in), contiguous :: point_Xg(:)
real(rk), allocatable :: distances(:)
integer :: i

allocate(distances(ng(1)*ng(2)*ng(3)))
!$OMP PARALLEL DO
do i = 1, ng(1)*ng(2)*ng(3)
distances(i) = norm2(Xg(i,:) - point_Xg)
end do
!$OMP END PARALLEL DO

end function
!===============================================================================
Loading