mod_pack_unpack_real.F90 5.91 KB
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43
!    This file is part of ELPA.
!
!    The ELPA library was originally created by the ELPA consortium,
!    consisting of the following organizations:
!
!    - Max Planck Computing and Data Facility (MPCDF), formerly known as
!      Rechenzentrum Garching der Max-Planck-Gesellschaft (RZG),
!    - Bergische Universität Wuppertal, Lehrstuhl für angewandte
!      Informatik,
!    - Technische Universität München, Lehrstuhl für Informatik mit
!      Schwerpunkt Wissenschaftliches Rechnen ,
!    - Fritz-Haber-Institut, Berlin, Abt. Theorie,
!    - Max-Plack-Institut für Mathematik in den Naturwissenschaftrn,
!      Leipzig, Abt. Komplexe Strukutren in Biologie und Kognition,
!      and
!    - IBM Deutschland GmbH
!
!
!    More information can be found here:
!    http://elpa.mpcdf.mpg.de/
!
!    ELPA is free software: you can redistribute it and/or modify
!    it under the terms of the version 3 of the license of the
!    GNU Lesser General Public License as published by the Free
!    Software Foundation.
!
!    ELPA is distributed in the hope that it will be useful,
!    but WITHOUT ANY WARRANTY; without even the implied warranty of
!    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
!    GNU Lesser General Public License for more details.
!
!    You should have received a copy of the GNU Lesser General Public License
!    along with ELPA.  If not, see <http://www.gnu.org/licenses/>
!
!    ELPA reflects a substantial effort on the part of the original
!    ELPA consortium, and we ask you to respect the spirit of the
!    license that we chose: i.e., please contribute any changes you
!    may have back to the original ELPA library distribution, and keep
!    any derivatives of ELPA under the same license that we chose for
!    the original distribution, the GNU Lesser General Public License.
!
! Author: Andreas Marek, MPCDF

44
module pack_unpack_real
45
#include "config-f90.h"
46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182
  implicit none

#ifdef WITH_OPENMP
  public pack_row_real_cpu_openmp, unpack_row_real_cpu_openmp
#else
  public pack_row_real_cpu, unpack_row_real_cpu
#endif
  contains

#ifdef WITH_OPENMP
        subroutine pack_row_real_cpu_openmp(a, row, n, stripe_width, stripe_count, max_threads, thread_width, l_nev)
#else
        subroutine pack_row_real_cpu(a, row, n, stripe_width, last_stripe_width, stripe_count)
#endif

#ifdef HAVE_DETAILED_TIMINGS
          use timings
#endif
          use precision
          implicit none
          integer(kind=ik), intent(in) :: n, stripe_count, stripe_width
#ifdef WITH_OPENMP
          integer(kind=ik), intent(in) :: max_threads, thread_width, l_nev
          real(kind=rk), intent(in)    :: a(:,:,:,:)
#else
          integer(kind=ik), intent(in) :: last_stripe_width
          real(kind=rk), intent(in)    :: a(:,:,:)
#endif
          real(kind=rk)                :: row(:)

          integer(kind=ik)             :: i, noff, nl
#ifdef WITH_OPENMP
          integer(kind=ik)             :: nt
#endif

#ifdef HAVE_DETAILED_TIMINGS
#ifdef WITH_OPENMP
          call timer%start("pack_row_real_cpu_openmp")

#else
          call timer%start("pack_row_real_cpu")
#endif
#endif

#ifdef WITH_OPENMP
          do nt = 1, max_threads
            do i = 1, stripe_count
              noff = (nt-1)*thread_width + (i-1)*stripe_width
              nl   = min(stripe_width, nt*thread_width-noff, l_nev-noff)
              if (nl<=0) exit
              row(noff+1:noff+nl) = a(1:nl,n,i,nt)
            enddo
          enddo
#else
          do i=1,stripe_count
            nl = merge(stripe_width, last_stripe_width, i<stripe_count)
            noff = (i-1)*stripe_width
            row(noff+1:noff+nl) = a(1:nl,n,i)
          enddo
#endif

#ifdef HAVE_DETAILED_TIMINGS
#ifdef WITH_OPENMP
          call timer%stop("pack_row_real_cpu_openmp")

#else
          call timer%stop("pack_row_real_cpu")
#endif
#endif

#ifdef WITH_OPENMP
        end subroutine pack_row_real_cpu_openmp
#else
        end subroutine pack_row_real_cpu
#endif

#ifdef WITH_OPENMP
        subroutine unpack_row_real_cpu_openmp(a, row, n, my_thread, stripe_count, thread_width, stripe_width, l_nev)
#ifdef HAVE_DETAILED_TIMINGS
          use timings
#endif
          use precision
          implicit none

          ! Private variables in OMP regions (my_thread) should better be in the argument list!
          integer(kind=ik), intent(in) :: stripe_count, thread_width, stripe_width, l_nev
          real(kind=rk)                :: a(:,:,:,:)
          integer(kind=ik), intent(in) :: n, my_thread
          real(kind=rk), intent(in)    :: row(:)
          integer(kind=ik)             :: i, noff, nl

#ifdef HAVE_DETAILED_TIMINGS
          call timer%start("unpack_row_real_cpu_openmp")
#endif
          do i=1,stripe_count
            noff = (my_thread-1)*thread_width + (i-1)*stripe_width
            nl   = min(stripe_width, my_thread*thread_width-noff, l_nev-noff)
            if(nl<=0) exit
            a(1:nl,n,i,my_thread) = row(noff+1:noff+nl)
          enddo

#ifdef HAVE_DETAILED_TIMINGS
          call timer%stop("unpack_row_real_cpu_openmp")
#endif

        end subroutine unpack_row_real_cpu_openmp

#else /* WITH_OPENMP */
        subroutine unpack_row_real_cpu(a, row, n, stripe_count, stripe_width, last_stripe_width)
#ifdef HAVE_DETAILED_TIMINGS
          use timings
#endif
         use precision
         implicit none

         integer(kind=ik), intent(in) :: n, stripe_count, stripe_width, last_stripe_width
         real(kind=rk)                :: row(:)
         real(kind=rk)                :: a(:,:,:)
         integer(kind=ik)             :: i, noff, nl

#ifdef HAVE_DETAILED_TIMINGS
          call timer%start("unpack_row_real_cpu")
#endif

          do i=1,stripe_count
            nl = merge(stripe_width, last_stripe_width, i<stripe_count)
            noff = (i-1)*stripe_width
            a(1:nl,n,i) = row(noff+1:noff+nl)
          enddo

#ifdef HAVE_DETAILED_TIMINGS
          call timer%stop("unpack_row_real_cpu")
#endif
        end subroutine unpack_row_real_cpu
#endif /* WITH_OPENMP */

end module