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 : #include <complex.h>
56 :
57 : #define DOUBLE_PRECISION_COMPLEX 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_COMPLEX
83 : complex double *a, *z, *as;
84 : double *ev;
85 : #else
86 : complex *a, *z, *as;
87 : float *ev;
88 : #endif
89 :
90 : int success;
91 :
92 : int THIS_COMPLEX_ELPA_KERNEL_API, useGPU;
93 :
94 : #ifdef WITH_MPI
95 128 : MPI_Init(&argc, &argv);
96 128 : MPI_Comm_size(MPI_COMM_WORLD, &nprocs);
97 128 : MPI_Comm_rank(MPI_COMM_WORLD, &myid);
98 : #else
99 64 : nprocs = 1;
100 64 : myid =0;
101 64 : MPI_COMM_WORLD=1;
102 : #endif
103 192 : na = 1000;
104 192 : nev = 500;
105 192 : nblk = 16;
106 :
107 192 : if (myid == 0) {
108 128 : printf("This is the c version of an ELPA test-programm\n");
109 128 : printf("\n");
110 128 : printf("It will call the 2stage ELPA complex solver for a matrix\n");
111 128 : printf("of matrix size %d. It will compute %d eigenvalues\n",na,nev);
112 128 : printf("and uses a blocksize of %d\n",nblk);
113 128 : printf("\n");
114 128 : printf("This is an example program with much less functionality\n");
115 128 : printf("as it's Fortran counterpart. It's only purpose is to show how \n");
116 128 : printf("to evoke ELPA 2 from a c programm\n");
117 :
118 128 : printf("\n");
119 :
120 : #ifdef DOUBLE_PRECISION_COMPLEX
121 128 : printf(" Double precision version of ELPA2 is used. \n");
122 : #else
123 : printf(" Single precision version of ELPA2 is used. \n");
124 : #endif
125 : }
126 :
127 192 : status = 0;
128 :
129 192 : startVal = sqrt((double) nprocs);
130 192 : np_colsStart = (int) round(startVal);
131 192 : for (np_cols=np_colsStart;np_cols>1;np_cols--){
132 0 : if (nprocs %np_cols ==0){
133 0 : break;
134 : }
135 : }
136 :
137 192 : np_rows = nprocs/np_cols;
138 :
139 192 : if (myid == 0) {
140 128 : printf("\n");
141 128 : printf("Number of processor rows %d, cols %d, total %d \n",np_rows,np_cols,nprocs);
142 : }
143 :
144 : /* set up blacs */
145 : /* convert communicators before */
146 : #ifdef WITH_MPI
147 128 : my_mpi_comm_world = MPI_Comm_c2f(MPI_COMM_WORLD);
148 : #else
149 64 : my_mpi_comm_world = 1;
150 : #endif
151 192 : set_up_blacsgrid_f(my_mpi_comm_world, np_rows, np_cols, 'C', &my_blacs_ctxt, &my_prow, &my_pcol);
152 :
153 192 : if (myid == 0) {
154 128 : printf("\n");
155 128 : printf("Past BLACS_Gridinfo...\n");
156 128 : printf("\n");
157 : }
158 :
159 : /* get the ELPA row and col communicators. */
160 : /* These are NOT usable in C without calling the MPI_Comm_f2c function on them !! */
161 : #ifdef WITH_MPI
162 128 : my_mpi_comm_world = MPI_Comm_c2f(MPI_COMM_WORLD);
163 : #endif
164 192 : mpierr = elpa_get_communicators(my_mpi_comm_world, my_prow, my_pcol, &mpi_comm_rows, &mpi_comm_cols);
165 :
166 192 : if (myid == 0) {
167 128 : printf("\n");
168 128 : printf("Past split communicator setup for rows and columns...\n");
169 128 : printf("\n");
170 : }
171 :
172 192 : sc_desc = malloc(9*sizeof(int));
173 :
174 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);
175 :
176 192 : if (myid == 0) {
177 128 : printf("\n");
178 128 : printf("Past scalapack descriptor setup...\n");
179 128 : printf("\n");
180 : }
181 :
182 : /* allocate the matrices needed for elpa */
183 192 : if (myid == 0) {
184 128 : printf("\n");
185 128 : printf("Allocating matrices with na_rows=%d and na_cols=%d\n",na_rows, na_cols);
186 128 : printf("\n");
187 : }
188 : #ifdef DOUBLE_PRECISION_COMPLEX
189 192 : a = malloc(na_rows*na_cols*sizeof(complex double));
190 192 : z = malloc(na_rows*na_cols*sizeof(complex double));
191 192 : as = malloc(na_rows*na_cols*sizeof(complex double));
192 192 : ev = malloc(na*sizeof(double));
193 : #else
194 : a = malloc(na_rows*na_cols*sizeof(complex));
195 : z = malloc(na_rows*na_cols*sizeof(complex));
196 : as = malloc(na_rows*na_cols*sizeof(complex));
197 : ev = malloc(na*sizeof(float));
198 : #endif
199 : #ifdef DOUBLE_PRECISION_COMPLEX
200 192 : prepare_matrix_random_complex_double_f(na, myid, na_rows, na_cols, sc_desc, a, z, as);
201 : #else
202 : prepare_matrix_random_complex_single_f(na, myid, na_rows, na_cols, sc_desc, a, z, as);
203 : #endif
204 :
205 192 : if (myid == 0) {
206 128 : printf("\n");
207 128 : printf("Entering ELPA 2stage complex solver\n");
208 128 : printf("\n");
209 : }
210 : #ifdef WITH_MPI
211 128 : mpierr = MPI_Barrier(MPI_COMM_WORLD);
212 : #endif
213 192 : useGPU = 0;
214 192 : THIS_COMPLEX_ELPA_KERNEL_API = ELPA_2STAGE_COMPLEX_DEFAULT;
215 : #ifdef DOUBLE_PRECISION_COMPLEX
216 192 : success = elpa_solve_evp_complex_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_COMPLEX_ELPA_KERNEL_API, useGPU);
217 : #else
218 : success = elpa_solve_evp_complex_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_COMPLEX_ELPA_KERNEL_API, useGPU);
219 : #endif
220 :
221 192 : if (success != 1) {
222 0 : printf("error in ELPA solve \n");
223 : #ifdef WITH_MPI
224 0 : mpierr = MPI_Abort(MPI_COMM_WORLD, 99);
225 : #else
226 0 : exit(99);
227 : #endif
228 : }
229 :
230 :
231 192 : if (myid == 0) {
232 128 : printf("\n");
233 128 : printf("2stage ELPA complex solver complete\n");
234 128 : printf("\n");
235 : }
236 :
237 : /* check the results */
238 : #ifdef DOUBLE_PRECISION_COMPLEX
239 192 : status = check_correctness_evp_numeric_residuals_complex_double_f(na, nev, na_rows, na_cols, as, z, ev, sc_desc, myid);
240 : #else
241 : status = check_correctness_evp_numeric_residuals_complex_single_f(na, nev, na_rows, na_cols, as, z, ev, sc_desc, myid);
242 : #endif
243 192 : if (status !=0){
244 0 : printf("The computed EVs are not correct !\n");
245 : }
246 192 : if (status ==0){
247 192 : if (myid == 0) {
248 128 : printf("All ok!\n");
249 : }
250 : }
251 :
252 192 : free(sc_desc);
253 192 : free(a);
254 192 : free(z);
255 192 : free(as);
256 192 : free(ev);
257 :
258 : #ifdef WITH_MPI
259 128 : MPI_Finalize();
260 : #endif
261 192 : return 0;
262 : }
|