test_read_input_parameters.F90 15 KB
Newer Older
Andreas Marek's avatar
Andreas Marek committed
1
2
3
4
5
!    This file is part of ELPA.
!
!    The ELPA library was originally created by the ELPA consortium,
!    consisting of the following organizations:
!
6
7
!    - Max Planck Computing and Data Facility (MPCDF), formerly known as
!      Rechenzentrum Garching der Max-Planck-Gesellschaft (RZG),
Andreas Marek's avatar
Andreas Marek committed
8
9
10
11
12
13
14
15
16
17
18
19
!    - 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 Naturwissenschaften,
!      Leipzig, Abt. Komplexe Strukutren in Biologie und Kognition,
!      and
!    - IBM Deutschland GmbH
!
!
!    More information can be found here:
20
!    http://elpa.mpcdf.mpg.de/
Andreas Marek's avatar
Andreas Marek committed
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
!
!    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.
!
!
#include "config-f90.h"
44
module test_read_input_parameters
45
46
  use elpa
  use elpa_utilities, only : error_unit
47
48
49

  use test_util
  use test_output_type
50
51

  implicit none
52

53
  type input_options_t
Andreas Marek's avatar
WIP    
Andreas Marek committed
54
55
    integer(kind=MPI_KIND)        :: datatype
    integer(kind=MPI_KIND)        :: na, nev, nblk
56
    type(output_t) :: write_to_file
Andreas Marek's avatar
WIP    
Andreas Marek committed
57
    integer(kind=MPI_KIND)        :: this_real_kernel, this_complex_kernel
58
    logical        :: realKernelIsSet, complexKernelIsSet
Andreas Marek's avatar
WIP    
Andreas Marek committed
59
    integer(kind=MPI_KIND)        :: useQrIsSet, useGPUIsSet
Andreas Marek's avatar
Andreas Marek committed
60
61
    logical        :: doSolveTridi, do1stage, do2stage, justHelpMessage, &
                      doCholesky, doInvertTrm, doTransposeMultiply
62
63
64
65
66
  end type

  interface read_input_parameters
    module procedure read_input_parameters_general
    module procedure read_input_parameters_traditional
67
    module procedure read_input_parameters_traditional_noskip
68
69
  end interface

Andreas Marek's avatar
Andreas Marek committed
70
71
  contains

72
    subroutine parse_arguments(command_line_argument, input_options)
73
74
75
76
      implicit none

      type(input_options_t) :: input_options
      character(len=128)    :: command_line_argument
Andreas Marek's avatar
WIP    
Andreas Marek committed
77
      integer(kind=MPI_KIND)               :: error
78
79

      if (command_line_argument == "--help") then
80
81
82
83
        print *,"usage: elpa_tests [--help] [datatype={real|complex}] [na=number] [nev=number] "
        print *,"                  [nblk=size of block cyclic distribution] [--output_eigenvalues]"
        print *,"                  [--output_eigenvectors] [--real-kernel=name_of_kernel]"
        print *,"                  [--complex-kernel=name_of_kernel] [--use-gpu={0|1}]"
Andreas Marek's avatar
Andreas Marek committed
84
85
        print *,"                  [--use-qr={0,1}] [--tests={all|solve-tridi|1stage|2stage|cholesky&
            &|invert-triangular|transpose-mulitply}]"
Andreas Marek's avatar
Andreas Marek committed
86
87
        input_options%justHelpMessage=.true.
        return
88
89
90
91
92
93
94
95
96
97
98
      endif


      if (command_line_argument(1:11) == "--datatype=") then
        if (command_line_argument(12:15) == "real") then
          input_options%datatype=1
        else
          if (command_line_argument(12:18) == "complex") then
            input_options%datatype=2
          else
            print *,"datatype unknown! use either --datatype=real or --datatpye=complex"
Pavel Kus's avatar
Pavel Kus committed
99
            stop 1
100
101
102
103
104
          endif
        endif
      endif

      if (command_line_argument(1:3) == "na=") then
105
        read(command_line_argument(4:), *) input_options%na
106
107
      endif
      if (command_line_argument(1:4) == "nev=") then
108
        read(command_line_argument(5:), *) input_options%nev
109
110
      endif
      if (command_line_argument(1:5) == "nblk=") then
111
        read(command_line_argument(6:), *) input_options%nblk
112
113
114
115
116
117
118
119
120
121
122
      endif

      if (command_line_argument(1:21)   == "--output_eigenvectors") then
        input_options%write_to_file%eigenvectors = .true.
      endif

      if (command_line_argument(1:20)   == "--output_eigenvalues") then
        input_options%write_to_file%eigenvalues = .true.
      endif

      if (command_line_argument(1:14) == "--real-kernel=") then
