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 : #define DOUBLE_PRECISION_REAL 1
57 :
58 192 : int main(int argc, char** argv) {
59 : int myid;
60 : int nprocs;
61 : #ifndef WITH_MPI
62 : int MPI_COMM_WORLD;
63 : #endif
64 : int na, nev, nblk;
65 :
66 : int status;
67 :
68 : int np_cols, np_rows, np_colsStart;
69 :
70 : int my_blacs_ctxt, my_prow, my_pcol;
71 :
72 : int mpierr;
73 :
74 : int my_mpi_comm_world;
75 : int mpi_comm_rows, mpi_comm_cols;
76 :
77 : int info, *sc_desc;
78 :
79 : int na_rows, na_cols;
80 : double startVal;
81 : #ifdef DOUBLE_PRECISION_REAL
82 : double *a, *z, *as, *ev;
83 : #else
84 : float *a, *z, *as, *ev;
85 : #endif
86 :
87 : int success;
88 :
89 : int useQr, THIS_REAL_ELPA_KERNEL_API, useGPU;
90 :
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 2stage ELPA real solver for an\n");
108 128 : printf("matrix of 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 ELPA2 from a c programm\n");
114 128 : printf("\n");
115 : #ifdef DOUBLE_PRECISION_REAL
116 128 : printf(" Double precision version of ELPA2 is used. \n");
117 : #else
118 : printf(" Single precision version of ELPA2 is used. \n");
119 : #endif
120 : }
121 :
122 192 : status = 0;
123 :
124 192 : startVal = sqrt((double) nprocs);
125 192 : np_colsStart = (int) round(startVal);
126 192 : for (np_cols=np_colsStart;np_cols>1;np_cols--){
127 0 : if (nprocs %np_cols ==0){
128 0 : break;
129 : }
130 : }
131 :
132 192 : np_rows = nprocs/np_cols;
133 :
134 192 : if (myid == 0) {
135 128 : printf("\n");
136 128 : printf("Number of processor rows %d, cols %d, total %d \n",np_rows,np_cols,nprocs);
137 : }
138 :
139 : /* set up blacs */
140 : /* convert communicators before */
141 : #ifdef WITH_MPI
142 128 : my_mpi_comm_world = MPI_Comm_c2f(MPI_COMM_WORLD);
143 : #else
144 64 : my_mpi_comm_world = 1;
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 : #endif
159 192 : mpierr = elpa_get_communicators(my_mpi_comm_world, my_prow, my_pcol, &mpi_comm_rows, &mpi_comm_cols);
160 :
161 192 : if (myid == 0) {
162 128 : printf("\n");
163 128 : printf("Past split communicator setup for rows and columns...\n");
164 128 : printf("\n");
165 : }
166 :
167 192 : sc_desc = malloc(9*sizeof(int));
168 :
169 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);
170 :
171 192 : if (myid == 0) {
172 128 : printf("\n");
173 128 : printf("Past scalapack descriptor setup...\n");
174 128 : printf("\n");
175 : }
176 :
177 : /* allocate the matrices needed for elpa */
178 192 : if (myid == 0) {
179 128 : printf("\n");
180 128 : printf("Allocating matrices with na_rows=%d and na_cols=%d\n",na_rows, na_cols);
181 128 : printf("\n");
182 : }
183 : #ifdef DOUBLE_PRECISION_REAL
184 192 : a = malloc(na_rows*na_cols*sizeof(double));
185 192 : z = malloc(na_rows*na_cols*sizeof(double));
186 192 : as = malloc(na_rows*na_cols*sizeof(double));
187 192 : ev = malloc(na*sizeof(double));
188 : #else
189 : a = malloc(na_rows*na_cols*sizeof(float));
190 : z = malloc(na_rows*na_cols*sizeof(float));
191 : as = malloc(na_rows*na_cols*sizeof(float));
192 : ev = malloc(na*sizeof(float));
193 : #endif
194 : #ifdef DOUBLE_PRECISION_REAL
195 192 : prepare_matrix_random_real_double_f(na, myid, na_rows, na_cols, sc_desc, a, z, as);
196 : #else
197 : prepare_matrix_random_real_single_f(na, myid, na_rows, na_cols, sc_desc, a, z, as);
198 : #endif
199 192 : if (myid == 0) {
200 128 : printf("\n");
201 128 : printf("Entering ELPA 2stage real solver\n");
202 128 : printf("\n");
203 : }
204 : #ifdef WITH_MPI
205 128 : mpierr = MPI_Barrier(MPI_COMM_WORLD);
206 : #endif
207 192 : useGPU =0 ;
208 192 : useQr = 0;
209 192 : THIS_REAL_ELPA_KERNEL_API = ELPA_2STAGE_REAL_DEFAULT;
210 : #ifdef DOUBLE_PRECISION_REAL
211 192 : success = elpa_solve_evp_real_2stage_double_precision(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);
212 : #else
213 : success = elpa_solve_evp_real_2stage_single_precision(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);
214 : #endif
215 192 : if (success != 1) {
216 0 : printf("error in ELPA solve \n");
217 : #ifdef WITH_MPI
218 0 : mpierr = MPI_Abort(MPI_COMM_WORLD, 99);
219 : #else
220 0 : exit(99);
221 : #endif
222 : }
223 :
224 :
225 192 : if (myid == 0) {
226 128 : printf("\n");
227 128 : printf("2stage ELPA real solver complete\n");
228 128 : printf("\n");
229 : }
230 :
231 : /* check the results */
232 : #ifdef DOUBLE_PRECISION_REAL
233 192 : status = check_correctness_evp_numeric_residuals_real_double_f(na, nev, na_rows, na_cols, as, z, ev, sc_desc, myid);
234 : #else
235 : status = check_correctness_evp_numeric_residuals_real_single_f(na, nev, na_rows, na_cols, as, z, ev, sc_desc, myid);
236 : #endif
237 :
238 192 : if (status !=0){
239 0 : printf("The computed EVs are not correct !\n");
240 : }
241 192 : if (status ==0){
242 192 : if (myid ==0) {
243 128 : printf("All ok!\n");
244 : }
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 : }
|