4
c $Id: test.F,v 1.64.2.11 2007-04-06 22:37:35 d3g293 Exp $
5
c vector boxes lack arithmetic precision
14
#define MISMATCH(x,y) abs(x-y)/max(1d0,abs(x)).gt.THRESH
15
#define MISMATCHF(x,y) abs(x-y)/max(1.0,abs(x)).gt.THRESHF
22
c#define USE_SCALAPACK_DISTR
23
c#define USE_RESTRICTED
35
# undef USE_SCALAPAC_DISTR
40
#include "mafdecls.fh"
42
#include "testutil.fh"
43
integer heap, stack, fudge, ma_heap, me, nproc, map(4096), block
44
integer g_s, ndim, dim1, i
46
parameter (heap=200*200*4, fudge=100, stack=200*200)
48
c*** Intitialize a message passing library
54
c There are 2 choices: ga_initialize or ga_initialize_ltd.
55
c In the first case, there is no explicit limit on memory usage.
56
c In the second, user can set limit (per processor) in bytes.
61
c we can also use GA_set_memory_limit BEFORE first ga_create call
63
ma_heap = heap/nproc + fudge
68
call GA_set_memory_limit(util_mdtob(ma_heap))
70
if(ga_nodeid().eq.0)then
72
print *,' Performing tests on Mirrored Arrays'
74
print *,' GA initialized '
78
c*** Initialize the MA package
79
c MA must be initialized before any global array is allocated
81
status = ma_init(MT_DCPL, stack, ma_heap)
82
if (.not. status) call ga_error('ma_init failed',-1)
84
c Uncomment the below line to register external memory allocator
85
c for dynamic arrays inside GA routines.
86
c call register_ext_memory()
88
if(me.eq.(nproc-1))then
89
print *, 'using ', nproc,' process(es) ', ga_cluster_nnodes(),
91
print *,'process ', me, ' is on node ',ga_cluster_nodeid(),
92
$ ' with ', ga_cluster_nprocs(-1), ' processes'
96
c create array to force staggering of memory and uneven distribution
102
map(i) = MEM_INC*(i-1)+1
103
dim1 = dim1 + MEM_INC*i
105
g_s = ga_create_handle()
107
call ga_set_data(g_s,ndim,dim1,MT_INT)
108
call ga_set_array_name(g_s,'s')
109
call ga_set_irreg_distr(g_s,map,nproc)
112
c*** Check support for single precision complex arrays
116
write(6,*) ' CHECKING SINGLE COMPLEX '
121
call check_complex_float()
123
c*** Check support for double precision complex arrays
127
write(6,*) ' CHECKING DOUBLE COMPLEX '
133
if(me.eq.0) call ga_print_stats()
134
if(me.eq.0) print *,' '
135
if(me.eq.0) print *,'All tests successful '
136
status = ga_destroy(g_s)
138
c*** Tidy up the GA package
142
c*** Tidy up after message-passing library
151
subroutine check_complex_float()
153
#include "mafdecls.fh"
155
#include "testutil.fh"
160
complex a(n,n), b(n,n), v(m),w(m)
162
integer ndim, dims(2), chunk(2), p_mirror
165
integer ndim, dims(2), chunk(2), p_mirror
171
integer iran, i,j, loop,nloop,maxloop, ilo, ihi, jlo, jhi, itmp
172
integer nproc, me, int, ij, inc, ii, jj, nnodes
173
parameter (maxloop = 100)
175
parameter (maxproc = 4096)
176
double precision crap, real
177
double precision nwords
178
complex x, sum1, sum2, factor
179
integer lprocs, inode, iproc, lproc
180
integer scpl_type, istatus
181
#ifdef USE_RESTRICTED
183
integer rstrctd_list(maxproc/2)
186
iran(i) = int(drand(0)*real(i)) + 1
190
inode = ga_cluster_nodeid()
191
lprocs = ga_cluster_nprocs(inode)
192
nnodes = ga_cluster_nnodes()
193
iproc = mod(me,lprocs)
194
nloop = Min(maxloop,n)
195
#ifdef USE_RESTRICTED
196
num_rstrctd = nproc/2
197
if (num_rstrctd.eq.0) num_rstrctd = 1
198
do i = 1, num_rstrctd
199
rstrctd_list(i) = (num_rstrctd/2) + i-1
203
c a() is a local copy of what the global array should start as
208
a(i,j) = cmplx(real(i-1), real((j-1)*n))
210
a(i,j) = cmplx(real(inode),0.0d00)
211
+ + cmplx(real(i-1), real((j-1)*n))
213
b(i,j) = cmplx(-1d0,1d0)
219
scpl_type = nga_register_type(8)
221
c Create a global array
223
c print *,ga_nodeid(), ' creating array'
230
g_a = ga_create_handle()
231
call ga_set_data(g_a,ndim,dims,scpl_type)
232
call ga_set_array_name(g_a,'a')
233
#ifdef USE_RESTRICTED
234
call ga_set_restricted(g_a, rstrctd_list, num_rstrctd)
237
p_mirror = ga_pgroup_get_mirror()
238
call ga_set_pgroup(g_a,p_mirror)
240
status = ga_allocate(g_a)
243
status = ga_create(scpl_type, n, n, 'a', 0, 0, g_a)
250
p_mirror = ga_pgroup_get_mirror()
251
status = nga_create_config(scpl_type, ndim, dims, 'a', chunk,
255
if (.not. status) then
256
write(6,*) ' ga_create failed'
257
call ga_error('... exiting ',0)
260
g_b = ga_create_handle()
261
call ga_set_data(g_b,ndim,dims,scpl_type)
262
call ga_set_array_name(g_b,'b')
264
call ga_set_pgroup(g_b,p_mirror)
266
if (.not.ga_allocate(g_b)) then
269
if (.not. ga_create(scpl_type, n, n, 'b', 0, 0, g_b)) then
271
if (.not. nga_create_config(scpl_type, ndim, dims, 'b', chunk,
272
_ p_mirror, g_b)) then
275
call ga_error('ga_create failed for second array ',0)
279
call ga_distribution(g_a,me,ilo, ihi, jlo, jhi)
281
lproc = me - ga_cluster_procid(inode,0)
282
call ga_distribution(g_a, lproc, ilo, ihi, jlo, jhi)
290
21 format(/'> Checking zero ... ')
295
c Check that it is indeed zero
297
call ga_get(g_a, 1, n, 1, n, b, n)
301
if(b(i,j).ne.(0d0,0d0)) then
302
write(6,*) me,' zero ', i, j, b(i,j)
304
c call ga_error('... exiting ',0)
310
write(6,*) ' ga_zero is OK'
315
c Each node fills in disjoint sections of the array
319
2 format(/'> Checking disjoint put ... ')
329
if (mod(ij,nproc) .eq. me) then
331
if (mod(ij,lprocs) .eq. iproc) then
337
call ga_put(g_a, ilo, ihi, jlo, jhi, a(ilo, jlo), n)
344
c All nodes check all of a
346
call ga_get(g_a, 1, n, 1, n, b, n)
350
if (b(i,j) .ne. a(i,j)) then
351
write(6,*) ' put ', me, i, j, a(i,j),b(i,j)
353
call ga_error('... exiting ',0)
359
write(6,*) ' ga_put is OK'
364
c Now check nloop random gets from each node
368
5 format(/'> Checking random get (',i5,' calls)...')
375
crap = drand(ga_nodeid()*51 +1) !Different seed for each proc
379
if (ihi.lt. ilo) then
386
if (jhi.lt. jlo) then
392
nwords = nwords + (ihi-ilo+1)*(jhi-jlo+1)
394
call ga_get(g_a, ilo, ihi, jlo, jhi, b(ilo, jlo), n)
395
if (me .eq. 0 .and. mod(loop-1, max(1,nloop/20)).eq.0) then
396
write(6,1) loop, me, ilo, ihi, jlo, jhi, nwords
397
1 format(' call ',i5, ' node ',i2,' checking get ',4i4,
403
if (b(i,j) .ne. a(i,j)) then
404
write(6,*)'error:', i, j, b(i,j), a(i,j)
405
call ga_error('... exiting ',0)
413
write(6,*) ' ga_get is OK'
419
c Check the ga_copy function
423
write(6,*)'> Checking copy'
429
if(me.eq.0) call ga_put(g_a, 1, n, 1, n, a, n)
431
if(iproc.eq.0) call ga_put(g_a, 1, n, 1, n, a, n)
433
call ga_copy(g_a, g_b)
434
call ga_get(g_b, 1, n, 1, n, b, n)
437
if (b(i,j) .ne. a(i,j)) then
438
write(6,*) ' copy ', me, i, j, a(i,j), b(i,j)
439
call ga_error('... exiting ',0)
445
write(6,*) ' copy is OK '
449
c Check scatter&gather
453
write(6,*) '> Checking scatter/gather (might be slow)... '
455
if(me.eq.0) call ga_put(g_a, 1, n, 1, n, a, n)
459
crap = drand(ga_nodeid()*51 +1) !Different seed for each proc
466
itmp = iran(lprocs)-1
467
if(iproc.eq.itmp) then
475
call ga_gather(g_a, v, iv, jv, m)
479
call ga_get(g_a,ilo,ilo,jlo,jlo,v(loop),1)
480
if(v(loop) .ne. a(ilo,jlo))then
481
write(6,*)me,' gather ', ilo,',',jlo,',', a(ilo,jlo)
484
call ga_error('... exiting ',0)
492
write(6,*) ' gather is OK'
500
if(me.eq.iran(ga_nnodes())-1) then
502
if(me.eq.iran(lprocs)-1) then
509
v(loop) = (1d0,-1d0) *(ilo+jlo)
511
call ga_scatter(g_a, v, iv, jv, m)
515
call ga_get(g_a,ilo,ilo,jlo,jlo,w(loop),1)
516
if(w(loop) .ne. (1d0,-1d0) *(ilo+jlo) )then
517
write(6,*)me,' scatter ', ilo,',',jlo,',',w(loop)
518
& ,' ', (1d0,-1d0) *(ilo+jlo)
528
write(6,*) ' scatter is OK'
532
c Delete the global arrays
535
status = ga_destroy(g_b)
536
status = ga_destroy(g_a)
538
istatus = nga_deregister_type(scpl_type)
541
c-----------------------------------------------------------------
543
subroutine check_complex()
545
#include "mafdecls.fh"
547
#include "testutil.fh"
552
double complex a(n,n), b(n,n), v(m),w(m)
554
integer ndim, dims(2), chunk(2), p_mirror
557
integer ndim, dims(2), chunk(2), p_mirror
563
integer iran, i,j, loop,nloop,maxloop, ilo, ihi, jlo, jhi, itmp
564
integer nproc, me, int, ij, inc, ii, jj, nnodes
565
parameter (maxloop = 100)
567
parameter (maxproc = 4096)
568
double precision crap, real
569
double precision nwords
570
double complex x, sum1, sum2, factor
571
integer lprocs, inode, iproc, lproc
572
integer dcpl_type, istatus
573
#ifdef USE_RESTRICTED
575
integer rstrctd_list(maxproc/2)
578
integer block_size(2), proc_grid(2)
581
iran(i) = int(drand(0)*real(i)) + 1
585
inode = ga_cluster_nodeid()
586
lprocs = ga_cluster_nprocs(inode)
587
nnodes = ga_cluster_nnodes()
588
iproc = mod(me,lprocs)
589
nloop = Min(maxloop,n)
590
#ifdef USE_RESTRICTED
591
num_rstrctd = nproc/2
592
if (num_rstrctd.eq.0) num_rstrctd = 1
593
do i = 1, num_rstrctd
594
rstrctd_list(i) = (num_rstrctd/2) + i-1
600
#ifdef USE_SCALAPACK_DISTR
601
if (mod(nproc,2).ne.0)
602
+ call ga_error("Available procs must be divisible by 2",0)
604
proc_grid(2) = nproc/2
608
c a() is a local copy of what the global array should start as
613
a(i,j) = cmplx(dble(i-1), dble((j-1)*n))
615
a(i,j) = cmplx(dble(inode),0.0d00)
616
+ + cmplx(dble(i-1), dble((j-1)*n))
618
b(i,j) = cmplx(-1d0,1d0)
624
dcpl_type = nga_register_type(16)
626
c Create a global array
628
c print *,ga_nodeid(), ' creating array'
635
g_a = ga_create_handle()
636
call ga_set_data(g_a,ndim,dims,dcpl_type)
637
call ga_set_array_name(g_a,'a')
638
#ifdef USE_RESTRICTED
639
call ga_set_restricted(g_a, rstrctd_list, num_rstrctd)
642
#ifdef USE_SCALAPACK_DISTR
643
call ga_set_block_cyclic_proc_grid(g_a,block_size,proc_grid)
645
call ga_set_block_cyclic(g_a,block_size)
649
p_mirror = ga_pgroup_get_mirror()
650
call ga_set_pgroup(g_a,p_mirror)
652
status = ga_allocate(g_a)
655
status = ga_create(dcpl_type, n, n, 'a', 0, 0, g_a)
662
p_mirror = ga_pgroup_get_mirror()
663
status = nga_create_config(dcpl_type, ndim, dims, 'a', chunk,
667
if (.not. status) then
668
write(6,*) ' ga_create failed'
669
call ga_error('... exiting ',0)
672
g_b = ga_create_handle()
673
call ga_set_data(g_b,ndim,dims,dcpl_type)
674
call ga_set_array_name(g_b,'b')
676
#ifdef USE_SCALAPACK_DISTR
677
call ga_set_block_cyclic_proc_grid(g_b,block_size,proc_grid)
679
call ga_set_block_cyclic(g_b,block_size)
683
call ga_set_pgroup(g_b,p_mirror)
685
if (.not.ga_allocate(g_b)) then
688
if (.not. ga_create(dcpl_type, n, n, 'b', 0, 0, g_b)) then
690
if (.not. nga_create_config(dcpl_type, ndim, dims, 'b', chunk,
691
_ p_mirror, g_b)) then
694
call ga_error('ga_create failed for second array ',0)
698
call ga_distribution(g_a,me,ilo, ihi, jlo, jhi)
700
lproc = me - ga_cluster_procid(inode,0)
701
call ga_distribution(g_a, lproc, ilo, ihi, jlo, jhi)
709
21 format('> Checking zero ... ')
714
c Check that it is indeed zero
716
call ga_get(g_a, 1, n, 1, n, b, n)
720
if(b(i,j).ne.(0d0,0d0)) then
721
write(6,*) me,' zero ', i, j, b(i,j)
723
c call ga_error('... exiting ',0)
729
write(6,*) ' ga_zero is OK'
734
c Each node fills in disjoint sections of the array
738
2 format('> Checking disjoint put ... ')
748
if (mod(ij,nproc) .eq. me) then
750
if (mod(ij,lprocs) .eq. iproc) then
756
call ga_put(g_a, ilo, ihi, jlo, jhi, a(ilo, jlo), n)
763
c All nodes check all of a
765
call util_qfill(n*n, (0d0,0d0), b, 1)
766
call ga_get(g_a, 1, n, 1, n, b, n)
770
if (b(i,j) .ne. a(i,j)) then
771
write(6,*) ' put ', me, i, j, a(i,j),b(i,j)
773
call ga_error('... exiting ',0)
779
write(6,*) ' ga_put is OK'
784
c Now check nloop random gets from each node
788
5 format('> Checking random get (',i5,' calls)...')
795
crap = drand(ga_nodeid()*51 +1) !Different seed for each proc
799
if (ihi.lt. ilo) then
806
if (jhi.lt. jlo) then
812
nwords = nwords + (ihi-ilo+1)*(jhi-jlo+1)
814
call util_qfill(n*n, (0.0d0,0d0), b, 1)
815
call ga_get(g_a, ilo, ihi, jlo, jhi, b(ilo, jlo), n)
816
if (me .eq. 0 .and. mod(loop-1, max(1,nloop/20)).eq.0) then
817
write(6,1) loop, me, ilo, ihi, jlo, jhi, nwords
818
1 format(' call ',i5, ' node ',i2,' checking get ',4i4,
824
if (b(i,j) .ne. a(i,j)) then
825
write(6,*)'error:', i, j, b(i,j), a(i,j)
826
call ga_error('... exiting ',0)
834
write(6,*) ' ga_get is OK'
840
c Check the ga_copy function
844
write(6,*)'> Checking copy'
850
if(me.eq.0) call ga_put(g_a, 1, n, 1, n, a, n)
852
if(iproc.eq.0) call ga_put(g_a, 1, n, 1, n, a, n)
854
call ga_copy(g_a, g_b)
855
call ga_get(g_b, 1, n, 1, n, b, n)
858
if (b(i,j) .ne. a(i,j)) then
859
write(6,*) ' copy ', me, i, j, a(i,j), b(i,j)
860
call ga_error('... exiting ',0)
866
write(6,*) ' copy is OK '
870
c Check scatter&gather
874
write(6,*) '> Checking scatter/gather (might be slow)... '
876
if(me.eq.0) call ga_put(g_a, 1, n, 1, n, a, n)
880
crap = drand(ga_nodeid()*51 +1) !Different seed for each proc
887
itmp = iran(lprocs)-1
888
if(iproc.eq.itmp) then
896
call ga_gather(g_a, v, iv, jv, m)
900
call ga_get(g_a,ilo,ilo,jlo,jlo,v(loop),1)
901
if(v(loop) .ne. a(ilo,jlo))then
902
write(6,*)me,' gather ', ilo,',',jlo,',', a(ilo,jlo)
905
call ga_error('... exiting ',0)
913
write(6,*) ' gather is OK'
921
if(me.eq.iran(ga_nnodes())-1) then
923
if(me.eq.iran(lprocs)-1) then
930
v(loop) = (1d0,-1d0) *(ilo+jlo)
932
call ga_scatter(g_a, v, iv, jv, m)
936
call ga_get(g_a,ilo,ilo,jlo,jlo,w(loop),1)
937
if(w(loop) .ne. (1d0,-1d0) *(ilo+jlo) )then
938
write(6,*)me,' scatter ', ilo,',',jlo,',',w(loop)
939
& ,' ', (1d0,-1d0) *(ilo+jlo)
949
write(6,*) ' scatter is OK'
953
c Delete the global arrays
955
status = ga_destroy(g_b)
956
status = ga_destroy(g_a)
958
istatus = nga_deregister_type(dcpl_type)
962
subroutine util_qfill(n,val,a,ia)
964
double complex a(*), val
967
c initialise double complex array to scalar value
974
do 20 i = 1,(n-1)*ia+1,ia