File: update.F

package info (click to toggle)
ga 5.9.2-2
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 18,472 kB
  • sloc: ansic: 192,963; fortran: 53,761; f90: 11,218; cpp: 5,784; makefile: 2,248; sh: 1,945; python: 1,734; perl: 534; csh: 134; asm: 106
file content (584 lines) | stat: -rw-r--r-- 17,061 bytes parent folder | download | duplicates (10)
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
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
#if HAVE_CONFIG_H
#   include "config.fh"
#endif
      subroutine update
#include "common.fh"
c
      double precision xmax,ymax,zmax,xmin,ymin,zmin
      double precision xcell,ycell,zcell
      double precision tbeg,wraptime
      integer snode,rnode,pnum,inode,idx,idy,idz,ipx,ipy,ipz
      integer icnt,i,j,k,inx,iny,inz
c
c   This subroutine gathers coordinates of particles that have moved off
c   the processor and sends then to neighboring processors. It also recieves
c   the coordinates of particles that have moved onto the processor.
c
      tbeg = wraptime()
      call clear_hash
      pnum = ga_nnodes()
      call factor(pnum,idx,idy,idz)
      inode = ga_nodeid()
      call i_proc_to_xyz(inode,ipx,ipy,ipz,idx,idy,idz)
c
c   determine local boundaries
c
      xmax = xbox*dble(ipx+1)/dble(idx)
      ymax = ybox*dble(ipy+1)/dble(idy)
      zmax = zbox*dble(ipz+1)/dble(idz)
      xmin = xbox*dble(ipx)/dble(idx)
      ymin = ybox*dble(ipy)/dble(idy)
      zmin = zbox*dble(ipz)/dble(idz)
      xmax = xmax - xbox2
      ymax = ymax - ybox2
      zmax = zmax - zbox2
      xmin = xmin - xbox2
      ymin = ymin - ybox2
      zmin = zmin - zbox2
      xcell = xbox/dble(idx)
      ycell = ybox/dble(idy)
      zcell = zbox/dble(idz)
c
      btot = 0
c
c    Send particles along x-axis. Gather all particles that lie within
c    processor domain
c
      if (idx.ge.2) then
c
c    collect all particles that have moved off of processor
c
        if (idx.eq.2) then
c
c    both boundaries are adjacent to boundaries on next processor
c
          icnt = 0
          do i = 1, antot
            if (ra(i,1,1).ge.xmax.or.ra(i,1,1).lt.xmin) then
              btot = btot + 1
              xcrd(btot) = ra(i,1,6)
              ycrd(btot) = ra(i,2,6)
              zcrd(btot) = ra(i,3,6)
              xfrc(btot) = ra(i,1,2)
              yfrc(btot) = ra(i,2,2)
              zfrc(btot) = ra(i,3,2)
              xacc(btot) = ra(i,1,3)
              yacc(btot) = ra(i,2,3)
              zacc(btot) = ra(i,3,3)
              bat(btot) = at(i)    
              mbuf(btot) = mass(i)
              bidx(btot) = aidx(i)
            else
              icnt = icnt + 1
              do j = 1, 3   
                do k = 1, 6
                  ra(icnt,j,k) = ra(i,j,k)
                end do
              end do 
              at(icnt) = at(i)
              mass(icnt) = mass(i)
              aidx(icnt) = aidx(i)
            endif    
          end do
          antot = icnt
        else
c
c    processor bounded by two separate processors
c
          icnt = 0 
          do i = 1, antot 
            if ((ra(i,1,1).ge.xmax.and.ra(i,1,1)-xmax.lt.xcell).or.
     +          (ra(i,1,1).lt.xmin.and.xmin-ra(i,1,1).gt.xcell)) then
              btot = btot + 1
              xcrd(btot) = ra(i,1,6)
              ycrd(btot) = ra(i,2,6)
              zcrd(btot) = ra(i,3,6)
              xfrc(btot) = ra(i,1,2)
              yfrc(btot) = ra(i,2,2)
              zfrc(btot) = ra(i,3,2)
              xacc(btot) = ra(i,1,3)
              yacc(btot) = ra(i,2,3)
              zacc(btot) = ra(i,3,3)
              bat(btot) = at(i)
              mbuf(btot) = mass(i)
              bidx(btot) = aidx(i)
            else
              icnt = icnt + 1
              do j = 1, 3
                do k = 1, 6
                  ra(icnt,j,k) = ra(i,j,k)
                end do
              end do
              at(icnt) = at(i)
              mass(icnt) = mass(i)
              aidx(icnt) = aidx(i)
            endif
          end do
          antot = icnt
        endif
