Skip to content
This repository was archived by the owner on Aug 28, 2024. It is now read-only.

Commit

Permalink
Vectorized the operators
Browse files Browse the repository at this point in the history
  • Loading branch information
daminton committed Sep 22, 2021
1 parent 406bb80 commit 3b6854b
Show file tree
Hide file tree
Showing 5 changed files with 34 additions and 29 deletions.
12 changes: 6 additions & 6 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ LMKL = -L$(MKLROOT)/lib/intel64 -qopt-matmul

MODULES = $(SWIFTEST_MODULES) $(USER_MODULES)

.PHONY : all mod lib libdir fast drivers bin clean force
.PHONY : all mod lib fast drivers bin clean force

% : %.f90 force
$(FORTRAN) $(FFLAGS) -I$(SWIFTEST_HOME)/include -I$(NETCDF_FORTRAN_HOME)/include $(IMKL) $< -o $@ \
Expand Down Expand Up @@ -118,11 +118,6 @@ lib:
ln -s $(SWIFTEST_HOME)/Makefile.Defines .; \
ln -s $(SWIFTEST_HOME)/Makefile .; \
make libdir
cd $(SWIFTEST_HOME)/src/operators; \
rm -f Makefile.Defines Makefile; \
ln -s $(SWIFTEST_HOME)/Makefile.Defines .; \
ln -s $(SWIFTEST_HOME)/Makefile .; \
make libdir
cd $(SWIFTEST_HOME)/src/setup; \
rm -f Makefile.Defines Makefile; \
ln -s $(SWIFTEST_HOME)/Makefile.Defines .; \
Expand Down Expand Up @@ -165,6 +160,11 @@ lib:
make libdir

fast:
cd $(SWIFTEST_HOME)/src/operators; \
rm -f Makefile.Defines Makefile; \
ln -s $(SWIFTEST_HOME)/Makefile.Defines .; \
ln -s $(SWIFTEST_HOME)/Makefile .; \
make fastdir
cd $(SWIFTEST_HOME)/src/fraggle; \
rm -f Makefile.Defines Makefile; \
ln -s $(SWIFTEST_HOME)/Makefile.Defines .; \
Expand Down
4 changes: 2 additions & 2 deletions Makefile.Defines
Original file line number Diff line number Diff line change
Expand Up @@ -69,8 +69,8 @@ GPRODUCTION = -O2 -ffree-line-length-none $(GPAR)

#FFLAGS = $(IDEBUG) #$(SIMDVEC) $(PAR)
#FFASTFLAGS = $(IDEBUG) #$(SIMDVEC) $(PAR)
FFLAGS = $(IPRODUCTION) $(STRICTREAL) #$(ADVIXE_FLAGS)
FFASTFLAGS = $(IPRODUCTION) -fp-model fast #$(ADVIXE_FLAGS)
FFLAGS = $(IPRODUCTION) $(STRICTREAL) $(OPTREPORT) #$(ADVIXE_FLAGS)
FFASTFLAGS = $(IPRODUCTION) -fp-model fast $(OPTREPORT) #$(ADVIXE_FLAGS)
FORTRAN = ifort
AR = xiar

Expand Down
10 changes: 10 additions & 0 deletions src/modules/swiftest_operators.f90
Original file line number Diff line number Diff line change
Expand Up @@ -15,42 +15,49 @@ module swiftest_operators

interface operator(.cross.)
module pure function operator_cross_sp(A, B) result(C)
!$omp declare simd(operator_cross_sp)
implicit none
real(SP), dimension(:), intent(in) :: A, B
real(SP), dimension(3) :: C
end function operator_cross_sp

module pure function operator_cross_dp(A, B) result(C)
!$omp declare simd(operator_cross_dp)
implicit none
real(DP), dimension(:), intent(in) :: A, B
real(DP), dimension(3) :: C
end function operator_cross_dp

module pure function operator_cross_qp(A, B) result(C)
!$omp declare simd(operator_cross_qp)
implicit none
real(QP), dimension(:), intent(in) :: A, B
real(QP), dimension(3) :: C
end function operator_cross_qp

module pure function operator_cross_i1b(A, B) result(C)
!$omp declare simd(operator_cross_i1b)
implicit none
integer(I1B), dimension(:), intent(in) :: A, B
integer(I1B), dimension(3) :: C
end function operator_cross_i1b

