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

Generated by: LCOV version 1.12