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()
124
c*** Check support for double precision complex arrays
128
write(6,*) ' CHECKING DOUBLE COMPLEX '
135
if(me.eq.0) call ga_print_stats()
136
if(me.eq.0) print *,' '
137
if(me.eq.0) print *,'All tests successful '
138
status = ga_destroy(g_s)
140
c*** Tidy up the GA package
144
c*** Tidy up after message-passing library
153
subroutine check_complex_float()
155
#include "mafdecls.fh"
157
#include "testutil.fh"
162
real areal(n,n),aimg(n,n)
163
real breal(n,n),bimg(n,n)
165
integer ndim, dims(2), chunk(2), p_mirror
168
integer ndim, dims(2), chunk(2), p_mirror
174
integer iran, i,j, loop,nloop,maxloop, ilo, ihi, jlo, jhi, itmp
175
integer nproc, me, int, ij, inc, ii, jj, nnodes
176
parameter (maxloop = 100)
178
parameter (maxproc = 4096)
179
double precision crap, real
180
double precision nwords
181
complex x, sum1, sum2, factor
182
integer lprocs, inode, iproc, lproc
184
#ifdef USE_RESTRICTED
186
integer rstrctd_list(maxproc/2)
189
iran(i) = int(drand(0)*real(i)) + 1
193
inode = ga_cluster_nodeid()
194
lprocs = ga_cluster_nprocs(inode)
195
nnodes = ga_cluster_nnodes()
196
iproc = mod(me,lprocs)
197
nloop = Min(maxloop,n)
198
#ifdef USE_RESTRICTED
199
num_rstrctd = nproc/2
200
if (num_rstrctd.eq.0) num_rstrctd = 1
201
do i = 1, num_rstrctd
202
rstrctd_list(i) = (num_rstrctd/2) + i-1
206
c a() is a local copy of what the global array should start as
211
areal(i,j) = real(i-1)
212
aimg(i,j) = real((j-1)*n)
214
areal(i,j) = real(inode) + real(i-1)
215
aimg(i,j) = 0.0d00 + real((j-1)*n)
222
c Create a global array
224
c print *,ga_nodeid(), ' creating array'
231
g_a = ga_create_handle()
232
call ga_set_data(g_a,ndim,dims,MT_SCPL)
233
call ga_set_array_name(g_a,'a')
234
#ifdef USE_RESTRICTED
235
call ga_set_restricted(g_a, rstrctd_list, num_rstrctd)
238
p_mirror = ga_pgroup_get_mirror()
239
call ga_set_pgroup(g_a,p_mirror)
241
status = ga_allocate(g_a)
244
status = ga_create(MT_SCPL, n, n, 'a', 0, 0, g_a)
251
p_mirror = ga_pgroup_get_mirror()
252
status = nga_create_config(MT_SCPL, ndim, dims, 'a', chunk,
256
if (.not. status) then
257
write(6,*) ' ga_create failed'
258
call ga_error('... exiting ',0)
261
g_b = ga_create_handle()
262
call ga_set_data(g_b,ndim,dims,MT_SCPL)
263
call ga_set_array_name(g_b,'b')
265
call ga_set_pgroup(g_b,p_mirror)
267
if (.not.ga_allocate(g_b)) then
270
if (.not. ga_create(MT_SCPL, n, n, 'b', 0, 0, g_b)) then
272
if (.not. nga_create_config(MT_SCPL, ndim, dims, 'b', chunk,
273
_ p_mirror, g_b)) then
276
call ga_error('ga_create failed for second array ',0)
280
call ga_distribution(g_a,me,ilo, ihi, jlo, jhi)
282
lproc = me - ga_cluster_procid(inode,0)
283
call ga_distribution(g_a, lproc, ilo, ihi, jlo, jhi)
291
21 format(/'> Checking zero ... ')
297
c Check that it is indeed zero
303
call nga_get_field(g_a, lo, hi, 0, 4, breal, n)
304
call nga_get_field(g_a, lo, hi, 4, 4, bimg, n)
308
if(breal(i,j).ne.0d0) then
309
write(6,*) me,' real zero ', i, j, breal(i,j)
311
c call ga_error('... exiting ',0)
313
if(bimg(i,j).ne.0d0) then
314
write(6,*) me,' img zero ', i, j, bimg(i,j)
316
c call ga_error('... exiting ',0)
322
write(6,*) ' ga_zero is OK'
327
c Each node fills in disjoint sections of the array
331
2 format(/'> Checking disjoint put ... ')
341
if (mod(ij,nproc) .eq. me) then
343
if (mod(ij,lprocs) .eq. iproc) then
349
c call ga_put(g_a, ilo, ihi, jlo, jhi, a(ilo, jlo), n)
354
call nga_put_field(g_a, lo, hi, 0, 4, areal(ilo, jlo), n)
355
call nga_put_field(g_a, lo, hi, 4, 4, aimg(ilo, jlo), n)
362
c All nodes check all of a
364
c call ga_get(g_a, 1, n, 1, n, b, n)
369
call nga_get_field(g_a, lo, hi, 0, 4, breal, n)
370
call nga_get_field(g_a, lo, hi, 4, 4, bimg, n)
374
if (breal(i,j) .ne. areal(i,j)) then
375
write(6,*) ' put(real) ', me, i, j, areal(i,j),breal(i,j)
377
c call ga_error('... exiting ',0)
379
if (bimg(i,j) .ne. aimg(i,j)) then
380
write(6,*) ' put(img) ', me, i, j, aimg(i,j),bimg(i,j)
382
c call ga_error('... exiting ',0)
388
write(6,*) ' ga_put is OK'
393
c Now check nloop random gets from each node
397
5 format(/'> Checking random get (',i5,' calls)...')
404
crap = drand(ga_nodeid()*51 +1) !Different seed for each proc
408
if (ihi.lt. ilo) then
415
if (jhi.lt. jlo) then
421
nwords = nwords + (ihi-ilo+1)*(jhi-jlo+1)
423
c call ga_get(g_a, ilo, ihi, jlo, jhi, b(ilo, jlo), n)
428
call nga_get_field(g_a, lo, hi, 0, 4, breal(ilo, jlo), n)
429
call nga_get_field(g_a, lo, hi, 4, 4, bimg(ilo, jlo), n)
430
if (me .eq. 0 .and. mod(loop-1, max(1,nloop/20)).eq.0) then
431
write(6,1) loop, me, ilo, ihi, jlo, jhi, nwords
432
1 format(' call ',i5, ' node ',i2,' checking get ',4i4,
438
if (breal(i,j) .ne. areal(i,j)) then
439
write(6,*)'error:', i, j, breal(i,j), areal(i,j)
440
call ga_error('... exiting ',0)
442
if (bimg(i,j) .ne. aimg(i,j)) then
443
write(6,*)'error:', i, j, bimg(i,j), aimg(i,j)
444
call ga_error('... exiting ',0)
452
write(6,*) ' ga_get is OK'
458
c Check the ga_copy function
462
write(6,*)'> Checking copy'
469
c call ga_put(g_a, 1, n, 1, n, a, n)
474
call nga_put_field(g_a, lo, hi, 0, 4, areal, n)
475
call nga_put_field(g_a, lo, hi, 4, 4, aimg, n)
479
c call ga_put(g_a, 1, n, 1, n, a, n)
484
call nga_put_field(g_a, lo, hi, 0, 4, areal, n)
485
call nga_put_field(g_a, lo, hi, 4, 4, aimg, n)
488
call ga_copy(g_a, g_b)
489
c call ga_get(g_b, 1, n, 1, n, b, n)
494
call nga_get_field(g_b, lo, hi, 0, 4, breal, n)
495
call nga_get_field(g_b, lo, hi, 4, 4, bimg, n)
498
if (breal(i,j) .ne. areal(i,j)) then
499
write(6,*) ' copy ', me, i, j, areal(i,j), breal(i,j)
500
call ga_error('... exiting ',0)
502
if (bimg(i,j) .ne. aimg(i,j)) then
503
write(6,*) ' copy ', me, i, j, aimg(i,j), bimg(i,j)
504
call ga_error('... exiting ',0)
510
write(6,*) ' copy is OK '
514
c Delete the global arrays
517
status = ga_destroy(g_b)
518
status = ga_destroy(g_a)
521
c-----------------------------------------------------------------
523
subroutine check_complex()
525
#include "mafdecls.fh"
527
#include "testutil.fh"
532
double precision areal(n,n), breal(n,n)
533
double precision aimg(n,n), bimg(n,n)
535
integer ndim, dims(2), chunk(2), p_mirror
538
integer ndim, dims(2), chunk(2), p_mirror
544
integer iran, i,j, loop,nloop,maxloop, ilo, ihi, jlo, jhi, itmp
545
integer nproc, me, int, ij, inc, ii, jj, nnodes
546
parameter (maxloop = 100)
548
parameter (maxproc = 4096)
549
double precision crap, real
550
double precision nwords
551
double complex x, sum1, sum2, factor
553
integer lprocs, inode, iproc, lproc
554
#ifdef USE_RESTRICTED
556
integer rstrctd_list(maxproc/2)
559
integer block_size(2), proc_grid(2)
562
iran(i) = int(drand(0)*real(i)) + 1
566
inode = ga_cluster_nodeid()
567
lprocs = ga_cluster_nprocs(inode)
568
nnodes = ga_cluster_nnodes()
569
iproc = mod(me,lprocs)
570
nloop = Min(maxloop,n)
571
#ifdef USE_RESTRICTED
572
num_rstrctd = nproc/2
573
if (num_rstrctd.eq.0) num_rstrctd = 1
574
do i = 1, num_rstrctd
575
rstrctd_list(i) = (num_rstrctd/2) + i-1
581
#ifdef USE_SCALAPACK_DISTR
582
if (mod(nproc,2).ne.0)
583
+ call ga_error("Available procs must be divisible by 2",0)
585
proc_grid(2) = nproc/2
589
c a() is a local copy of what the global array should start as
594
areal(i,j) = dble(i-1)
595
aimg(i,j) = dble((j-1)*n)
597
areal(i,j) = dble(inode) + dble(i-1)
598
aimg(i,j) = 0.0d00 + dble((j-1)*n)
608
c Create a global array
610
c print *,ga_nodeid(), ' creating array'
617
g_a = ga_create_handle()
618
call ga_set_data(g_a,ndim,dims,MT_DCPL)
619
call ga_set_array_name(g_a,'a')
620
#ifdef USE_RESTRICTED
621
call ga_set_restricted(g_a, rstrctd_list, num_rstrctd)
624
#ifdef USE_SCALAPACK_DISTR
625
call ga_set_block_cyclic_proc_grid(g_a,block_size,proc_grid)
627
call ga_set_block_cyclic(g_a,block_size)
631
p_mirror = ga_pgroup_get_mirror()
632
call ga_set_pgroup(g_a,p_mirror)
634
status = ga_allocate(g_a)
637
status = ga_create(MT_DCPL, n, n, 'a', 0, 0, g_a)
644
p_mirror = ga_pgroup_get_mirror()
645
status = nga_create_config(MT_DCPL, ndim, dims, 'a', chunk,
649
if (.not. status) then
650
write(6,*) ' ga_create failed'
651
call ga_error('... exiting ',0)
654
g_b = ga_create_handle()
655
call ga_set_data(g_b,ndim,dims,MT_DCPL)
656
call ga_set_array_name(g_b,'b')
658
#ifdef USE_SCALAPACK_DISTR
659
call ga_set_block_cyclic_proc_grid(g_b,block_size,proc_grid)
661
call ga_set_block_cyclic(g_b,block_size)
665
call ga_set_pgroup(g_b,p_mirror)
667
if (.not.ga_allocate(g_b)) then
670
if (.not. ga_create(MT_DCPL, n, n, 'b', 0, 0, g_b)) then
672
if (.not. nga_create_config(MT_DCPL, ndim, dims, 'b', chunk,
673
_ p_mirror, g_b)) then
676
call ga_error('ga_create failed for second array ',0)
680
call ga_distribution(g_a,me,ilo, ihi, jlo, jhi)
682
lproc = me - ga_cluster_procid(inode,0)
683
call ga_distribution(g_a, lproc, ilo, ihi, jlo, jhi)
691
21 format('> Checking zero ... ')
696
c Check that it is indeed zero
698
c call ga_get(g_a, 1, n, 1, n, b, n)
703
call nga_get_field(g_a, lo, hi, 0, 8, breal, n)
704
call nga_get_field(g_a, lo, hi, 8, 8, bimg, n)
708
if(breal(i,j).ne.(0d0,0d0)) then
709
write(6,*) me,' real zero ', i, j, breal(i,j)
711
call ga_error('... exiting ',0)
713
if(bimg(i,j).ne.(0d0,0d0)) then
714
write(6,*) me,' img zero ', i, j, bimg(i,j)
716
call ga_error('... exiting ',0)
722
write(6,*) ' ga_zero is OK'
727
c Each node fills in disjoint sections of the array
731
2 format('> Checking disjoint put ... ')
741
if (mod(ij,nproc) .eq. me) then
743
if (mod(ij,lprocs) .eq. iproc) then
749
c call ga_put(g_a, ilo, ihi, jlo, jhi, a(ilo, jlo), n)
754
call nga_put_field(g_a, lo, hi, 0, 8, areal(ilo,jlo),n)
755
call nga_put_field(g_a, lo, hi, 8, 8, aimg(ilo,jlo),n)
763
c All nodes check all of a
765
call util_qfill(n*n, 0.0d0, breal, 1)
766
call util_qfill(n*n, 0d0, bimg, 1)
767
c call ga_get(g_a, 1, n, 1, n, b, n)
772
call nga_get_field(g_a, lo, hi, 0, 8, breal, n)
773
call nga_get_field(g_a, lo, hi, 8, 8, bimg, n)
777
if (breal(i,j) .ne. areal(i,j)) then
778
write(6,*) ' real put ', me, i, j, areal(i,j),breal(i,j)
780
call ga_error('... exiting ',0)
782
if (bimg(i,j) .ne. aimg(i,j)) then
783
write(6,*) ' img put ', me, i, j, aimg(i,j),bimg(i,j)
785
call ga_error('... exiting ',0)
791
write(6,*) ' ga_put is OK'
796
c Now check nloop random gets from each node
800
5 format('> Checking random get (',i5,' calls)...')
807
crap = drand(ga_nodeid()*51 +1) !Different seed for each proc
811
if (ihi.lt. ilo) then
818
if (jhi.lt. jlo) then
824
nwords = nwords + (ihi-ilo+1)*(jhi-jlo+1)
826
call util_qfill(n*n, 0.0d0, breal, 1)
827
call util_qfill(n*n, 0d0, bimg, 1)
828
c call ga_get(g_a, ilo, ihi, jlo, jhi, b(ilo, jlo), n)
833
call nga_get_field(g_a, lo, hi, 0, 8, breal(ilo,jlo),n)
834
call nga_get_field(g_a, lo, hi, 8, 8, bimg(ilo,jlo),n)
835
if (me .eq. 0 .and. mod(loop-1, max(1,nloop/20)).eq.0) then
836
write(6,1) loop, me, ilo, ihi, jlo, jhi, nwords
837
1 format(' call ',i5, ' node ',i2,' checking get ',4i4,
843
if (breal(i,j) .ne. areal(i,j)) then
844
write(6,*)'real error:', i, j, breal(i,j), areal(i,j)
845
call ga_error('... exiting ',0)
847
if (bimg(i,j) .ne. aimg(i,j)) then
848
write(6,*)'img error:', i, j, bimg(i,j), aimg(i,j)
849
call ga_error('... exiting ',0)
857
write(6,*) ' ga_get is OK'
863
c Check the ga_copy function
867
write(6,*)'> Checking copy'
874
c call ga_put(g_a, 1, n, 1, n, a, n)
879
call nga_put_field(g_a, lo, hi, 0, 8, areal, n)
880
call nga_put_field(g_a, lo, hi, 8, 8, aimg, n)
884
c call ga_put(g_a, 1, n, 1, n, a, n)
889
call nga_put_field(g_a, lo, hi, 0, 8, areal, n)
890
call nga_put_field(g_a, lo, hi, 8, 8, aimg, n)
893
call ga_copy(g_a, g_b)
894
c call ga_get(g_b, 1, n, 1, n, b, n)
899
call nga_get_field(g_b, lo, hi, 0, 8, breal, n)
900
call nga_get_field(g_b, lo, hi, 8, 8, bimg, n)
903
if (breal(i,j) .ne. areal(i,j)) then
904
write(6,*) ' copy ', me, i, j, areal(i,j), breal(i,j)
905
call ga_error('... exiting ',0)
907
if (bimg(i,j) .ne. aimg(i,j)) then
908
write(6,*) ' copy ', me, i, j, aimg(i,j), bimg(i,j)
909
call ga_error('... exiting ',0)
915
write(6,*) ' copy is OK '
919
c Delete the global arrays
921
status = ga_destroy(g_b)
922
status = ga_destroy(g_a)
926
subroutine util_qfill(n,val,a,ia)
928
double precision a(*), val
931
c initialise double complex array to scalar value
938
do 20 i = 1,(n-1)*ia+1,ia