elpa_t.F90 4.72 KB
Newer Older
Andreas Marek's avatar
Andreas Marek committed
1
2
module elpa_type
 use iso_c_binding
Andreas Marek's avatar
Andreas Marek committed
3
 use init_elpa
Andreas Marek's avatar
Andreas Marek committed
4
5
6

 private

Andreas Marek's avatar
Andreas Marek committed
7
 public :: elpa_init, elpa_initialized, elpa_uninit, elpa_create, elpa_t, C_INT, C_DOUBLE, C_FLOAT
Andreas Marek's avatar
Andreas Marek committed
8
9

 type :: elpa_t
Andreas Marek's avatar
Andreas Marek committed
10
11
   private
   integer(kind=c_int) :: mpi_comm_parent, mpi_comm_rows, mpi_comm_cols
Andreas Marek's avatar
Andreas Marek committed
12
13
   integer(kind=c_int) :: na, nev, local_nrows, local_ncols, nblk
   contains
Andreas Marek's avatar
Andreas Marek committed
14
15
     generic, public :: set => elpa_set_string, elpa_set_integer
     generic, public :: get => elpa_get_string, elpa_get_integer
Andreas Marek's avatar
Andreas Marek committed
16

Andreas Marek's avatar
Andreas Marek committed
17
18
     procedure, private :: elpa_set_string, elpa_set_integer
     procedure, private :: elpa_get_string, elpa_get_integer
Andreas Marek's avatar
Andreas Marek committed
19

Andreas Marek's avatar
Andreas Marek committed
20
21
     procedure, public :: get_communicators => get_communicators
     procedure, public :: solve => elpa_solve_real_double
Andreas Marek's avatar
Andreas Marek committed
22
23
24
25
 end type elpa_t

 contains

Andreas Marek's avatar
Andreas Marek committed
26
27
28
29
30
31
32
33
   function elpa_create(self, na, nev, local_nrows, local_ncols, nblk, mpi_comm_parent, process_row, process_col) result(success)
      use precision
      use init_elpa
      use elpa_mpi
      use elpa_utilities, only : error_unit
      use elpa2_utilities, only : DEFAULT_REAL_ELPA_KERNEL, DEFAULT_COMPLEX_ELPA_KERNEL
      use elpa1, only : elpa_get_communicators
      implicit none
Andreas Marek's avatar
Andreas Marek committed
34
35

      integer(kind=ik), intent(in) :: na, nev, local_nrows, local_ncols, nblk
Andreas Marek's avatar
Andreas Marek committed
36
37
38
      integer, intent(in) :: mpi_comm_parent, process_row, process_col
      type(elpa_t), intent(out) :: self
      integer :: mpierr
Andreas Marek's avatar
Andreas Marek committed
39

Andreas Marek's avatar
Andreas Marek committed
40
      logical :: success
Andreas Marek's avatar
Andreas Marek committed
41

Andreas Marek's avatar
Andreas Marek committed
42
      success = .true.
Andreas Marek's avatar
Andreas Marek committed
43

Andreas Marek's avatar
Andreas Marek committed
44
45
46
47
48
49
      ! check whether init has ever been called
      if (.not.(elpa_initialized())) then
        write(error_unit, *) "elpa_create(): you must call elpa_init() once before creating instances of ELPA"
        success = .false.
        return
      endif
Andreas Marek's avatar
Andreas Marek committed
50

Andreas Marek's avatar
Andreas Marek committed
51
52
53
54
55
56
57
58
59
60
61
62
63
      self%na          = na
      self%nev         = nev
      self%local_nrows = local_nrows
      self%local_ncols = local_ncols
      self%nblk        = nblk

      self%mpi_comm_parent = mpi_comm_parent
      mpierr = elpa_get_communicators(mpi_comm_parent, process_row, process_col, self%mpi_comm_rows, self%mpi_comm_cols)
      if (mpierr /= MPI_SUCCESS) then
        write(error_unit, *) "elpa_create(): error constructing row and column communicators"
        success = .false.
        return
      endif
Andreas Marek's avatar
Andreas Marek committed
64
65
66

    end function

Andreas Marek's avatar
Andreas Marek committed
67
    function elpa_set_string(self, keyword, value) result(success)
Andreas Marek's avatar
Andreas Marek committed
68
69
70
71
72
73
      use iso_c_binding
      use elpa1, only : elpa_print_times
      implicit none
      class(elpa_t)            :: self
      character(*), intent(in) :: keyword
      character(*), intent(in) :: value
