LCOV - code coverage report
Current view: top level - test/Fortran/elpa2 - complex_2stage_banded.F90 (source / functions) Hit Total Coverage
Test: coverage_50ab7a7628bba174fc62cee3ab72b26e81f87fe5.info Lines: 70 73 95.9 %
Date: 2018-01-10 09:29:53 Functions: 2 2 100.0 %

          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             : #include "../assert.h"
      45             : !>
      46             : !> Fortran test programm to demonstrates the use of
      47             : !> ELPA 2 complex case library.
      48             : !> If "HAVE_REDIRECT" was defined at build time
      49             : !> the stdout and stderr output of each MPI task
      50             : !> can be redirected to files if the environment
      51             : !> variable "REDIRECT_ELPA_TEST_OUTPUT" is set
      52             : !> to "true".
      53             : !>
      54             : !> By calling executable [arg1] [arg2] [arg3] [arg4]
      55             : !> one can define the size (arg1), the number of
      56             : !> Eigenvectors to compute (arg2), and the blocking (arg3).
      57             : !> If these values are not set default values (500, 150, 16)
      58             : !> are choosen.
      59             : !> If these values are set the 4th argument can be
      60             : !> "output", which specifies that the EV's are written to
      61             : !> an ascii file.
      62             : !>
      63             : !> The complex ELPA 2 kernel is set as the default kernel.
      64             : !> However, this can be overriden by setting
      65             : !> the environment variable "COMPLEX_ELPA_KERNEL" to an
      66             : !> appropiate value.
      67             : !>
      68         192 : program test_complex2_double_banded
      69             : 
      70             : !-------------------------------------------------------------------------------
      71             : ! Standard eigenvalue problem - COMPLEX version
      72             : !
      73             : ! This program demonstrates the use of the ELPA module
      74             : ! together with standard scalapack routines
      75             : !
      76             : ! Copyright of the original code rests with the authors inside the ELPA
      77             : ! consortium. The copyright of any additional modifications shall rest
      78             : ! with their original authors, but shall adhere to the licensing terms
      79             : ! distributed along with the original code in the file "COPYING".
      80             : !-------------------------------------------------------------------------------
      81         192 :    use elpa
      82             : 
      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             : #ifdef WITH_MPI
     110             :    integer(kind=ik), external    :: numroc
     111             : #endif
     112             :    complex(kind=ck8), parameter   :: CZERO = (0.0_rk8,0.0_rk8), CONE = (1.0_rk8,0.0_rk8)
     113         192 :    real(kind=rk8), allocatable    :: ev(:)
     114             : 
     115         384 :    complex(kind=ck8), allocatable :: a(:,:), z(:,:), as(:,:)
     116             : 
     117             :    integer(kind=ik)              :: STATUS
     118             : #ifdef WITH_OPENMP
     119             :    integer(kind=ik)              :: omp_get_max_threads,  required_mpi_thread_level, provided_mpi_thread_level
     120             : #endif
     121             :    type(output_t)                :: write_to_file
     122             :    integer(kind=ik)              :: success
     123             :    character(len=8)              :: task_suffix
     124             :    integer(kind=ik)              :: j
     125             : 
     126             : 
     127             :    integer(kind=ik)              :: numberOfDevices
     128             :    integer(kind=ik)              :: global_row, global_col, local_row, local_col
     129             :    integer(kind=ik)              :: bandwidth
     130             :    class(elpa_t), pointer        :: e
     131             : 
     132             : #define COMPLEXCASE
     133             : #define DOUBLE_PRECISION_COMPLEX 1
     134             : 
     135         192 :    call read_input_parameters_traditional(na, nev, nblk, write_to_file)
     136             :       !-------------------------------------------------------------------------------
     137             :    !  MPI Initialization
     138         192 :    call setup_mpi(myid, nprocs)
     139             : 
     140         192 :    STATUS = 0
     141             : 
     142             :    !-------------------------------------------------------------------------------
     143             :    ! Selection of number of processor rows/columns
     144             :    ! We try to set up the grid square-like, i.e. start the search for possible
     145             :    ! divisors of nprocs with a number next to the square root of nprocs
     146             :    ! and decrement it until a divisor is found.
     147             : 
     148         192 :    do np_cols = NINT(SQRT(REAL(nprocs))),2,-1
     149           0 :       if(mod(nprocs,np_cols) == 0 ) exit
     150             :    enddo
     151             :    ! at the end of the above loop, nprocs is always divisible by np_cols
     152             : 
     153         192 :    np_rows = nprocs/np_cols
     154             : 
     155         192 :    if(myid==0) then
     156         128 :       print *
     157         128 :       print '(a)','Standard eigenvalue problem - COMPLEX version'
     158         128 :       print *
     159         128 :       print '(3(a,i0))','Matrix size=',na,', Number of eigenvectors=',nev,', Block size=',nblk
     160         128 :       print '(3(a,i0))','Number of processor rows=',np_rows,', cols=',np_cols,', total=',nprocs
     161         128 :       print *
     162             :    endif
     163             : 
     164             :    !-------------------------------------------------------------------------------
     165             :    ! Set up BLACS context and MPI communicators
     166             :    !
     167             :    ! The BLACS context is only necessary for using Scalapack.
     168             :    !
     169             :    ! For ELPA, the MPI communicators along rows/cols are sufficient,
     170             :    ! and the grid setup may be done in an arbitrary way as long as it is
     171             :    ! consistent (i.e. 0<=my_prow<np_rows, 0<=my_pcol<np_cols and every
     172             :    ! process has a unique (my_prow,my_pcol) pair).
     173             : 
     174             :    call set_up_blacsgrid(mpi_comm_world, np_rows, np_cols, 'C', &
     175         192 :                          my_blacs_ctxt, my_prow, my_pcol)
     176             : 
     177         192 :    if (myid==0) then
     178         128 :      print '(a)','| Past BLACS_Gridinfo.'
     179             :    end if
     180             : 
     181             :    ! Determine the necessary size of the distributed matrices,
     182             :    ! we use the Scalapack tools routine NUMROC for that.
     183             : 
     184             :    call set_up_blacs_descriptor(na ,nblk, my_prow, my_pcol, np_rows, np_cols, &
     185         192 :                                 na_rows, na_cols, sc_desc, my_blacs_ctxt, info)
     186             : 
     187         192 :    if (myid==0) then
     188         128 :      print '(a)','| Past scalapack descriptor setup.'
     189             :    end if
     190             :    !-------------------------------------------------------------------------------
     191             :    ! Allocate matrices and set up a test matrix for the eigenvalue problem
     192             : 
     193         192 :    allocate(a (na_rows,na_cols))
     194         192 :    allocate(z (na_rows,na_cols))
     195         192 :    allocate(as(na_rows,na_cols))
     196             : 
     197         192 :    allocate(ev(na))
     198             : 
     199         192 :    call prepare_matrix_random(na, myid, sc_desc, a, z, as)
     200             : 
     201             :    ! set values outside of the bandwidth to zero
     202         192 :    bandwidth = nblk
     203             : 
     204       19392 :    do local_row = 1, na_rows
     205       19200 :      global_row = index_l2g( local_row, nblk, my_prow, np_rows )
     206     2899200 :      do local_col = 1, na_cols
     207     2880000 :        global_col = index_l2g( local_col, nblk, my_pcol, np_cols )
     208             : 
     209     2880000 :        if (ABS(global_row-global_col) > bandwidth) then
     210     2281216 :          a(local_row, local_col) = 0
     211     2281216 :          as(local_row, local_col) = 0
     212             :        end if
     213             :      end do
     214             :    end do
     215             : 
     216             : 
     217         192 :    if (elpa_init(CURRENT_API_VERSION) /= ELPA_OK) then
     218           0 :      print *, "ELPA API version not supported"
     219           0 :      stop 1
     220             :    endif
     221             : 
     222         192 :    e => elpa_allocate()
     223             : 
     224         192 :    call e%set("na", na, success)
     225         192 :    assert_elpa_ok(success)
     226         192 :    call e%set("nev", nev, success)
     227         192 :    assert_elpa_ok(success)
     228         192 :    call e%set("local_nrows", na_rows, success)
     229         192 :    assert_elpa_ok(success)
     230         192 :    call e%set("local_ncols", na_cols, success)
     231         192 :    assert_elpa_ok(success)
     232         192 :    call e%set("nblk", nblk, success)
     233         192 :    assert_elpa_ok(success)
     234         192 :    call e%set("mpi_comm_parent", MPI_COMM_WORLD, success)
     235         192 :    assert_elpa_ok(success)
     236         192 :    call e%set("process_row", my_prow, success)
     237         192 :    assert_elpa_ok(success)
     238         192 :    call e%set("process_col", my_pcol, success)
     239         192 :    assert_elpa_ok(success)
     240             : 
     241         192 :    call e%set("bandwidth", bandwidth, success)
     242         192 :    assert_elpa_ok(success)
     243             : 
     244         192 :    assert(e%setup() .eq. ELPA_OK)
     245             : 
     246         192 :    call e%set("solver", ELPA_SOLVER_2STAGE, success)
     247         192 :    assert_elpa_ok(success)
     248         192 :    call e%eigenvectors(a, ev, z, success)
     249         192 :    assert_elpa_ok(success)
     250         192 :    call elpa_deallocate(e)
     251             : 
     252         192 :    call elpa_uninit()
     253             : 
     254             :    !-------------------------------------------------------------------------------
     255             :    ! Test correctness of result (using plain scalapack routines)
     256         192 :    status = check_correctness_evp_numeric_residuals(na, nev, as, z, ev, sc_desc, nblk, myid, np_rows, np_cols, my_prow, my_pcol)
     257             : 
     258         192 :    deallocate(a)
     259         192 :    deallocate(as)
     260             : 
     261         192 :    deallocate(z)
     262         192 :    deallocate(ev)
     263             : 
     264             : #ifdef WITH_MPI
     265         128 :    call blacs_gridexit(my_blacs_ctxt)
     266         128 :    call mpi_finalize(mpierr)
     267             : #endif
     268         192 :    call EXIT(STATUS)
     269             : end
     270             : 
     271             : !-------------------------------------------------------------------------------

Generated by: LCOV version 1.12