c
c    send particles in positive x direction
c
        inx = ipx - 1
        if (inx.eq.-1) inx = idx - 1
        call i_xyz_to_proc(rnode,inx,ipy,ipz,idx,idy,idz)
        call update_buf(rnode)
        call ucull
      endif
c
      if (idx.gt.2) then
c
c    each boundary is adjacent to a different processor
c
        icnt = 0  
        do i = 1, antot  
          if ((ra(i,1,1).lt.xmin.and.xmin-ra(i,1,1).lt.xcell).or.
     +        (ra(i,1,1).gt.xmax.and.ra(i,1,1)-xmax.gt.xcell)) then
            btot = btot + 1 
            xcrd(btot) = ra(i,1,6) 
            ycrd(btot) = ra(i,2,6) 
            zcrd(btot) = ra(i,3,6) 
            xfrc(btot) = ra(i,1,2) 
            yfrc(btot) = ra(i,2,2) 
            zfrc(btot) = ra(i,3,2) 
            xacc(btot) = ra(i,1,3) 
            yacc(btot) = ra(i,2,3) 
            zacc(btot) = ra(i,3,3)
            bat(btot) = at(i)
            mbuf(btot) = mass(i)
            bidx(btot) = aidx(i)
          else
            icnt = icnt + 1
            do j = 1, 3
              do k = 1, 6
                ra(icnt,j,k) = ra(i,j,k)
              end do
            end do
            at(icnt) = at(i)
            mass(icnt) = mass(i)
            aidx(icnt) = aidx(i)
          endif
        end do
        antot = icnt
c
c    send particles in negative x direction
c
        inx = ipx + 1
        if (inx.eq.idx) inx = 0
        call i_xyz_to_proc(rnode,inx,ipy,ipz,idx,idy,idz)
        call update_buf(rnode)
        call ucull
      endif
c
c    repeat for y axis
c
      if (idy.ge.2) then
c
c    both boundaries are adjacent to boundaries on next processor
c
        if (idy.eq.2) then
          icnt = 0
          do i = 1, antot
            if (ra(i,2,1).ge.ymax.or.ra(i,2,1).lt.ymin) then
              btot = btot + 1
              xcrd(btot) = ra(i,1,6)
              ycrd(btot) = ra(i,2,6)
              zcrd(btot) = ra(i,3,6)
              xfrc(btot) = ra(i,1,2)
              yfrc(btot) = ra(i,2,2)
              zfrc(btot) = ra(i,3,2)
              xacc(btot) = ra(i,1,3)
              yacc(btot) = ra(i,2,3)
              zacc(btot) = ra(i,3,3)
              bat(btot) = at(i)
              mbuf(btot) = mass(i)
              bidx(btot) = aidx(i)
            else
              icnt = icnt + 1
              do j = 1, 3
                do k = 1, 6
                  ra(icnt,j,k) = ra(i,j,k)
                end do
              end do
              at(icnt) = at(i)
              mass(icnt) = mass(i)
              aidx(icnt) = aidx(i)
            endif
          end do
          antot = icnt
        else
c
c    processor bounded by two separate processors
c
          icnt = 0 
          do i = 1, antot 
            if ((ra(i,2,1).ge.ymax.and.ra(i,2,1)-ymax.lt.ycell).or.
     +          (ra(i,2,1).lt.ymin.and.ymin-ra(i,2,1).gt.ycell)) then
              btot = btot + 1
              xcrd(btot) = ra(i,1,6)
              ycrd(btot) = ra(i,2,6)
              zcrd(btot) = ra(i,3,6)
              xfrc(btot) = ra(i,1,2)
              yfrc(btot) = ra(i,2,2)
              zfrc(btot) = ra(i,3,2)
              xacc(btot) = ra(i,1,3)
              yacc(btot) = ra(i,2,3)
              zacc(btot) = ra(i,3,3)
              bat(btot) = at(i)
              mbuf(btot) = mass(i)
              bidx(btot) = aidx(i)
            else
              icnt = icnt + 1
              do j = 1, 3
                do k = 1, 6
                  ra(icnt,j,k) = ra(i,j,k)
                end do
              end do
              at(icnt) = at(i)
              mass(icnt) = mass(i)
              aidx(icnt) = aidx(i)
            endif
          end do
          antot = icnt
        endif