123
124
125
        input_options%this_real_kernel = elpa_int_string_to_value("real_kernel", command_line_argument(15:), error)
        if (error /= ELPA_OK) then
          print *, "Invalid argument for --real-kernel"
126
127
          stop 1
        endif
128
129
        print *,"Setting ELPA2 real kernel to ", elpa_int_value_to_string("real_kernel", input_options%this_real_kernel)
        input_options%realKernelIsSet = .true.
130
131
132
      endif

      if (command_line_argument(1:17) == "--complex-kernel=") then
133
134
135
        input_options%this_complex_kernel = elpa_int_string_to_value("complex_kernel", command_line_argument(18:), error)
        if (error /= ELPA_OK) then
          print *, "Invalid argument for --complex-kernel"
136
137
          stop 1
        endif
138
139
        print *,"Setting ELPA2 complex kernel to ", elpa_int_value_to_string("complex_kernel", input_options%this_complex_kernel)
        input_options%complexKernelIsSet = .true.
140
141
142
      endif

      if (command_line_argument(1:9) == "--use-qr=") then
143
        read(command_line_argument(10:), *) input_options%useQrIsSet
144
145
146
      endif

      if (command_line_argument(1:10) == "--use-gpu=") then
147
        read(command_line_argument(11:), *) input_options%useGPUIsSet
148
149
150
151
152
153
154
      endif

      if (command_line_argument(1:8) == "--tests=") then
        if (command_line_argument(9:11) == "all") then
          input_options%doSolveTridi=.true.
          input_options%do1stage=.true.
          input_options%do2stage=.true.
Andreas Marek's avatar
Andreas Marek committed
155
156
157
          input_options%doCholesky=.true.
          input_options%doInvertTrm=.true.
          input_options%doTransposeMultiply=.true.
158
159
160
161
        else if (command_line_argument(9:19) == "solve-tride") then
          input_options%doSolveTridi=.true.
          input_options%do1stage=.false.
          input_options%do2stage=.false.
Andreas Marek's avatar
Andreas Marek committed
162
163
164
          input_options%doCholesky=.false.
          input_options%doInvertTrm=.false.
          input_options%doTransposeMultiply=.false.
165
166
167
168
        else if (command_line_argument(9:14) == "1stage") then
          input_options%doSolveTridi=.false.
          input_options%do1stage=.true.
          input_options%do2stage=.false.
Andreas Marek's avatar
Andreas Marek committed
169
170
171
          input_options%doCholesky=.false.
          input_options%doInvertTrm=.false.
          input_options%doTransposeMultiply=.false.
172
173
174
175
        else if (command_line_argument(9:14) == "2stage") then
          input_options%doSolveTridi=.false.
          input_options%do1stage=.false.
          input_options%do2stage=.true.
Andreas Marek's avatar
Andreas Marek committed
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
          input_options%doCholesky=.false.
          input_options%doInvertTrm=.false.
          input_options%doTransposeMultiply=.false.
        else if (command_line_argument(9:16) == "cholesky") then
          input_options%doSolveTridi=.false.
          input_options%do1stage=.false.
          input_options%do2stage=.false.
          input_options%doCholesky=.true.
          input_options%doInvertTrm=.false.
          input_options%doTransposeMultiply=.false.
        else if (command_line_argument(9:25) == "invert-triangular") then
          input_options%doSolveTridi=.false.
          input_options%do1stage=.false.
          input_options%do2stage=.false.
          input_options%doCholesky=.false.
          input_options%doInvertTrm=.true.
          input_options%doTransposeMultiply=.false.
        else if (command_line_argument(9:26) == "transpose-multiply") then
          input_options%doSolveTridi=.false.
          input_options%do1stage=.false.
          input_options%do2stage=.false.
          input_options%doCholesky=.false.
          input_options%doInvertTrm=.false.
          input_options%doTransposeMultiply=.true.
200
201
        else
           print *,"unknown test specified"
Pavel Kus's avatar
Pavel Kus committed
202
           stop 1
203
204
205
206
207
        endif
      endif

    end subroutine

208
    subroutine read_input_parameters_general(input_options)
209
      use precision
210
211
212
213
214
215
      implicit none

      type(input_options_t)         :: input_options

      ! Command line arguments
      character(len=128)            :: arg1, arg2, arg3, arg4, arg5, arg6, arg7, arg8, arg9, arg10
