-
Notifications
You must be signed in to change notification settings - Fork 0
/
mpi_routines.f90
executable file
·1753 lines (1353 loc) · 58.7 KB
/
mpi_routines.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
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
!===============================================
subroutine block(n, p, irank, istart, iend, blcsz)
implicit none
integer,intent(in) :: n,p,irank
integer,intent(out) :: istart,iend
integer :: i
integer,dimension(0:p-1),intent(out) :: blcsz
do i=0,p-1
blcsz(i) = floor(real((n+p-i-1)/p))
enddo
istart = sum(blcsz(0:irank))-blcsz(irank)+1
iend = istart+blcsz(irank)-1
end subroutine block
!=================================================
subroutine mpi_workdistribution
use param
use mpih
use mpi_param
implicit none
integer :: i
if(.not. allocated(countj)) allocate(countj(0:numtasks-1))
if(.not. allocated(countjp)) allocate(countjp(0:numtasks-1))
if(.not. allocated(countk)) allocate(countk(0:numtasks-1))
!EP For PERIODIC pressure solver
call block(n2+1, numtasks, myid, jstartp, jendp, countjp)
djp=jendp-jstartp+1
call block(n2m, numtasks, myid, jstart, jend, countj)
dj=jend-jstart+1
call block(n3m, numtasks, myid, kstart, kend, countk)
dk=kend-kstart+1
!KZ FOR DEBUG
!write(*,*) "myid: ",myid, "kstart is: ", kstart, "kend is: ", kend
#ifdef DEBUG
write(*,*) "jstart: ",jstart
write(*,*) "jend: ",jend
write(*,*) "jstartp: ",jstart
write(*,*) "jendp: ",jend
write(*,*) "kstart: ",kstart
write(*,*) "kend: ",kend
#endif
if( dj .lt. 1 ) then
write(6,*)'process ',myid,' has work load <1 cell in j direction'
write(6,*)"Check grid dimensions and number of processes"
call MPI_Abort(MPI_COMM_WORLD, 1, ierr )
endif
if( dk .lt. 1 ) then
write(6,*)'process ',myid,' has work load <1 cell in k direction'
write(6,*)"Check grid dimensions and number of processes"
call MPI_Abort(MPI_COMM_WORLD, 1, ierr )
endif
if(.not. allocated(offsetjp)) allocate(offsetjp(0:numtasks-1))
if(.not. allocated(offsetj)) allocate(offsetj(0:numtasks-1))
if(.not. allocated(offsetk)) allocate(offsetk(0:numtasks-1))
offsetjp(:)=0
offsetj(:)=0
offsetk(:)=0
do i=1,numtasks-1
offsetjp(i)= offsetjp(i-1) + countjp(i-1)
offsetj(i)= offsetj(i-1) + countj(i-1)
offsetk(i)= offsetk(i-1) + countk(i-1)
end do
!-------For MPI-IO--------------------------------
mydata= n2*dk*n1
mydatam = n2m*dk*n1m
if(myid .eq. numtasks-1) mydata = n2*(dk+1)*n1
if(.not. allocated(countf)) allocate(countf(0:numtasks-1))
if(.not. allocated(offsetf)) allocate(offsetf(0:numtasks-1))
call MPI_ALLGATHER(mydata, 1, MPI_INTEGER, countf, 1, MPI_INTEGER, &
MPI_COMM_WORLD,ierr)
offsetf(:)=0
do i=1,numtasks-1
offsetf(i)= offsetf(i-1) + countf(i-1)
end do
!------------------------------------------------
end subroutine mpi_workdistribution
!===============================================
subroutine update_both_ghosts(n1,n2,q,ks,ke)
use mpih
implicit none
integer, intent(in) :: ks,ke
real,intent(inout) :: q(n1,n2,ks-lvlhalo:ke+lvlhalo)
integer,intent(in) :: n1,n2
integer :: mydata
integer :: my_down, my_up,tag
mydata= n1*n2*lvlhalo
my_down=myid-1
my_up=myid+1
if(myid .eq. 0) my_down=numtasks-1
if(myid .eq. numtasks-1) my_up=0
tag=1
call MPI_ISEND(q(1,1,ke-lvlhalo+1), mydata, MDP, &
my_up,tag,MPI_COMM_WORLD,req(1),ierr)
call MPI_ISEND(q(1,1,ks), mydata, MDP, &
my_down,tag,MPI_COMM_WORLD,req(2), ierr)
call MPI_IRECV(q(1,1,ks-lvlhalo), mydata, MDP, &
my_down,tag,MPI_COMM_WORLD,req(3),ierr)
call MPI_IRECV(q(1,1,ke+1), mydata, MDP, &
my_up, tag,MPI_COMM_WORLD,req(4),ierr)
call MPI_Waitall(4,req,status,ierr)
end subroutine update_both_ghosts
!=========================================
subroutine update_upper_ghost(n1,n2,q)
use mpih
use mpi_param, only: kstart,kend
implicit none
real,intent(inout) :: q(n1,n2,kstart-lvlhalo:kend+lvlhalo)
integer,intent(in) :: n1,n2
integer :: mydata
integer :: my_down, my_up,tag
mydata= n1*n2*lvlhalo
my_down= myid-1
my_up= myid+1
if(myid .eq. 0) my_down=numtasks-1
if(myid .eq. numtasks-1) my_up= 0
tag=1
call MPI_ISEND(q(1,1,kstart), mydata, MDP, &
my_down, tag, MPI_COMM_WORLD, req(1), ierr)
call MPI_IRECV(q(1,1,kend+1), mydata, MDP, &
my_up,tag, MPI_COMM_WORLD, req(2), ierr)
call MPI_Waitall(2,req,status,ierr)
end subroutine update_upper_ghost
!=========================================
subroutine update_lower_ghost(n1,n2,q)
use mpih
use mpi_param, only: kstart,kend
implicit none
real,intent(inout) :: q(n1,n2,kstart-lvlhalo:kend+lvlhalo)
integer,intent(in) :: n1,n2
integer :: mydata
integer :: my_down, my_up,tag
mydata= n1*n2*lvlhalo
my_down= myid-1
my_up= myid+1
if(myid .eq. 0) my_down= numtasks-1
if(myid .eq. numtasks-1) my_up= 0
tag=1
call MPI_ISEND(q(1,1,kend-lvlhalo+1), mydata, MDP, &
my_up, tag, MPI_COMM_WORLD, req(1), ierr)
call MPI_IRECV(q(1,1,kstart-lvlhalo), mydata, MDP, &
my_down,tag, MPI_COMM_WORLD, req(2), ierr)
call MPI_Waitall(2,req,status,ierr)
end subroutine update_lower_ghost
!=========================================
subroutine update_add_lower_ghost(q1)
use param, only: n1, n2
use mpi_param, only: kstart,kend
use mpih
implicit none
real,intent(inout) :: q1(n1,n2,kstart-1:kend+1)
real :: buf(n1,n2)
integer :: mydata
integer :: my_down, my_up,tag
integer :: kc,ii
mydata= n1*n2
my_down= myid-1
my_up= myid+1
buf=0.0d0
if(myid .eq. 0) my_down= numtasks-1
if(myid .eq. numtasks-1) my_up= 0
tag=1
call MPI_ISEND(q1(1,1,kend+1),mydata,MDP, my_up, tag, MPI_COMM_WORLD, req(1), ierr)
call MPI_IRECV(buf(1,1), mydata, MDP, my_down,tag, MPI_COMM_WORLD, req(2), ierr)
call MPI_Waitall(2,req,status,ierr)
kc = kstart
do ii = 1,n2
q1(:,ii,kc) = q1(:,ii,kc) + buf(:,ii)
end do
end subroutine update_add_lower_ghost
subroutine update_add_upper_ghost(q1)
use param, only: n1, n2
use mpi_param, only: kstart,kend
use mpih
implicit none
real,intent(inout) :: q1(n1,n2,kstart-lvlhalo:kend+lvlhalo)
real :: buf(n1,n2)
integer :: mydata
integer :: my_down, my_up,tag
integer :: kc,ii
!write(*,*) "proc", myid, "entering upperGhost routine"
mydata= n1*n2
my_down= myid-1
my_up= myid+1
buf=0.0d0
if(myid .eq. 0) my_down= numtasks-1
if(myid .eq. numtasks-1) my_up= 0
tag=1
call MPI_ISEND(q1(1,1,kstart-1),mydata,MDP, my_down, tag, MPI_COMM_WORLD, req(1), ierr)
call MPI_IRECV(buf(1,1), mydata, MDP, my_up,tag, MPI_COMM_WORLD, req(2), ierr)
call MPI_Waitall(2,req,status,ierr)
!write(*,*) "myid starting loop", myid
kc=kend
do ii=1,n2
q1(:,ii,kc) = q1(:,ii,kc) + buf(:,ii)
enddo
end subroutine update_add_upper_ghost
!
subroutine get_prow_pcol
! KZ: auxilary pencil routine for pencil-accelerated ray-tagging
use mpih
implicit none
integer :: i, factor1, factor2
real :: aspect_ratio, best_aspect_ratio
! First, find the best choice of p_row * p_col given numtasks
! Initialize best aspect ratio to a large value
best_aspect_ratio = 1.0e30
p_row = 1
p_col = numtasks
! Loop over possible factors of numtasks
do i = 1, int(sqrt(real(numtasks, 8)))
if (mod(numtasks, i) == 0) then
! i is a factor, so numtasks / i is the corresponding pair
factor1 = i
factor2 = numtasks / i
! Compute the aspect ratio and find the best one
aspect_ratio = abs(real(factor1, 8) / real(factor2, 8) - 1.0)
if (aspect_ratio < best_aspect_ratio) then
best_aspect_ratio = aspect_ratio
p_row = factor1
p_col = factor2
end if
end if
end do
my_p_row = myid / p_col
my_p_col = mod(myid, p_col)
!write(*,*) "Total prow, pcol: ", p_row, p_col
end subroutine get_prow_pcol
!==============================================
subroutine mpi_globalsum_double_arr(var,nvar)
use mpih
implicit none
real,intent(inout),dimension(nvar) :: var
real,dimension(nvar) :: var2
integer,intent(in) :: nvar
call MPI_ALLREDUCE(var,var2,nvar,MPI_DOUBLE_PRECISION, &
MPI_SUM,MPI_COMM_WORLD,ierr)
var = var2
end subroutine mpi_globalsum_double_arr
subroutine mpi_globalsum_double_var(var)
use mpih
implicit none
real,intent(inout) :: var
real :: var2
call MPI_ALLREDUCE(var,var2,1,MPI_DOUBLE_PRECISION, MPI_SUM,MPI_COMM_WORLD,ierr)
var = var2
end subroutine mpi_globalsum_double_var
!==============================================
subroutine mpi_globalsum_double_forc(var)
use mpih
implicit none
real,intent(inout),dimension(6,7,7,7) :: var
real,dimension(6,7,7,7) :: var2
! integer :: nvar=1715
integer :: nvar=2058!6*7*7*7
call MPI_ALLREDUCE(var,var2,nvar,MPI_DOUBLE_PRECISION, &
MPI_SUM,MPI_COMM_WORLD,ierr)
var = var2
end subroutine mpi_globalsum_double_forc
!==================================================
subroutine mem_dealloc
use local_arrays
use local_aux
use mpi_param
use stat_arrays
use mls_param
use mls_local
implicit none
if(allocated(vx)) deallocate(vx)
if(allocated(vy)) deallocate(vy)
if(allocated(vz)) deallocate(vz)
if(allocated(temp)) deallocate(temp)
if(allocated(qcap)) deallocate(qcap)
if(allocated(pr)) deallocate(pr)
if(allocated(rhs)) deallocate(rhs)
if(allocated(dph)) deallocate(dph)
if(allocated(ru1)) deallocate(ru1)
if(allocated(ru2)) deallocate(ru2)
if(allocated(ru3)) deallocate(ru3)
if(allocated(vorx)) deallocate(vorx)
if(allocated(vory)) deallocate(vory)
if(allocated(vorz)) deallocate(vorz)
!---------------------------------------
if(allocated(countj)) deallocate(countj)
if(allocated(countk)) deallocate(countk)
if(allocated(offsetj)) deallocate(offsetj)
if(allocated(offsetk)) deallocate(offsetk)
if(allocated(countf)) deallocate(countf)
if(allocated(offsetf)) deallocate(offsetf)
if(allocated(vx_me)) deallocate(vx_me)
if(allocated(vy_me)) deallocate(vy_me)
if(allocated(vz_me)) deallocate(vz_me)
if(allocated(vx_rms)) deallocate(vx_rms)
if(allocated(vy_rms)) deallocate(vy_rms)
if(allocated(vz_rms)) deallocate(vz_rms)
if(allocated(pr_rms)) deallocate(pr_rms)
if(allocated(pr_me)) deallocate(pr_me)
!------------------------------------------
! KZ HIT stuff
deallocate( waveN )
deallocate( bhat )
deallocate( exp_I_kl_xi, exp_I_km_yj, exp_I_kn_zk)
deallocate( exp_I_kl_xsi, exp_I_km_ysj, exp_I_kn_zsk)
! KZ: IBM stuff
! Cell-tagging masks
if(allocated(VOFx)) deallocate(VOFx)
if(allocated(VOFy)) deallocate(VOFy)
if(allocated(VOFz)) deallocate(VOFz)
if(allocated(VOFp)) deallocate(VOFp)
if(allocated(d_UsolidT_dxj)) deallocate(d_UsolidT_dxj)
if(allocated(solid_mask)) deallocate(solid_mask)
! HIT forcing field
if(allocated(forcx)) deallocate(forcx)
if(allocated(forcy)) deallocate(forcy)
if(allocated(forcz)) deallocate(forcz)
! IBM force
if(allocated(for_xc)) deallocate(for_xc)
if(allocated(for_yc)) deallocate(for_yc)
if(allocated(for_zc)) deallocate(for_zc)
if(allocated(for_temp)) deallocate(for_temp)
end subroutine mem_dealloc
!================================================
subroutine mpi_write_continua
use param
use mpih
use mpi_param, only: kstart,kend
use local_arrays, only: vy,vz,vx,pr,temp
use hdf5
implicit none
integer hdf_error
integer(HID_T) :: file_id
integer(HID_T) :: filespace
integer(HID_T) :: slabspace
integer(HID_T) :: memspace
integer(HID_T) :: dset_vx
integer(HID_T) :: dset_vy
integer(HID_T) :: dset_vz
integer(HID_T) :: dset_pr
integer(HID_T) :: dset_temp
integer(HID_T) :: dset_enst
integer(HSIZE_T) :: dims(3)
integer(HID_T) :: plist_id
integer(HSIZE_T), dimension(3) :: data_count
integer(HSSIZE_T), dimension(3) :: data_offset
integer(HSIZE_T) :: dims_grid(1)
integer(HID_T) :: dset_grid
integer(HID_T) :: dspace_grid
integer :: comm, info
integer :: ndims
character(40) filnam2,filnam3,filnam4
character(40) filnamgrid,filnam5,filnam6
!RO Sort out MPI definitions
comm = MPI_COMM_WORLD
info = MPI_INFO_NULL
!RO Form the name of the file
filnam2 = 'continuation/continua_vx.h5'
filnam3 = 'continuation/continua_vy.h5'
filnam4 = 'continuation/continua_vz.h5'
filnam5 = 'continuation/continua_pr.h5'
filnam6 = 'continuation/continua_temp.h5'
!RO Set offsets and element counts
ndims = 3
dims(1)=n1
dims(2)=n2
dims(3)=n3m
call h5screate_simple_f(ndims, dims, filespace, hdf_error)
data_count(1) = n1
data_count(2) = n2
data_count(3) = kend-kstart+1
data_offset(1) = 0
data_offset(2) = 0
data_offset(3) = kstart-1
!RO pressure
call h5pcreate_f(H5P_FILE_ACCESS_F, plist_id, &
hdf_error)
call h5pset_fapl_mpio_f(plist_id, comm, info, &
hdf_error)
call h5fcreate_f(filnam5, H5F_ACC_TRUNC_F, file_id, &
hdf_error, access_prp=plist_id)
call h5pclose_f(plist_id, hdf_error)
call h5dcreate_f(file_id, 'pr', H5T_NATIVE_DOUBLE, &
filespace, dset_pr, hdf_error)
call h5screate_simple_f(ndims, data_count, memspace, hdf_error)
call h5dget_space_f(dset_pr, slabspace, hdf_error)
call h5sselect_hyperslab_f (slabspace, H5S_SELECT_SET_F,&
data_offset, data_count, hdf_error)
call h5pcreate_f(H5P_DATASET_XFER_F, plist_id, hdf_error)
call h5pset_dxpl_mpio_f(plist_id, H5FD_MPIO_COLLECTIVE_F, &
hdf_error)
call h5dwrite_f(dset_pr, H5T_NATIVE_DOUBLE, &
pr(1:n1,1:n2,kstart:kend), dims, &
hdf_error, file_space_id = slabspace, mem_space_id = memspace, &
xfer_prp = plist_id)
call h5pclose_f(plist_id, hdf_error)
call h5dclose_f(dset_pr, hdf_error)
call h5sclose_f(memspace, hdf_error)
call h5fclose_f(file_id, hdf_error)
!EP vx
call h5pcreate_f(H5P_FILE_ACCESS_F, plist_id, hdf_error)
call h5pset_fapl_mpio_f(plist_id, comm, info, hdf_error)
call h5fcreate_f(filnam2, H5F_ACC_TRUNC_F, file_id, &
hdf_error, access_prp=plist_id)
call h5pclose_f(plist_id, hdf_error)
call h5dcreate_f(file_id, 'Vx', H5T_NATIVE_DOUBLE, &
filespace, dset_vx, hdf_error)
call h5screate_simple_f(ndims, data_count, memspace, hdf_error)
call h5dget_space_f(dset_vx, slabspace, hdf_error)
call h5sselect_hyperslab_f (slabspace, H5S_SELECT_SET_F, &
data_offset, data_count, hdf_error)
call h5pcreate_f(H5P_DATASET_XFER_F, plist_id, hdf_error)
call h5pset_dxpl_mpio_f(plist_id, H5FD_MPIO_COLLECTIVE_F, &
hdf_error)
call h5dwrite_f(dset_vx, H5T_NATIVE_DOUBLE, &
vx(1:n1,1:n2,kstart:kend), dims, &
hdf_error, file_space_id = slabspace, mem_space_id = memspace, &
xfer_prp = plist_id)
call h5pclose_f(plist_id, hdf_error)
call h5dclose_f(dset_vx, hdf_error)
call h5sclose_f(memspace, hdf_error)
call h5fclose_f(file_id, hdf_error)
!EP vy
call h5pcreate_f(H5P_FILE_ACCESS_F, plist_id, hdf_error)
call h5pset_fapl_mpio_f(plist_id, comm, info, hdf_error)
call h5fcreate_f(filnam3, H5F_ACC_TRUNC_F, file_id, &
hdf_error, access_prp=plist_id)
call h5pclose_f(plist_id, hdf_error)
call h5dcreate_f(file_id, 'Vy', H5T_NATIVE_DOUBLE, &
filespace, dset_vy, hdf_error)
call h5screate_simple_f(ndims, data_count, memspace, hdf_error)
call h5dget_space_f(dset_vy, slabspace, hdf_error)
call h5sselect_hyperslab_f (slabspace, H5S_SELECT_SET_F, &
data_offset, data_count, hdf_error)
call h5pcreate_f(H5P_DATASET_XFER_F, plist_id, hdf_error)
call h5pset_dxpl_mpio_f(plist_id, H5FD_MPIO_COLLECTIVE_F, &
hdf_error)
call h5dwrite_f(dset_vy, H5T_NATIVE_DOUBLE, &
vy(1:n1,1:n2,kstart:kend), dims, &
hdf_error, file_space_id = slabspace, mem_space_id = memspace, &
xfer_prp = plist_id)
call h5pclose_f(plist_id, hdf_error)
call h5dclose_f(dset_vy, hdf_error)
call h5sclose_f(memspace, hdf_error)
call h5fclose_f(file_id, hdf_error)
!EP vz
call h5pcreate_f(H5P_FILE_ACCESS_F, plist_id, hdf_error)
call h5pset_fapl_mpio_f(plist_id, comm, info, hdf_error)
call h5fcreate_f(filnam4, H5F_ACC_TRUNC_F, file_id, &
hdf_error, access_prp=plist_id)
call h5pclose_f(plist_id, hdf_error)
call h5dcreate_f(file_id, 'Vz', H5T_NATIVE_DOUBLE, &
filespace, dset_vz, hdf_error)
call h5screate_simple_f(ndims, data_count, memspace, hdf_error)
call h5dget_space_f(dset_vz, slabspace, hdf_error)
call h5sselect_hyperslab_f (slabspace, H5S_SELECT_SET_F, &
data_offset, data_count, hdf_error)
call h5pcreate_f(H5P_DATASET_XFER_F, plist_id, hdf_error)
call h5pset_dxpl_mpio_f(plist_id, H5FD_MPIO_COLLECTIVE_F, &
hdf_error)
call h5dwrite_f(dset_vz, H5T_NATIVE_DOUBLE, &
vz(1:n1,1:n2,kstart:kend), dims, &
hdf_error, file_space_id = slabspace, mem_space_id = memspace, &
xfer_prp = plist_id)
call h5pclose_f(plist_id, hdf_error)
call h5dclose_f(dset_vz, hdf_error)
call h5sclose_f(memspace, hdf_error)
call h5fclose_f(file_id, hdf_error)
! Temperature
call h5pcreate_f(H5P_FILE_ACCESS_F, plist_id, hdf_error)
call h5pset_fapl_mpio_f(plist_id, comm, info, hdf_error)
call h5fcreate_f(filnam6, H5F_ACC_TRUNC_F, file_id, &
hdf_error, access_prp=plist_id)
call h5pclose_f(plist_id, hdf_error)
call h5dcreate_f(file_id, 'Temp', H5T_NATIVE_DOUBLE, &
filespace, dset_temp, hdf_error)
call h5screate_simple_f(ndims, data_count, memspace, hdf_error)
call h5dget_space_f(dset_temp, slabspace, hdf_error)
call h5sselect_hyperslab_f (slabspace, H5S_SELECT_SET_F, &
data_offset, data_count, hdf_error)
call h5pcreate_f(H5P_DATASET_XFER_F, plist_id, hdf_error)
call h5pset_dxpl_mpio_f(plist_id, H5FD_MPIO_COLLECTIVE_F, &
hdf_error)
call h5dwrite_f(dset_temp, H5T_NATIVE_DOUBLE, &
temp(1:n1,1:n2,kstart:kend), dims, &
hdf_error, file_space_id = slabspace, mem_space_id = memspace, &
xfer_prp = plist_id)
call h5pclose_f(plist_id, hdf_error)
call h5dclose_f(dset_temp, hdf_error)
call h5sclose_f(memspace, hdf_error)
call h5fclose_f(file_id, hdf_error)
if (myid .eq. 0) then
open(13,file='continuation/continua_grid.dat',status='unknown')
rewind(13)
write(13,*) n1,n2,n3,time
close(13)
endif
!RO Write the grid & statistics information
!RO only if master process
if (myid.eq.0) then
ndims=1
filnamgrid = 'continuation/continua_master.h5'
call h5fcreate_f(filnamgrid,H5F_ACC_TRUNC_F, file_id, hdf_error)
!RO Write Reynolds number
dims_grid(1)=1
call h5screate_simple_f(ndims, dims_grid, dspace_grid, hdf_error)
call h5dcreate_f(file_id, 'Re', H5T_NATIVE_DOUBLE, &
dspace_grid, dset_grid, hdf_error)
call h5dwrite_f(dset_grid, H5T_NATIVE_DOUBLE, ren, &
dims_grid,hdf_error)
call h5dclose_f(dset_grid, hdf_error)
call h5sclose_f(dspace_grid, hdf_error)
!EP Write Prandtl number
dims_grid(1)=1
call h5screate_simple_f(ndims, dims_grid, dspace_grid, hdf_error)
call h5dcreate_f(file_id, 'Pr', H5T_NATIVE_DOUBLE, &
dspace_grid, dset_grid, hdf_error)
call h5dwrite_f(dset_grid, H5T_NATIVE_DOUBLE, pra, &
dims_grid,hdf_error)
call h5dclose_f(dset_grid, hdf_error)
call h5sclose_f(dspace_grid, hdf_error)
!RO Write the grid information
dims_grid(1)=n1
call h5screate_simple_f(ndims, dims_grid, dspace_grid, hdf_error)
call h5dcreate_f(file_id, 'X_cordin', H5T_NATIVE_DOUBLE, &
dspace_grid, dset_grid, hdf_error)
call h5dwrite_f(dset_grid, H5T_NATIVE_DOUBLE, xc(1:n1), &
dims_grid,hdf_error)
call h5dclose_f(dset_grid, hdf_error)
call h5sclose_f(dspace_grid, hdf_error)
dims_grid(1)=n2
call h5screate_simple_f(ndims, dims_grid, dspace_grid, hdf_error)
call h5dcreate_f(file_id, 'Y_cordin', H5T_NATIVE_DOUBLE, &
dspace_grid, dset_grid, hdf_error)
call h5dwrite_f(dset_grid, H5T_NATIVE_DOUBLE, yc(1:n2), &
dims_grid,hdf_error)
call h5dclose_f(dset_grid, hdf_error)
call h5sclose_f(dspace_grid, hdf_error)
dims_grid(1)=n3m
call h5screate_simple_f(ndims, dims_grid, dspace_grid, hdf_error)
call h5dcreate_f(file_id, 'Z_cordin', H5T_NATIVE_DOUBLE, &
dspace_grid, dset_grid, hdf_error)
call h5dwrite_f(dset_grid, H5T_NATIVE_DOUBLE, zm(1:n3m), &
dims_grid, hdf_error)
call h5dclose_f(dset_grid, hdf_error)
call h5sclose_f(dspace_grid, hdf_error)
!RO Close file
call h5fclose_f(file_id, hdf_error)
endif
end subroutine mpi_write_continua
!================================================
subroutine mpi_read_continua(n1o,n2o,n3o,ks,ke,intvar,qua)
use mpih
use param
use hdf5
implicit none
integer, intent(in) :: ks,ke,n2o,n1o,n3o
real, dimension(1:n1o,1:n2o,ks-1:ke+1)::qua
integer hdf_error
integer(HID_T) :: file_id
integer(HID_T) :: slabspace
integer(HID_T) :: memspace
integer(HID_T) :: dset_qua
integer(HSIZE_T) :: dims(3)
integer(HID_T) :: plist_id
integer(HSIZE_T), dimension(3) :: data_count
integer(HSSIZE_T), dimension(3) :: data_offset
integer :: comm, info
integer :: ndims
integer, intent(in) :: intvar
character*70 :: filnam1
character*10 :: dsetname
comm = MPI_COMM_WORLD
info = MPI_INFO_NULL
!EP Select file and dataset based on intvar
select case (intvar)
case (1)
dsetname = trim('Vx')
filnam1 = trim('continuation/continua_vx.h5')
case (2)
dsetname = trim('Vy')
filnam1 = trim('continuation/continua_vy.h5')
case (3)
dsetname = trim('Vz')
filnam1 = trim('continuation/continua_vz.h5')
case (4)
dsetname = trim('pr')
filnam1 = trim('continuation/continua_pr.h5')
case (5)
dsetname = trim('Temp')
filnam1 = trim('continuation/continua_temp.h5')
end select
!RO Set offsets and element counts
ndims = 3
dims(1)=n1o
dims(2)=n2o
dims(3)=n3o-1
data_count(1) = n1o
data_count(2) = n2o
data_count(3) = ke-ks+1
data_offset(1) = 0
data_offset(2) = 0
data_offset(3) = ks-1
! call h5open_f(hdf_error)
call h5pcreate_f(H5P_FILE_ACCESS_F, plist_id, hdf_error)
call h5pset_fapl_mpio_f(plist_id, comm, info, hdf_error)
call h5fopen_f(filnam1, H5F_ACC_RDONLY_F, file_id, hdf_error, access_prp=plist_id)
call h5pclose_f(plist_id, hdf_error)
call h5dopen_f(file_id, dsetname, dset_qua, hdf_error)
call h5screate_simple_f(ndims, data_count, memspace, hdf_error)
call h5dget_space_f(dset_qua, slabspace, hdf_error)
call h5sselect_hyperslab_f (slabspace, H5S_SELECT_SET_F, data_offset, data_count, hdf_error)
call h5pcreate_f(H5P_DATASET_XFER_F, plist_id, hdf_error)
call h5pset_dxpl_mpio_f(plist_id, H5FD_MPIO_COLLECTIVE_F, hdf_error)
call h5dread_f(dset_qua, H5T_NATIVE_DOUBLE, &
qua(1:n1o,1:n2o,ks:ke), dims, &
hdf_error, file_space_id = slabspace, mem_space_id = memspace, &
xfer_prp = plist_id)
call h5pclose_f(plist_id, hdf_error)
call h5dclose_f(dset_qua, hdf_error)
call h5sclose_f(memspace, hdf_error)
call h5fclose_f(file_id, hdf_error)
! call h5close_f(hdf_error)
if(myid.eq.0)write(*,'(5x,a)')'reading complete: '//filnam1
end subroutine mpi_read_continua
!================================================
subroutine mpi_write_field
use param
use mpih
use mpi_param, only: kstart,kend
use local_arrays, only: vy,vz,vx,pr,temp
use hdf5
implicit none
integer ic,jc,kc
integer hdf_error
integer(HID_T) :: file_id
integer(HID_T) :: filespace
integer(HID_T) :: slabspace
integer(HID_T) :: memspace
integer(HID_T) :: dset_vx
integer(HID_T) :: dset_vy
integer(HID_T) :: dset_vz
integer(HID_T) :: dset_pr
integer(HID_T) :: dset_temp
integer(HID_T) :: dset_VOFx
integer(HID_T) :: dset_VOFy
integer(HID_T) :: dset_VOFz
integer(HID_T) :: dset_VOFp
integer(HSIZE_T) :: dims(3)
integer(HID_T) :: plist_id
integer(HSIZE_T), dimension(3) :: data_count
integer(HSSIZE_T), dimension(3) :: data_offset
integer(HSIZE_T) :: dims_grid(1)
integer(HID_T) :: dset_grid
integer(HID_T) :: dspace_grid
integer :: comm, info
integer :: ndims
real tprfi
integer itime
character(70) filnam2,filnam3,filnam4,xdmnam
character(70) filnamgrid,filnam5,filnam6
character(7) ipfi
tprfi = 1/tframe
itime=nint(time*tprfi)
write(ipfi,82)itime
82 format(i7.7)
!RO Sort out MPI definitions
comm = MPI_COMM_WORLD
info = MPI_INFO_NULL
!RO Form the name of the file
! filnam2 = 'continuation/field.h5'
filnam2 = 'continuation/field_'//ipfi//'.h5'
xdmnam = 'continuation/field_'//ipfi//'.xmf'
!RO Set offsets and element counts
ndims = 3
dims(1)=n1
dims(2)=n2
dims(3)=n3m
call h5screate_simple_f(ndims, dims, filespace, hdf_error)
data_count(1) = n1
data_count(2) = n2
data_count(3) = kend-kstart+1
data_offset(1) = 0
data_offset(2) = 0
data_offset(3) = kstart-1
!EP vx
call h5pcreate_f(H5P_FILE_ACCESS_F, plist_id, hdf_error)
call h5pset_fapl_mpio_f(plist_id, comm, info, hdf_error)
call h5fcreate_f(filnam2, H5F_ACC_TRUNC_F, file_id, &
hdf_error, access_prp=plist_id)
call h5pclose_f(plist_id, hdf_error)
call h5dcreate_f(file_id, 'Vx', H5T_NATIVE_DOUBLE, &
filespace, dset_vx, hdf_error)
call h5dcreate_f(file_id, 'Vy', H5T_NATIVE_DOUBLE, &
filespace, dset_vy, hdf_error)
call h5dcreate_f(file_id, 'Vz', H5T_NATIVE_DOUBLE, &
filespace, dset_vz, hdf_error)
call h5dcreate_f(file_id, 'Pr', H5T_NATIVE_DOUBLE, &
filespace, dset_pr, hdf_error)
call h5dcreate_f(file_id, 'Temp', H5T_NATIVE_DOUBLE, &
filespace, dset_temp, hdf_error)
call h5dcreate_f(file_id, 'VOFx', H5T_NATIVE_DOUBLE, &
filespace, dset_VOFx, hdf_error)
call h5dcreate_f(file_id, 'VOFy', H5T_NATIVE_DOUBLE, &
filespace, dset_VOFy, hdf_error)
call h5dcreate_f(file_id, 'VOFz', H5T_NATIVE_DOUBLE, &
filespace, dset_VOFz, hdf_error)
call h5dcreate_f(file_id, 'VOFp', H5T_NATIVE_DOUBLE, &
filespace, dset_VOFp, hdf_error)
call h5screate_simple_f(ndims, data_count, memspace, hdf_error)
! vx
call h5dget_space_f(dset_vx, slabspace, hdf_error)
call h5sselect_hyperslab_f (slabspace, H5S_SELECT_SET_F, &
data_offset, data_count, hdf_error)
call h5pcreate_f(H5P_DATASET_XFER_F, plist_id, hdf_error)
call h5pset_dxpl_mpio_f(plist_id, H5FD_MPIO_COLLECTIVE_F, &
hdf_error)
call h5dwrite_f(dset_vx, H5T_NATIVE_DOUBLE, &
vx(1:n1,1:n2,kstart:kend), dims, &
hdf_error, file_space_id = slabspace, mem_space_id = memspace, &
xfer_prp = plist_id)
! vy
call h5dget_space_f(dset_vy, slabspace, hdf_error)
call h5sselect_hyperslab_f (slabspace, H5S_SELECT_SET_F, &
data_offset, data_count, hdf_error)
call h5pcreate_f(H5P_DATASET_XFER_F, plist_id, hdf_error)
call h5pset_dxpl_mpio_f(plist_id, H5FD_MPIO_COLLECTIVE_F, &
hdf_error)
call h5dwrite_f(dset_vy, H5T_NATIVE_DOUBLE, &
vy(1:n1,1:n2,kstart:kend), dims, &
hdf_error, file_space_id = slabspace, mem_space_id = memspace, &
xfer_prp = plist_id)
!vz