c
c    send particles in positive y direction
c
        iny = ipy - 1
        if (iny.eq.-1) iny = idy - 1
        call i_xyz_to_proc(rnode,ipx,iny,ipz,idx,idy,idz)
        call update_buf(rnode)
        call ucull
      endif
      icnt = 0
      if (idy.gt.2) then
c
c    each boundary is adjacent to a different processor
c
        icnt = 0  
        do i = 1, antot  
          if ((ra(i,2,1).lt.ymin.and.ymin-ra(i,2,1).lt.ycell).or.
     +        (ra(i,2,1).gt.ymax.and.ra(i,2,1)-ymax.gt.ycell)) then
            btot = btot + 1 
            xcrd(btot) = ra(i,1,6)
            ycrd(btot) = ra(i,2,6)
            zcrd(btot) = ra(i,3,6)
            xfrc(btot) = ra(i,1,2)
            yfrc(btot) = ra(i,2,2)
            zfrc(btot) = ra(i,3,2)
            xacc(btot) = ra(i,1,3)
            yacc(btot) = ra(i,2,3)
            zacc(btot) = ra(i,3,3)
            bat(btot) = at(i)
            mbuf(btot) = mass(i)
            bidx(btot) = aidx(i)
          else
            icnt = icnt + 1
            do j = 1, 3
              do k = 1, 6
                ra(icnt,j,k) = ra(i,j,k)
              end do
            end do
            at(icnt) = at(i)
            mass(icnt) = mass(i)
            aidx(icnt) = aidx(i)
          endif
        end do
        antot = icnt
c
c    send particles in negative y direction
c
        iny = ipy + 1
        if (iny.eq.idy) iny = 0
        call i_xyz_to_proc(rnode,ipx,iny,ipz,idx,idy,idz)
        call update_buf(rnode)
        call ucull
      endif
c
c    repeat for z axis
c
      if (idz.ge.2) then
c
c    both boundaries are adjacent to boundaries on next processor
c
        if (idz.eq.2) then
          icnt = 0
          do i = 1, antot
            if (ra(i,3,1).ge.zmax.or.ra(i,3,1).lt.zmin) then
              btot = btot + 1
              xcrd(btot) = ra(i,1,6)
              ycrd(btot) = ra(i,2,6)
              zcrd(btot) = ra(i,3,6)
              xfrc(btot) = ra(i,1,2)
              yfrc(btot) = ra(i,2,2)
              zfrc(btot) = ra(i,3,2)
              xacc(btot) = ra(i,1,3)
              yacc(btot) = ra(i,2,3)
              zacc(btot) = ra(i,3,3)
              bat(btot) = at(i)
              mbuf(btot) = mass(i)
              bidx(btot) = aidx(i)
            else
              icnt = icnt + 1
              do j = 1, 3
                do k = 1, 6
                  ra(icnt,j,k) = ra(i,j,k)
                end do
              end do
              at(icnt) = at(i)
              mass(icnt) = mass(i)
              aidx(icnt) = aidx(i)
            endif
          end do
          antot = icnt
        else
c
c    processor bounded by two separate processors
c
          icnt = 0
          do i = 1, antot
            if ((ra(i,3,1).ge.zmax.and.ra(i,3,1)-zmax.lt.zcell).or.
     +          (ra(i,3,1).lt.zmin.and.zmin-ra(i,3,1).gt.zcell)) then
              btot = btot + 1
              xcrd(btot) = ra(i,1,6)
              ycrd(btot) = ra(i,2,6)
              zcrd(btot) = ra(i,3,6)
              xfrc(btot) = ra(i,1,2)
              yfrc(btot) = ra(i,2,2)
              zfrc(btot) = ra(i,3,2)
              xacc(btot) = ra(i,1,3)
              yacc(btot) = ra(i,2,3)
              zacc(btot) = ra(i,3,3)
              bat(btot) = at(i)
              mbuf(btot) = mass(i)
              bidx(btot) = aidx(i)
            else
              icnt = icnt + 1
              do j = 1, 3
                do k = 1, 6
                  ra(icnt,j,k) = ra(i,j,k)
                end do
              end do
              at(icnt) = at(i)
              mass(icnt) = mass(i)
              aidx(icnt) = aidx(i)
            endif
          end do
          antot = icnt
        endif
