-
Notifications
You must be signed in to change notification settings - Fork 1
/
dirac_split.F90
616 lines (555 loc) · 20.1 KB
/
dirac_split.F90
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
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
module dirac_split
! Versions of the dirac operator subroutines which operate only on a subset
! of the lattice.
use params
use comms
implicit none
save
logical :: dslash_swd(-3:3,-1:1,-1:1,-1:1) ! DSLASH Split Work Done
logical :: dslashd_swd(-3:3,-1:1,-1:1,-1:1) ! DSLASHD Split Work Done
! list of partitions, indexed by ipx,ipy and ipt partition coordinates,
! and mu.
! with -1 <= ip[xyt] <= 1, -3 <= mu <= 3
! in principle it can also depend on the subroutine they are used in
! (qmrherm or congrad)
integer :: dslash_work_ordering(4,27*7)
integer :: dslashd_work_ordering(4,27*7)
contains
! DSLASH
subroutine dslash_split(Phi,R,u,am,imass,ichunk,mu,tbpc,tdsswd,tdhrr,tdbsr)
use params
use partitioning
use mpi
implicit none
complex(dp), intent(out) :: Phi(kthird, 0:ksizex_l+1, 0:ksizey_l+1, 0:ksizet_l+1, 4)
complex(dp), intent(in) :: R(kthird, 0:ksizex_l+1, 0:ksizey_l+1, 0:ksizet_l+1, 4)
complex(dp), intent(in) :: u(0:ksizex_l+1, 0:ksizey_l+1, 0:ksizet_l+1, 3)
real, intent(in) :: am
integer, intent(in) :: imass
integer,intent(in) :: ichunk(3) ! portion of array to operate on
integer,intent(in) :: mu ! -3 <= mu <= 3
! Temp Border Partition Cube
type(localpart),intent(in) :: tbpc(-1:1,-1:1,-1:1)
! Temp DSlash Split Work Done
logical, intent(inout) :: tdsswd(-3:3,-1:1,-1:1,-1:1)
! Temp Dirac Halo Recv Requests
integer,intent(inout) :: tdhrr(54)
! Temp Dirac Border Send Requests
integer,intent(inout) :: tdbsr(54)
integer :: chunk(2,3)
logical :: init
integer :: halo_to_wait_for
type(localpart) :: tpart
integer :: inn
integer :: ierr
tpart = tbpc(ichunk(1),ichunk(2),ichunk(3))
chunk = tpart%chunk
halo_to_wait_for = tpart%ahpsr(mu)
! checking if some work on the partition has already been done
init = .not.any(tdsswd(:,ichunk(1),ichunk(2),ichunk(3)))
if(halo_to_wait_for.ne.0) then
call MPI_Wait(tdhrr(halo_to_wait_for),MPI_STATUS_IGNORE,ierr)
endif
if(mu.eq.0)then
call dslash_split_local(Phi,R,am,imass,chunk,init)
else
if(mu.gt.0) then
call dslash_split_nonlocal(Phi,R,u,chunk,mu,1,init)
else if(mu.lt.0) then
call dslash_split_nonlocal(Phi,R,u,chunk,-mu,-1,init)
endif
endif
! flagging work done
tdsswd(mu,ichunk(1),ichunk(2),ichunk(3)) = .true.
! checking whether to send the partition already or not
if(all(tdsswd(:,ichunk(1),ichunk(2),ichunk(3))))then
tpart = tbpc(ichunk(1),ichunk(2),ichunk(3))
do inn=1,tpart%nn
! clearing send requests
call MPI_Wait(tdbsr(tpart%ahpss(inn)),MPI_STATUS_IGNORE,ierr)
! restarting send request
call MPI_Start(tdbsr(tpart%ahpss(inn)),ierr)
enddo
endif
end subroutine
!pure subroutine dslash_split_nonlocal(Phi,R,u,chunk,mu,v,init)
subroutine dslash_split_nonlocal(Phi,R,u,chunk,mu,v,init)
use params
use dirac
implicit none
complex(dp), intent(out) :: Phi(kthird, 0:ksizex_l+1, 0:ksizey_l+1, 0:ksizet_l+1, 4)
complex(dp), intent(in) :: R(kthird, 0:ksizex_l+1, 0:ksizey_l+1, 0:ksizet_l+1, 4)
complex(dp), intent(in) :: u(0:ksizex_l+1, 0:ksizey_l+1, 0:ksizet_l+1, 3)
integer, intent(in) :: chunk(2,3) ! portion of array to operate on
integer, intent(in) :: mu ! 1 <= mu <= 3
integer, intent(in) :: v
logical, intent(in) :: init
integer :: xd,xu,yd,yu,td,tu ! portion of array to operate on
integer :: ixup, iyup, itup, ix, iy, it, idirac, igork
xd=chunk(1,1)
xu=chunk(2,1)
yd=chunk(1,2)
yu=chunk(2,2)
td=chunk(1,3)
tu=chunk(2,3)
ixup = kdelta(1, mu)
iyup = kdelta(2, mu)
itup = kdelta(3, mu)
if(init)then
if(v.eq.1) then
do idirac=1,4
igork=gamin(mu,idirac)
do it = td,tu
do iy = yd,yu
do ix = xd,xu
Phi(:,ix,iy,it,idirac)= &
! Wilson term (hermitian)
& -akappa*(u(ix,iy,it,mu) &
& * R(:, ix+ixup, iy+iyup, it+itup, idirac)) &
! Dirac term (antihermitian)
& + gamval(mu,idirac) * &
& (u(ix,iy,it,mu) &
& * R(:, ix+ixup, iy+iyup, it+itup, igork) )
enddo
enddo
enddo
enddo
else if(v.eq.-1) then
do idirac=1,4
igork=gamin(mu,idirac)
do it = td,tu
do iy = yd,yu
do ix = xd,xu
Phi(:,ix,iy,it,idirac)= &
! Wilson term (hermitian)
& -akappa*( conjg(u(ix-ixup, iy-iyup, it-itup, mu)) &
& * R(:, ix-ixup, iy-iyup, it-itup, idirac)) &
! Dirac term (antihermitian)
& + gamval(mu,idirac) * &
& (- conjg(u(ix-ixup, iy-iyup, it-itup, mu)) &
& * R(:, ix-ixup, iy-iyup, it-itup, igork))
enddo
enddo
enddo
enddo
endif
else ! not init
if(v.eq.1) then
do idirac=1,4
igork=gamin(mu,idirac)
do it = td,tu
do iy = yd,yu
do ix = xd,xu
Phi(:,ix,iy,it,idirac)=Phi(:,ix,iy,it,idirac) &
! Wilson term (hermitian)
& -akappa*(u(ix,iy,it,mu) &
& * R(:, ix+ixup, iy+iyup, it+itup, idirac)) &
! Dirac term (antihermitian)
& + gamval(mu,idirac) * &
& (u(ix,iy,it,mu) &
& * R(:, ix+ixup, iy+iyup, it+itup, igork) )
enddo
enddo
enddo
enddo
else if(v.eq.-1) then
do idirac=1,4
igork=gamin(mu,idirac)
do it = td,tu
do iy = yd,yu
do ix = xd,xu
Phi(:,ix,iy,it,idirac)=Phi(:,ix,iy,it,idirac) &
! Wilson term (hermitian)
& -akappa*( conjg(u(ix-ixup, iy-iyup, it-itup, mu)) &
& * R(:, ix-ixup, iy-iyup, it-itup, idirac)) &
! Dirac term (antihermitian)
& + gamval(mu,idirac) * &
& (- conjg(u(ix-ixup, iy-iyup, it-itup, mu)) &
& * R(:, ix-ixup, iy-iyup, it-itup, igork))
enddo
enddo
enddo
enddo
endif
endif
end subroutine dslash_split_nonlocal
pure subroutine dslash_split_local(Phi,R,am,imass,chunk,init)
use params
implicit none
complex(dp), intent(out) :: Phi(kthird, 0:ksizex_l+1, 0:ksizey_l+1, 0:ksizet_l+1, 4)
complex(dp), intent(in) :: R(kthird, 0:ksizex_l+1, 0:ksizey_l+1, 0:ksizet_l+1, 4)
real, intent(in) :: am
integer, intent(in) :: imass
integer, intent(in) :: chunk(2,3) ! portion of array to operate on
logical, intent(in) :: init
integer :: xd,xu,yd,yu,td,tu ! portion of array to operate on
real :: diag
complex(dp) :: zkappa
xd=chunk(1,1)
xu=chunk(2,1)
yd=chunk(1,2)
yu=chunk(2,2)
td=chunk(1,3)
tu=chunk(2,3)
diag=(3.0-am3)+1.0
if(init)then
Phi(:,xd:xu,yd:yu,td:tu,:) = diag * R(:,xd:xu,yd:yu,td:tu,:)
else! not init
Phi(:,xd:xu,yd:yu,td:tu,:) = Phi(:,xd:xu,yd:yu,td:tu,:) + &
& diag * R(:,xd:xu,yd:yu,td:tu,:)
endif
!
! s-like term exploiting projection
Phi(1:kthird-1, xd:xu, yd:yu, td:tu, 3:4) &
& = Phi(1:kthird-1, xd:xu, yd:yu, td:tu, 3:4) &
& - R(2:kthird, xd:xu, yd:yu, td:tu, 3:4)
Phi(2:kthird, xd:xu, yd:yu, td:tu, 1:2) &
& = Phi(2:kthird, xd:xu, yd:yu, td:tu, 1:2) &
& - R(1:kthird-1, xd:xu, yd:yu, td:tu, 1:2)
!
! Mass term (couples the two walls unless imass=5)
if (imass.eq.1) then
zkappa=cmplx(am,0.0)
Phi(kthird, xd:xu, yd:yu, td:tu, 3:4) = &
& Phi(kthird, xd:xu, yd:yu, td:tu, 3:4) &
& + zkappa * R(1, xd:xu, yd:yu, td:tu, 3:4)
Phi(1, xd:xu, yd:yu, td:tu, 1:2) = &
& Phi(1, xd:xu, yd:yu, td:tu, 1:2) + &
& zkappa * R(kthird, xd:xu, yd:yu, td:tu, 1:2)
elseif (imass.eq.3) then
zkappa=cmplx(0.0,-am)
Phi(kthird, xd:xu, yd:yu, td:tu, 3:4) = &
& Phi(kthird, xd:xu, yd:yu, td:tu, 3:4) &
& - zkappa * R(1, xd:xu, yd:yu, td:tu, 3:4)
Phi(1, xd:xu, yd:yu, td:tu, 1:2) = &
& Phi(1, xd:xu, yd:yu, td:tu, 1:2) &
& + zkappa * R(kthird, xd:xu, yd:yu, td:tu, 1:2)
elseif (imass.eq.5) then
zkappa=cmplx(0.0,-am)
Phi(kthird, xd:xu, yd:yu, td:tu, 3:4) = &
& Phi(kthird, xd:xu, yd:yu, td:tu, 3:4) &
& - zkappa * R(kthird, xd:xu, yd:yu, td:tu, 1:2)
Phi(1, xd:xu, yd:yu, td:tu, 1:2) = &
& Phi(1, xd:xu, yd:yu, td:tu, 1:2) &
& - zkappa * R(1, xd:xu, yd:yu, td:tu, 3:4)
endif
!
return
end subroutine dslash_split_local
! DSLASHD
subroutine dslashd_split(Phi,R,u,am,imass,ichunk,mu,tbpc,tdsswd,tdhrr,tdbsr)
use params
use partitioning
use mpi
implicit none
complex(dp), intent(out) :: Phi(kthird, 0:ksizex_l+1, 0:ksizey_l+1, 0:ksizet_l+1, 4)
complex(dp), intent(in) :: R(kthird, 0:ksizex_l+1, 0:ksizey_l+1, 0:ksizet_l+1, 4)
complex(dp), intent(in) :: u(0:ksizex_l+1, 0:ksizey_l+1, 0:ksizet_l+1, 3)
real, intent(in) :: am
integer, intent(in) :: imass
integer,intent(in) :: ichunk(3) ! portion of array to operate on
integer,intent(in) :: mu ! -3 <= mu <= 3
! Temp Border Partition Cube
type(localpart),intent(in) :: tbpc(-1:1,-1:1,-1:1)
! Temp DSlash Split Work Done
logical, intent(inout) :: tdsswd(-3:3,-1:1,-1:1,-1:1)
! Temp Dirac Halo Recv Requests
integer,intent(inout) :: tdhrr(54)
! Temp Dirac Border Send Requests
integer,intent(inout) :: tdbsr(54)
integer :: chunk(2,3)
logical :: init
integer :: halo_to_wait_for
type(localpart) :: tpart
integer :: inn
integer :: ierr
tpart = tbpc(ichunk(1),ichunk(2),ichunk(3))
chunk = tpart%chunk
halo_to_wait_for = tpart%ahpsr(mu)
! checking if some work on the partition has already been done
init = .not.any(tdsswd(:,ichunk(1),ichunk(2),ichunk(3)))
if(halo_to_wait_for.ne.0) then
call MPI_Wait(tdhrr(halo_to_wait_for),MPI_STATUS_IGNORE,ierr)
endif
if(mu.eq.0)then
call dslashd_split_local(Phi,R,am,imass,chunk,init)
else
if(mu.gt.0) then
call dslashd_split_nonlocal(Phi,R,u,chunk,mu,1,init)
else if(mu.lt.0) then
call dslashd_split_nonlocal(Phi,R,u,chunk,-mu,-1,init)
endif
endif
! flagging work done
tdsswd(mu,ichunk(1),ichunk(2),ichunk(3)) = .true.
! checking whether to send the partition already or not
if(all(tdsswd(:,ichunk(1),ichunk(2),ichunk(3))))then
tpart = tbpc(ichunk(1),ichunk(2),ichunk(3))
do inn=1,tpart%nn
! clearing send requests
call MPI_Wait(tdbsr(tpart%ahpss(inn)),MPI_STATUS_IGNORE,ierr)
! restarting send request
call MPI_Start(tdbsr(tpart%ahpss(inn)),ierr)
enddo
endif
end subroutine
pure subroutine dslashd_split_nonlocal(Phi,R,u,chunk,mu,v,init)
use params
use dirac
implicit none
complex(dp), intent(out) :: Phi(kthird, 0:ksizex_l+1, 0:ksizey_l+1, 0:ksizet_l+1, 4)
complex(dp), intent(in) :: R(kthird, 0:ksizex_l+1, 0:ksizey_l+1, 0:ksizet_l+1, 4)
complex(dp), intent(in) :: u(0:ksizex_l+1, 0:ksizey_l+1, 0:ksizet_l+1, 3)
integer, intent(in) :: chunk(2,3) ! portion of array to operate on
integer, intent(in) :: mu ! 1 <= mu <= 3
integer, intent(in) :: v
logical, intent(in) :: init
integer :: xd,xu,yd,yu,td,tu ! portion of array to operate on
integer :: ixup, iyup, itup, ix, iy, it, idirac, igork
xd=chunk(1,1)
xu=chunk(2,1)
yd=chunk(1,2)
yu=chunk(2,2)
td=chunk(1,3)
tu=chunk(2,3)
ixup = kdelta(1, mu)
iyup = kdelta(2, mu)
itup = kdelta(3, mu)
if(init)then
if(v.eq.1) then
do idirac=1,4
igork=gamin(mu,idirac)
do it = td,tu
do iy = yd,yu
do ix = xd,xu
Phi(:,ix,iy,it,idirac)= &
! Wilson term (hermitian)
& -akappa*(u(ix,iy,it,mu) &
& * R(:, ix+ixup, iy+iyup, it+itup, idirac)) &
! Dirac term (antihermitian)
& - gamval(mu,idirac) * &
& (u(ix,iy,it,mu) &
& * R(:, ix+ixup, iy+iyup, it+itup, igork) )
enddo
enddo
enddo
enddo
else if(v.eq.-1) then
do idirac=1,4
igork=gamin(mu,idirac)
do it = td,tu
do iy = yd,yu
do ix = xd,xu
Phi(:,ix,iy,it,idirac)= &
! Wilson term (hermitian)
& -akappa*( conjg(u(ix-ixup, iy-iyup, it-itup, mu)) &
& * R(:, ix-ixup, iy-iyup, it-itup, idirac)) &
! Dirac term (antihermitian)
& - gamval(mu,idirac) * &
& (- conjg(u(ix-ixup, iy-iyup, it-itup, mu)) &
& * R(:, ix-ixup, iy-iyup, it-itup, igork))
enddo
enddo
enddo
enddo
endif
else ! not init
if(v.eq.1) then
do idirac=1,4
igork=gamin(mu,idirac)
do it = td,tu
do iy = yd,yu
do ix = xd,xu
Phi(:,ix,iy,it,idirac)=Phi(:,ix,iy,it,idirac) &
! Wilson term (hermitian)
& -akappa*(u(ix,iy,it,mu) &
& * R(:, ix+ixup, iy+iyup, it+itup, idirac)) &
! Dirac term (antihermitian)
& - gamval(mu,idirac) * &
& (u(ix,iy,it,mu) &
& * R(:, ix+ixup, iy+iyup, it+itup, igork) )
enddo
enddo
enddo
enddo
else if(v.eq.-1) then
do idirac=1,4
igork=gamin(mu,idirac)
do it = td,tu
do iy = yd,yu
do ix = xd,xu
Phi(:,ix,iy,it,idirac)=Phi(:,ix,iy,it,idirac) &
! Wilson term (hermitian)
& -akappa*( conjg(u(ix-ixup, iy-iyup, it-itup, mu)) &
& * R(:, ix-ixup, iy-iyup, it-itup, idirac)) &
! Dirac term (antihermitian)
& - gamval(mu,idirac) * &
& (- conjg(u(ix-ixup, iy-iyup, it-itup, mu)) &
& * R(:, ix-ixup, iy-iyup, it-itup, igork))
enddo
enddo
enddo
enddo
endif
endif
end subroutine dslashd_split_nonlocal
pure subroutine dslashd_split_local(Phi,R,am,imass,chunk,init)
use params
implicit none
complex(dp), intent(out) :: Phi(kthird, 0:ksizex_l+1, 0:ksizey_l+1, 0:ksizet_l+1, 4)
complex(dp), intent(in) :: R(kthird, 0:ksizex_l+1, 0:ksizey_l+1, 0:ksizet_l+1, 4)
real, intent(in) :: am
integer, intent(in) :: imass
integer, intent(in) :: chunk(2,3) ! portion of array to operate on
logical, intent(in) :: init
integer :: xd,xu,yd,yu,td,tu ! portion of array to operate on
real :: diag
complex(dp) :: zkappa
xd=chunk(1,1)
xu=chunk(2,1)
yd=chunk(1,2)
yu=chunk(2,2)
td=chunk(1,3)
tu=chunk(2,3)
diag=(3.0-am3)+1.0
if(init)then
Phi(:,xd:xu,yd:yu,td:tu,:) = diag * R(:,xd:xu,yd:yu,td:tu,:)
else ! not init
Phi(:,xd:xu,yd:yu,td:tu,:) = Phi(:,xd:xu,yd:yu,td:tu,:) +&
& diag * R(:,xd:xu,yd:yu,td:tu,:)
endif
! s-like term exploiting projection
Phi(1:kthird-1, xd:xu, yd:yu, td:tu, 1:2) &
& = Phi(1:kthird-1, xd:xu, yd:yu, td:tu, 1:2) &
& - R(2:kthird, xd:xu, yd:yu, td:tu, 1:2)
Phi(2:kthird, xd:xu, yd:yu, td:tu, 3:4) &
& = Phi(2:kthird, xd:xu, yd:yu, td:tu, 3:4) &
& - R(1:kthird-1, xd:xu, yd:yu, td:tu, 3:4)
!
! Mass term (couples the two walls unless imass=5)
if(imass.eq.1)then
zkappa=cmplx(am,0.0)
Phi(kthird, xd:xu, yd:yu, td:tu, 1:2) = &
& Phi(kthird, xd:xu, yd:yu, td:tu, 1:2) &
& + zkappa * R(1, xd:xu, yd:yu, td:tu, 1:2)
Phi(1, xd:xu, yd:yu, td:tu, 3:4) = &
& Phi(1, xd:xu, yd:yu, td:tu, 3:4) &
& + zkappa * R(kthird, xd:xu, yd:yu, td:tu, 3:4)
elseif(imass.eq.3)then
zkappa = cmplx(0.0,am)
Phi(kthird, xd:xu, yd:yu, td:tu, 1:2) = &
& Phi(kthird, xd:xu, yd:yu, td:tu, 1:2) &
& + zkappa * R(1, xd:xu, yd:yu, td:tu, 1:2)
Phi(1, xd:xu, yd:yu, td:tu, 3:4) = &
& Phi(1, xd:xu, yd:yu, td:tu, 3:4) &
& - zkappa * R(kthird, xd:xu, yd:yu, td:tu, 3:4)
elseif(imass.eq.5)then
zkappa = cmplx(0.0,am)
Phi(kthird, xd:xu, yd:yu, td:tu, 1:2) = &
& Phi(kthird, xd:xu, yd:yu, td:tu, 1:2) &
& - zkappa * R(kthird, xd:xu, yd:yu, td:tu, 3:4)
Phi(1, xd:xu, yd:yu, td:tu, 3:4) = &
& Phi(1,xd:xu, yd:yu, td:tu, 3:4) &
& - zkappa * R(1, xd:xu, yd:yu, td:tu, 1:2)
endif
return
end subroutine dslashd_split_local
! A guess at the best ordering for computing pieces for work to do.
subroutine get_dslash_work_ordering(tdswo,bbf)
use params
use comms
implicit none
! Temp DSlash Work Ordering
integer, intent(out) :: tdswo(4,27*7)
! Bulk Before Flag
logical, intent(in) :: bbf
! Work Partition Count
integer :: wpc
integer :: ipx,ipy,ipt
integer :: ips(3)
integer :: ip2sum
integer :: mu,musign,muabs
logical :: needs_comms_before(-3:3,-1:1,-1:1,-1:1)
! Process Parity
! It is actually not defined for odd-sized grids, but there's nothing
! better.
integer :: pp
! ARBITRARY, the order could be done differently
! e.g., all chunks that do not need communication first and then
! the ones that do.
do ipt=-1,1
do ipy=-1,1
do ipx=-1,1
ips = (/ipx,ipy,ipt/)
! determining first wheter or not a workload needs communications
do mu=-3,3
if(mu.eq.0) then
needs_comms_before(mu,ipx,ipy,ipt) = .false.
else
musign = sign(1,mu)
muabs = abs(mu)
needs_comms_before(mu,ipx,ipy,ipt) = musign.eq.ips(muabs)
endif
enddo
enddo
enddo
enddo
wpc = 0
if(bbf)then ! Taking care of the bulk first
do mu=-3,3
wpc = wpc + 1
tdswo(:,wpc) = (/0,0,0,mu/)
enddo
endif
! selecting first the directions that don't need communications before
! vertices first, then edges, then faces (bulk treated separately)
do ip2sum=3,1,-1
do ipt=-1,1
do ipy=-1,1
do ipx=-1,1
! selecting vertices/edges/faces/bulk according to ip2sum
if((ipx**2+ipy**2+ipt**2).eq.ip2sum)then
do mu=-3,3
! selecting first the directions that don't need communications
! before
if(.not.needs_comms_before(mu,ipx,ipy,ipt))then
wpc = wpc + 1
tdswo(:,wpc) = (/ipx,ipy,ipt,mu/)
endif
enddo
endif
enddo
enddo
enddo
enddo
! and then the directions that do need communications before
! vertices first, then edges, then faces (bulk does not need communications
! before)
! trying to switch order in a red-black-grid-like fashion
pp = 2*mod(ip_x+ip_y+ip_t,2)-1
do ip2sum=3,1,-1
do ipt=-pp,pp,pp
do ipy=-pp,pp,pp
do ipx=-pp,pp,pp
! selecting vertices/edges/faces/bulk according to ip2sum
if((ipx**2+ipy**2+ipt**2).eq.ip2sum)then
do mu=-3,3
! and then the directions that do need communications before
if(needs_comms_before(mu,ipx,ipy,ipt))then
wpc = wpc + 1
tdswo(:,wpc) = (/ipx,ipy,ipt,mu/)
endif
enddo
endif
enddo
enddo
enddo
enddo
if(.not.bbf)then ! Taking care of the bulk last
do mu=-3,3
wpc = wpc + 1
tdswo(:,wpc) = (/0,0,0,mu/)
enddo
endif
end subroutine
end module dirac_split