summaryrefslogtreecommitdiff
path: root/gcc/testsuite/gfortran.dg/coarray_36.f
blob: d06a01ec6bc04ad2cdf94d61c039d980f62b78b8 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
! { dg-do compile }
! { dg-options "-fcoarray=lib" }
!
! PR fortran/64771
!
! Contributed by Alessandro Fanfarill
!
! Reduced version of the full NAS CG benchmark
!

!-------------------------------------------------------------------------!
!                                                                         !
!        N  A  S     P A R A L L E L     B E N C H M A R K S  3.3         !
!                                                                         !
!                                   C G                                   !
!                                                                         !
!-------------------------------------------------------------------------!
!                                                                         !
!    This benchmark is part of the NAS Parallel Benchmark 3.3 suite.      !
!    It is described in NAS Technical Reports 95-020 and 02-007           !
!                                                                         !
!    Permission to use, copy, distribute and modify this software         !
!    for any purpose with or without fee is hereby granted.  We           !
!    request, however, that all derived work reference the NAS            !
!    Parallel Benchmarks 3.3. This software is provided "as is"           !
!    without express or implied warranty.                                 !
!                                                                         !
!    Information on NPB 3.3, including the technical report, the          !
!    original specifications, source code, results and information        !
!    on how to submit new results, is available at:                       !
!                                                                         !
!           http://www.nas.nasa.gov/Software/NPB/                         !
!                                                                         !
!    Send comments or suggestions to  npb@nas.nasa.gov                    !
!                                                                         !
!          NAS Parallel Benchmarks Group                                  !
!          NASA Ames Research Center                                      !
!          Mail Stop: T27A-1                                              !
!          Moffett Field, CA   94035-1000                                 !
!                                                                         !
!          E-mail:  npb@nas.nasa.gov                                      !
!          Fax:     (650) 604-3957                                        !
!                                                                         !
!-------------------------------------------------------------------------!


c---------------------------------------------------------------------
c
c Authors: M. Yarrow
c          C. Kuszmaul
c          R. F. Van der Wijngaart
c          H. Jin
c
c---------------------------------------------------------------------


c---------------------------------------------------------------------
c---------------------------------------------------------------------
      program cg
c---------------------------------------------------------------------
c---------------------------------------------------------------------
      implicit none

      integer            na, nonzer, niter
      double precision   shift, rcond
      parameter(  na=75000,
     >     nonzer=13,
     >     niter=75,
     >     shift=60.,
     >     rcond=1.0d-1 )



      integer num_proc_rows, num_proc_cols
      parameter( num_proc_rows = 2, num_proc_cols = 2)
      integer    num_procs
      parameter( num_procs = num_proc_cols * num_proc_rows )

      integer    nz
      parameter( nz = na*(nonzer+1)/num_procs*(nonzer+1)+nonzer
     >              + na*(nonzer+2+num_procs/256)/num_proc_cols )

      common / partit_size  /  naa, nzz,
     >                         npcols, nprows,
     >                         proc_col, proc_row,
     >                         firstrow,
     >                         lastrow,
     >                         firstcol,
     >                         lastcol,
     >                         exch_proc,
     >                         exch_recv_length,
     >                         send_start,
     >                         send_len
      integer                  naa, nzz,
     >                         npcols, nprows,
     >                         proc_col, proc_row,
     >                         firstrow,
     >                         lastrow,
     >                         firstcol,
     >                         lastcol,
     >                         exch_proc,
     >                         exch_recv_length,
     >                         send_start,
     >                         send_len


      common / main_int_mem /  colidx,     rowstr,
     >                         iv,         arow,     acol
      integer                  colidx(nz), rowstr(na+1),
     >                         iv(2*na+1), arow(nz), acol(nz)


c---------------------------------
c     Coarray Decalarations
c---------------------------------
      double precision         v(na+1)[0:*], aelt(nz)[0:*], a(nz)[0:*],
     >                         x(na/num_proc_rows+2)[0:*],
     >                         z(na/num_proc_rows+2)[0:*],
     >                         p(na/num_proc_rows+2)[0:*],
     >                         q(na/num_proc_rows+2)[0:*],
     >                         r(na/num_proc_rows+2)[0:*],
     >                         w(na/num_proc_rows+2)[0:*]


      common /urando/          amult, tran
      double precision         amult, tran



      integer            l2npcols
      integer            reduce_exch_proc(num_proc_cols)
      integer            reduce_send_starts(num_proc_cols)
      integer            reduce_send_lengths(num_proc_cols)
      integer            reduce_recv_lengths(num_proc_cols)
      integer            reduce_rrecv_starts(num_proc_cols)
c---------------------------------
c     Coarray Decalarations
c---------------------------------
      integer            reduce_recv_starts(num_proc_cols)[0:*]

      integer            i, j, k, it, me, nprocs, root

      double precision   zeta, randlc
      external           randlc
      double precision   rnorm
c---------------------------------
c     Coarray Decalarations
c---------------------------------
      double precision   norm_temp1(2)[0:*], norm_temp2(2)[0:*]

      double precision   t, tmax, mflops
      double precision   u(1), umax(1)
      external           timer_read
      double precision   timer_read
      character          class
      logical            verified
      double precision   zeta_verify_value, epsilon, err

