source: src/main/aggr.F90 @ bac5f50

Revision bac5f50, 10.1 KB checked in by Oleg Batrashev <ogbash@…>, 2 years ago (diff)

Fixed the 'strong' handling.

  • Property mode set to 100644
Line 
1! DOUG - Domain decomposition On Unstructured Grids
2! Copyright (C) 1998-2006 Faculty of Computer Science, University of Tartu and
3! Department of Mathematics, University of Bath
4!
5! This library is free software; you can redistribute it and/or
6! modify it under the terms of the GNU Lesser General Public
7! License as published by the Free Software Foundation; either
8! version 2.1 of the License, or (at your option) any later version.
9!
10! This library is distributed in the hope that it will be useful,
11! but WITHOUT ANY WARRANTY; without even the implied warranty of
12! MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
13! Lesser General Public License for more details.
14!
15! You should have received a copy of the GNU Lesser General Public
16! License along with this library; if not, write to the Free Software
17! Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA
18! or contact the authors (University of Tartu, Faculty of Computer Science, Chair
19! of Distributed Systems, Liivi 2, 50409 Tartu, Estonia, http://dougdevel.org,
20! mailto:info(at)dougdevel.org)
21
22!> Main program for running DOUG with input files in assembled form.
23!> \section aggregation_running Running the aggregation-based DOUG code: (example)
24!>   <tt>mpirun -np 3 doug_aggr -f doug.ctl</tt>
25!>     where \c doug.ctl may contain the following fields
26!>   \subsection example Input-file example:
27!> \code
28!> solver 2
29!> solve_maxiters 300
30!> method 1
31!> coarse_method 1
32!> levels  2
33!> overlap -1
34!> smoothers 0
35!> input_type 2
36!> symmstruct T
37!> symmnumeric T
38!> # ###################
39!> # aggregate level 1:
40!> radius1 5
41!> strong1 0.67e0
42!> minasize1 2
43!> #maxasize1 19
44!> # aggregate level 2:
45!> radius2 35
46!> strong2 0.67e0
47!> minasize2 2
48!> #maxasize2 96
49!> # ###################
50!> matrix_type 1
51!> number_of_blocks 1
52!> initial_guess 2
53!> start_vec_file ./NOT.DEFINED.start_vec_file
54!> start_vec_type 2
55!> solve_tolerance 1.0e-12
56!> solution_format 2
57!> solution_file ./solution.file
58!> #debug -5
59!> debug 0
60!> verbose 0
61!> plotting 1
62!> assembled_mtx_file Hetero32.txt
63!> \endcode
64program main_aggr
65
66  use doug
67  use Distribution_mod
68  use Partitioning_mod
69  use Mesh_class
70  use Mesh_plot_mod
71  use SpMtx_mods
72  use Vect_mod
73  use DenseMtx_mod
74  use solvers_mod
75  use Aggregate_mod
76  use Aggregate_utils_mod
77  use CoarseMtx_mod
78  use CoarseAllgathers
79  use RobustCoarseMtx_mod
80  use pcgRobust_mod
81
82  implicit none
83
84#include<doug_config.h>
85
86#ifdef D_COMPLEX
87#define float complex
88#else
89#define float real
90#endif
91
92  type(SpMtx)    :: AC  !< coarse matrix
93  type(SpMtx)    :: Restrict !< Restriction matrix (for operation)
94  type(SumOfInversedSubMtx) :: B_RCS !< B matrix for the Robust Coarse Spaces
95  !type(SpMtx)    :: Rest_cmb !< Restriction matrix (for coarse matrix build)
96
97  float(kind=rk), dimension(:), pointer :: xl !< local solution vector
98  float(kind=rk), dimension(:), pointer :: x  !< global solution on master
99  float(kind=rk), dimension(:), pointer :: sol, rhs  !< for testing solver
100  real(kind=rk), pointer :: rhs_1(:), g(:)
101
102  ! Partitioning
103  integer               :: nparts !< number of partitons to partition a mesh
104  integer, dimension(6) :: part_opts = (/0,0,0,0,0,0/)
105
106  type(ConvInf) :: resStat
107
108  real(kind=rk) :: t,t1
109  integer :: i,j,k,it,ol
110  float(kind=rk), dimension(:), pointer :: r, y
111  character :: str
112  character(len=40) :: frm
113  float(kind=rk) :: cond_num,nrm
114  integer,allocatable :: nodes(:), inds(:)
115
116  type(Distribution) :: D !< mesh and matrix distribution
117  type(Decomposition) :: DD !< domains
118  type(Partitionings) :: P !< fine and coarse aggregates
119  type(RobustPreconditionMtx) :: C
120  type(CoarseSpace) :: CS
121  ! Parallel coarse level
122  !type(CoarseData) :: cdat -- moved into the module itself...
123
124  ! Init DOUG
125  call DOUG_Init()
126
127  ! Master participates in calculations as well
128  nparts = numprocs
129
130  D = Distribution_NewInit(sctls%input_type,nparts,part_opts)
131
132  if (sctls%levels>1.or.(numprocs==1.and.sctls%levels==1)) then !todo remove
133    P = Partitionings_New()
134    call Partitionings_CreateFine(P,D)
135    ! profile info
136    if(pstream/=0) then
137      write(pstream, "(I0,':fine aggregates:',I0)") myrank, P%fAggr%inner%nagr
138    end if
139
140    !if (sctls%plotting>=2) then
141    !   call SpMtx_writeLogicalValues(A, D%A%strong, 'strong.txt')
142    !end if
143
144    call Mesh_printInfo(D%mesh)
145   
146    if (numprocs==1.and.sctls%plotting==2.and.D%mesh%nell>0) then
147      call Mesh_pl2D_plotAggregate(P%fAggr%inner,D%mesh,&
148                      D%A%strong_rowstart,D%A%strong_colnrs,&
149                      mctls%assembled_mtx_file, &
150                                 INIT_CONT_END=D_PLPLOT_INIT)
151                                 !D_PLPLOT_END)
152    endif
153   
154    ! Testing coarse matrix and aggregation through it:
155    if (numprocs>1) then
156     
157      call SpMtx_find_strong(A=D%A,alpha=P%strong_conn1,A_ghost=D%A_ghost)
158      call SpMtx_exchange_strong(D%A,D%A_ghost,D%mesh)
159      call SpMtx_symm_strong(D%A,D%A_ghost,.false.)
160      call SpMtx_unscale(D%A)
161
162      call IntRestBuild(D%A,P%fAggr%inner,Restrict,D%A_ghost)
163      CS = CoarseSpace_Init(Restrict)
164      call CoarseData_Copy(cdat,cdat_vec)
165      call CoarseSpace_Expand(CS,Restrict,D%mesh,cdat)
166      call CoarseMtxBuild(D%A,cdat%LAC,Restrict,D%mesh%ninner,D%A_ghost)
167      call KeepGivenRowIndeces(Restrict, (/(i,i=1,P%fAggr%inner%nagr)/))
168
169      if (sctls%verbose>3.and.cdat%LAC%nnz<400) then
170        write(stream,*)'Restrict (local) is:=================='
171        call SpMtx_printRaw(A=Restrict)
172        write(stream,*)'A coarse (local) is:=================='
173        call SpMtx_printRaw(A=cdat%LAC)
174      endif
175
176    else
177      ! non-parallel
178      call IntRestBuild(D%A,P%fAggr%inner,Restrict)
179
180      if (sctls%coarse_method<=1) then ! if not specified or ==1
181         call CoarseMtxBuild(D%A,AC,Restrict,D%mesh%ninner)
182
183      else if (sctls%coarse_method==2) then
184         ! use the Robust Coarse Spaces algorithm
185         B_RCS = CoarseProjectionMtxsBuild(D%A,Restrict,P%fAggr%inner%nagr)
186         allocate(rhs_1(D%A%nrows))
187         allocate(g(D%A%ncols))
188
189         rhs_1 = 1.0
190         call pcg_forRCS(B_RCS,rhs_1,g)
191
192         if(sctls%verbose>5) then
193            write (stream, *) "Solution g = ", g
194         end if
195
196         call RobustRestrictMtxBuild(B_RCS,g,Restrict)
197         call CoarseMtxBuild(D%A,AC,Restrict,D%mesh%ninner)
198
199      else
200         write(stream,'(A," ",I2)') 'Wrong coarse method', sctls%coarse_method
201         call DOUG_abort('Error in aggr', -1)
202      endif
203           
204      if (sctls%verbose>3.and.AC%nnz<400) then
205        write(stream,*)'A coarse is:=================='
206        call SpMtx_printRaw(A=AC)
207      endif
208    endif
209   
210    ! coarse aggregates
211    if (numprocs==1) then
212      call Partitionings_CreateCoarse(P,D,AC)
213      !call Aggrs_readFile_coarse(P%cAggr, "aggregates.txt")
214
215      ! profile info
216      if(pstream/=0) then
217        write(pstream, "(I0,':coarse aggregates:',I0)") myrank, P%cAggr%inner%nagr
218      end if
219
220      if (sctls%plotting==2) then
221         call Aggr_writeFile(P%fAggr%inner, 'aggr2.txt', P%cAggr%inner)
222      end if
223      if (sctls%plotting==2.and.D%mesh%nell>0) then
224        !print *,'press Key<Enter>'
225        !read *,str
226        call Mesh_pl2D_plotAggregate(P%fAggr%inner,D%mesh,&
227                        D%A%strong_rowstart,D%A%strong_colnrs,&
228                        mctls%assembled_mtx_file, &
229                        caggrnum=P%cAggr%inner%num, &
230                      INIT_CONT_END=D_PLPLOT_END)!, &
231                      !INIT_CONT_END=D_PLPLOT_CONT)!, &
232                                  ! D_PLPLOT_END)
233      endif
234      write(stream,*)'# coarse aggregates:',P%cAggr%inner%nagr
235
236    endif
237  endif
238
239  ! overlap for subdomains
240  if (sctls%overlap<0) then ! autom. overlap from smoothing
241    ol = max(sctls%smoothers,0)
242  else
243    ol = sctls%overlap
244  endif
245
246  if (numprocs==1) then
247    DD = Decomposition_from_aggrs(D%A, P%cAggr%full, P%fAggr%full, ol)
248    call AggrInfo_Destroy(P%cAggr)
249    call AggrInfo_Destroy(P%fAggr)
250  else
251    DD = Decomposition_full(D%A,D%A_ghost,D%mesh%ninner,ol)
252    ! call Aggrs_writeFile(M, P%fAggr, cdat, "aggregates.txt")
253    if (sctls%levels>1) call AggrInfo_Destroy(P%fAggr)
254  end if
255
256  ! Testing UMFPACK:
257  allocate(sol(D%A%nrows))
258  allocate(rhs(D%A%ncols))
259
260  ! Solve the system
261  allocate(xl(D%mesh%nlf))
262  xl = 0.0_rk
263
264  select case(sctls%solver)
265  case (DCTL_SOLVE_CG)
266     ! Conjugate gradient
267     call cg(D%A, D%rhs, xl, D%mesh, solinf=resStat, resvects_=.true.)
268     !call cg(A, b, xl, M, solinf=resStat)
269  case (DCTL_SOLVE_PCG)
270     ! Preconditioned conjugate gradient
271     t1 = MPI_WTIME()
272     if (sctls%levels==2) then
273       write(stream,*)'calling pcg_weigs with coarse matrix'
274       call pcg_weigs(A=D%A,b=D%rhs,x=xl,Msh=D%mesh,DomDec=DD,it=it,cond_num=cond_num, &
275            A_interf_=D%A_ghost, &
276            CoarseMtx_=AC,Restrict=Restrict, &
277            refactor_=.true.)
278     else
279       write(stream,*)'calling pcg_weigs'
280       call pcg_weigs(D%A, D%rhs, xl, D%mesh,DD,it,cond_num, &
281            A_interf_=D%A_ghost, refactor_=.true.)
282     endif
283     t=MPI_WTIME()-t1
284     write(stream,*) 'time spent in pcg():',t
285     t1=total_setup_time()
286     write(stream,*) '    ...of which setup:',t1
287     write(stream,*) '       ...of which factorisation:', &
288        total_factorisation_time()
289     write(stream,*) 'solve time without setup:',t-t1
290  case default
291     call DOUG_abort('[DOUG main] : Wrong solution method specified', -1)
292  end select
293
294  if (numprocs>1) then
295    ! Assemble result on master
296    if (ismaster()) then
297       print *, "freedoms", D%mesh%ngf
298      allocate(x(D%mesh%ngf)); x = 0.0_rk
299    end if
300    call Vect_Gather(xl, x, D%mesh)
301    if (ismaster().and.sctls%verbose>2.and.(size(x) <= 100)) &
302      call Vect_Print(x, 'sol > ')
303    if (ismaster()) then
304       call WriteSolutionToFile(x)
305    end if
306
307  else
308    if (sctls%verbose>2.and.size(xl)<=100) then
309      call Vect_Print(xl, 'sol > ')
310    endif
311    call WriteSolutionToFile(xl)
312  endif
313
314
315  ! Destroy objects
316  call Mesh_Destroy(D%mesh)
317  call SpMtx_Destroy(D%A)
318  call ConvInf_Destroy(resStat)
319  if (associated(xl)) deallocate(xl)
320  if (associated(x)) deallocate(x)
321  if (associated(sol)) deallocate(sol)
322
323  call DOUG_Finalize()
324
325
326end program main_aggr
Note: See TracBrowser for help on using the repository browser.