1 /* Copyright (C) 2005 The Scalable Software Infrastructure Project. All rights reserved.
2 
3    Redistribution and use in source and binary forms, with or without
4    modification, are permitted provided that the following conditions are met:
5    1. Redistributions of source code must retain the above copyright
6       notice, this list of conditions and the following disclaimer.
7    2. Redistributions in binary form must reproduce the above copyright
8       notice, this list of conditions and the following disclaimer in the
9       documentation and/or other materials provided with the distribution.
10    3. Neither the name of the project nor the names of its contributors
11       may be used to endorse or promote products derived from this software
12       without specific prior written permission.
13 
14    THIS SOFTWARE IS PROVIDED BY THE SCALABLE SOFTWARE INFRASTRUCTURE PROJECT
15    ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
16    TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
17    PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE SCALABLE SOFTWARE INFRASTRUCTURE
18    PROJECT BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY,
19    OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
20    SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
21    INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
22    CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
23    ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
24    POSSIBILITY OF SUCH DAMAGE.
25 */
26 
27 #ifdef HAVE_CONFIG_H
28         #include "lis_config.h"
29 #else
30 #ifdef HAVE_CONFIG_WIN_H
31         #include "lis_config_win.h"
32 #endif
33 #endif
34 
35 #include <stdio.h>
36 #include <stdlib.h>
37 #include <math.h>
38 #include "lis.h"
39 
40 #undef __FUNC__
41 #define __FUNC__ "main"
main(int argc,char * argv[])42 LIS_INT main(int argc, char* argv[])
43 {
44   LIS_Comm comm;
45   LIS_INT err;
46   int nprocs,my_rank;
47   LIS_INT nesol;
48   LIS_MATRIX A,X;
49   LIS_VECTOR x,y,z,w;
50   LIS_SCALAR evalue0;
51   LIS_ESOLVER esolver;
52   LIS_REAL residual;
53   LIS_INT iter;
54   double time;
55   double itime,ptime,p_c_time,p_i_time;
56   char esolvername[128];
57 
58   LIS_DEBUG_FUNC_IN;
59 
60   lis_initialize(&argc, &argv);
61 
62   comm = LIS_COMM_WORLD;
63 
64 #ifdef USE_MPI
65   MPI_Comm_size(comm,&nprocs);
66   MPI_Comm_rank(comm,&my_rank);
67 #else
68   nprocs  = 1;
69   my_rank = 0;
70 #endif
71 
72   if( argc < 6 )
73     {
74       lis_printf(comm,"Usage: %s matrix_filename evalues_filename evectors_filename residuals_filename iters_filename [options]\n", argv[0]);
75       CHKERR(1);
76     }
77 
78   lis_printf(comm,"\n");
79   lis_printf(comm,"number of processes = %d\n",nprocs);
80 
81 #ifdef _OPENMP
82   lis_printf(comm,"max number of threads = %d\n",omp_get_num_procs());
83   lis_printf(comm,"number of threads = %d\n",omp_get_max_threads());
84 #endif
85 
86   /* create matrix and vectors */
87   lis_matrix_create(LIS_COMM_WORLD,&A);
88   lis_input_matrix(A,argv[1]);
89   lis_vector_duplicate(A,&x);
90   lis_esolver_create(&esolver);
91   lis_esolver_set_option("-e si -ss 1 -eprint mem",esolver);
92   err = lis_esolver_set_optionC(esolver);
93   CHKERR(err);
94   err = lis_esolve(A, x, &evalue0, esolver);
95   CHKERR(err);
96   lis_esolver_get_esolver(esolver,&nesol);
97   lis_esolver_get_esolvername(nesol,esolvername);
98   lis_esolver_get_residualnorm(esolver, &residual);
99   lis_esolver_get_iter(esolver, &iter);
100   lis_esolver_get_timeex(esolver,&time,&itime,&ptime,&p_c_time,&p_i_time);
101 
102   lis_printf(comm,"%s: mode number          = %d\n", esolvername, 0);
103 #ifdef _COMPLEX
104   lis_printf(comm,"%s: eigenvalue           = (%e, %e)\n", esolvername, (double)creal(evalue0), (double)cimag(evalue0));
105 #else
106   lis_printf(comm,"%s: eigenvalue           = %e\n", esolvername, (double)evalue0);
107 #endif
108   lis_printf(comm,"%s: number of iterations = %D\n",esolvername, iter);
109   lis_printf(comm,"%s: elapsed time         = %e sec.\n", esolvername, time);
110   lis_printf(comm,"%s:   preconditioner     = %e sec.\n", esolvername, ptime);
111   lis_printf(comm,"%s:     matrix creation  = %e sec.\n", esolvername, p_c_time);
112   lis_printf(comm,"%s:   linear solver      = %e sec.\n", esolvername, itime);
113   lis_printf(comm,"%s: relative residual    = %e\n\n",esolvername, (double)residual);
114 
115   lis_vector_create(LIS_COMM_WORLD,&y);
116   lis_vector_create(LIS_COMM_WORLD,&z);
117   lis_vector_create(LIS_COMM_WORLD,&w);
118   lis_matrix_create(LIS_COMM_WORLD,&X);
119   lis_esolver_get_evalues(esolver,y);
120   lis_esolver_get_residualnorms(esolver,z);
121   lis_esolver_get_iters(esolver,w);
122   lis_esolver_get_evectors(esolver,X);
123 
124   /* write eigenvalues */
125   lis_output_vector(y,LIS_FMT_MM,argv[2]);
126 
127   /* write eigenvectors */
128   lis_output_matrix(X,LIS_FMT_MM,argv[3]);
129 
130   /* write residual norms */
131   lis_output_vector(z,LIS_FMT_MM,argv[4]);
132 
133   /* write numbers of iterations */
134   lis_output_vector(w,LIS_FMT_MM,argv[5]);
135 
136   lis_esolver_destroy(esolver);
137   lis_matrix_destroy(A);
138   lis_vector_destroy(x);
139   lis_matrix_destroy(X);
140   lis_vector_destroy(y);
141   lis_vector_destroy(z);
142   lis_vector_destroy(w);
143 
144   lis_finalize();
145 
146   LIS_DEBUG_FUNC_OUT;
147 
148   return 0;
149 }
150 
151 
152