c
c    send particles in positive z direction
c
        inz = ipz - 1
        if (inz.eq.-1) inz = idz - 1
        call i_xyz_to_proc(rnode,ipx,ipy,inz,idx,idy,idz)
        call update_buf(rnode)
        call ucull
      endif
      if (idz.gt.2) then
c
c    each boundary is adjacent to a different processor
c
        icnt = 0  
        do i = 1, antot  
          if ((ra(i,3,1).lt.zmin.and.zmin-ra(i,3,1).lt.zcell).or.
     +        (ra(i,3,1).gt.zmax.and.ra(i,3,1)-zmax.gt.zcell)) then
            btot = btot + 1 
            xcrd(btot) = ra(i,1,6)
            ycrd(btot) = ra(i,2,6)
            zcrd(btot) = ra(i,3,6)
            xfrc(btot) = ra(i,1,2)
            yfrc(btot) = ra(i,2,2)
            zfrc(btot) = ra(i,3,2)
            xacc(btot) = ra(i,1,3)
            yacc(btot) = ra(i,2,3)
            zacc(btot) = ra(i,3,3)
            bat(btot) = at(i)
            mbuf(btot) = mass(i)
            bidx(btot) = aidx(i)
          else
            icnt = icnt + 1
            do j = 1, 3
              do k = 1, 6
                ra(icnt,j,k) = ra(i,j,k)
              end do
            end do
            at(icnt) = at(i)
            mass(icnt) = mass(i)
            aidx(icnt) = aidx(i)
          endif
        end do
        antot = icnt
c
c    send particles in negative z direction
c
        inz = ipz + 1
        if (inz.eq.idz) inz = 0
        call i_xyz_to_proc(rnode,ipx,ipy,inz,idx,idy,idz)
        call update_buf(rnode)
        call ucull
      endif
c
c      call heapsort(0)
      do i = 1, antot
        call add_hash_a(aidx(i),i)
      end do
c
      tmstat(8) = tmstat(8) + wraptime() - tbeg
c
      return
      end
c
      subroutine update_buf(rnode)
#include "common.fh"
c
      integer ibuf(2,MAXAT)
      double precision cbuf(3,MAXAT),fbuf(3,MAXAT),abuf(3,MAXAT)
      double precision vbuf(MAXAT)
      double precision tbeg,wraptime
      integer i, stot, rtot
      integer me,rnode,one,is,ld2,ld3

c
c   Reassign all particles to the appropriate node.
c
      me = ga_nodeid()
      one = 1
      ld2 = 2
      ld3 = 3
c
      tbeg = wraptime()
c
      stot = btot
      do i = 1, stot
        cbuf(1,i) = xcrd(i)
        cbuf(2,i) = ycrd(i)
        cbuf(3,i) = zcrd(i)
        fbuf(1,i) = xfrc(i)
        fbuf(2,i) = yfrc(i)
        fbuf(3,i) = zfrc(i)
        abuf(1,i) = xacc(i)
        abuf(2,i) = yacc(i)
        abuf(3,i) = zacc(i)
        vbuf(i) = mbuf(i)
        ibuf(1,i) = bidx(i)
        ibuf(2,i) = bat(i)
      end do
c
      gsize_hi = gsize_lo(me)
      call nga_put(g_size,gsize_lo(me),gsize_hi,stot,one)
      gcoords_hi(1) = 3
      gcoords_hi(2) = gcoords_lo(2,me) + stot - 1
      if (stot.gt.0) call nga_put(g_coords,gcoords_lo(1,me),
     +                            gcoords_hi,cbuf,ld3)
      gfrc_hi(1) = 3
      gfrc_hi(2) = gfrc_lo(2,me) + stot - 1
      if (stot.gt.0) call nga_put(g_frc,gfrc_lo(1,me),gfrc_hi,fbuf,ld3)
      gacc_hi(1) = 3
      gacc_hi(2) = gacc_lo(2,me) + stot - 1
      if (stot.gt.0) call nga_put(g_acc,gacc_lo(1,me),gacc_hi,abuf,ld3)
      grvec_hi = grvec_lo(me) + stot - 1
      if (stot.gt.0) call nga_put(g_rvec,grvec_lo(me),grvec_hi,vbuf,one)
      giat_hi(1) = 2
      giat_hi(2) = giat_lo(2,me) + stot - 1
      if (stot.gt.0) call nga_put(g_iat,giat_lo(1,me),giat_hi,ibuf,ld2)
