From 8abd9cee96de4eda75397c5c3344702fa90b9527 Mon Sep 17 00:00:00 2001 From: Dmitry Pekurovsky Date: Wed, 16 Dec 2015 12:29:07 -0800 Subject: [PATCH] Making the code suitable for either using or not using openmp --- ChangeLog | 0 build/fft_exec.F90 | 78 +++++++++++++++++++++++++++++++++++++++++---- build/init_plan.F90 | 6 ++++ 3 files changed, 77 insertions(+), 7 deletions(-) create mode 100644 ChangeLog diff --git a/ChangeLog b/ChangeLog new file mode 100644 index 0000000..e69de29 diff --git a/build/fft_exec.F90 b/build/fft_exec.F90 index 4951ac5..a75d3ce 100644 --- a/build/fft_exec.F90 +++ b/build/fft_exec.F90 @@ -78,7 +78,11 @@ subroutine exec_b_c1(X,stride_x1,stride_x2,Y,stride_y1, & !$OMP PARALLEL private(tid,stx,sty,plan) +#ifdef OPENMP tid = omp_get_thread_num() +#else + tid = 0 +#endif stx = startx_b_c1(tid) sty = starty_b_c1(tid) plan = plan1_bc(tid) @@ -157,7 +161,11 @@ subroutine exec_b_c2_same(X,stride_x1,stride_x2,Y,stride_y1, & #ifdef FFTW !$OMP PARALLEL private(tid,stx,sty,plan) +#ifdef OPENMP tid = omp_get_thread_num() +#else + tid = 0 +#endif stx = startx_b_c2_same(tid) sty = starty_b_c2_same(tid) plan = plan2_bc_same(tid) @@ -199,7 +207,11 @@ subroutine exec_b_c2_dif(X,stride_x1,stride_x2,Y,stride_y1, & #ifdef FFTW !$OMP PARALLEL private(tid,stx,sty,plan) +#ifdef OPENMP tid = omp_get_thread_num() +#else + tid = 0 +#endif stx = startx_b_c2_dif(tid) sty = starty_b_c2_dif(tid) plan = plan2_bc_dif(tid) @@ -243,7 +255,11 @@ subroutine exec_b_c2r(X,dimx,Y,dimy,N,m) #ifdef FFTW !$OMP PARALLEL private(tid,stx,sty,plan) +#ifdef OPENMP tid = omp_get_thread_num() +#else + tid = 0 +#endif stx = startx_bcr(tid) sty = starty_bcr(tid) plan = plan1_bcr(tid) @@ -285,12 +301,16 @@ subroutine exec_f_c1(X,stride_x1,stride_x2,Y,stride_y1,stride_y2,N,m) #ifdef FFTW -!!$OMP PARALLEL private(tid,stx,sty,plan) +!$OMP PARALLEL private(tid,stx,sty,plan) -! tid = omp_get_thread_num() +#ifdef OPENMP + tid = omp_get_thread_num() +#else + tid = 0 +#endif - do tid=0,num_thr-1 +! do tid=0,num_thr-1 stx = startx_f_c1(tid) sty = starty_f_c1(tid) @@ -304,8 +324,8 @@ subroutine exec_f_c1(X,stride_x1,stride_x2,Y,stride_y1,stride_y2,N,m) call sfftw_execute_dft(plan,X(stx),Y(sty)) #endif - enddo -!!$OMP END PARALLEL +! enddo +!$OMP END PARALLEL #elif defined ESSL @@ -337,7 +357,11 @@ subroutine exec_f_c2_same(X,stride_x1,stride_x2,Y,stride_y1,stride_y2,N,m) #ifdef FFTW !$OMP PARALLEL private(tid,stx,sty,plan) +#ifdef OPENMP tid = omp_get_thread_num() +#else + tid = 0 +#endif stx = startx_f_c2_same(tid) sty = starty_f_c2_same(tid) plan = plan2_fc_same(tid) @@ -379,7 +403,11 @@ subroutine exec_f_c2_dif(X,stride_x1,stride_x2,Y,stride_y1,stride_y2,N,m) #ifdef FFTW !$OMP PARALLEL private(tid,stx,sty,plan) - tid = omp_get_thread_num() +#ifdef OPENMP + tid = omp_get_thread_num() +#else + tid = 0 +#endif stx = startx_f_c2_dif(tid) sty = starty_f_c2_dif(tid) plan = plan2_fc_dif(tid) @@ -424,7 +452,11 @@ subroutine exec_f_r2c(X,dimx,Y,dimy,N,m) !$OMP PARALLEL private(tid,stx,sty,plan) +#ifdef OPENMP tid = omp_get_thread_num() +#else + tid = 0 +#endif stx = startx_frc(tid) sty = starty_frc(tid) plan = plan1_frc(tid) @@ -471,7 +503,11 @@ subroutine exec_ctrans_r2_same (X, stride_x1, stride_x2, Y, stride_y1, stride_y2 #ifdef FFTW !$OMP PARALLEL private(tid,stx,sty,plan) +#ifdef OPENMP tid = omp_get_thread_num() +#else + tid = 0 +#endif stx = startx_ctrans_same(tid) sty = starty_ctrans_same(tid) plan = plan_ctrans_same(tid) @@ -516,7 +552,11 @@ subroutine exec_ctrans_r2_dif (X, stride_x1, stride_x2, Y, stride_y1, stride_y2, #ifdef FFTW !$OMP PARALLEL private(tid,stx,sty,plan) +#ifdef OPENMP tid = omp_get_thread_num() +#else + tid = 0 +#endif stx = startx_ctrans_dif(tid) sty = starty_ctrans_dif(tid) plan = plan_ctrans_dif(tid) @@ -562,7 +602,11 @@ subroutine exec_ctrans_r2_complex_same (X, stride_x1, stride_x2, Y, stride_y1, s #ifdef FFTW !$OMP PARALLEL private(tid,stx,sty,plan) +#ifdef OPENMP tid = omp_get_thread_num() +#else + tid = 0 +#endif stx = startx_ctrans_same(tid) sty = starty_ctrans_same(tid) plan = plan_ctrans_same(tid) @@ -616,7 +660,11 @@ subroutine exec_ctrans_r2_complex_dif (X, stride_x1, stride_x2, Y, stride_y1, st #ifdef FFTW !$OMP PARALLEL private(tid,stx,sty,plan) +#ifdef OPENMP tid = omp_get_thread_num() +#else + tid = 0 +#endif stx = startx_ctrans_dif(tid) sty = starty_ctrans_dif(tid) plan = plan_ctrans_dif(tid) @@ -675,7 +723,11 @@ subroutine exec_strans_r2_same (X, stride_x1, stride_x2, Y, stride_y1, stride_y2 #ifdef FFTW !$OMP PARALLEL private(tid,stx,sty,plan) +#ifdef OPENMP tid = omp_get_thread_num() +#else + tid = 0 +#endif stx = startx_strans_same(tid) sty = starty_strans_same(tid) plan = plan_strans_same(tid) @@ -720,7 +772,11 @@ subroutine exec_strans_r2_dif (X, stride_x1, stride_x2, Y, stride_y1, stride_y2, #ifdef FFTW !$OMP PARALLEL private(tid,stx,sty,plan) +#ifdef OPENMP tid = omp_get_thread_num() +#else + tid = 0 +#endif stx = startx_strans_dif(tid) sty = starty_strans_dif(tid) plan = plan_strans_dif(tid) @@ -766,7 +822,11 @@ subroutine exec_strans_r2_complex_same (X, stride_x1, stride_x2, Y, stride_y1, s #ifdef FFTW !$OMP PARALLEL private(tid,stx,sty,plan) - tid = omp_get_thread_num() +#ifdef OPENMP + tid = omp_get_thread_num() +#else + tid = 0 +#endif stx = startx_strans_same(tid) sty = starty_strans_same(tid) plan = plan_strans_same(tid) @@ -820,7 +880,11 @@ subroutine exec_strans_r2_complex_dif (X, stride_x1, stride_x2, Y, stride_y1, st #ifdef FFTW !$OMP PARALLEL private(tid,stx,sty,plan) +#ifdef OPENMP tid = omp_get_thread_num() +#else + tid = 0 +#endif stx = startx_strans_dif(tid) sty = starty_strans_dif(tid) plan = plan_strans_dif(tid) diff --git a/build/init_plan.F90 b/build/init_plan.F90 index 0c5ced2..57bf0a7 100644 --- a/build/init_plan.F90 +++ b/build/init_plan.F90 @@ -38,12 +38,18 @@ subroutine init_plan complex(mytype), allocatable :: A(:),C(:) integer omp_get_num_threads,omp_get_thread_num,l,m,tid,ierr +#ifdef OPENMP + !$OMP PARALLEL !$OMP MASTER num_thr = omp_get_num_threads() !$OMP END MASTER !$OMP END PARALLEL +#else + num_thr = 1 +#endif + if(taskid .eq. 0) then print *,'Running on ',num_thr,'threads' endif