4
c $Id: testeig.F,v 1.10 2004-11-13 02:49:18 edo Exp $
10
c#define BLOCK_CYCLIC 0
14
c*** Intitialize a message passing library
23
call mxinit() ! PEIGS needs mxinit
27
c Intitialize the GA package
31
c Initialize the MA package
35
if (.not. ma_init(MT_DBL, heap, stack))
36
$ call ga_error("ma init failed",heap+stack)
49
#include "mafdecls.fh"
54
double precision a(n,n), b(n,n), c(n,n), evals(n)
55
double precision eva(n), evb(n)
56
integer g_a,g_b,g_c,g_d
57
integer i, j, index(n),ind(n)
59
double precision dsin, sum
62
integer g_aa, g_bb, g_cc, g_dd
63
integer dims(2), proc_grid(2), block(2)
70
c*** a() is a local copy of what the global array should start as
75
b(i,j) = DSIN(1d0* (i+j))
88
c*** Create global arrays
93
write(6,*) '> Creating Block-Cyclic Arrays'
100
call factor(nproc,g1,g2)
104
write(6,'(a,i3,a,i3)') ' Proc grid dimensions: ',g1,' x ',g2
107
g_a = ga_create_handle()
108
call ga_set_data(g_a,2,dims,MT_DBL)
109
call ga_set_block_cyclic_proc_grid(g_a,block,proc_grid)
110
if (.not.ga_allocate(g_a))
111
& call ga_error(' ga_create a failed ', 2)
113
g_b = ga_create_handle()
114
call ga_set_data(g_b,2,dims,MT_DBL)
115
call ga_set_block_cyclic_proc_grid(g_b,block,proc_grid)
116
if (.not.ga_allocate(g_b))
117
& call ga_error(' ga_create b failed ', 2)
119
g_c = ga_create_handle()
120
call ga_set_data(g_c,2,dims,MT_DBL)
121
call ga_set_block_cyclic_proc_grid(g_c,block,proc_grid)
122
if (.not.ga_allocate(g_c))
123
& call ga_error(' ga_create c failed ', 2)
125
g_d = ga_create_handle()
126
call ga_set_data(g_d,2,dims,MT_DBL)
127
call ga_set_block_cyclic_proc_grid(g_d,block,proc_grid)
128
if (.not.ga_allocate(g_d))
129
& call ga_error(' ga_create d failed ', 2)
131
if (.not. ga_create(MT_DBL, n, n, 'AA', 1, 1, g_aa))
132
$ call ga_error(' ga_create aa failed ',2)
133
if (.not. ga_create(MT_DBL, n, n, 'BB', 1, 1, g_bb))
134
$ call ga_error(' ga_create bb failed ',2)
135
if (.not. ga_create(MT_DBL, n, n, 'CC', 1, 1, g_cc))
136
$ call ga_error(' ga_create cc failed ',2)
137
if (.not. ga_create(MT_DBL, n, n, 'DD', 1, 1, g_dd))
138
$ call ga_error(' ga_create dd failed ',2)
140
if (.not. ga_create(MT_DBL, n, n, 'A', 1, 1, g_a))
141
$ call ga_error(' ga_create a failed ',2)
142
if (.not. ga_create(MT_DBL, n, n, 'B', 1, 1, g_b))
143
$ call ga_error(' ga_create b failed ',2)
144
if (.not. ga_create(MT_DBL, n, n, 'C', 1, 1, g_c))
145
$ call ga_error(' ga_create c failed ',2)
146
if (.not. ga_create(MT_DBL, n, n, 'D', 1, 1, g_d))
147
$ call ga_error(' ga_create d failed ',2)
150
c*** Fill in arrays A & B
154
21 format(/' filling in ... ')
157
call ga_put(g_a, 1,n, j,j, a(1,j),n)
158
call ga_put(g_b, 1,n, j,j, b(1,j),n)
159
call ga_put(g_c, 1,n, j,j, c(1,j),n)
163
c call GA_GET(g_a, 1,n, j,j, eva,1)
164
c write(6,'(10e8.2)')(eva(i),i=1,n)
168
c*** check symmetrization
172
print *,'>checking ga_symmetrize '
176
call ga_symmetrize(g_c)
178
call GA_GET(g_c, 1,n, 1,n,c,n)
179
do j = ga_nodeid()+1, n, ga_nnodes()
181
if(c(i,j).ne.c(j,i))then
182
print *, me, ' symmetrize ',i,j,c(i,j),c(j,i)
184
call ga_error('exiting',-1)
191
print *,' ga_symmetrize is OK'
197
c*** check symmetrization
201
print *,'>checking ga_transpose '
206
call ga_transpose(g_c,g_d)
209
call GA_GET(g_d, 1,n, 1,n,a,n)
210
do j = ga_nodeid()+1, n, ga_nnodes()
211
call GA_GET(g_d, 1,n, j,j, a,n)
213
if(a(i,1).ne.c(j,i))then
214
print *, me, ' transpose ',i,j,a(i,1),c(j,i)
216
call ga_error('exiting',-1)
223
print *,' ga_transpose is OK'
229
c*** solve the eigenproblem
232
write(6,*) '>checking the generalized eigensolver ... '
238
call ga_diag_seq(g_a,g_b,g_c,evals)
240
#ifdef HAVE_SCALAPACK
242
call ga_copy(g_a, g_aa)
243
call ga_copy(g_b, g_bb)
245
call ga_pdsygv( g_a, g_b, g_c, evals)
247
call ga_copy(g_aa, g_a)
248
call ga_copy(g_bb, g_b)
251
call ga_diag(g_a,g_b,g_c,evals)
256
print *,' checking multiplication'
263
call ga_copy(g_a, g_aa)
264
call ga_copy(g_c, g_cc)
265
call ga_dgemm('t','n',n,n,n, 1d0, g_cc, g_aa, 0d0, g_dd)
266
call ga_dgemm('n','n',n,n,n, 1d0, g_dd, g_cc, 0d0, g_aa)
267
call ga_copy(g_aa, g_a)
269
call ga_dgemm('t','n',n,n,n, 1d0, g_c, g_a, 0d0, g_d)
270
call ga_dgemm('n','n',n,n,n, 1d0, g_d, g_c, 0d0, g_a)
276
call GA_GET(g_a, j,j, j,j, eva(j),1)
282
call ga_copy(g_b, g_bb)
283
call ga_dgemm('t','n',n,n,n, 1d0, g_cc, g_bb, 0d0, g_dd)
285
call ga_dgemm('n','n',n,n,n, 1d0, g_dd, g_cc, 0d0, g_bb)
286
call ga_copy(g_bb, g_b)
288
call ga_dgemm('t','n',n,n,n, 1d0, g_c, g_b, 0d0, g_d)
290
call ga_dgemm('n','n',n,n,n, 1d0, g_d, g_c, 0d0, g_b)
296
call GA_GET(g_b, j,j, j,j, evb(j),1)
298
write(6,*)' j lambda eva evb eva/evb'
299
write(6,*)' ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^'
302
if(ABS(evals(j) - eva(j)/evb(j)).gt.1d-5)
303
& write(6,'(i4,1h_,6(e10.3,1h,))')
304
@ j,evals(j), eva(j), evb(j),eva(j)/evb(j)
306
write(6,*)' OK OK OK OK'
311
print *,' eigensolver & multiplication are OK'
317
c..................................................................
319
c*** solve the std eigenproblem
322
write(6,*) '>checking the standard eigensolver ... '
333
#ifdef HAVE_SCALAPACK
335
call ga_copy(g_a, g_aa)
337
call ga_pdsyev( g_a, g_c, evals, 16)
339
call ga_copy(g_aa, g_a)
342
call ga_diag_std(g_a,g_c,evals)
345
call ga_diag_std_seq(g_a,g_c,evals)
352
call ga_copy(g_a, g_aa)
353
call ga_copy(g_c, g_cc)
354
call ga_dgemm('n','n',n,n,n, 1d0, g_aa, g_cc, 0d0, g_dd) ! d := a*c
355
call ga_copy(g_dd, g_d)
357
call ga_dgemm('n','n',n,n,n, 1d0, g_a, g_c, 0d0, g_d) ! d := a*c
360
c copy eigenvalues to diagonal of g_b
362
if (me .eq. 0) call ga_scatter(g_b, evals, index, ind, n)
366
call ga_copy(g_b, g_bb)
367
call ga_dgemm('n','n',n,n,n, 1d0, g_cc, g_bb, 0d0, g_aa) ! a := c*b
368
call ga_copy(g_aa, g_a)
370
call ga_dgemm('n','n',n,n,n, 1d0, g_c, g_b, 0d0, g_a) ! a := c*b
374
call ga_add(1d0, g_d, -1d0, g_a, g_c)
375
sum = ga_ddot(g_c,g_c)
377
if(dsqrt(sum)/n.lt.1d-11)then
378
print *, ' std eigensolver is OK '
380
print *, ' test failed: norm = ', dsqrt(sum)/n
385
c status = MA_summarize_allocated_blocks()
386
status = ga_destroy(g_d)
387
status = ga_destroy(g_c)
388
status = ga_destroy(g_b)
389
status = ga_destroy(g_a)
393
subroutine factor(p,idx,idy)
395
integer i,j,p,idx,idy,it
396
integer ip,ifac,pmax,prime(1280)
402
c factor p completely
403
c first, find all prime numbers less than or equal to p
408
if (mod(i,prime(j)).eq.0) go to 100
415
c find all prime factors of p
419
200 if (mod(ip,prime(i)).eq.0) then
427
c determine two factors of p of approximately the