LCOV - code coverage report
Current view: top level - test/C/elpa1/legacy_interface - legacy_real_1stage_c_version.c (source / functions) Hit Total Coverage
Test: coverage_50ab7a7628bba174fc62cee3ab72b26e81f87fe5.info Lines: 82 88 93.2 %
Date: 2018-01-10 09:29:53 Functions: 1 1 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             : 
      44             : #include "config-f90.h"
      45             : 
      46             : #include <stdio.h>
      47             : #include <stdlib.h>
      48             : #ifdef WITH_MPI
      49             : #include <mpi.h>
      50             : #endif
      51             : #include <math.h>
      52             : 
      53             : #include <elpa/elpa_legacy.h>
      54             : 
      55             : #include "test/shared/generated.h"
      56             : 
      57             : #define DOUBLE_PRECISION_REAL 1
      58             : 
      59         192 : int main(int argc, char** argv) {
      60             :    int myid;
      61             :    int nprocs;
      62             : #ifndef WITH_MPI
      63             :    int MPI_COMM_WORLD;
      64             : #endif
      65             :    int na, nev, nblk;
      66             : 
      67             :    int status;
      68             : 
      69             :    int np_cols, np_rows, np_colsStart;
      70             : 
      71             :    int my_blacs_ctxt, my_prow, my_pcol;
      72             : 
      73             :    int mpierr;
      74             : 
      75             :    int my_mpi_comm_world;
      76             :    int mpi_comm_rows, mpi_comm_cols;
      77             : 
      78             :    int info, *sc_desc;
      79             : 
      80             :    int na_rows, na_cols;
      81             :    double startVal;
      82             : #ifdef DOUBLE_PRECISION_REAL
      83             :    double *a, *z, *as, *ev;
      84             : #else
      85             :    float *a, *z, *as, *ev;
      86             : #endif
      87             : 
      88             :    int success;
      89             : 
      90             :    int useGPU;
      91             : #ifdef WITH_MPI
      92         128 :    MPI_Init(&argc, &argv);
      93         128 :    MPI_Comm_size(MPI_COMM_WORLD, &nprocs);
      94         128 :    MPI_Comm_rank(MPI_COMM_WORLD, &myid);
      95             : #else
      96          64 :    nprocs = 1;
      97          64 :    myid = 0;
      98          64 :    MPI_COMM_WORLD=1;
      99             : #endif
     100         192 :    na = 1000;
     101         192 :    nev = 500;
     102         192 :    nblk = 16;
     103             : 
     104         192 :    if (myid == 0) {
     105         128 :      printf("This is the c version of an ELPA test-programm\n");
     106         128 :      printf("\n");
     107         128 :      printf("It will call the 1stage ELPA real solver for an\n");
     108         128 :      printf("of matrix size %d. It will compute %d eigenvalues\n",na,nev);
     109         128 :      printf("and uses a blocksize of %d\n",nblk);
     110         128 :      printf("\n");
     111         128 :      printf("This is an example program with much less functionality\n");
     112         128 :      printf("as it's Fortran counterpart. It's only purpose is to show how \n");
     113         128 :      printf("to evoke ELPA1 from a c programm\n");
     114         128 :      printf("\n");
     115             : #ifdef DOUBLE_PRECISION_REAL
     116         128 :      printf("The double precision version of ELPA1 is used\n");
     117             : #else
     118             :      printf("The single precision version of ELPA1 is used\n");
     119             : #endif
     120         128 :      printf("\n");
     121             : 
     122             :    }
     123             : 
     124         192 :    status = 0;
     125             : 
     126         192 :    startVal = sqrt((double) nprocs);
     127         192 :    np_colsStart = (int) round(startVal);
     128         192 :    for (np_cols=np_colsStart;np_cols>1;np_cols--){
     129           0 :      if (nprocs %np_cols ==0){
     130           0 :      break;
     131             :      }
     132             :    }
     133             : 
     134         192 :    np_rows = nprocs/np_cols;
     135             : 
     136         192 :    if (myid == 0) {
     137         128 :      printf("\n");
     138         128 :      printf("Number of processor rows %d, cols %d, total %d \n",np_rows,np_cols,nprocs);
     139             :    }
     140             : 
     141             :    /* set up blacs */
     142             :    /* convert communicators before */
     143             : #ifdef WITH_MPI
     144         128 :    my_mpi_comm_world = MPI_Comm_c2f(MPI_COMM_WORLD);
     145             : #endif
     146         192 :    set_up_blacsgrid_f(my_mpi_comm_world, np_rows, np_cols, 'C', &my_blacs_ctxt, &my_prow, &my_pcol);
     147             : 
     148         192 :    if (myid == 0) {
     149         128 :      printf("\n");
     150         128 :      printf("Past BLACS_Gridinfo...\n");
     151         128 :      printf("\n");
     152             :    }
     153             : 
     154             :    /* get the ELPA row and col communicators. */
     155             :    /* These are NOT usable in C without calling the MPI_Comm_f2c function on them !! */
     156             : #ifdef WITH_MPI
     157         128 :    my_mpi_comm_world = MPI_Comm_c2f(MPI_COMM_WORLD);
     158             : #else
     159          64 :    my_mpi_comm_world =1 ;
     160             : #endif
     161         192 :    mpierr = elpa_get_communicators(my_mpi_comm_world, my_prow, my_pcol, &mpi_comm_rows, &mpi_comm_cols);
     162             : 
     163         192 :    if (myid == 0) {
     164         128 :      printf("\n");
     165         128 :      printf("Past split communicator setup for rows and columns...\n");
     166         128 :      printf("\n");
     167             :    }
     168             : 
     169         192 :    sc_desc = malloc(9*sizeof(int));
     170             : 
     171         192 :    set_up_blacs_descriptor_f(na, nblk, my_prow, my_pcol, np_rows, np_cols, &na_rows, &na_cols, sc_desc, my_blacs_ctxt, &info);
     172             : 
     173         192 :    if (myid == 0) {
     174         128 :      printf("\n");
     175         128 :      printf("Past scalapack descriptor setup...\n");
     176         128 :      printf("\n");
     177             :    }
     178             : 
     179             :    /* allocate the matrices needed for elpa */
     180         192 :    if (myid == 0) {
     181         128 :      printf("\n");
     182         128 :      printf("Allocating matrices with na_rows=%d and na_cols=%d\n",na_rows, na_cols);
     183         128 :      printf("\n");
     184             :    }
     185             : #ifdef DOUBLE_PRECISION_REAL
     186         192 :    a  = malloc(na_rows*na_cols*sizeof(double));
     187         192 :    z  = malloc(na_rows*na_cols*sizeof(double));
     188         192 :    as = malloc(na_rows*na_cols*sizeof(double));
     189         192 :    ev = malloc(na*sizeof(double));
     190             : #else
     191             :    a  = malloc(na_rows*na_cols*sizeof(float));
     192             :    z  = malloc(na_rows*na_cols*sizeof(float));
     193             :    as = malloc(na_rows*na_cols*sizeof(float));
     194             :    ev = malloc(na*sizeof(float));
     195             : #endif
     196             : 
     197             : #ifdef DOUBLE_PRECISION_REAL
     198         192 :    prepare_matrix_random_real_double_f(na, myid, na_rows, na_cols, sc_desc, a, z, as);
     199             : #else
     200             :    prepare_matrix_random_real_single_f(na, myid, na_rows, na_cols, sc_desc, a, z, as);
     201             : #endif
     202         192 :    if (myid == 0) {
     203         128 :      printf("\n");
     204         128 :      printf("Entering ELPA 1stage real solver\n");
     205         128 :      printf("\n");
     206             :    }
     207             : #ifdef WITH_MPI
     208         128 :    mpierr = MPI_Barrier(MPI_COMM_WORLD);
     209             : #endif
     210             : 
     211             : #ifdef DOUBLE_PRECISION_REAL
     212         192 :    useGPU = 0;
     213         192 :    success = elpa_solve_evp_real_1stage_double_precision(na, nev, a, na_rows, ev, z, na_rows, nblk, na_cols, mpi_comm_rows, mpi_comm_cols, my_mpi_comm_world, useGPU);
     214             : #else
     215             :    success = elpa_solve_evp_real_1stage_single_precision(na, nev, a, na_rows, ev, z, na_rows, nblk, na_cols, mpi_comm_rows, mpi_comm_cols, my_mpi_comm_world, useGPU);
     216             : #endif
     217             : 
     218         192 :    if (success != 1) {
     219           0 :      printf("error in ELPA solve \n");
     220             : #ifdef WITH_MPI
     221           0 :      mpierr = MPI_Abort(MPI_COMM_WORLD, 99);
     222             : #else
     223           0 :      exit(99);
     224             : #endif
     225             :    }
     226             : 
     227             : 
     228         192 :    if (myid == 0) {
     229         128 :      printf("\n");
     230         128 :      printf("1stage ELPA real solver complete\n");
     231         128 :      printf("\n");
     232             :    }
     233             : 
     234             : #ifdef DOUBLE_PRECISION_REAL
     235             :    /* check the results */
     236         192 :    status = check_correctness_evp_numeric_residuals_real_double_f(na, nev, na_rows, na_cols, as, z, ev, sc_desc, myid);
     237             : #else
     238             :    status = check_correctness_evp_numeric_residuals_real_single_f(na, nev, na_rows, na_cols, as, z, ev, sc_desc, myid);
     239             : #endif
     240         192 :    if (status !=0){
     241           0 :      printf("The computed EVs are not correct !\n");
     242             :    }
     243         192 :    if (status ==0){
     244         192 :      printf("All ok!\n");
     245             :    }
     246             : 
     247         192 :    free(sc_desc);
     248         192 :    free(a);
     249         192 :    free(z);
     250         192 :    free(as);
     251         192 :    free(ev);
     252             : 
     253             : #ifdef WITH_MPI
     254         128 :    MPI_Finalize();
     255             : #endif
     256         192 :    return 0;
     257             : }

Generated by: LCOV version 1.12