Line data Source code
1 : ! This file is part of ELPA.
2 : !
3 : ! The ELPA library was originally created by the ELPA consortium,
4 : ! consisting of the following organizations:
5 : !
6 : ! - Max Planck Computing and Data Facility (MPCDF), formerly known as
7 : ! Rechenzentrum Garching der Max-Planck-Gesellschaft (RZG),
8 : ! - Bergische Universität Wuppertal, Lehrstuhl für angewandte
9 : ! Informatik,
10 : ! - Technische Universität München, Lehrstuhl für Informatik mit
11 : ! Schwerpunkt Wissenschaftliches Rechnen ,
12 : ! - Fritz-Haber-Institut, Berlin, Abt. Theorie,
13 : ! - Max-Plack-Institut für Mathematik in den Naturwissenschaften,
14 : ! Leipzig, Abt. Komplexe Strukutren in Biologie und Kognition,
15 : ! and
16 : ! - IBM Deutschland GmbH
17 : !
18 : !
19 : ! More information can be found here:
20 : ! http://elpa.mpcdf.mpg.de/
21 : !
22 : ! ELPA is free software: you can redistribute it and/or modify
23 : ! it under the terms of the version 3 of the license of the
24 : ! GNU Lesser General Public License as published by the Free
25 : ! Software Foundation.
26 : !
27 : ! ELPA is distributed in the hope that it will be useful,
28 : ! but WITHOUT ANY WARRANTY; without even the implied warranty of
29 : ! MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
30 : ! GNU Lesser General Public License for more details.
31 : !
32 : ! You should have received a copy of the GNU Lesser General Public License
33 : ! along with ELPA. If not, see <http://www.gnu.org/licenses/>
34 : !
35 : ! ELPA reflects a substantial effort on the part of the original
36 : ! ELPA consortium, and we ask you to respect the spirit of the
37 : ! license that we chose: i.e., please contribute any changes you
38 : ! may have back to the original ELPA library distribution, and keep
39 : ! any derivatives of ELPA under the same license that we chose for
40 : ! the original distribution, the GNU Lesser General Public License.
41 : !
42 : !
43 : #include "config-f90.h"
44 : !>
45 : !> Fortran test programm to demonstrates the use of
46 : !> ELPA 2 real case library.
47 : !> If "HAVE_REDIRECT" was defined at build time
48 : !> the stdout and stderr output of each MPI task
49 : !> can be redirected to files if the environment
50 : !> variable "REDIRECT_ELPA_TEST_OUTPUT" is set
51 : !> to "true".
52 : !>
53 : !> By calling executable [arg1] [arg2] [arg3] [arg4]
54 : !> one can define the size (arg1), the number of
55 : !> Eigenvectors to compute (arg2), and the blocking (arg3).
56 : !> If these values are not set default values (500, 150, 16)
57 : !> are choosen.
58 : !> If these values are set the 4th argument can be
59 : !> "output", which specifies that the EV's are written to
60 : !> an ascii file.
61 : !>
62 : !> The real ELPA 2 kernel is set as the default kernel.
63 : !> However, this can be overriden by setting
64 : !> the environment variable "REAL_ELPA_KERNEL" to an
65 : !> appropiate value.
66 : !>
67 192 : program test_real2
68 :
69 : !-------------------------------------------------------------------------------
70 : ! Standard eigenvalue problem - REAL version
71 : !
72 : ! This program demonstrates the use of the ELPA module
73 : ! together with standard scalapack routines
74 : !
75 : ! Copyright of the original code rests with the authors inside the ELPA
76 : ! consortium. The copyright of any additional modifications shall rest
77 : ! with their original authors, but shall adhere to the licensing terms
78 : ! distributed along with the original code in the file "COPYING".
79 : !
80 : !-------------------------------------------------------------------------------
81 192 : use elpa_driver
82 : use elpa_utilities, only : error_unit
83 : use test_util
84 : use test_read_input_parameters
85 : use test_check_correctness
86 : use test_setup_mpi
87 : use test_blacs_infrastructure
88 : use test_prepare_matrix
89 : #ifdef HAVE_REDIRECT
90 : use test_redirect
91 : #endif
92 : use test_output_type
93 : implicit none
94 :
95 : !-------------------------------------------------------------------------------
96 : ! Please set system size parameters below!
97 : ! na: System size
98 : ! nev: Number of eigenvectors to be calculated
99 : ! nblk: Blocking factor in block cyclic distribution
100 : !-------------------------------------------------------------------------------
101 :
102 : integer(kind=ik) :: nblk
103 : integer(kind=ik) :: na, nev
104 :
105 : integer(kind=ik) :: np_rows, np_cols, na_rows, na_cols
106 :
107 : integer(kind=ik) :: myid, nprocs, my_prow, my_pcol, mpi_comm_rows, mpi_comm_cols
108 : integer(kind=ik) :: i, mpierr, my_blacs_ctxt, sc_desc(9), info, nprow, npcol
109 :
110 : integer, external :: numroc
111 :
112 192 : real(kind=rk8), allocatable :: a(:,:), z(:,:), as(:,:), ev(:)
113 :
114 : integer(kind=ik) :: STATUS
115 : #ifdef WITH_OPENMP
116 : integer(kind=ik) :: omp_get_max_threads, required_mpi_thread_level, provided_mpi_thread_level
117 : #endif
118 : type(output_t) :: write_to_file
119 : logical :: success
120 : character(len=8) :: task_suffix
121 : integer(kind=ik) :: j
122 :
123 192 : success = .true.
124 :
125 192 : call read_input_parameters_traditional(na, nev, nblk, write_to_file)
126 :
127 : !-------------------------------------------------------------------------------
128 : ! MPI Initialization
129 192 : call setup_mpi(myid, nprocs)
130 :
131 192 : STATUS = 0
132 :
133 : #define DATATYPE REAL
134 : #include "../../elpa_print_headers.F90"
135 :
136 : !-------------------------------------------------------------------------------
137 : ! Selection of number of processor rows/columns
138 : ! We try to set up the grid square-like, i.e. start the search for possible
139 : ! divisors of nprocs with a number next to the square root of nprocs
140 : ! and decrement it until a divisor is found.
141 :
142 192 : do np_cols = NINT(SQRT(REAL(nprocs))),2,-1
143 0 : if(mod(nprocs,np_cols) == 0 ) exit
144 : enddo
145 : ! at the end of the above loop, nprocs is always divisible by np_cols
146 :
147 192 : np_rows = nprocs/np_cols
148 :
149 192 : if(myid==0) then
150 128 : print *
151 128 : print '(a)','Standard eigenvalue problem - REAL version'
152 128 : print *
153 128 : print '(3(a,i0))','Matrix size=',na,', Number of eigenvectors=',nev,', Block size=',nblk
154 128 : print '(3(a,i0))','Number of processor rows=',np_rows,', cols=',np_cols,', total=',nprocs
155 128 : print *
156 : endif
157 :
158 : !-------------------------------------------------------------------------------
159 : ! Set up BLACS context and MPI communicators
160 : !
161 : ! The BLACS context is only necessary for using Scalapack.
162 : !
163 : ! For ELPA, the MPI communicators along rows/cols are sufficient,
164 : ! and the grid setup may be done in an arbitrary way as long as it is
165 : ! consistent (i.e. 0<=my_prow<np_rows, 0<=my_pcol<np_cols and every
166 : ! process has a unique (my_prow,my_pcol) pair).
167 :
168 : call set_up_blacsgrid(mpi_comm_world, np_rows, np_cols, 'C', &
169 192 : my_blacs_ctxt, my_prow, my_pcol)
170 :
171 192 : if (myid==0) then
172 128 : print '(a)','| Past BLACS_Gridinfo.'
173 : end if
174 :
175 : ! All ELPA routines need MPI communicators for communicating within
176 : ! rows or columns of processes, these are set in elpa_get_communicators.
177 :
178 : mpierr = elpa_get_communicators(mpi_comm_world, my_prow, my_pcol, &
179 192 : mpi_comm_rows, mpi_comm_cols)
180 :
181 192 : if (myid==0) then
182 128 : print '(a)','| Past split communicator setup for rows and columns.'
183 : end if
184 :
185 : call set_up_blacs_descriptor(na ,nblk, my_prow, my_pcol, np_rows, np_cols, &
186 192 : na_rows, na_cols, sc_desc, my_blacs_ctxt, info)
187 :
188 192 : if (myid==0) then
189 128 : print '(a)','| Past scalapack descriptor setup.'
190 : end if
191 :
192 : !-------------------------------------------------------------------------------
193 : ! Allocate matrices and set up a test matrix for the eigenvalue problem
194 192 : allocate(a (na_rows,na_cols))
195 192 : allocate(z (na_rows,na_cols))
196 192 : allocate(as(na_rows,na_cols))
197 :
198 192 : allocate(ev(na))
199 :
200 192 : call prepare_matrix_random(na, myid, sc_desc, a, z, as)
201 :
202 : ! set print flag in elpa1
203 192 : elpa_print_times = .true.
204 :
205 : !-------------------------------------------------------------------------------
206 : ! Calculate eigenvalues/eigenvectors
207 :
208 192 : if (myid==0) then
209 128 : print '(a)','| Entering one-stage ELPA solver ... '
210 128 : print *
211 : end if
212 : #ifdef WITH_MPI
213 128 : call mpi_barrier(mpi_comm_world, mpierr) ! for correct timings only
214 : #endif
215 : success = elpa_solve_evp_real_double(na, nev, a, na_rows, ev, z, na_rows, nblk, na_cols, &
216 192 : mpi_comm_rows, mpi_comm_cols, mpi_comm_world, method="1stage")
217 :
218 192 : if (.not.(success)) then
219 0 : write(error_unit,*) "elpa_solve_evp_real produced an error! Aborting..."
220 : #ifdef WITH_MPI
221 0 : call MPI_ABORT(mpi_comm_world, 1, mpierr)
222 : #else
223 0 : call exit(1)
224 : #endif
225 : endif
226 :
227 192 : if (myid==0) then
228 128 : print '(a)','| One-step ELPA solver complete.'
229 128 : print *
230 : end if
231 :
232 192 : a = as
233 192 : z = as
234 :
235 192 : if (myid==0) then
236 128 : print '(a)','| Entering two-stage ELPA solver ... '
237 128 : print *
238 : end if
239 : #ifdef WITH_MPI
240 128 : call mpi_barrier(mpi_comm_world, mpierr) ! for correct timings only
241 : #endif
242 : success = elpa_solve_evp_real_double(na, nev, a, na_rows, ev, z, na_rows, nblk, na_cols, &
243 192 : mpi_comm_rows, mpi_comm_cols, mpi_comm_world, method="2stage")
244 :
245 192 : if (.not.(success)) then
246 0 : write(error_unit,*) "elpa_solve_evp_real produced an error! Aborting..."
247 : #ifdef WITH_MPI
248 0 : call MPI_ABORT(mpi_comm_world, 1, mpierr)
249 : #else
250 0 : call exit(1)
251 : #endif
252 : endif
253 :
254 192 : if (myid==0) then
255 128 : print '(a)','| two-step ELPA solver complete.'
256 128 : print *
257 : end if
258 :
259 192 : a = as
260 192 : z = as
261 :
262 192 : if (myid==0) then
263 128 : print '(a)','| Entering auto-chosen ELPA solver ... '
264 128 : print *
265 : end if
266 : #ifdef WITH_MPI
267 128 : call mpi_barrier(mpi_comm_world, mpierr) ! for correct timings only
268 : #endif
269 : success = elpa_solve_evp_real_double(na, nev, a, na_rows, ev, z, na_rows, nblk, na_cols, &
270 192 : mpi_comm_rows, mpi_comm_cols, mpi_comm_world, method="auto")
271 :
272 192 : if (.not.(success)) then
273 0 : write(error_unit,*) "elpa_solve_evp_real produced an error! Aborting..."
274 : #ifdef WITH_MPI
275 0 : call MPI_ABORT(mpi_comm_world, 1, mpierr)
276 : #else
277 0 : call exit(1)
278 : #endif
279 : endif
280 :
281 192 : if (myid==0) then
282 128 : print '(a)','| auto-chosen ELPA solver complete.'
283 128 : print *
284 : end if
285 :
286 192 : if(myid == 0) print *,'Time transform to tridi :',time_evp_fwd
287 192 : if(myid == 0) print *,'Time solve tridi :',time_evp_solve
288 192 : if(myid == 0) print *,'Time transform back EVs :',time_evp_back
289 192 : if(myid == 0) print *,'Total time (sum above) :',time_evp_back+time_evp_solve+time_evp_fwd
290 :
291 :
292 : ! if(write_to_file%eigenvectors) then
293 : ! write(unit = task_suffix, fmt = '(i8.8)') myid
294 : ! open(17,file="EVs_real2_out_task_"//task_suffix(1:8)//".txt",form='formatted',status='new')
295 : ! write(17,*) "Part of eigenvectors: na_rows=",na_rows,"of na=",na," na_cols=",na_cols," of na=",na
296 : !
297 : ! do i=1,na_rows
298 : ! do j=1,na_cols
299 : ! write(17,*) "row=",i," col=",j," element of eigenvector=",z(i,j)
300 : ! enddo
301 : ! enddo
302 : ! close(17)
303 : ! endif
304 : !
305 : ! if(write_to_file%eigenvalues) then
306 : ! if (myid == 0) then
307 : ! open(17,file="Eigenvalues_real2_out.txt",form='formatted',status='new')
308 : ! do i=1,na
309 : ! write(17,*) i,ev(i)
310 : ! enddo
311 : ! close(17)
312 : ! endif
313 : ! endif
314 :
315 :
316 : !-------------------------------------------------------------------------------
317 : ! Test correctness of result (using plain scalapack routines)
318 192 : status = check_correctness_evp_numeric_residuals(na, nev, as, z, ev, sc_desc, nblk, myid, np_rows, np_cols, my_prow, my_pcol)
319 :
320 192 : deallocate(a)
321 192 : deallocate(as)
322 :
323 192 : deallocate(z)
324 192 : deallocate(ev)
325 :
326 : #ifdef WITH_MPI
327 128 : call blacs_gridexit(my_blacs_ctxt)
328 128 : call mpi_finalize(mpierr)
329 : #endif
330 192 : call EXIT(STATUS)
331 : end
332 :
333 : !-------------------------------------------------------------------------------
|