diff --git a/4-add-test-cases-for-openmp-optimization.patch b/4-add-test-cases-for-openmp-optimization.patch new file mode 100644 index 0000000000000000000000000000000000000000..aa72067d8959c6e1d0379fe2c287eb3b34a8f5f8 --- /dev/null +++ b/4-add-test-cases-for-openmp-optimization.patch @@ -0,0 +1,676 @@ +From d285972f0bd71a1db981008cbadda8909da8b1ac Mon Sep 17 00:00:00 2001 +From: xieyihui +Date: Thu, 13 Oct 2022 18:25:41 +0800 +Subject: [PATCH] Add references to test cases and README.md. + +diff --git a/test/openmp_optimization/fortran_main001.f90 b/test/openmp_optimization/fortran_main001.f90 +new file mode 100644 +index 0000000..2ef72a2 +--- /dev/null ++++ b/test/openmp_optimization/fortran_main001.f90 +@@ -0,0 +1,28 @@ ++! Test optimizaton for fortran use openmp about parallel region merge ++! ++program main ++ use omp_lib ++ real(kind = 8) :: starttime, endtime, time ++ integer :: a(100) ++ integer :: b(100) ++ starttime = omp_get_wtime() ++ do n = 1, 100000 ++ !$omp parallel do ++ do i = 1, 100 ++ a(i) = i ++ end do ++ !$omp end parallel do ++ !$omp parallel do ++ do i = 1, 100 ++ b(i) = i ++ end do ++ !$omp end parallel do ++ end do ++ endtime = omp_get_wtime() ++ time = endtime - starttime ++print *, time ++end program main ++ ++! Reference ++! Müller, Matthias S.. "Some Simple OpenMP Optimization Techniques." ++! WOMPAT (2001). +\ No newline at end of file +diff --git a/test/openmp_optimization/fortran_main002.f90 b/test/openmp_optimization/fortran_main002.f90 +new file mode 100644 +index 0000000..84302b4 +--- /dev/null ++++ b/test/openmp_optimization/fortran_main002.f90 +@@ -0,0 +1,25 @@ ++! Test optimizaton for fortran use openmp about implicit nowait at end ++! of parallel region ++! ++program main ++ use omp_lib ++ real(kind = 8) :: starttime, endtime, time ++ integer :: a(100) ++ starttime = omp_get_wtime() ++ do n = 1, 100000 ++ !$omp parallel ++ !$omp do ++ do i = 1, 100 ++ a(i) = i ++ end do ++ !$omp end do ++ !$omp end parallel ++ end do ++ endtime = omp_get_wtime() ++ time = endtime - starttime ++ print *, time ++end program main ++ ++! Reference ++! Müller, Matthias S.. "Some Simple OpenMP Optimization Techniques." ++! WOMPAT (2001). +\ No newline at end of file +diff --git a/test/openmp_optimization/fortran_main003.f90 b/test/openmp_optimization/fortran_main003.f90 +new file mode 100644 +index 0000000..687127f +--- /dev/null ++++ b/test/openmp_optimization/fortran_main003.f90 +@@ -0,0 +1,31 @@ ++! Test help optimize code with the OpenMP directive. OpenMP directives ++! may help the compiler to generate better code because he knows that ++! certain preconditions are fulfilled. Compiler cannot assume that the ++! different iterations of the loop are independent. But there is omp ++! parallel do. The loop also can be optimized by vectorization ++! ++program main ++ use omp_lib ++ real(kind = 8) :: starttime, endtime, time ++ integer :: a(100) ++ integer :: b(100) ++ integer :: index(100) ++ do i = 1, 100 ++ index(i) = i ++ end do ++ starttime = omp_get_wtime() ++ do n = 1, 100000 ++ !$omp parallel do ++ do i = 1, 100 ++ a(index(i)) = a(index(i)) + b(i) ++ end do ++ !$omp end parallel do ++ end do ++ endtime = omp_get_wtime() ++ time = endtime - starttime ++ print *, time ++end program main ++ ++! Reference ++! Müller, Matthias S.. "Some Simple OpenMP Optimization Techniques." ++! WOMPAT (2001). +\ No newline at end of file +diff --git a/test/openmp_optimization/fortran_main004.f90 b/test/openmp_optimization/fortran_main004.f90 +new file mode 100644 +index 0000000..1ce7826 +--- /dev/null ++++ b/test/openmp_optimization/fortran_main004.f90 +@@ -0,0 +1,33 @@ ++! Test optimizaton for fortran use openmp about remove the redundant ++! barrier ++! ++program main ++ use omp_lib ++ real(kind = 8) :: starttime, endtime, time ++ integer :: a(100), b(100), c(100), d(100) ++ starttime = omp_get_wtime() ++ do n = 1, 100000 ++ !$omp parallel ++ !$omp do ++ do i = 1, 100 ++ a(i) = d(i) ++ end do ++ !$omp end do ++ !$omp do ++ do i = 1, 100 ++ b(i) = c(i) ++ end do ++ !$omp end do ++ !$omp end parallel ++ end do ++ endtime = omp_get_wtime() ++ time = endtime - starttime ++ print *, time ++end program main ++ ++! Reference ++! H. Ma, R. Zhao, X. Gao and Y. Zhang, "Barrier Optimization for ++! OpenMP Program," 2009 10th ACIS International Conference on Software ++! Engineering, Artificial Intelligences, Networking and ++! Parallel/Distributed Computing, 2009, pp. 495-500, doi: ++! 10.1109/SNPD.2009.16. +\ No newline at end of file +diff --git a/test/openmp_optimization/fortran_main005.f90 b/test/openmp_optimization/fortran_main005.f90 +new file mode 100644 +index 0000000..f79d9d7 +--- /dev/null ++++ b/test/openmp_optimization/fortran_main005.f90 +@@ -0,0 +1,33 @@ ++! Test optimizaton for fortran use openmp about remove the redundant ++! barrier ++! ++program main ++ use omp_lib ++ real(kind = 8) :: starttime, endtime, time ++ integer :: a(100), b(100) ++ starttime = omp_get_wtime() ++ do n = 1, 100000 ++ !$omp parallel ++ !$omp do ++ do i = 1, 99, 2 ++ a(i) = b(i) ++ end do ++ !$omp end do ++ !$omp do ++ do i = 2, 100, 2 ++ a(i) = b(i) ++ end do ++ !$omp end do ++ !$omp end parallel ++ end do ++ endtime = omp_get_wtime() ++ time = endtime - starttime ++ print *, time ++end program main ++ ++! Reference ++! H. Ma, R. Zhao, X. Gao and Y. Zhang, "Barrier Optimization for ++! OpenMP Program," 2009 10th ACIS International Conference on Software ++! Engineering, Artificial Intelligences, Networking and ++! Parallel/Distributed Computing, 2009, pp. 495-500, doi: ++! 10.1109/SNPD.2009.16. +\ No newline at end of file +diff --git a/test/openmp_optimization/fortran_main006.f90 b/test/openmp_optimization/fortran_main006.f90 +new file mode 100644 +index 0000000..653a0c9 +--- /dev/null ++++ b/test/openmp_optimization/fortran_main006.f90 +@@ -0,0 +1,26 @@ ++! Test optimizaton for fortran use openmp about implement of DOACROSS ++! parallelism ++! ++program main ++ use omp_lib ++ real(kind = 8) :: starttime, endtime, time ++ integer :: a(100, 100) ++ starttime = omp_get_wtime() ++ do n = 1, 50000 ++ do i = 2, 100 ++ do j = 2, 100 ++ a(i, j) = a(i - 1, j) + a(i, j-1) ++ end do ++ end do ++ end do ++ endtime = omp_get_wtime() ++ time = endtime - starttime ++ print *, time ++end program main ++ ++! Reference ++! H. Ma, R. Zhao, X. Gao and Y. Zhang, "Barrier Optimization for ++! OpenMP Program," 2009 10th ACIS International Conference on Software ++! Engineering, Artificial Intelligences, Networking and ++! Parallel/Distributed Computing, 2009, pp. 495-500, doi: ++! 10.1109/SNPD.2009.16. +\ No newline at end of file +diff --git a/test/openmp_optimization/fortran_main007.f90 b/test/openmp_optimization/fortran_main007.f90 +new file mode 100644 +index 0000000..b8feee7 +--- /dev/null ++++ b/test/openmp_optimization/fortran_main007.f90 +@@ -0,0 +1,25 @@ ++! Test optimizaton for fortran use openmp about orphaned directives ++! ++subroutine add1(s) ++ use omp_lib ++ real :: s ++ !$omp critical ++ s = s + 1 ++ !$omp end critical ++end subroutine add1 ++program main ++ use omp_lib ++ real(kind = 8) :: starttime, endtime, time ++ real :: a ++ starttime = omp_get_wtime() ++ do n = 1, 50000000 ++ call add1(a) ++ end do ++ endtime = omp_get_wtime() ++ time = endtime - starttime ++ print *, time ++end program main ++ ++! Reference ++! Müller, Matthias S.. "Some Simple OpenMP Optimization Techniques." ++! WOMPAT (2001). +\ No newline at end of file +diff --git a/test/openmp_optimization/fortran_main008.f90 b/test/openmp_optimization/fortran_main008.f90 +new file mode 100644 +index 0000000..fac91c0 +--- /dev/null ++++ b/test/openmp_optimization/fortran_main008.f90 +@@ -0,0 +1,28 @@ ++! Test optimizaton for fortran use openmp about alternative code. The ++! goal is to have the performance of the serial code if it is faster ++! than the parallel ++! ++subroutine add1(s, n) ++ use omp_lib ++ real :: s ++ integer :: n ++ !$omp parallel do ++ do i = 1, n ++ s = s + 1 ++ end do ++ !$omp end parallel do ++end subroutine add1 ++program main ++ use omp_lib ++ real(kind = 8) :: starttime, endtime, time ++ real :: a ++ starttime = omp_get_wtime() ++ call add1(a, 8000) ++ endtime = omp_get_wtime() ++ time = endtime - starttime ++ print *, time ++end program main ++ ++! Reference ++! Müller, Matthias S.. "Some Simple OpenMP Optimization Techniques." ++! WOMPAT (2001). +\ No newline at end of file +diff --git a/test/openmp_optimization/fortran_main009.f90 b/test/openmp_optimization/fortran_main009.f90 +new file mode 100644 +index 0000000..6f219de +--- /dev/null ++++ b/test/openmp_optimization/fortran_main009.f90 +@@ -0,0 +1,32 @@ ++! Test optimizaton for fortran use openmp about parallel region expand ++! ++program main ++ use omp_lib ++ real(kind = 8) :: starttime, endtime, time ++ integer :: a(100) ++ integer :: n = 0 ++ starttime = omp_get_wtime() ++ do while (n <= 100000) ++ !$omp parallel do ++ do i = 1, 100 ++ a(i) = i + 1 ++ end do ++ !$omp end parallel do ++ !$omp parallel do ++ do i = 1, 100 ++ a(i) = i + a(i) ++ end do ++ !$omp end parallel do ++ n = n + 1 ++ end do ++ endtime = omp_get_wtime() ++ time = endtime - starttime ++ print *, time ++end program main ++ ++! Reference ++! Doerfert, J., Finkel, H. (2018). Compiler Optimizations for OpenMP. ++! In: de Supinski, B., Valero-Lara, P., Martorell, X., Mateo Bellido S. ++! , Labarta, J. (eds) Evolving OpenMP for Evolving Architectures. ++! IWOMP 2018. Lecture Notes in Computer Science(), vol 11128. Springer, ++! Cham. https://doi.org/10.1007/978-3-319-98521-3_8 +\ No newline at end of file +diff --git a/test/openmp_optimization/optimized_main001.f90 b/test/openmp_optimization/optimized_main001.f90 +new file mode 100644 +index 0000000..f3c3cfa +--- /dev/null ++++ b/test/openmp_optimization/optimized_main001.f90 +@@ -0,0 +1,24 @@ ++! Test optimizaton for fortran use openmp about parallel region merge ++! ++program main ++ use omp_lib ++ real(kind = 8) :: starttime, endtime, time ++ integer :: a(100) ++ integer :: b(100) ++ starttime = omp_get_wtime() ++ do n = 1, 100000 ++ !$omp parallel do ++ do i = 1, 100 ++ a(i) = i ++ b(i) = i ++ end do ++ !$omp end parallel do ++ end do ++ endtime = omp_get_wtime() ++ time = endtime - starttime ++ print *, time ++end program main ++ ++! Reference ++! Müller, Matthias S.. "Some Simple OpenMP Optimization Techniques." ++! WOMPAT (2001). +\ No newline at end of file +diff --git a/test/openmp_optimization/optimized_main002.f90 b/test/openmp_optimization/optimized_main002.f90 +new file mode 100644 +index 0000000..8a9a641 +--- /dev/null ++++ b/test/openmp_optimization/optimized_main002.f90 +@@ -0,0 +1,25 @@ ++! Test optimizaton for fortran use openmp about implicit nowait at end ++! of parallel region ++! ++program main ++ use omp_lib ++ real(kind = 8) :: starttime, endtime, time ++ integer :: a(100) ++ starttime = omp_get_wtime() ++ do n = 1, 100000 ++ !$omp parallel ++ !$omp do ++ do i = 1, 100 ++ a(i) = i ++ end do ++ !$omp end do nowait ++ !$omp end parallel ++ end do ++ endtime = omp_get_wtime() ++ time = endtime - starttime ++ print *, time ++end program main ++ ++! Reference ++! Müller, Matthias S.. "Some Simple OpenMP Optimization Techniques." ++! WOMPAT (2001). +diff --git a/test/openmp_optimization/optimized_main004.f90 b/test/openmp_optimization/optimized_main004.f90 +new file mode 100644 +index 0000000..234aa76 +--- /dev/null ++++ b/test/openmp_optimization/optimized_main004.f90 +@@ -0,0 +1,33 @@ ++! Test optimizaton for fortran use openmp about remove the redundant ++! barrier ++! ++program main ++ use omp_lib ++ real(kind = 8) :: starttime, endtime, time ++ integer :: a(100), b(100), c(100), d(100) ++ starttime = omp_get_wtime() ++ do n = 1, 100000 ++ !$omp parallel ++ !$omp do ++ do i = 1, 100 ++ a(i) = d(i) ++ end do ++ !$omp end do nowait ++ !$omp do ++ do i = 1, 100 ++ b(i) = c(i) ++ end do ++ !$omp end do nowait ++ !$omp end parallel ++ end do ++ endtime = omp_get_wtime() ++ time = endtime - starttime ++ print *, time ++end program main ++ ++! Reference ++! H. Ma, R. Zhao, X. Gao and Y. Zhang, "Barrier Optimization for ++! OpenMP Program," 2009 10th ACIS International Conference on Software ++! Engineering, Artificial Intelligences, Networking and ++! Parallel/Distributed Computing, 2009, pp. 495-500, doi: ++! 10.1109/SNPD.2009.16. +\ No newline at end of file +diff --git a/test/openmp_optimization/optimized_main005.f90 b/test/openmp_optimization/optimized_main005.f90 +new file mode 100644 +index 0000000..102e387 +--- /dev/null ++++ b/test/openmp_optimization/optimized_main005.f90 +@@ -0,0 +1,33 @@ ++! Test optimizaton for fortran use openmp about remove the redundant ++! barrier ++! ++program main ++ use omp_lib ++ real(kind = 8) :: starttime, endtime, time ++ integer :: a(100), b(100) ++ starttime = omp_get_wtime() ++ do n = 1, 100000 ++ !$omp parallel ++ !$omp do ++ do i = 1, 99, 2 ++ a(i) = b(i) ++ end do ++ !$omp end do nowait ++ !$omp do ++ do i = 2, 100, 2 ++ a(i) = b(i) ++ end do ++ !$omp end do nowait ++ !$omp end parallel ++ end do ++ endtime = omp_get_wtime() ++ time = endtime - starttime ++ print *, time ++end program main ++ ++! Reference ++! H. Ma, R. Zhao, X. Gao and Y. Zhang, "Barrier Optimization for ++! OpenMP Program," 2009 10th ACIS International Conference on Software ++! Engineering, Artificial Intelligences, Networking and ++! Parallel/Distributed Computing, 2009, pp. 495-500, doi: ++! 10.1109/SNPD.2009.16. +\ No newline at end of file +diff --git a/test/openmp_optimization/optimized_main007.f90 b/test/openmp_optimization/optimized_main007.f90 +new file mode 100644 +index 0000000..5b35421 +--- /dev/null ++++ b/test/openmp_optimization/optimized_main007.f90 +@@ -0,0 +1,29 @@ ++! Test optimizaton for fortran use openmp about orphaned directives ++! ++subroutine add1(s) ++ use omp_lib ++ real :: s ++ if(omp_in_parallel()) then ++ !$omp critical ++ s = s + 1 ++ !$omp end critical ++ else ++ s = s + 1 ++ end if ++end subroutine add1 ++program main ++ use omp_lib ++ real(kind = 8) :: starttime, endtime, time ++ real :: a ++ starttime = omp_get_wtime() ++ do n = 1, 50000000 ++ call add1(a) ++ end do ++ endtime = omp_get_wtime() ++ time = endtime - starttime ++ print *, time ++end program main ++ ++! Reference ++! Müller, Matthias S.. "Some Simple OpenMP Optimization Techniques." ++! WOMPAT (2001). +\ No newline at end of file +diff --git a/test/openmp_optimization/optimized_main008.f90 b/test/openmp_optimization/optimized_main008.f90 +new file mode 100644 +index 0000000..728c8a8 +--- /dev/null ++++ b/test/openmp_optimization/optimized_main008.f90 +@@ -0,0 +1,34 @@ ++! Test optimizaton for fortran use openmp about alternative code. The ++! goal is to have the performance of the serial code if it is faster ++! than the parallel ++! ++subroutine add1(s, n) ++ use omp_lib ++ real :: s ++ integer :: n ++ if(n > 10000) then ++ !$omp parallel do ++ do i = 1, n ++ s = s + 1 ++ end do ++ !$omp end parallel do ++ else ++ do i = 1, n ++ s = s + 1 ++ end do ++ end if ++end subroutine add1 ++program main ++ use omp_lib ++ real(kind = 8) :: starttime, endtime, time ++ real :: a ++ starttime = omp_get_wtime() ++ call add1(a, 8000) ++ endtime = omp_get_wtime() ++ time = endtime - starttime ++ print *, time ++end program main ++ ++! Reference ++! Müller, Matthias S.. "Some Simple OpenMP Optimization Techniques." ++! WOMPAT (2001). +\ No newline at end of file +diff --git a/test/openmp_optimization/optimized_main009.f90 b/test/openmp_optimization/optimized_main009.f90 +new file mode 100644 +index 0000000..1111c77 +--- /dev/null ++++ b/test/openmp_optimization/optimized_main009.f90 +@@ -0,0 +1,37 @@ ++! Test optimizaton for fortran use openmp about parallel region expand ++! ++program main ++ use omp_lib ++ real(kind = 8) :: starttime, endtime, time ++ integer :: a(100) ++ integer :: n = 0 ++ starttime = omp_get_wtime() ++ !$omp parallel shared(n, a) ++ do while (n <= 100000) ++ !$omp do ++ do i = 1, 100 ++ a(i) = i + 1 ++ end do ++ !$omp end do ++ !$omp do ++ do i = 1, 100 ++ a(i) = i + a(i) ++ end do ++ !$omp end do ++ !$omp master ++ n = n + 1 ++ !$omp end master ++ !$omp barrier ++ end do ++ !$omp end parallel ++ endtime = omp_get_wtime() ++ time = endtime - starttime ++ print *, time ++end program main ++ ++! Reference ++! Doerfert, J., Finkel, H. (2018). Compiler Optimizations for OpenMP. ++! In: de Supinski, B., Valero-Lara, P., Martorell, X., Mateo Bellido S. ++! , Labarta, J. (eds) Evolving OpenMP for Evolving Architectures. ++! IWOMP 2018. Lecture Notes in Computer Science(), vol 11128. Springer, ++! Cham. https://doi.org/10.1007/978-3-319-98521-3_8 +\ No newline at end of file +diff --git a/test/openmp_optimization/readme.md b/test/openmp_optimization/readme.md +new file mode 100644 +index 0000000..e12c628 +--- /dev/null ++++ b/test/openmp_optimization/readme.md +@@ -0,0 +1,35 @@ ++These files are designed to test how OpenMP programs can be optimized. ++This folder has two types of test file, one is unoptimized, the other ++one is optimized. ++ ++Testing Environment: 2-way 32-core Intel(R) Xeon(R) Silver 4215R CPU @ ++3.20GHz, 512GB RAM, X86 ++OMP_NUM_THREADS=8 ++ ++test every case 10 times ++ unoptimized optimized ++test001: 0.771 0.395 ++test002: 0.270 0.153 ++test003: Unable to optimize with hand-written code ++test004: 0.571 0.201 ++test005: 0.524 0.199 ++test006: Unable to optimize with hand-written code ++test007: 1.808 0.614 ++test008: 6.265E-03 1.313E-04 ++test009: 0.798 0.466 ++ ++Reference ++[1] Müller, Matthias S.. "Some Simple OpenMP Optimization Techniques." ++WOMPAT (2001). ++ ++[2] Doerfert, J., Finkel, H. (2018). Compiler Optimizations for OpenMP. ++In: de Supinski, B., Valero-Lara, P., Martorell, X., Mateo Bellido S., ++Labarta, J. (eds) Evolving OpenMP for Evolving Architectures.IWOMP 2018 ++. Lecture Notes in Computer Science(), vol 11128. Springer,Cham. ++https://doi.org/10.1007/978-3-319-98521-3_8 ++ ++[3] H. Ma, R. Zhao, X. Gao and Y. Zhang, "Barrier Optimization for ++OpenMP Program," 2009 10th ACIS International Conference on Software ++Engineering, Artificial Intelligences, Networking and ++Parallel/Distributed Computing, 2009, pp. 495-500, doi: ++10.1109/SNPD.2009.16. +\ No newline at end of file +diff --git a/test/openmp_optimization/run.sh b/test/openmp_optimization/run.sh +new file mode 100644 +index 0000000..510f119 +--- /dev/null ++++ b/test/openmp_optimization/run.sh +@@ -0,0 +1,32 @@ ++for i in {001..009} ++do ++echo "------- test $i ------." ++flang-new fortran_main$i.f90 -fopenmp ++export OMP_NUM_THREADS=8 ++./a.out ++rm a.out ++done ++for i in {001..002} ++do ++echo "------- test $i ------." ++flang-new optimized_main$i.f90 -fopenmp ++export OMP_NUM_THREADS=8 ++./a.out ++rm a.out ++done ++for i in {004..005} ++do ++echo "------- test $i ------." ++flang-new optimized_main$i.f90 -fopenmp ++export OMP_NUM_THREADS=8 ++./a.out ++rm a.out ++done ++for i in {007..009} ++do ++echo "------- test $i ------." ++flang-new optimized_main$i.f90 -fopenmp ++export OMP_NUM_THREADS=8 ++./a.out ++rm a.out ++done +\ No newline at end of file +-- +2.25.1 +