c
      call ga_sync()
c
      gsize_hi = gsize_lo(rnode)
      call nga_get(g_size,gsize_lo(rnode),gsize_hi,rtot,one)
      gcoords_hi(2) = gcoords_lo(2,rnode) + rtot - 1
      if (rtot.gt.0) call nga_get(g_coords,gcoords_lo(1,rnode),
     +                            gcoords_hi,cbuf,ld3)
      gfrc_hi(2) = gfrc_lo(2,rnode) + rtot - 1
      if (rtot.gt.0) call nga_get(g_frc,gfrc_lo(1,rnode),
     +                            gfrc_hi,fbuf,ld3)
      gacc_hi(2) = gacc_lo(2,rnode) + rtot - 1
      if (rtot.gt.0) call nga_get(g_acc,gacc_lo(1,rnode),
     +                            gacc_hi,abuf,ld3)
      grvec_hi = grvec_lo(rnode) + rtot - 1
      if (rtot.gt.0) call nga_get(g_rvec,grvec_lo(rnode),
     +                            grvec_hi,vbuf,one)
      giat_hi(2) = giat_lo(2,rnode) + rtot - 1
      if (rtot.gt.0) call nga_get(g_iat,giat_lo(1,rnode),
     +                            giat_hi,ibuf,ld2)
c
      do i = 1, rtot
        xcrd(i) = cbuf(1,i)
        ycrd(i) = cbuf(2,i)
        zcrd(i) = cbuf(3,i)
        xfrc(i) = fbuf(1,i)
        yfrc(i) = fbuf(2,i)
        zfrc(i) = fbuf(3,i)
        xacc(i) = abuf(1,i)
        yacc(i) = abuf(2,i)
        zacc(i) = abuf(3,i)
        mbuf(i) = vbuf(i)
        bidx(i) = ibuf(1,i)
        bat(i) = ibuf(2,i)
      end do
c
      btot = rtot
      call ga_sync()
c
      tmstat(13) = tmstat(13) + wraptime() - tbeg
c
      return
      end
c
      subroutine ucull
#include "common.fh"
c
      double precision xmax,ymax,zmax,xmin,ymin,zmin
      double precision xt,yt,zt
      integer pnum,inode,idx,idy,idz,ipx,ipy,ipz
      integer i,icnt
c
      pnum = ga_nnodes()
      call factor(pnum,idx,idy,idz)
      inode = ga_nodeid()
      call i_proc_to_xyz(inode,ipx,ipy,ipz,idx,idy,idz)
c
c   determine local boundaries
c
      xmax = xbox*dble(ipx+1)/dble(idx)
      ymax = ybox*dble(ipy+1)/dble(idy)
      zmax = zbox*dble(ipz+1)/dble(idz)
      xmin = xbox*dble(ipx)/dble(idx)
      ymin = ybox*dble(ipy)/dble(idy)
      zmin = zbox*dble(ipz)/dble(idz)
      xmax = xmax - xbox2
      ymax = ymax - ybox2
      zmax = zmax - zbox2
      xmin = xmin - xbox2
      ymin = ymin - ybox2
      zmin = zmin - zbox2
c
c   select out particles from buffers that belong on the home array
c
      icnt = 0
      do i = 1, btot
        xt = xcrd(i) - xbox*anint(xcrd(i)/xbox)
        yt = ycrd(i) - ybox*anint(ycrd(i)/ybox)
        zt = zcrd(i) - zbox*anint(zcrd(i)/zbox)
        antot = antot + 1
        ra(antot,1,6) = xcrd(i)
        ra(antot,2,6) = ycrd(i)
        ra(antot,3,6) = zcrd(i)
        ra(antot,1,2) = xfrc(i)
        ra(antot,2,2) = yfrc(i)
        ra(antot,3,2) = zfrc(i)
        ra(antot,1,3) = xacc(i)
        ra(antot,2,3) = yacc(i)
        ra(antot,3,3) = zacc(i)
        ra(antot,1,1) = xt
        ra(antot,2,1) = yt
        ra(antot,3,1) = zt
        at(antot) = bat(i)
        mass(antot) = mbuf(i)
        aidx(antot) = bidx(i)
      end do
      btot = icnt
c
      return
      end