-
Notifications
You must be signed in to change notification settings - Fork 22
/
Copy pathgtable.f90
663 lines (547 loc) · 20.9 KB
/
gtable.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
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
!
! Copyright (C) 2002-2010 Quantum ESPRESSO groups
! This file is distributed under the terms of the
! GNU General Public License. See the file `License'
! in the root directory of the present distribution,
! or http://www.gnu.org/copyleft/gpl.txt .
!
subroutine gtable( ipol, ctable)
! this subroutine prepares the correspondence array to
! compute the operator exp(iG_ipol.r)
! ctable : output correspondence table
! in (ig,1) correspondence for g+1
! in (ig,2) correspondence for (-g)+1
! we use the rule: if non point ngw+1
! if found positive = normal
! negative = conjugate
! ipol : input polarization direction
! a orthorombic primitive cell is supposed
use kinds, only: dp
use gvecw, only: ngw
use gvect, only: mill
use mp, only: mp_sum
use io_global, only: ionode, stdout
use mp_global, only: intra_bgrp_comm
implicit none
integer :: ipol, ctable(ngw,2)
!local variables
integer :: i,j,k, ig, jg
logical :: found
real(dp) :: test
test=0.d0
do ig=1,ngw!loop on g vectors
! first +g
i = mill(1,ig)
j = mill(2,ig)
k = mill(3,ig)
if(ipol.eq.1) i=i+1
if(ipol.eq.2) j=j+1
if(ipol.eq.3) k=k+1
found = .false.
do jg=1,ngw
if(mill(1,jg).eq.i .and. mill(2,jg).eq.j .and. mill(3,jg).eq.k) then
found=.true.
ctable(ig,1)=jg
endif
enddo
if(.not. found) then
do jg=1,ngw
if(-mill(1,jg).eq.i .and. -mill(2,jg).eq.j .and. -mill(3,jg).eq.k) then
found=.true.
ctable(ig,1)=-jg
endif
enddo
if(.not. found) then
ctable(ig,1)= ngw+1
test=test+1.d0
endif
endif
! now -g
i = -mill(1,ig)
j = -mill(2,ig)
k = -mill(3,ig)
if(ipol.eq.1) i=i+1
if(ipol.eq.2) j=j+1
if(ipol.eq.3) k=k+1
found = .false.
do jg=1,ngw
if (-mill(1,jg).eq.i .and. -mill(2,jg).eq.j .and. -mill(3,jg).eq.k)then
found=.true.
ctable(ig,2)=-jg
endif
enddo
if(.not.found) then
do jg=1,ngw
if(mill(1,jg).eq.i .and. mill(2,jg).eq.j .and. mill(3,jg).eq.k)then
found=.true.
ctable(ig,2)=jg
endif
enddo
if(.not.found) then
ctable(ig,2)=ngw+1
test=test+1.d0
endif
endif
enddo
call mp_sum(test, intra_bgrp_comm)
if(ionode) write(stdout,*) '#not found, gtable: ', test
return
end subroutine gtable
subroutine gtablein( ipol, ctabin)
! this subroutine prepare the inverse correspondence array to
! compute the operator exp(iG_ipol.r)
! ctabin(ngw,2) : output correspondence table
! if negative to take complex conjugate, 1 g'+1, 2 g' -1
! if not found = ngw+1
! ipol : input polarization direction
! a orthorombic primitive cell is supposed
use kinds, only: dp
use gvecw, only: ngw
use gvect, only: mill
use mp, only: mp_sum
use io_global, only: ionode, stdout
use mp_global, only: intra_bgrp_comm
implicit none
integer :: ipol, ctabin(ngw,2)
!local variables
integer :: i,j,k, ig, jg
logical :: found
real(dp) :: test
test=0.d0
do ig=1,ngw!loop on g vectors
i = mill(1,ig)
j = mill(2,ig)
k = mill(3,ig)
if(ipol.eq.1) i=i+1
if(ipol.eq.2) j=j+1
if(ipol.eq.3) k=k+1
found = .false.
do jg=1,ngw
if(i.eq.mill(1,jg).and. j.eq.mill(2,jg) .and. k.eq.mill(3,jg))then
found = .true.
ctabin(ig,1)=jg
else if(i.eq.-mill(1,jg).and. j.eq.-mill(2,jg) .and. k.eq.-mill(3,jg))then
found=.true.
ctabin(ig,1)=-jg
endif
enddo
if(.not.found) then
ctabin(ig,1)=ngw+1
test=test+1
endif
enddo
do ig=1,ngw!loop on g vectors
i = mill(1,ig)
j = mill(2,ig)
k = mill(3,ig)
if(ipol.eq.1) i=i-1
if(ipol.eq.2) j=j-1
if(ipol.eq.3) k=k-1
found = .false.
do jg=1,ngw
if(i.eq.mill(1,jg).and. j.eq.mill(2,jg) .and. k.eq.mill(3,jg))then
found = .true.
ctabin(ig,2)=jg
else if(i.eq.-mill(1,jg).and. j.eq.-mill(2,jg) .and. k.eq.-mill(3,jg))then
found=.true.
ctabin(ig,2)=-jg
endif
enddo
if(.not.found) then
ctabin(ig,2)=ngw+1
test=test+1
endif
enddo
call mp_sum(test, intra_bgrp_comm)
if(ionode) write(stdout,*) '#not found, gtabin: ', test
return
end subroutine gtablein
subroutine find_whose_is_g
!this subroutine set the correspondence G-->Proc
USE gvecw, ONLY : ngw, ngw_g
USE gvect, ONLY : ig_l2g, mill_g, mill
USE mp, ONLY : mp_sum
USE io_global, ONLY : stdout
USE mp_global, ONLY : me_bgrp, nproc_bgrp, intra_bgrp_comm
USE efield_module, ONLY : whose_is_g
implicit none
INTEGER :: ig
whose_is_g(:)=0
do ig=1,ngw
if(ig_l2g(ig) > ngw_g) then
write(stdout,*) 'find_whose_is_g: too large'
stop
endif
whose_is_g(ig_l2g(ig))=me_bgrp+1
enddo
call mp_sum(whose_is_g,intra_bgrp_comm)
whose_is_g(:)=whose_is_g(:)-1
! mill_g is used in gtable_missing and re-initialized here
! workaround by PG to avoid a large array like mill_g allocated all the time
allocate ( mill_g(3,ngw_g) )
do ig=1,ngw
mill_g(:,ig_l2g(ig)) = mill(:,ig)
end do
call mp_sum(mill_g,intra_bgrp_comm)
return
end subroutine find_whose_is_g
subroutine gtable_missing
USE efield_module, ONLY : ctable_missing_1, ctable_missing_2, &
whose_is_g,n_g_missing_p, &
ctable_missing_rev_1,ctable_missing_rev_2
USE gvecw, ONLY : ngw, ngw_g
USE gvect, ONLY : ig_l2g, mill_g, mill, gstart
USE mp, ONLY : mp_sum, mp_max, mp_alltoall
USE io_global, ONLY : stdout
USE mp_global, ONLY : me_bgrp, nproc_bgrp, intra_bgrp_comm
USE parallel_include
implicit none
INTEGER :: ipol, i,j,k,ig,igg, nfound_max, ip
LOGICAL :: found
INTEGER :: nfound_proc(nproc_bgrp,2)
INTEGER, ALLOCATABLE :: igg_found(:,:,:), ig_send(:,:,:), igg_found_snd(:,:,:)
INTEGER, ALLOCATABLE :: igg_found_rcv(:,:,:)
INTEGER :: ierr,sndint,rcvint
allocate( igg_found(ngw_g,2,nproc_bgrp), ig_send(ngw_g,2,nproc_bgrp) )
do ipol=1,2
nfound_max=0
nfound_proc(:,:)=0
ig_send(:,:,:)=0
do ig=1,ngw!loop on g vectors
! first +g
i = mill(1,ig)
j = mill(2,ig)
k = mill(3,ig)
if(ipol.eq.1) i=i+1
if(ipol.eq.2) j=j+1
if(ipol.eq.3) k=k+1
do igg=1,ngw_g
if( i==mill_g(1,igg) .and. j==mill_g(2,igg) .and. k==mill_g(3,igg)) then
if(whose_is_g(igg) /= -1 .and. whose_is_g(igg) /= me_bgrp) then
nfound_max=nfound_max+1
nfound_proc(whose_is_g(igg)+1,1)=nfound_proc(whose_is_g(igg)+1,1)+1
ig_send(nfound_proc(whose_is_g(igg)+1,1),1,whose_is_g(igg)+1)=ig
igg_found(nfound_proc(whose_is_g(igg)+1,1),1,whose_is_g(igg)+1)=igg
endif
else if( i==-mill_g(1,igg) .and. j==-mill_g(2,igg) .and. k==-mill_g(3,igg)) then
if(whose_is_g(igg) /= -1 .and. whose_is_g(igg) /= me_bgrp) then
nfound_max=nfound_max+1
nfound_proc(whose_is_g(igg)+1,1)=nfound_proc(whose_is_g(igg)+1,1)+1
ig_send(nfound_proc(whose_is_g(igg)+1,1),1,whose_is_g(igg)+1)=ig
igg_found(nfound_proc(whose_is_g(igg)+1,1),1,whose_is_g(igg)+1)=-igg
endif
endif
enddo
enddo
do ig=gstart,ngw!loop on g vectors
! first +g
i = -mill(1,ig)
j = -mill(2,ig)
k = -mill(3,ig)
if(ipol.eq.1) i=i+1
if(ipol.eq.2) j=j+1
if(ipol.eq.3) k=k+1
do igg=1,ngw_g
if( i==mill_g(1,igg) .and. j==mill_g(2,igg) .and. k==mill_g(3,igg)) then
if(whose_is_g(igg) /= -1 .and. whose_is_g(igg) /= me_bgrp) then
nfound_max=nfound_max+1
nfound_proc(whose_is_g(igg)+1,2)=nfound_proc(whose_is_g(igg)+1,2)+1
ig_send(nfound_proc(whose_is_g(igg)+1,2),2,whose_is_g(igg)+1)=ig
igg_found(nfound_proc(whose_is_g(igg)+1,2),2,whose_is_g(igg)+1)=igg
endif
else if( i==-mill_g(1,igg) .and. j==-mill_g(2,igg) .and. k==-mill_g(3,igg)) then
if(whose_is_g(igg) /= -1 .and. whose_is_g(igg) /= me_bgrp) then
nfound_max=nfound_max+1
nfound_proc(whose_is_g(igg)+1,2)=nfound_proc(whose_is_g(igg)+1,2)+1
ig_send(nfound_proc(whose_is_g(igg)+1,2),2,whose_is_g(igg)+1)=ig
igg_found(nfound_proc(whose_is_g(igg)+1,2),2,whose_is_g(igg)+1)=-igg
endif
endif
enddo
enddo
! determine the largest nfound for processor and set it as dimension
! for ctable_missing and ctable_missing_rev
! copy ig_send to ctable_missing
call mp_sum(nfound_max, intra_bgrp_comm)
write(stdout,*) 'Additional found:', nfound_max
n_g_missing_p(ipol)=maxval(nfound_proc(:,:))
call mp_max(n_g_missing_p(ipol), intra_bgrp_comm)
if(ipol==1) then
allocate(ctable_missing_1(n_g_missing_p(ipol),2,nproc_bgrp))
ctable_missing_1(:,:,:)=0
do ip=1,nproc_bgrp
ctable_missing_1(1:nfound_proc(ip,1),1,ip)=ig_send(1:nfound_proc(ip,1),1,ip)
ctable_missing_1(1:nfound_proc(ip,2),2,ip)=ig_send(1:nfound_proc(ip,2),2,ip)
enddo
else
allocate(ctable_missing_2(n_g_missing_p(ipol),2,nproc_bgrp))
ctable_missing_2(:,:,:)=0
do ip=1,nproc_bgrp
ctable_missing_2(1:nfound_proc(ip,1),1,ip)=ig_send(1:nfound_proc(ip,1),1,ip)
ctable_missing_2(1:nfound_proc(ip,2),2,ip)=ig_send(1:nfound_proc(ip,2),2,ip)
enddo
endif
!mpi all to all for igg_found
allocate(igg_found_snd(n_g_missing_p(ipol),2,nproc_bgrp))
allocate(igg_found_rcv(n_g_missing_p(ipol),2,nproc_bgrp))
igg_found_snd(:,:,:)=0
do ip=1,nproc_bgrp
igg_found_snd(1:nfound_proc(ip,1),1,ip)=igg_found(1:nfound_proc(ip,1),1,ip)
igg_found_snd(1:nfound_proc(ip,2),2,ip)=igg_found(1:nfound_proc(ip,2),2,ip)
enddo
call mp_alltoall( igg_found_snd, igg_found_rcv, intra_bgrp_comm )
if(ipol==1) then
allocate(ctable_missing_rev_1(n_g_missing_p(ipol),2,nproc_bgrp))
ctable_missing_rev_1(:,:,:)=0
else
allocate(ctable_missing_rev_2(n_g_missing_p(ipol),2,nproc_bgrp))
ctable_missing_rev_2(:,:,:)=0
endif
nfound_max=0
do ip=1,nproc_bgrp
do igg=1, n_g_missing_p(ipol)
if(igg_found_rcv(igg,1,ip) /= 0 ) then
found=.false.
do ig=1,ngw
if(igg_found_rcv(igg,1,ip)>0) then
if(ig_l2g(ig)==igg_found_rcv(igg,1,ip)) then
nfound_max=nfound_max+1
if(ipol==1) then
ctable_missing_rev_1(igg,1,ip)=ig
else
ctable_missing_rev_2(igg,1,ip)=ig
endif
found=.true.
endif
else
if(ig_l2g(ig)==-igg_found_rcv(igg,1,ip)) then
nfound_max=nfound_max+1
if(ipol==1) then
ctable_missing_rev_1(igg,1,ip)=-ig
else
ctable_missing_rev_2(igg,1,ip)=-ig
endif
found=.true.
endif
endif
enddo
if(.not.found) write(stdout,*) 'NOT FOUND:', igg_found_rcv(igg,1,ip)
endif
enddo
do igg=1, n_g_missing_p(ipol)
if(igg_found_rcv(igg,2,ip) /= 0 ) then
found=.false.
do ig=1,ngw
if(igg_found_rcv(igg,2,ip)>0) then
if(ig_l2g(ig)==igg_found_rcv(igg,2,ip)) then
nfound_max=nfound_max+1
if(ipol==1) then
ctable_missing_rev_1(igg,2,ip)=ig
else
ctable_missing_rev_2(igg,2,ip)=ig
endif
found=.true.
endif
else
if(ig_l2g(ig)==-igg_found_rcv(igg,2,ip)) then
nfound_max=nfound_max+1
if(ipol==1) then
ctable_missing_rev_1(igg,2,ip)=-ig
else
ctable_missing_rev_2(igg,2,ip)=-ig
endif
found=.true.
endif
endif
enddo
if(.not.found) write(stdout,*) 'NOT FOUND:', igg_found_rcv(igg,2,ip)
endif
enddo
enddo
call mp_sum(nfound_max, intra_bgrp_comm)
!write(stdout,*) 'Found check', nfound_max
deallocate(igg_found_snd,igg_found_rcv)
enddo
deallocate(igg_found, ig_send)
return
end subroutine gtable_missing
subroutine gtable_missing_inv
USE efield_module, ONLY : ctabin_missing_1,ctabin_missing_2, whose_is_g,n_g_missing_m,&
& ctabin_missing_rev_1,ctabin_missing_rev_2
USE gvecw, ONLY : ngw, ngw_g
USE gvect, ONLY : ig_l2g, mill_g, mill, gstart
USE mp, ONLY : mp_sum, mp_max, mp_alltoall
USE io_global, ONLY : stdout
USE mp_global, ONLY : me_bgrp, nproc_bgrp, intra_bgrp_comm
USE parallel_include
implicit none
INTEGER :: ipol, i,j,k,ig,igg, nfound_max, ip
LOGICAL :: found
INTEGER :: nfound_proc(nproc_bgrp,2)
INTEGER, ALLOCATABLE :: igg_found(:,:,:), ig_send(:,:,:), igg_found_snd(:,:,:)
INTEGER, ALLOCATABLE :: igg_found_rcv(:,:,:)
INTEGER :: ierr,sndint,rcvint
allocate( igg_found(ngw_g,2,nproc_bgrp), ig_send(ngw_g,2,nproc_bgrp))
do ipol=1,2
nfound_max=0
nfound_proc(:,:)=0
ig_send(:,:,:)=0
do ig=1,ngw!loop on g vectors
! first +g
i = mill(1,ig)
j = mill(2,ig)
k = mill(3,ig)
if(ipol.eq.1) i=i+1
if(ipol.eq.2) j=j+1
if(ipol.eq.3) k=k+1
do igg=1,ngw_g
if( i==mill_g(1,igg) .and. j==mill_g(2,igg) .and. k==mill_g(3,igg)) then
if(whose_is_g(igg) /= -1 .and. whose_is_g(igg) /= me_bgrp) then
nfound_max=nfound_max+1
nfound_proc(whose_is_g(igg)+1,1)=nfound_proc(whose_is_g(igg)+1,1)+1
ig_send(nfound_proc(whose_is_g(igg)+1,1),1,whose_is_g(igg)+1)=ig
igg_found(nfound_proc(whose_is_g(igg)+1,1),1,whose_is_g(igg)+1)=igg
endif
else if( i==-mill_g(1,igg) .and. j==-mill_g(2,igg) .and. k==-mill_g(3,igg)) then
if(whose_is_g(igg) /= -1 .and. whose_is_g(igg) /= me_bgrp) then
nfound_max=nfound_max+1
nfound_proc(whose_is_g(igg)+1,1)=nfound_proc(whose_is_g(igg)+1,1)+1
ig_send(nfound_proc(whose_is_g(igg)+1,1),1,whose_is_g(igg)+1)=ig
igg_found(nfound_proc(whose_is_g(igg)+1,1),1,whose_is_g(igg)+1)=-igg
endif
endif
enddo
enddo
do ig=1,ngw!loop on g vectors
! first +g
i = mill(1,ig)
j = mill(2,ig)
k = mill(3,ig)
if(ipol.eq.1) i=i-1
if(ipol.eq.2) j=j-1
if(ipol.eq.3) k=k-1
do igg=1,ngw_g
if( i==mill_g(1,igg) .and. j==mill_g(2,igg) .and. k==mill_g(3,igg)) then
if(whose_is_g(igg) /= -1 .and. whose_is_g(igg) /= me_bgrp) then
nfound_max=nfound_max+1
nfound_proc(whose_is_g(igg)+1,2)=nfound_proc(whose_is_g(igg)+1,2)+1
ig_send(nfound_proc(whose_is_g(igg)+1,2),2,whose_is_g(igg)+1)=ig
igg_found(nfound_proc(whose_is_g(igg)+1,2),2,whose_is_g(igg)+1)=igg
endif
else if( i==-mill_g(1,igg) .and. j==-mill_g(2,igg) .and. k==-mill_g(3,igg)) then
if(whose_is_g(igg) /= -1 .and. whose_is_g(igg) /= me_bgrp) then
nfound_max=nfound_max+1
nfound_proc(whose_is_g(igg)+1,2)=nfound_proc(whose_is_g(igg)+1,2)+1
ig_send(nfound_proc(whose_is_g(igg)+1,2),2,whose_is_g(igg)+1)=ig
igg_found(nfound_proc(whose_is_g(igg)+1,2),2,whose_is_g(igg)+1)=-igg
endif
endif
enddo
enddo
!determine the largest nfound for processor and set it as dimensione for ctabin_missing and ctabin_missing_rev
!copy ig_send to ctabin_missing
call mp_sum(nfound_max, intra_bgrp_comm)
write(stdout,*) 'Additional found:', nfound_max
n_g_missing_m(ipol)=maxval(nfound_proc(:,:))
call mp_max(n_g_missing_m(ipol), intra_bgrp_comm)
if(ipol==1) then
allocate(ctabin_missing_1(n_g_missing_m(ipol),2,nproc_bgrp))
ctabin_missing_1(:,:,:)=0
do ip=1,nproc_bgrp
ctabin_missing_1(1:nfound_proc(ip,1),1,ip)=ig_send(1:nfound_proc(ip,1),1,ip)
ctabin_missing_1(1:nfound_proc(ip,2),2,ip)=ig_send(1:nfound_proc(ip,2),2,ip)
enddo
else
allocate(ctabin_missing_2(n_g_missing_m(ipol),2,nproc_bgrp))
ctabin_missing_2(:,:,:)=0
do ip=1,nproc_bgrp
ctabin_missing_2(1:nfound_proc(ip,1),1,ip)=ig_send(1:nfound_proc(ip,1),1,ip)
ctabin_missing_2(1:nfound_proc(ip,2),2,ip)=ig_send(1:nfound_proc(ip,2),2,ip)
enddo
endif
!mpi all to all for igg_found
allocate(igg_found_snd(n_g_missing_m(ipol),2,nproc_bgrp))
allocate(igg_found_rcv(n_g_missing_m(ipol),2,nproc_bgrp))
igg_found_snd(:,:,:)=0
do ip=1,nproc_bgrp
igg_found_snd(1:nfound_proc(ip,1),1,ip)=igg_found(1:nfound_proc(ip,1),1,ip)
igg_found_snd(1:nfound_proc(ip,2),2,ip)=igg_found(1:nfound_proc(ip,2),2,ip)
enddo
CALL mp_alltoall( igg_found_snd, igg_found_rcv, intra_bgrp_comm )
if(ipol==1) then
allocate(ctabin_missing_rev_1(n_g_missing_m(ipol),2,nproc_bgrp))
ctabin_missing_rev_1(:,:,:)=0
else
allocate(ctabin_missing_rev_2(n_g_missing_m(ipol),2,nproc_bgrp))
ctabin_missing_rev_2(:,:,:)=0
endif
nfound_max=0
do ip=1,nproc_bgrp
do igg=1, n_g_missing_m(ipol)
if(igg_found_rcv(igg,1,ip) /= 0 ) then
found=.false.
do ig=1,ngw
if(igg_found_rcv(igg,1,ip)>0) then
if(ig_l2g(ig)==igg_found_rcv(igg,1,ip)) then
nfound_max=nfound_max+1
if(ipol==1) then
ctabin_missing_rev_1(igg,1,ip)=ig
else
ctabin_missing_rev_2(igg,1,ip)=ig
endif
found=.true.
endif
else
if(ig_l2g(ig)==-igg_found_rcv(igg,1,ip)) then
nfound_max=nfound_max+1
if(ipol==1) then
ctabin_missing_rev_1(igg,1,ip)=-ig
else
ctabin_missing_rev_2(igg,1,ip)=-ig
endif
found=.true.
endif
endif
enddo
if(.not.found) write(stdout,*) 'NOT FOUND:', igg_found_rcv(igg,1,ip)
endif
enddo
do igg=1, n_g_missing_m(ipol)
if(igg_found_rcv(igg,2,ip) /= 0 ) then
found=.false.
do ig=1,ngw
if(igg_found_rcv(igg,2,ip)>0) then
if(ig_l2g(ig)==igg_found_rcv(igg,2,ip)) then
nfound_max=nfound_max+1
if(ipol==1) then
ctabin_missing_rev_1(igg,2,ip)=ig
else
ctabin_missing_rev_2(igg,2,ip)=ig
endif
found=.true.
endif
else
if(ig_l2g(ig)==-igg_found_rcv(igg,2,ip)) then
nfound_max=nfound_max+1
if(ipol==1) then
ctabin_missing_rev_1(igg,2,ip)=-ig
else
ctabin_missing_rev_2(igg,2,ip)=-ig
endif
found=.true.
endif
endif
enddo
if(.not.found) write(stdout,*) 'NOT FOUND:', igg_found_rcv(igg,2,ip)
endif
enddo
enddo
call mp_sum(nfound_max, intra_bgrp_comm)
!write(stdout,*) 'Found check', nfound_max
deallocate(igg_found_snd,igg_found_rcv)
enddo
deallocate(igg_found, ig_send)
! workaround by PG to avoid a large array like mill_g allocated all the time
deallocate ( mill_g )
return
end subroutine gtable_missing_inv