LCOV - code coverage report
Current view: top level - test/Fortran/elpa1/legacy_interface - legacy_single_real.F90 (source / functions) Hit Total Coverage
Test: coverage_50ab7a7628bba174fc62cee3ab72b26e81f87fe5.info Lines: 62 78 79.5 %
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             : !>
      45             : !> Fortran test programm to demonstrates the use of
      46             : !> ELPA 1 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          96 : program test_real_single_precision
      63             : 
      64             : !-------------------------------------------------------------------------------
      65             : ! Standard eigenvalue problem - REAL version
      66             : !
      67             : ! This program demonstrates the use of the ELPA module
      68             : ! together with standard scalapack routines
      69             : !
      70             : ! Copyright of the original code rests with the authors inside the ELPA
      71             : ! consortium. The copyright of any additional modifications shall rest
      72             : ! with their original authors, but shall adhere to the licensing terms
      73             : ! distributed along with the original code in the file "COPYING".
      74             : !
      75             : !-------------------------------------------------------------------------------
      76          96 :    use elpa1
      77             :    use elpa_utilities, only : error_unit
      78             :    use test_util
      79             : 
      80             :    use test_read_input_parameters
      81             :    use test_check_correctness
      82             :    use test_setup_mpi
      83             :    use test_blacs_infrastructure
      84             :    use test_prepare_matrix
      85             : 
      86             : #ifdef HAVE_REDIRECT
      87             :    use test_redirect
      88             : #endif
      89             :   use test_output_type
      90             : 
      91             :    implicit none
      92             : 
      93             :    !-------------------------------------------------------------------------------
      94             :    ! Please set system size parameters below!
      95             :    ! na:   System size
      96             :    ! nev:  Number of eigenvectors to be calculated
      97             :    ! nblk: Blocking factor in block cyclic distribution
      98             :    !-------------------------------------------------------------------------------
      99             :    integer(kind=ik)           :: nblk
     100             :    integer(kind=ik)           :: na, nev
     101             : 
     102             :    integer(kind=ik)           :: np_rows, np_cols, na_rows, na_cols
     103             : 
     104             :    integer(kind=ik)           :: myid, nprocs, my_prow, my_pcol, mpi_comm_rows, mpi_comm_cols
     105             :    integer(kind=ik)           :: i, mpierr, my_blacs_ctxt, sc_desc(9), info, nprow, npcol
     106             : 
     107             :    integer(kind=ik), external :: numroc
     108             : 
     109          96 :    real(kind=rk4), allocatable :: a(:,:), z(:,:), as(:,:), ev(:)
     110             : 
     111             :    integer(kind=ik)           :: STATUS
     112             : #ifdef WITH_OPENMP
     113             :    integer(kind=ik)           :: omp_get_max_threads,  required_mpi_thread_level, &
     114             :                                  provided_mpi_thread_level
     115             : #endif
     116             :    type(output_t)             :: write_to_file
     117             :    logical                    :: success
     118             :    character(len=8)           :: task_suffix
     119             :    integer(kind=ik)           :: j
     120             :    !-------------------------------------------------------------------------------
     121             : 
     122             : #undef DOUBLE_PRECISION_REAL
     123             : 
     124          96 :    success = .true.
     125             : 
     126          96 :    call read_input_parameters(na, nev, nblk, write_to_file)
     127             : 
     128             :    !-------------------------------------------------------------------------------
     129             :    !  MPI Initialization
     130          96 :    call setup_mpi(myid, nprocs)
     131             : 
     132          96 :    STATUS = 0
     133             : 
     134             : #define REALCASE
     135             : #define ELPA1
     136             : #include "../../elpa_print_headers.F90"
     137             : 
     138          96 :    do np_cols = NINT(SQRT(REAL(nprocs))),2,-1
     139           0 :       if(mod(nprocs,np_cols) == 0 ) exit
     140             :    enddo
     141             : 
     142             :    ! at the end of the above loop, nprocs is always divisible by np_cols
     143             : 
     144          96 :    np_rows = nprocs/np_cols
     145             : 
     146          96 :    if(myid==0) then
     147          64 :       print *
     148          64 :       print '(a)','Standard eigenvalue problem - ELPA1, REAL version'
     149          64 :       print *
     150          64 :       print '((a,i0))', 'Matrix size: ', na 
     151          64 :       print '((a,i0))', 'Num eigenvectors: ', nev
     152          64 :       print '((a,i0))', 'Blocksize: ', nblk 
     153          64 :       print '((a,i0))', 'Num MPI proc: ', nprocs 
     154          64 :       print '((a))', 'Using gpu: NO'
     155          64 :       print '((a,i0))', 'Num gpu devices: ', 0
     156          64 :       print '((a))', 'Number type: real'
     157          64 :       print '((a))', 'Number precision: single'
     158          64 :       print *
     159          64 :       print '(3(a,i0))','Number of processor rows=',np_rows,', cols=',np_cols,', total=',nprocs
     160          64 :       print *
     161             :    endif
     162             : 
     163             :    !-------------------------------------------------------------------------------
     164             :    ! Set up BLACS context and MPI communicators
     165             :    !
     166             :    ! The BLACS context is only necessary for using Scalapack.
     167             :    !
     168             :    ! For ELPA, the MPI communicators along rows/cols are sufficient,
     169             :    ! and the grid setup may be done in an arbitrary way as long as it is
     170             :    ! consistent (i.e. 0<=my_prow<np_rows, 0<=my_pcol<np_cols and every
     171             :    ! process has a unique (my_prow,my_pcol) pair).
     172             : 
     173             :    call set_up_blacsgrid(mpi_comm_world, np_rows, np_cols, 'C', &
     174          96 :                          my_blacs_ctxt, my_prow, my_pcol)
     175             : 
     176          96 :    if (myid==0) then
     177          64 :      print '(a)','| Past BLACS_Gridinfo.'
     178             :    end if
     179             : 
     180             :    ! All ELPA routines need MPI communicators for communicating within
     181             :    ! rows or columns of processes, these are set in elpa_get_communicators.
     182             : 
     183             :    mpierr = elpa_get_communicators(mpi_comm_world, my_prow, my_pcol, &
     184          96 :                                    mpi_comm_rows, mpi_comm_cols)
     185             : 
     186          96 :    if (myid==0) then
     187          64 :      print '(a)','| Past split communicator setup for rows and columns.'
     188             :    end if
     189             : 
     190             :    call set_up_blacs_descriptor(na ,nblk, my_prow, my_pcol, np_rows, np_cols, &
     191          96 :                                 na_rows, na_cols, sc_desc, my_blacs_ctxt, info)
     192             : 
     193          96 :    if (myid==0) then
     194          64 :      print '(a)','| Past scalapack descriptor setup.'
     195             :    end if
     196             : 
     197             :    !-------------------------------------------------------------------------------
     198             :    ! Allocate matrices and set up a test matrix for the eigenvalue problem
     199          96 :    allocate(a (na_rows,na_cols))
     200          96 :    allocate(z (na_rows,na_cols))
     201          96 :    allocate(as(na_rows,na_cols))
     202             : 
     203          96 :    allocate(ev(na))
     204             : 
     205          96 :    call prepare_matrix_random(na, myid, sc_desc, a, z, as)
     206             : 
     207             :    !-------------------------------------------------------------------------------
     208             :    ! Calculate eigenvalues/eigenvectors
     209          96 :    elpa_print_times = .true.
     210          96 :    if (myid==0) then
     211          64 :      print '(a)','| Entering one-step ELPA solver ... '
     212          64 :      print *
     213             :    end if
     214             : #ifdef WITH_MPI
     215          64 :    call mpi_barrier(mpi_comm_world, mpierr) ! for correct timings only
     216             : #endif
     217             :    success = elpa_solve_evp_real_1stage_single(na, nev, a, na_rows, ev, z, na_rows, nblk, &
     218          96 :                             na_cols, mpi_comm_rows, mpi_comm_cols, mpi_comm_world)
     219             : 
     220          96 :    if (.not.(success)) then
     221           0 :       write(error_unit,*) "solve_evp_real_1stage produced an error! Aborting..."
     222             : #ifdef WITH_MPI
     223           0 :       call MPI_ABORT(mpi_comm_world, 1, mpierr)
     224             : #else
     225           0 :       call exit(1)
     226             : #endif
     227             :    endif
     228             : 
     229             : 
     230          96 :    if (myid==0) then
     231          64 :      print '(a)','| One-step ELPA solver complete.'
     232          64 :      print *
     233             :    end if
     234             : 
     235          96 :    if(myid == 0) print *,'Time tridiag_real     :',time_evp_fwd
     236          96 :    if(myid == 0) print *,'Time solve_tridi      :',time_evp_solve
     237          96 :    if(myid == 0) print *,'Time trans_ev_real    :',time_evp_back
     238          96 :    if(myid == 0) print *,'Total time (sum above):',time_evp_back+time_evp_solve+time_evp_fwd
     239             : 
     240          96 :    if(write_to_file%eigenvectors) then
     241           0 :      write(unit = task_suffix, fmt = '(i8.8)') myid
     242           0 :      open(17,file="EVs_real_out_task_"//task_suffix(1:8)//".txt",form='formatted',status='new')
     243           0 :      write(17,*) "Part of eigenvectors: na_rows=",na_rows,"of na=",na," na_cols=",na_cols," of na=",na
     244             : 
     245           0 :      do i=1,na_rows
     246           0 :        do j=1,na_cols
     247           0 :          write(17,*) "row=",i," col=",j," element of eigenvector=",z(i,j)
     248             :        enddo
     249             :      enddo
     250           0 :      close(17)
     251             :    endif
     252             : 
     253          96 :    if(write_to_file%eigenvalues) then
     254           0 :       if (myid == 0) then
     255           0 :          open(17,file="Eigenvalues_real_out.txt",form='formatted',status='new')
     256           0 :          do i=1,na
     257           0 :             write(17,*) i,ev(i)
     258             :          enddo
     259           0 :          close(17)
     260             :       endif
     261             :    endif
     262             : 
     263             : 
     264             :    !-------------------------------------------------------------------------------
     265             :    ! Test correctness of result (using plain scalapack routines)
     266          96 :    status = check_correctness_evp_numeric_residuals(na, nev, as, z, ev, sc_desc, nblk, myid, np_rows, np_cols, my_prow, my_pcol)
     267             : 
     268          96 :    deallocate(a)
     269          96 :    deallocate(as)
     270          96 :    deallocate(z)
     271          96 :    deallocate(ev)
     272             : 
     273             : #ifdef WITH_MPI
     274          64 :    call blacs_gridexit(my_blacs_ctxt)
     275          64 :    call mpi_finalize(mpierr)
     276             : #endif
     277             : 
     278          96 :    call EXIT(STATUS)
     279             : 
     280             : 
     281             : end
     282             : 
     283             : !-------------------------------------------------------------------------------

Generated by: LCOV version 1.12