module pure function operator_cross_i2b(A, B) result(C)
!$omp declare simd(operator_cross_i2b)
implicit none
integer(I2B), dimension(:), intent(in) :: A, B
integer(I2B), dimension(3) :: C
end function operator_cross_i2b

module pure function operator_cross_i4b(A, B) result(C)
!$omp declare simd(operator_cross_i4b)
implicit none
integer(I4B), dimension(:), intent(in) :: A, B
integer(I4B), dimension(3) :: C
end function operator_cross_i4b

module pure function operator_cross_i8b(A, B) result(C)
!$omp declare simd(operator_cross_i8b)
implicit none
integer(I8B), dimension(:), intent(in) :: A, B
integer(I8B), dimension(3) :: C
Expand Down Expand Up @@ -105,18 +112,21 @@ end function operator_cross_el_i8b

interface operator(.mag.)
module pure function operator_mag_sp(A) result(B)
!$omp declare simd(operator_mag_sp)
implicit none
real(SP), dimension(:), intent(in) :: A
real(SP) :: B
end function operator_mag_sp

module pure function operator_mag_dp(A) result(B)
!$omp declare simd(operator_mag_dp)
implicit none
real(DP), dimension(:), intent(in) :: A
real(DP) :: B
end function operator_mag_dp

module pure function operator_mag_qp(A) result(B)
!$omp declare simd(operator_mag_qp)
implicit none
real(QP), dimension(:), intent(in) :: A
real(QP) :: B
Expand Down
35 changes: 14 additions & 21 deletions src/operators/operator_cross.f90
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
contains

module pure function operator_cross_sp(A, B) result(C)
!$omp declare simd(operator_cross_sp)
implicit none
real(SP), dimension(:), intent(in) :: A, B
real(SP), dimension(3) :: C
Expand All @@ -18,6 +19,7 @@ module pure function operator_cross_sp(A, B) result(C)
end function operator_cross_sp

module pure function operator_cross_dp(A, B) result(C)
!$omp declare simd(operator_cross_dp)
implicit none
real(DP), dimension(:), intent(in) :: A, B
real(DP), dimension(3) :: C
Expand All @@ -28,6 +30,7 @@ module pure function operator_cross_dp(A, B) result(C)
end function operator_cross_dp

module pure function operator_cross_qp(A, B) result(C)
!$omp declare simd(operator_cross_qp)
implicit none
real(QP), dimension(:), intent(in) :: A, B
real(QP), dimension(3) :: C
Expand All @@ -38,6 +41,7 @@ module pure function operator_cross_qp(A, B) result(C)
end function operator_cross_qp

module pure function operator_cross_i1b(A, B) result(C)
!$omp declare simd(operator_cross_i1b)
implicit none
integer(I1B), dimension(:), intent(in) :: A, B
integer(I1B), dimension(3) :: C
Expand All @@ -48,6 +52,7 @@ module pure function operator_cross_i1b(A, B) result(C)
end function operator_cross_i1b

module pure function operator_cross_i2b(A, B) result(C)
!$omp declare simd(operator_cross_i2b)
implicit none
integer(I2B), dimension(:), intent(in) :: A, B
integer(I2B), dimension(3) :: C
Expand All @@ -58,6 +63,7 @@ module pure function operator_cross_i2b(A, B) result(C)
end function operator_cross_i2b

module pure function operator_cross_i4b(A, B) result(C)
!$omp declare simd(operator_cross_i4b)
implicit none
integer(I4B), dimension(:), intent(in) :: A, B
integer(I4B), dimension(3) :: C
Expand All @@ -68,6 +74,7 @@ module pure function operator_cross_i4b(A, B) result(C)
end function operator_cross_i4b