c---------------------------------------------------------------------
c  Explicit interface for conj_grad, due to coarray args
c---------------------------------------------------------------------
      interface

      subroutine conj_grad ( colidx,
     >                       rowstr,
     >                       x,
     >                       z,
     >                       a,
     >                       p,
     >                       q,
     >                       r,
     >                       w,
     >                       rnorm,
     >                       l2npcols,
     >                       reduce_exch_proc,
     >                       reduce_send_starts,
     >                       reduce_send_lengths,
     >                       reduce_recv_starts,
     >                       reduce_recv_lengths,
     >                       reduce_rrecv_starts )

      common / partit_size  /  naa, nzz,
     >                         npcols, nprows,
     >                         proc_col, proc_row,
     >                         firstrow,
     >                         lastrow,
     >                         firstcol,
     >                         lastcol,
     >                         exch_proc,
     >                         exch_recv_length,
     >                         send_start,
     >                         send_len

      integer                  naa, nzz,
     >                         npcols, nprows,
     >                         proc_col, proc_row,
     >                         firstrow,
     >                         lastrow,
     >                         firstcol,
     >                         lastcol,
     >                         exch_proc,
     >                         exch_recv_length,
     >                         send_start,
     >                         send_len

      double precision   x(*),
     >                   z(*),
     >                   a(nzz)
      integer            colidx(nzz), rowstr(naa+1)

      double precision   p(*),
     >                   q(*)[0:*],
     >                   r(*)[0:*],
     >                   w(*)[0:*]        ! used as work temporary

      integer   l2npcols
      integer   reduce_exch_proc(l2npcols)
      integer   reduce_send_starts(l2npcols)
      integer   reduce_send_lengths(l2npcols)
      integer   reduce_recv_starts(l2npcols)[0:*]
      integer   reduce_recv_lengths(l2npcols)
      integer   reduce_rrecv_starts(l2npcols)

      double precision   rnorm

      end subroutine

      end interface

c---------------------------------------------------------------------
c  The call to the conjugate gradient routine:
c---------------------------------------------------------------------
         call conj_grad ( colidx,
     >                    rowstr,
     >                    x,
     >                    z,
     >                    a,
     >                    p,
     >                    q,
     >                    r,
     >                    w,
     >                    rnorm,
     >                    l2npcols,
     >                    reduce_exch_proc,
     >                    reduce_send_starts,
     >                    reduce_send_lengths,
     >                    reduce_recv_starts,
     >                    reduce_recv_lengths,
     >                    reduce_rrecv_starts ) 


      sync all

      end                              ! end main

c---------------------------------------------------------------------
c---------------------------------------------------------------------
      subroutine conj_grad ( colidx,
     >                       rowstr,
     >                       x,
     >                       z,
     >                       a,
     >                       p,
     >                       q,
     >                       r,
     >                       w,
     >                       rnorm,
     >                       l2npcols,
     >                       reduce_exch_proc,
     >                       reduce_send_starts,
     >                       reduce_send_lengths,
     >                       reduce_recv_starts,
     >                       reduce_recv_lengths,
     >                       reduce_rrecv_starts )
c---------------------------------------------------------------------
c---------------------------------------------------------------------

c---------------------------------------------------------------------
c  Floaging point arrays here are named as in NPB1 spec discussion of
c  CG algorithm
c---------------------------------------------------------------------

      implicit none

c      include 'cafnpb.h'

      common / partit_size  /  naa, nzz,
     >                         npcols, nprows,
     >                         proc_col, proc_row,
     >                         firstrow,
     >                         lastrow,
     >                         firstcol,
     >                         lastcol,
     >                         exch_proc,
     >                         exch_recv_length,
     >                         send_start,
     >                         send_len
      integer                  naa, nzz,
     >                         npcols, nprows,
     >                         proc_col, proc_row,
     >                         firstrow,
     >                         lastrow,
     >                         firstcol,
     >                         lastcol,
     >                         exch_proc,
     >                         exch_recv_length,
     >                         send_start,
     >                         send_len



      double precision   x(*),
     >                   z(*),
     >                   a(nzz)
      integer            colidx(nzz), rowstr(naa+1)

      double precision   p(*),
     >                   q(*)[0:*],
     >                   r(*)[0:*],
     >                   w(*)[0:*]        ! used as work temporary

      integer   l2npcols
      integer   reduce_exch_proc(l2npcols)
      integer   reduce_send_starts(l2npcols)
      integer   reduce_send_lengths(l2npcols)
      integer   reduce_recv_starts(l2npcols)[0:*]
      integer   reduce_recv_lengths(l2npcols)
      integer   reduce_rrecv_starts(l2npcols)

      integer   recv_start_idx, recv_end_idx, send_start_idx,
     >          send_end_idx, recv_length

      integer   i, j, k, ierr
      integer   cgit, cgitmax

      double precision, save :: d[0:*], rho[0:*]
      double precision   sum, rho0, alpha, beta, rnorm

      external         timer_read
      double precision timer_read

      data      cgitmax / 25 /


      return
      end                       ! end of routine conj_grad