Andreas Marek's avatar
WIP    
Andreas Marek committed
216
      integer(kind=MPI_KIND)              :: mpierr
217
218
219

      ! default parameters
      input_options%datatype = 1
220
221
      input_options%na = 500
      input_options%nev = 150
222
      input_options%nblk = 16
223
224
225
226

      input_options%write_to_file%eigenvectors = .false.
      input_options%write_to_file%eigenvalues  = .false.

227
228
      input_options%this_real_kernel = ELPA_2STAGE_REAL_DEFAULT
      input_options%this_complex_kernel = ELPA_2STAGE_COMPLEX_DEFAULT
229
230
231
232
233
234
235
      input_options%realKernelIsSet = .false.
      input_options%complexKernelIsSet = .false.

      input_options%useQrIsSet = 0

      input_options%useGPUIsSet = 0

236
237
238
      input_options%do1Stage = .true.
      input_options%do2Stage = .true.
      input_options%doSolveTridi = .true.
Andreas Marek's avatar
Andreas Marek committed
239
240
241
      input_options%doCholesky=.true.
      input_options%doInvertTrm=.true.
      input_options%doTransposeMultiply=.true.
Andreas Marek's avatar
Andreas Marek committed
242
243
      input_options%justHelpMessage=.false.

244
245
246
247
248
249
250
251
252
253
      ! test na=1500 nev=50 nblk=16 --help --kernel --output_eigenvectors --output_eigenvalues
      if (COMMAND_ARGUMENT_COUNT() .gt. 8) then
        write(error_unit, '(a,i0,a)') "Invalid number (", COMMAND_ARGUMENT_COUNT(), ") of command line arguments!"
        stop 1
      endif

      if (COMMAND_ARGUMENT_COUNT() .gt. 0) then

        call get_COMMAND_ARGUMENT(1, arg1)

254
        call parse_arguments(arg1, input_options)
255
256
257
258
259
260
261



        if (COMMAND_ARGUMENT_COUNT() .ge. 2) then
          ! argument 2
          call get_COMMAND_ARGUMENT(2, arg2)

262
          call parse_arguments(arg2, input_options)
263
264
265
266
267
268
269
        endif

        ! argument 3
        if (COMMAND_ARGUMENT_COUNT() .ge. 3) then

          call get_COMMAND_ARGUMENT(3, arg3)

270
          call parse_arguments(arg3, input_options)
271
272
273
274
275
276
277
        endif

        ! argument 4
        if (COMMAND_ARGUMENT_COUNT() .ge. 4) then

          call get_COMMAND_ARGUMENT(4, arg4)

278
          call parse_arguments(arg4, input_options)
279
280
281
282
283
284
285
286

        endif

        ! argument 5
        if (COMMAND_ARGUMENT_COUNT() .ge. 5) then

          call get_COMMAND_ARGUMENT(5, arg5)

287
          call parse_arguments(arg5, input_options)
288
289
290
291
292
293
294
        endif

        ! argument 6
        if (COMMAND_ARGUMENT_COUNT() .ge. 6) then

          call get_COMMAND_ARGUMENT(6, arg6)

295
          call parse_arguments(arg6, input_options)
296
297
298
299
300
301
302
        endif

        ! argument 7
        if (COMMAND_ARGUMENT_COUNT() .ge. 7) then

          call get_COMMAND_ARGUMENT(7, arg7)

303
          call parse_arguments(arg7, input_options)
304
305
306
307
308
309
310
311

        endif

        ! argument 8
        if (COMMAND_ARGUMENT_COUNT() .ge. 8) then

          call get_COMMAND_ARGUMENT(8, arg8)

312
          call parse_arguments(arg8, input_options)
313
314
315
316
317
318
319
320

        endif

        ! argument 9
        if (COMMAND_ARGUMENT_COUNT() .ge. 9) then

          call get_COMMAND_ARGUMENT(9, arg9)

321
          call parse_arguments(arg8, input_options)
322
323
324
325
326
327
328
329

        endif

        ! argument 10
        if (COMMAND_ARGUMENT_COUNT() .ge. 10) then

          call get_COMMAND_ARGUMENT(10, arg10)

330
          call parse_arguments(arg8, input_options)
331
332
333
334
335

        endif

      endif

336
      if (input_options%useQrIsSet .eq. 1 .and. input_options%datatype .eq. 2) then
337
338
339
340
341
342
        print *,"You cannot use QR-decomposition in complex case"
        stop 1
      endif

    end subroutine

343
    subroutine read_input_parameters_traditional_noskip(na, nev, nblk, write_to_file)