module pure function operator_cross_i8b(A, B) result(C)
!$omp declare simd(operator_cross_i8b)
implicit none
integer(I8B), dimension(:), intent(in) :: A, B
integer(I8B), dimension(3) :: C
Expand All @@ -86,9 +93,7 @@ module pure function operator_cross_el_sp(A, B) result(C)
if (allocated(C)) deallocate(C)
allocate(C, mold = A)
do concurrent (i = 1:n)
C(1, i) = A(2, i) * B(3, i) - A(3, i) * B(2, i)
C(2, i) = A(3, i) * B(1, i) - A(1, i) * B(3, i)
C(3, i) = A(1, i) * B(2, i) - A(2, i) * B(1, i)
C(:,i) = operator_cross_sp(A(:,i), B(:,i))
end do
return
end function operator_cross_el_sp
Expand All @@ -102,9 +107,7 @@ module pure function operator_cross_el_dp(A, B) result(C)
if (allocated(C)) deallocate(C)
allocate(C, mold = A)
do concurrent (i = 1:n)
C(1, i) = A(2, i) * B(3, i) - A(3, i) * B(2, i)
C(2, i) = A(3, i) * B(1, i) - A(1, i) * B(3, i)
C(3, i) = A(1, i) * B(2, i) - A(2, i) * B(1, i)
C(:,i) = operator_cross_dp(A(:,i), B(:,i))
end do
return
end function operator_cross_el_dp
Expand All @@ -118,9 +121,7 @@ module pure function operator_cross_el_qp(A, B) result(C)
if (allocated(C)) deallocate(C)
allocate(C, mold = A)
do concurrent (i = 1:n)
C(1, i) = A(2, i) * B(3, i) - A(3, i) * B(2, i)
C(2, i) = A(3, i) * B(1, i) - A(1, i) * B(3, i)
C(3, i) = A(1, i) * B(2, i) - A(2, i) * B(1, i)
C(:,i) = operator_cross_qp(A(:,i), B(:,i))
end do
return
end function operator_cross_el_qp
Expand All @@ -134,9 +135,7 @@ module pure function operator_cross_el_i1b(A, B) result(C)
if (allocated(C)) deallocate(C)
allocate(C, mold = A)
do concurrent (i = 1:n)
C(1, i) = A(2, i) * B(3, i) - A(3, i) * B(2, i)
C(2, i) = A(3, i) * B(1, i) - A(1, i) * B(3, i)
C(3, i) = A(1, i) * B(2, i) - A(2, i) * B(1, i)
C(:,i) = operator_cross_i1b(A(:,i), B(:,i))
end do
return
end function operator_cross_el_i1b
Expand All @@ -150,9 +149,7 @@ module pure function operator_cross_el_i2b(A, B) result(C)
if (allocated(C)) deallocate(C)
allocate(C, mold = A)
do concurrent (i = 1:n)
C(1, i) = A(2, i) * B(3, i) - A(3, i) * B(2, i)
C(2, i) = A(3, i) * B(1, i) - A(1, i) * B(3, i)
C(3, i) = A(1, i) * B(2, i) - A(2, i) * B(1, i)
C(:,i) = operator_cross_i2b(A(:,i), B(:,i))
end do
return
end function operator_cross_el_i2b
Expand All @@ -166,9 +163,7 @@ module pure function operator_cross_el_i4b(A, B) result(C)
if (allocated(C)) deallocate(C)
allocate(C, mold = A)
do concurrent (i = 1:n)
C(1, i) = A(2, i) * B(3, i) - A(3, i) * B(2, i)
C(2, i) = A(3, i) * B(1, i) - A(1, i) * B(3, i)
C(3, i) = A(1, i) * B(2, i) - A(2, i) * B(1, i)
C(:,i) = operator_cross_i4b(A(:,i), B(:,i))
end do
return
end function operator_cross_el_i4b
Expand All @@ -182,9 +177,7 @@ module pure function operator_cross_el_i8b(A, B) result(C)
if (allocated(C)) deallocate(C)
allocate(C, mold = A)
do concurrent (i = 1:n)
C(1, i) = A(2, i) * B(3, i) - A(3, i) * B(2, i)
C(2, i) = A(3, i) * B(1, i) - A(1, i) * B(3, i)
C(3, i) = A(1, i) * B(2, i) - A(2, i) * B(1, i)
C(:,i) = operator_cross_i8b(A(:,i), B(:,i))
end do
return
end function operator_cross_el_i8b
Expand Down
2 changes: 2 additions & 0 deletions src/operators/operator_mag.f90
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
contains

module pure function operator_mag_sp(A) result(B)
!$omp declare simd(operator_mag_sp)
implicit none
real(SP), dimension(:), intent(in) :: A
real(SP) :: B
Expand All @@ -15,6 +16,7 @@ module pure function operator_mag_sp(A) result(B)
end function operator_mag_sp

module pure function operator_mag_dp(A) result(B)
!$omp declare simd(operator_mag_dp)
implicit none
real(DP), dimension(:), intent(in) :: A
real(DP) :: B
Expand Down

0 comments on commit 3b6854b

Please sign in to comment.