1
subroutine m4_func_NGA_ADD_PATCH(m4_test_type, m4_ndim)
9
parameter (m = (m4_n**m4_ndim)/100)
10
parameter (ndim = m4_ndim)
11
m4_data_type a(substr(m4_array, 1, eval(m4_ndim*2-1)))
12
m4_data_type b(substr(m4_array, 1, eval(m4_ndim*2-1)))
17
integer elems, count_elems
19
double precision util_drand
20
m4_data_type alpha, beta
21
integer lop(ndim), hip(ndim), hipl(ndim)
22
integer alo(ndim), ahi(ndim)
23
integer blo(ndim), bhi(ndim)
24
integer clo(ndim), chi(ndim)
25
c for different array dimensions
27
m4_data_type d(substr(m4_array, 1, eval((m4_ndim-1)*2-1)))
29
parameter (dndim = m4_ndim-1)
30
integer ddims(dndim),dlo(dndim),dhi(dndim),dtotal
40
c---------------------- initialize the GA -----------------------
41
c initialize the chunk, dims, ld, and calculate the number
47
total = total * dims(i)
50
c*** Create global arrays
51
if (.not. nga_create(m4_MT, ndim, dims, 'a', chunk, g_a))
52
$ call ga_error(' ga_create failed ',1)
54
c test the same distribution and different distribution seperately
57
status = ga_duplicate(g_a, g_b, 'a_duplicated')
58
if(.not.ga_compare_distr(g_a, g_b))
59
$ call ga_error("g_b distribution different",0)
61
status = ga_duplicate(g_a, g_c, 'a_duplicated_again')
62
if(.not.ga_compare_distr(g_a, g_c))
63
$ call ga_error("g_c distribution different",0)
67
if(mod(i,2).eq.0) chunk(i) = n
69
if (.not. nga_create(m4_MT, ndim, dims, 'b', chunk, g_b))
70
$ call ga_error(' ga_create failed ',1)
72
if(mod(i,2).eq.0) chunk(i) = 0
73
if(mod(i,2).eq.1) chunk(i) = n
75
if (.not. nga_create(m4_MT, ndim, dims, 'c', chunk, g_c))
76
$ call ga_error(' ga_create failed ',1)
81
c---------------------------NGA_ADD_PATCH -------------------------
84
m4_print_info(nga_add_patch)
85
if(me.eq.0) print *, 'Testing with the same distributions'
87
if(me.eq.0) print *, 'Testing with different distributions'
91
call m4_util_init_array(m4_test_type)(a,total)
92
call nga_distribution(g_a, me, lop, hip)
93
elems = count_elems(lop, hip, ndim)
94
if(elems.gt.0) call nga_put(g_a,lop,hip,
95
$ a(substr(m4_lop_all, 1, eval(m4_ndim*7-1))),dims)
96
call m4_util_init_array(m4_test_type)(b,total)
97
call nga_distribution(g_b, me, lop, hip)
98
elems = count_elems(lop, hip, ndim)
99
if(elems.gt.0) call nga_put(g_b,lop,hip,
100
$ b(substr(m4_lop_all, 1, eval(m4_ndim*7-1))),dims)
111
call random_range(lop,hipl,alo,ahi,ndim)
119
call add_range(loop,alo,ahi,ndim,blo,bhi,ndim)
120
c$$$ print *, loop,': [',(alo(i),':',ahi(i), i=1,ndim),']',
121
c$$$ $ '+', '[',(blo(i),':',bhi(i), i=1,ndim),']'
127
c keep copies of the origian arrays
128
call nga_get(g_a,alo,ahi,
129
$ a(substr(m4_alo_all, 1, eval(m4_ndim*7-1))),dims)
130
call nga_get(g_b,blo,bhi,
131
$ b(substr(m4_blo_all, 1, eval(m4_ndim*7-1))),dims)
132
c the result should be (in a)
133
call m4_util_scale_patch(m4_test_type)(total,
134
$ alpha,a,alo,ahi,ndim,dims,
135
$ beta,b,blo,bhi,ndim,dims)
137
call nga_add_patch(alpha, g_a, alo, ahi, beta, g_b, blo, bhi,
140
call nga_get(g_c,clo,chi,
141
$ b(substr(m4_clo_all, 1, eval(m4_ndim*7-1))),dims)
143
call m4_util_compare_patches(m4_test_type)(1d-5,total,
144
$ a,alo,ahi,ndim,dims,total,b,clo,chi,ndim,dims)
153
c---------------------------
155
status = ga_destroy(g_b)
157
c-----------------------------------------------------------------
159
ifelse(m4_ndim,1,{},{
160
c testing copy on differet dimensions
164
dtotal = dtotal * ddims(i)
167
if (.not. nga_create(m4_MT, dndim, ddims, 'd', chunk, g_b))
168
$ call ga_error(' ga_create failed ',1)
171
$ print *, 'Testing adding patch on different dimensions'
176
call m4_util_init_array(m4_test_type)(d,dtotal)
177
call nga_distribution(g_b, me, dlo, dhi)
178
elems = count_elems(dlo, dhi, dndim)
179
if(elems.gt.0) call nga_put(g_b,dlo,dhi,
180
$ d(substr(m4_dlo_all, 1, eval((m4_ndim-1)*7-1))),ddims)
182
c calculate the maximum range of g_a that can fit into g_b
192
call random_range(lop,hip,alo,ahi,ndim)
195
dlo(i) = alo(dndim-i+1)
196
dhi(i) = ahi(dndim-i+1)
202
call add_range(loop,alo,ahi,ndim,dlo,dhi,dndim)
203
c$$$ print *, loop,': [',(alo(i),':',ahi(i), i=1,ndim),']',
204
c$$$ $ '+', '[',(dlo(i),':',dhi(i), i=1,dndim),']'
210
c keep copies of the origian arrays
211
call nga_get(g_a,alo,ahi,
212
$ a(substr(m4_alo_all, 1, eval(m4_ndim*7-1))),dims)
213
call nga_get(g_b,dlo,dhi,
214
$ d(substr(m4_dlo_all, 1, eval((m4_ndim-1)*7-1))),ddims)
216
c the result should be (in a)
217
call m4_util_scale_patch(m4_test_type)(total,
218
$ alpha,a,alo,ahi,ndim,dims,
219
$ beta,d,dlo,dhi,dndim,ddims)
221
call nga_add_patch(alpha,g_a,alo,ahi,beta,g_b,dlo,dhi,
224
call nga_get(g_c,alo,ahi,
225
$ b(substr(m4_alo_all, 1, eval(m4_ndim*7-1))),dims)
227
call m4_util_compare_patches(m4_test_type)(1d-5,total,
228
$ a,alo,ahi,ndim,dims,total,b,alo,ahi,ndim,dims)
233
print *, ' add patches on different dimensions: OK'
238
status = ga_destroy(g_b)
243
status = ga_destroy(g_c)
244
status = ga_destroy(g_a)