344
      use precision
Andreas Marek's avatar
Andreas Marek committed
345
      implicit none
346

Andreas Marek's avatar
WIP    
Andreas Marek committed
347
      integer(kind=MPI_KIND), intent(out) :: na, nev, nblk
348
349

      type(output_t), intent(out)   :: write_to_file
350
351
352
353
354
355
      logical                       :: skip_check_correctness

      call read_input_parameters_traditional(na, nev, nblk, write_to_file, skip_check_correctness)
    end subroutine

    subroutine read_input_parameters_traditional(na, nev, nblk, write_to_file, skip_check_correctness)
356
      use precision
357
358
      implicit none

Andreas Marek's avatar
WIP    
Andreas Marek committed
359
      integer(kind=MPI_KIND), intent(out) :: na, nev, nblk
360
361
362

      type(output_t), intent(out)   :: write_to_file
      logical, intent(out)          :: skip_check_correctness
Andreas Marek's avatar
Andreas Marek committed
363

364
      ! Command line arguments
365
      character(len=128)            :: arg1, arg2, arg3, arg4, arg5
Andreas Marek's avatar
WIP    
Andreas Marek committed
366
      integer(kind=MPI_KIND)              :: mpierr
Andreas Marek's avatar
Andreas Marek committed
367

368
      ! default parameters
369
370
      na = 5000
      nev = 150
371
      nblk = 16
372
373
      write_to_file%eigenvectors = .false.
      write_to_file%eigenvalues  = .false.
374
      skip_check_correctness = .false.
Andreas Marek's avatar
Andreas Marek committed
375

376
      if (.not. any(COMMAND_ARGUMENT_COUNT() == [0, 3, 4, 5])) then
377
        write(error_unit, '(a,i0,a)') "Invalid number (", COMMAND_ARGUMENT_COUNT(), ") of command line arguments!"
378
379
        write(error_unit, *) "Expected: program [ [matrix_size num_eigenvalues block_size] &
            ""output_eigenvalues"" ""output_eigenvectors""]"
380
381
        stop 1
      endif
Andreas Marek's avatar
Andreas Marek committed
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401

      if (COMMAND_ARGUMENT_COUNT() == 3) then
        call GET_COMMAND_ARGUMENT(1, arg1)
        call GET_COMMAND_ARGUMENT(2, arg2)
        call GET_COMMAND_ARGUMENT(3, arg3)

        read(arg1, *) na
        read(arg2, *) nev
        read(arg3, *) nblk
      endif

      if (COMMAND_ARGUMENT_COUNT() == 4) then
        call GET_COMMAND_ARGUMENT(1, arg1)
        call GET_COMMAND_ARGUMENT(2, arg2)
        call GET_COMMAND_ARGUMENT(3, arg3)
        call GET_COMMAND_ARGUMENT(4, arg4)
        read(arg1, *) na
        read(arg2, *) nev
        read(arg3, *) nblk

402
        if (arg4 .eq. "output_eigenvalues") then
403
          write_to_file%eigenvalues = .true.
404
405
        elseif (arg4 .eq. "skip_check_correctness") then
          skip_check_correctness = .true.
406
        else
407
408
          write(error_unit, *) &
          "Invalid value for parameter 4.  Must be ""output_eigenvalues"", ""skip_check_correctness"" or omitted"
409
410
411
          stop 1
        endif

Andreas Marek's avatar
Andreas Marek committed
412
413
      endif

414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
      if (COMMAND_ARGUMENT_COUNT() == 5) then
        call GET_COMMAND_ARGUMENT(1, arg1)
        call GET_COMMAND_ARGUMENT(2, arg2)
        call GET_COMMAND_ARGUMENT(3, arg3)
        call GET_COMMAND_ARGUMENT(4, arg4)
        call GET_COMMAND_ARGUMENT(5, arg5)
        read(arg1, *) na
        read(arg2, *) nev
        read(arg3, *) nblk

        if (arg4 .eq. "output_eigenvalues") then
          write_to_file%eigenvalues = .true.
        else
          write(error_unit, *) "Invalid value for output flag! Must be ""output_eigenvalues"" or omitted"
          stop 1
        endif

        if (arg5 .eq. "output_eigenvectors") then
          write_to_file%eigenvectors = .true.
        else
          write(error_unit, *) "Invalid value for output flag! Must be ""output_eigenvectors"" or omitted"
          stop 1
        endif

      endif
Andreas Marek's avatar
Andreas Marek committed
439
440
441
    end subroutine

end module