Andreas Marek's avatar
Andreas Marek committed
74
      logical                  :: success
Andreas Marek's avatar
Andreas Marek committed
75

Andreas Marek's avatar
Andreas Marek committed
76
77
      success = .false.
    end function elpa_set_string
Andreas Marek's avatar
Andreas Marek committed
78

Andreas Marek's avatar
Andreas Marek committed
79
    function elpa_set_integer(self, keyword, value) result(success)
Andreas Marek's avatar
Andreas Marek committed
80
81
82
83
84
85
      use iso_c_binding
      use elpa2_utilities, only : check_allowed_real_kernels, check_allowed_complex_kernels
      implicit none
      class(elpa_t)                   :: self
      character(*), intent(in)        :: keyword
      integer(kind=c_int), intent(in) :: value
Andreas Marek's avatar
Andreas Marek committed
86
      logical                         :: success
Andreas Marek's avatar
Andreas Marek committed
87

Andreas Marek's avatar
Andreas Marek committed
88
89
      success = .false.
    end function elpa_set_integer
Andreas Marek's avatar
Andreas Marek committed
90

Andreas Marek's avatar
Andreas Marek committed
91
    function elpa_get_string(self, keyword, value) result(success)
Andreas Marek's avatar
Andreas Marek committed
92
93
94
95
96
97
      use iso_c_binding
      use elpa1, only : elpa_print_times
      implicit none
      class(elpa_t)               :: self
      character(*), intent(in)    :: keyword
      character(*), intent(inout) :: value
Andreas Marek's avatar
Andreas Marek committed
98
      logical                     :: success
Andreas Marek's avatar
Andreas Marek committed
99

Andreas Marek's avatar
Andreas Marek committed
100
101
      success = .false.
    end function elpa_get_string
Andreas Marek's avatar
Andreas Marek committed
102

Andreas Marek's avatar
Andreas Marek committed
103
    function elpa_get_integer(self, keyword, value) result(success)
Andreas Marek's avatar
Andreas Marek committed
104
105
106
107
108
      use iso_c_binding
      implicit none
      class(elpa_t)                      :: self
      character(*), intent(in)           :: keyword
      integer(kind=c_int), intent(inout) :: value
Andreas Marek's avatar
Andreas Marek committed
109
      logical                            :: success
Andreas Marek's avatar
Andreas Marek committed
110

Andreas Marek's avatar
Andreas Marek committed
111
112
      success = .false.
    end function elpa_get_integer
Andreas Marek's avatar
Andreas Marek committed
113

Andreas Marek's avatar
Andreas Marek committed
114
    subroutine get_communicators(self, mpi_comm_rows, mpi_comm_cols)
Andreas Marek's avatar
Andreas Marek committed
115
116
      use iso_c_binding
      implicit none
Andreas Marek's avatar
Andreas Marek committed
117
      class(elpa_t)                   :: self
Andreas Marek's avatar
Andreas Marek committed
118
119

      integer(kind=c_int), intent(out) :: mpi_comm_rows, mpi_comm_cols
Andreas Marek's avatar
Andreas Marek committed
120
121
122
      mpi_comm_rows = self%mpi_comm_rows
      mpi_comm_cols = self%mpi_comm_cols
    end subroutine
Andreas Marek's avatar
Andreas Marek committed
123
124
125
126
127
128

    function elpa_solve_real_double(self, a, ev, q) result(success)
      use elpa

      use iso_c_binding
      implicit none
Andreas Marek's avatar
Andreas Marek committed
129
      class(elpa_t)                   :: self
Andreas Marek's avatar
Andreas Marek committed
130
131
132

      real(kind=c_double) :: a(self%local_nrows, self%local_ncols), q(self%local_nrows, self%local_ncols), &
                             ev(self%na)
Andreas Marek's avatar
Andreas Marek committed
133
      logical :: success
Andreas Marek's avatar
Andreas Marek committed
134

Andreas Marek's avatar
Andreas Marek committed
135
136
137
138
      success = elpa_solve_evp_real_double(self%na, self%nev, a, self%local_nrows, ev, q,  &
                                           self%local_nrows,  self%nblk, self%local_ncols, &
                                           self%mpi_comm_rows, self%mpi_comm_cols,         &
                                           self%mpi_comm_parent)
Andreas Marek's avatar
Andreas Marek committed
139
140
141
142
143
    end function


end module