-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy paths_msg.F
1657 lines (1640 loc) · 54.1 KB
/
s_msg.F
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 initmess
c
c=======================================================================
c
c @(#) SCCS module: s_msg.F version: 1.1
c Creation date: 10/13/97
c
c=======================================================================
c slave subroutine to initialise message passing logic
c=======================================================================
c
#include "def_slave.h"
#include "param.h"
#include "mesdta.h"
c
c set logical values
c
lsend = .true.
lbrkpt = .false.
ltsip = .false.
ltsiw = .false.
lsnapp = .false.
larchp = .false.
c
c set flags to indicate that all boundary data is in place at the
c start of the first timestep
c
nfalse(1)=0
nfalse(2)=0
iclnclr = 0
lbcln = .false.
lbtrp = .false.
itrpclr = 0
c
return
end
subroutine schkpnt(iposn0)
c
c=======================================================================
c slave subroutine to report to master and wait until
c message to proceed has arrived
c=======================================================================
c
c input: iposn0 - position
c
#include "param.h"
#include "mesdta.h"
c
c send position message MSG_POSN
c
iposn = iposn0
call s_send(MSG_POSN)
c
c process messages until continue (message MSG_CONT) received
c and flag set
c
lbrkpt = .false.
10 call s_recv(MSG_ANY)
if(.not.lbrkpt)goto 10
return
end
subroutine sendposn(iposn0)
c
c=======================================================================
c slave subroutine to report position to master
c=======================================================================
c
c input: iposn0 - position
c
#include "param.h"
#include "mesdta.h"
c
c send position message MSG_POSN
c
iposn = iposn0
call s_send(MSG_POSN)
c
c exit
c
return
end
subroutine initslvc(n)
c
c=======================================================================
c initialise slave flags ready to receive 'ready to send' messages
c=======================================================================
c
#include "param.h"
#include "mesdta.h"
c
if(n.eq.1) then
lbcln = .false.
iclnclr = 0
else
lbtrp = .false.
itrpclr = 0
endif
return
end
subroutine initslvd(n)
c
c=======================================================================
c initialise slave message passing logic ready to receive new data
c=======================================================================
c
c iota = true for all but outer halo points at all times
c = false for outer halo points before data arrives
c
#include "param.h"
#include "ctmngr.h"
#include "mesdta.h"
#include "switch.h"
#include "timelv.h"
c
do 10 j = 1, JMT_S
do 10 i = 1, IMT_S
iota(i,j,n) = .true.
10 continue
c
do 20 k = 1, nouter
i = iout(k)
j = jout(k)
iota(i,j,n) = .false.
20 continue
nfalse(n) = nouter
c
if(n.eq.1) then
do 30 na = 1, nactive
bclnflg(na)=.false.
30 continue
itt3 = itt
np3 = np
if(mxpas2)then
ittp3 = 2
else
ittp3 = 1
endif
else
do 40 na = 1, nactive
btrpflg(na)=.false.
40 continue
itt2 = itt
itbt2 = itbt
itbtp2 = itbtp
np02 = np0
endif
c
return
end
subroutine msgbye
c
c=======================================================================
c subroutine to send the MSG_BYE message to the master process.
c This subroutine is a copy of the entry in the block-if in s_send
c and should only be used to send the message from within s_send
c in order to avoid recursion. Other routines in s_msg can use
c "call s_send(MSG_BYE)". Other routines should use "call s_abort".
c=======================================================================
c
#include "param.h"
#include "mesdta.h"
#include "switch.h"
#include "iounit.h"
double precision time0,time1
c
c Note: pvmfinitsend will clear the buffer of any partially packed
c messages.
c
MPII = MPI_INTEGER
MPIR = MPI_REAL
MPIL = LENBUF*4
MPIC = MPI_COMM_WORLD
c
c turn transmit flags off
c
lsend = .false.
lsnapq = .false.
larchq = .false.
c
time0 = MPI_WTIME()
c
10 call MPI_BSEND(me,1,MPII,0,MSG_BYE,MPIC,ierr)
call S_BERR(ierr,*10)
if(ierr.ne.0)then
time1 = MPI_WTIME()
if(time1-time0.lt.10.0)then
call s_recv(MSG_ANY)
ierr = 0
goto 10
endif
call MPI_ABORT(MPIC,-999)
stop
endif
c
if(idebug.gt.3)then
write(ioslave,*)' Slave, routine msgbye ',
& ' message MSG_BYE sent.'
endif
c
call schkpnt(1)
call closedown(info)
stop
end
subroutine s_abort
c
c=======================================================================
c subroutine to abort slave
c=======================================================================
c
#include "param.h"
#include "mesdta.h"
#include "iounit.h"
c
write(ioslave,*)' Slave, routine s_abort entered'
call s_send(MSG_BYE)
return
end
subroutine s_send(msgtype)
c
c=======================================================================
c generic message handling subroutine for moma.pvm. This
c subroutine is used by the slave programs to pack
c and send messages.
c=======================================================================
c
#include "def_slave.h"
#include "param.h"
#include "scalar.h"
#include "slabs.h"
#include "frees.h"
#include "switch.h"
#include "iounit.h"
#include "cdiag.h"
#include "chmix.h"
#include "cvbc.h"
#include "ctmngr.h"
#include "timelv.h"
#include "levind.h"
#include "archive.h"
#include "snaps.h"
#include "varinfo.h"
#include "mesdta.h"
integer msgtype
MPII = MPI_INTEGER
MPIR = MPI_REAL
MPIL = LENBUF*4
MPIC = MPI_COMM_WORLD
c
c=======================================================================
c Type MSG_BYE: inform the master that the slave is aborting
c=======================================================================
c
if(msgtype.eq.MSG_BYE)then
101 call MPI_BSEND(me,1,MPII,0,msgtype,MPIC,ierr)
call S_BERR(ierr,*101)
if(idebug.gt.3)then
write(ioslave,*)' Slave - message MSG_BYE sent. '
endif
c
c turn transmit flags off
c
lsend = .false.
lsnapq = .false.
larchq = .false.
call schkpnt(1)
call closedown(info)
stop
c
c=======================================================================
c Type MSG_POSN: send status information message
c=======================================================================
c
elseif(msgtype.eq.MSG_POSN)then
ibufout(1) = me
ibufout(2) = iposn
ibufout(3) = itt
ibufout(4) = itbt
102 call MPI_BSEND(ibufout,4,MPII,0,msgtype,MPIC,ierr)
call S_BERR(ierr,*102)
if(idebug.gt.3)then
write(ioslave,"(a,i5)")
& ' Slave - message MSG_POSN sent. iposn=',iposn
endif
c
c=======================================================================
c Type MSG_OUTSTR: send string 'outstr' for printing by master
c=======================================================================
c
elseif(msgtype.eq.MSG_OUTSTR) then
ib = 0
call MPI_PACK(me ,1,MPII,bufout,MPIL,ib,MPIC,ierr)
call MPI_PACK(outstr,80,MPI_CHARACTER,bufout,MPIL,ib,
& MPIC,ierr)
103 call MPI_BSEND(bufout,ib,MPI_PACKED,0,msgtype,MPIC,ierr)
call S_BERR(ierr,*103)
if(idebug.gt.3)then
write(ioslave,"(a,/,' :',a,':')")
& ' Slave - message MSG_OUTSTR sent. outstr =',outstr
endif
c
c=======================================================================
c Type MSG_CLR_MET: tell the master that this slave is ready for
c the next set of met data
c=======================================================================
c
elseif(msgtype.eq.MSG_CLR_MET) then
ibufout(1) = me
ibufout(2) = mnextp
104 call MPI_BSEND(ibufout,2,MPII,0,msgtype,MPIC,ierr)
call S_BERR(ierr,*104)
c
c set lmetq back to false to indicate that a met request has been sent
c
lmetq = .false.
c
if(idebug.gt.3)then
write(ioslave,"(a)")' Slave - message MSG_CLR_MET sent'
endif
c
c=======================================================================
c Type MSG_RY_TSI: pack and send time step information to master
c=======================================================================
c
elseif(msgtype.eq.MSG_RY_TSI) then
ib = 0
call MPI_PACK(me ,1,MPII,bufout,MPIL,ib,MPIC,ierr)
call MPI_PACK(itttsi,1,MPII,bufout,MPIL,ib,MPIC,ierr)
call MPI_PACK(volume,1,MPIR,bufout,MPIL,ib,MPIC,ierr)
call MPI_PACK(ektot ,1,MPIR,bufout,MPIL,ib,MPIC,ierr)
call MPI_PACK(dtabs(1),2,MPIR,bufout,MPIL,ib,MPIC,ierr)
105 call MPI_BSEND(bufout,ib,MPI_PACKED,0,msgtype,MPIC,ierr)
call S_BERR(ierr,*105)
if(idebug.gt.3)then
write(ioslave,"(a)")' Slave - message MSG_RY_TSI sent'
endif
c
c=======================================================================
c Type MSG_RY_ARC: pack and send partial archive reply to master
c=======================================================================
c
elseif(msgtype.eq.MSG_RY_ARC) then
c
c convert jarchu and jarchl to "slave indices" and limit to slave bounds
c
jarchl = max(1,jarchl-jswm1)
jarchu = min(jt,jarchu-jswm1)
nchk = 0
c
c pack and send requested data
c
do 50 j=jarchl,jarchu
do 50 i=2,itm1
if(kpn(i,j).eq.me) then
c
c initialise buffer
c
if(nchk.eq.0 .and.(vartgrd(idvar).or.kmu(i,j).ne.0))then
bufout(2) = ittsav
bufout(3) = idvar
lbuff = 3
endif
c
c convert to master indices and pack values
c
imast = mod(iswm1 + i-1,IMT_M) + 1
jmast = jswm1 + j
c
c Now pack requested variable(s) for this point
c
c
if(idvar.le.NUM2D.and.vartgrd(idvar)) then
nchk =nchk + 1
lbuff = lbuff+3
if(lbuff+1.gt.LENBUF)then
write(ioslave,*) ' error in s_send while packing',
& ' MSG_RY_ARC (1):'
write(ioslave,*) ' buffer overflow. lbuff =',lbuff
write(ioslave,*)idvar,vartgrd(idvar),nchk,LENBUF
write(ioslave,*)imast,jmast,i,j
call msgbye
endif
bufout(lbuff-2) = imast
bufout(lbuff-1) = jmast
bufout(lbuff ) = hsave(i,j,idvar)
elseif(idvar.le.NUM2D.and.kmu(i,j).ne.0) then
nchk =nchk + 1
lbuff = lbuff+3
if(lbuff+1.gt.LENBUF)then
write(ioslave,*) ' error in s_send while packing',
& ' MSG_RY_ARC (2):'
write(ioslave,*) ' buffer overflow. lbuff =',lbuff
write(ioslave,*)idvar,vartgrd(idvar),nchk,LENBUF
write(ioslave,*)imast,jmast,i,j
call msgbye
endif
bufout(lbuff-2) = imast
bufout(lbuff-1) = jmast
bufout(lbuff ) = hsave(i,j,idvar)
c
elseif(vartgrd(idvar)) then
nchk =nchk + 1
if(lbuff+3+kmt(i,j).gt.LENBUF)then
write(ioslave,*) ' error in s_send while packing',
& ' MSG_RY_ARC (3):'
write(ioslave,*) ' buffer overflow. lbuff =',lbuff
write(ioslave,*)idvar,vartgrd(idvar),nchk,LENBUF
write(ioslave,*)imast,jmast,i,j,kmt(i,j)
call msgbye
endif
bufout(lbuff+1) = imast
bufout(lbuff+2) = jmast
lbuff = lbuff+2
do 48 k = 1,kmt(i,j)
lbuff = lbuff+1
bufout(lbuff) = tsave(k,i,j,idvar-NUM2D)
48 continue
c
elseif(kmu(i,j).ne.0) then
nchk =nchk + 1
if(lbuff+3+kmu(i,j).gt.LENBUF)then
write(ioslave,*) ' error in s_send while packing',
& ' MSG_RY_ARC (4):'
write(ioslave,*) ' buffer overflow. lbuff =',lbuff
write(ioslave,*)idvar,vartgrd(idvar),nchk,LENBUF
write(ioslave,*)imast,jmast,i,j,kmu(i,j)
call msgbye
endif
bufout(lbuff+1) = imast
bufout(lbuff+2) = jmast
lbuff = lbuff+2
do 49 k = 1,kmu(i,j)
lbuff = lbuff+1
bufout(lbuff) = tsave(k,i,j,idvar-NUM2D)
49 continue
endif
endif
50 continue
c
c send buffer only if it has data in it
c
if(nchk.ne.0)then
c
c Pack a negative integer to indicate "end of message"
c
lbuff = lbuff + 1
bufout(lbuff) = -999
bufout(1) = lbuff
c
106 call MPI_BSEND(bufout,lbuff,MPIR,0,msgtype,MPIC,ierr)
call S_BERR(ierr,*106)
if(idebug.gt.3) then
write(ioslave,"(a,i5,a,i5)")
& ' Slave - message MSG_RY_ARC sent for idvar =',idvar,
& ' nsea chk = ',nchk
endif
else
if(idebug.gt.3) then
write(ioslave,*)' Slave - message MSG_RY_ARC not sent.',
& ' for idvar:',idvar, ' Slave had no data to send.'
endif
endif
c
c clear the "partial out-standing flag"
c
larchq = .false.
c
c=======================================================================
c Type MSG_RY_SNAP: pack and send partial snapshot reply to master
c=======================================================================
c
elseif(msgtype.eq.MSG_RY_SNAP) then
c
c
c pack and send requested data
c
idsvar=ispvar(idsnp)
kslev =isplev(idsnp)
nchk = 0
c
do 60 j=1,jt
do 60 i=2,itm1
if(kpn(i,j).eq.me.and.(kslev.le.kmu(i,j) .or.
& (vartgrd(idsvar).and.kslev.le.kmt(i,j)) ) ) then
c
c initialise buffer
c
if(nchk.eq.0)then
nchk = 1
bufout(2) = ittsnap
bufout(3) = idsnp
lbuff = 3
endif
c
c convert to master indices and pack values
c
imast = mod(iswm1 + i-1,IMT_M) + 1
jmast = jswm1 + j
c
c Now pack requested variable(s) for this point
c
lbuff = lbuff+3
if(lbuff+1.gt.LENBUF)then
write(ioslave,*) ' error in s_send while packing',
& ' MSG_RY_SNAP:'
write(ioslave,*) ' buffer overflow. m =',me
call msgbye
endif
bufout(lbuff-2) = imast
bufout(lbuff-1) = jmast
bufout(lbuff ) = snap2d(i,j,idsnp)
endif
60 continue
if(nchk.ne.0)then
c
c Pack a negative integer to indicate "end of message"
c
lbuff = lbuff + 1
bufout(lbuff) = -999
bufout(1) = lbuff
c
107 call MPI_BSEND(bufout,lbuff,MPIR,0,msgtype,MPIC,ierr)
call S_BERR(ierr,*107)
if(idebug.gt.3) then
write(ioslave,"(a,i5)")
& ' Slave - message MSG_RY_SNAP sent. idsnp = ',idsnp
endif
else
if(idebug.gt.3) then
write(ioslave,*)' Slave - message MSG_RY_SNAP not sent.',
& ' for idvar:',idvar, ' Slave had no data to send.'
endif
endif
c
c clear the "partial out-standing flag" plus "snapshot in progress"
c and snapshot needed this timestep" flags if this is the last field
c
lsnapq = .false.
if(idsnp.eq.NSNAPS)then
c unset snapts flag (in case next master request arrives early)
snapts = .false.
lsnapp = .false.
endif
c
c
c=======================================================================
c Type MSG_BOUND1: pack and send 3-d boundary information to other
c slaves
c=======================================================================
c
elseif (msgtype .eq. MSG_BOUND1) then
moffset=0
do 20 knb = nactive, 1, -1
mes=nactme(knb)
bufout(2) = me
bufout(3) = itt3
bufout(4) = ittp3
bufout(5) = nsend(mes)
lbuff = 5
do 10 m = moffset+1, moffset+nsend(mes)
if (isd(m,3) .ne. mes) then
write(ioslave,*) ' s_send. error while packing',
& ' MSG_BOUND1:'
write(ioslave,*) ' knb,mes,m,moffset,nsend(mes) = ',
& knb,mes,m,moffset,nsend(mes)
write(ioslave,*) ' isd(m,1),isd(m,2),isd(m,3) = ',
& isd(m,1),isd(m,2),isd(m,3)
call msgbye
endif
i = mod(isd(m,1)-1 + iswm1, IMT_M) + 1
j = isd(m,2) + jswm1
lbuff = lbuff + 2
if(lbuff+kmt(isd(m,1), isd(m,2))*2
& +kmu(isd(m,1), isd(m,2))*2 .gt.LENBUF)then
write(ioslave,*) ' error in s_send while packing',
& ' MSG_BOUND1:'
write(ioslave,*) ' buffer overflow'
write(ioslave,*) ' m,nsend(mes)= ', m,nsend(mes)
call msgbye
endif
bufout(lbuff-1) = i
bufout(lbuff ) = j
do 51 k=1, kmt(isd(m,1), isd(m,2))
lbuff = lbuff+1
bufout(lbuff) = t(k,isd(m,1),isd(m,2),1,np)
51 continue
do 52 k=1, kmt(isd(m,1), isd(m,2))
lbuff = lbuff+1
bufout(lbuff) = t(k,isd(m,1),isd(m,2),2,np)
52 continue
do 53 k=1, kmu(isd(m,1), isd(m,2))
lbuff = lbuff+1
bufout(lbuff) = u(k,isd(m,1),isd(m,2),np)
53 continue
do 54 k=1, kmu(isd(m,1), isd(m,2))
lbuff = lbuff+1
bufout(lbuff) = v(k,isd(m,1),isd(m,2),np)
54 continue
10 continue
c
bufout(1) = lbuff
108 call MPI_BSEND(bufout,lbuff,MPIR,mes,msgtype,MPIC,ierr)
call S_BERR(ierr,*108)
moffset=moffset + nsend(mes)
20 continue
if(idebug.gt.4)then
write(ioslave,"(a,i5,a,i8,a,i8)")
& ' Slave - message MSG_BOUND1 sent. iposn=',iposn,
& ' itt = ',itt3,' ittp = ',ittp3
endif
c
c=======================================================================
c Type MSG_BOUND2: pack and send 2-d boundary information to other
c slaves. Free surface timestep is incremented before sending
c=======================================================================
c
elseif (msgtype .eq. MSG_BOUND2) then
moffset = 0
do 40 knb = nactive, 1, -1
mes = nactme(knb)
bufout(2) = me
bufout(3) = itt2
bufout(4) = itbt2
bufout(5) = itbtp2
bufout(6) = nsend(mes)
lbuff = 6
do 30 m = moffset + 1, moffset+nsend(mes)
if (isd(m,3) .ne. mes) then
write(ioslave,*) ' s_send: error while packing MSG_BOUND2'
write(ioslave,*) ' isd,m,mes = ',
& isd(m,1),isd(m,2),isd(m,3),m,mes
call msgbye
endif
i = mod(isd(m,1) - 1 + iswm1, IMT_M) + 1
j = isd(m,2) + jswm1
c
lbuff = lbuff + 5
if(lbuff.gt.LENBUF)then
write(ioslave,*) ' s_send: error while packing MSG_BOUND2'
write(ioslave,*) ' buffer overflow'
write(ioslave,*) ' m,nsend(mes)= ', m,nsend(mes)
call msgbye
endif
bufout(lbuff-4) = i
bufout(lbuff-3) = j
bufout(lbuff-2) = h0(isd(m,1),isd(m,2),np0)
bufout(lbuff-1) = u0(isd(m,1),isd(m,2),np0)
bufout(lbuff ) = v0(isd(m,1),isd(m,2),np0)
30 continue
c
bufout(1) = lbuff
109 call MPI_BSEND(bufout,lbuff,MPIR,mes,msgtype,MPIC,ierr)
call S_BERR(ierr,*109)
moffset = moffset + nsend(mes)
40 continue
if(idebug.gt.4)then
write(ioslave,"(a,i5,a,i8,a,i8,a,i8)")
& ' Slave - message MSG_BOUND2 sent. iposn=',iposn,
& ' itt = ',itt2,' itbt = ',itbt2,' itbtp = ',itbtp2
endif
c
c=======================================================================
c Type MSG_CLR_BD1: inform active neighbours that you are ready for
c for the next batch of baroclinic boundary information
c=======================================================================
c
elseif (msgtype .eq. MSG_CLR_BD1) then
do iproc = 1,nactive
110 call MPI_BSEND(me,1,MPII,nactid(iproc),msgtype,MPIC,ierr)
call S_BERR(ierr,*110)
end do
if(idebug.gt.4)then
write(ioslave,"(a)")
& ' Slave. Message MSG_CLR_BD1 sent to active neighbours'
endif
c
c=======================================================================
c Type MSG_CLR_BD2: inform active neighbours that you are ready for
c for the next batch of barotropic boundary information
c=======================================================================
c
elseif (msgtype .eq. MSG_CLR_BD2) then
do iproc = 1,nactive
111 call MPI_BSEND(me,1,MPII,nactid(iproc),msgtype,MPIC,ierr)
call S_BERR(ierr,*111)
end do
if(idebug.gt.4)then
write(ioslave,"(a)")
& ' Slave. Message MSG_CLR_BD2 sent to active neighbours'
endif
c
c=======================================================================
c Unrecognised message type:
c=======================================================================
c
else
c
write(ioslave,901) msgtype
901 format(' Slave - trying to send message type: ',i5,
& '. Not yet implemented.')
write(outstr,901) msgtype
ib = 0
call MPI_PACK(me ,1,MPII,bufout,MPIL,ib,MPIC,ierr)
call MPI_PACK(outstr,80,MPI_CHARACTER,bufout,MPIL,ib,
& MPIC,ierr)
112 call MPI_BSEND(bufout,ib,MPI_PACKED,0,msgtype,MPIC,ierr)
call S_BERR(ierr,*112)
if(idebug.gt.3)then
write(ioslave,"(a)")
& ' Slave - message MSG_OUTSTR indicating error sent'
endif
endif
return
end
subroutine s_recv(msgtype)
c
c=======================================================================
c generic message handling subroutine for moma.pvm. This
c subroutine is used by the slave programs to wait for,
c receive and unpack messages from the master.
c=======================================================================
c
c if msgtype .ge. zero:
c 1. wait for required message and exit after processing
c otherwise:
c 1. check for, receive and unpack any waiting messages,
c and either set flags or respond.
c 2. check the message passing flags and send off messages
c which can now be sent
c
#include "def_slave.h"
#include "param.h"
#include "scalar.h"
#include "frees.h"
#include "slabs.h"
#include "switch.h"
#include "iounit.h"
#include "ctmngr.h"
#include "timelv.h"
#include "chmix.h"
#include "cvmix.h"
#include "cvbc.h"
#include "grdvar.h"
#include "coord.h"
#include "levind.h"
#include "archive.h"
#include "snaps.h"
#include "varinfo.h"
#include "mesdta.h"
c
integer msgtype
logical lflag
c
c=======================================================================
c PART 1. blocking or non-blocking receive.
c=======================================================================
c
MPII = MPI_INTEGER
MPIR = MPI_REAL
MPIL = LENBUF*4
MPIC = MPI_COMM_WORLD
c
c=======================================================================
c check for abort requests (usually from the Master)
c=======================================================================
c
call MPI_IPROBE(MPI_ANY_SOURCE,MSG_ABORT,
& MPIC,lflag,istat,ierr)
if (lflag) then
if(idebug.gt.3)then
write(ioslave,"(a)")' Slave - message MSG_ABORT received'
endif
call sendposn(1)
call closedown(info)
stop
endif
c
10 if(msgtype.ge.0)then
call MPI_PROBE(MPI_ANY_SOURCE,msgtype,MPIC,istat,ierr)
lflag = .true.
else
call MPI_IPROBE(MPI_ANY_SOURCE,MPI_ANY_TAG,
& MPIC,lflag,istat,ierr)
endif
c
c=======================================================================
c processes messages
c=======================================================================
c
if(lflag)then
msgtag = istat(MPI_TAG)
itid = istat(MPI_SOURCE)
c
c=======================================================================
c 0. Receive abort and close-down message
c=======================================================================
c
if(msgtag.eq.MSG_ABORT) then
call MPI_RECV(bufout,1,MPII,itid,msgtag,
& MPIC,istat,ierr)
if(idebug.gt.3)then
write(ioslave,"(a)")' Slave - message MSG_ABORT received'
endif
lsend = .false.
call sendposn(1)
call closedown(info)
stop
c
c=======================================================================
c 1. Receive message type MSG_CONT
c wait for permission to continue and set flag
c continue without further processing of messages
c=======================================================================
c
elseif(msgtag.eq.MSG_CONT) then
call MPI_RECV(bufout,1,MPII,itid,msgtag,
& MPIC,istat,ierr)
lbrkpt = .true.
if(idebug.gt.3)then
write(ioslave,"(a)")' Slave - message MSG_CONT received'
endif
return
c
c=======================================================================
c 2. Receive message type MSG_IDS
c receive and unpack tid information from the master
c=======================================================================
c
elseif(msgtag.eq.MSG_IDS) then
call MPI_RECV(ibufout,MPIL,MPII,itid,msgtag,MPIC,istat,ierr)
nproc = ibufout(1)
if(.false.)then
write(stdout,"(a)")' Slave - message MSG_IDS received'
endif
c
c=======================================================================
c 3. Receive message type MSG_CONTROL
c receive and unpack control information from the master
c=======================================================================
c
elseif(msgtag.eq.MSG_CONTROL) then
call MPI_RECV(bufout,MPIL,MPI_PACKED,itid,msgtag,
& MPIC,istat,ierr)
call MPI_GET_COUNT(istat,MPI_PACKED,lb,ierr)
ib = 0
call MPI_UNPACK(bufout,MPIL,ib,init ,1,MPII,MPIC,ierr)
call MPI_UNPACK(bufout,MPIL,ib,restrt,1,MPII,MPIC,ierr)
call MPI_UNPACK(bufout,MPIL,ib,eb ,1,MPII,MPIC,ierr)
call MPI_UNPACK(bufout,MPIL,ib,days ,1,MPIR,MPIC,ierr)
call MPI_UNPACK(bufout,MPIL,ib,tsi ,1,MPIR,MPIC,ierr)
call MPI_UNPACK(bufout,MPIL,ib,acor ,1,MPIR,MPIC,ierr)
call MPI_UNPACK(bufout,MPIL,ib,dgnsts,1,MPIR,MPIC,ierr)
call MPI_UNPACK(bufout,MPIL,ib,snapd ,1,MPIR,MPIC,ierr)
call MPI_UNPACK(bufout,MPIL,ib,archd ,1,MPIR,MPIC,ierr)
call MPI_UNPACK(bufout,MPIL,ib,dtts ,1,MPIR,MPIC,ierr)
call MPI_UNPACK(bufout,MPIL,ib,dtuv ,1,MPIR,MPIC,ierr)
call MPI_UNPACK(bufout,MPIL,ib,dtbt ,1,MPIR,MPIC,ierr)
call MPI_UNPACK(bufout,MPIL,ib,am ,1,MPIR,MPIC,ierr)
call MPI_UNPACK(bufout,MPIL,ib,ah ,1,MPIR,MPIC,ierr)
call MPI_UNPACK(bufout,MPIL,ib,fkpm ,1,MPIR,MPIC,ierr)
call MPI_UNPACK(bufout,MPIL,ib,fkph ,1,MPIR,MPIC,ierr)
call MPI_UNPACK(bufout,MPIL,ib,cdbot ,1,MPIR,MPIC,ierr)
call MPI_UNPACK(bufout,MPIL,ib,dxdeg ,1,MPIR,MPIC,ierr)
call MPI_UNPACK(bufout,MPIL,ib,dydeg ,1,MPIR,MPIC,ierr)
call MPI_UNPACK(bufout,MPIL,ib,dz ,KM,MPIR,MPIC,ierr)
#ifdef de_checkbd
call MPI_UNPACK(bufout,MPIL,ib,dchkbd ,1,MPIR,MPIC,ierr)
#endif
call MPI_UNPACK(bufout,MPIL,ib,nmix ,1,MPII,MPIC,ierr)
call MPI_UNPACK(bufout,MPIL,ib,ncon ,1,MPII,MPIC,ierr)
call MPI_UNPACK(bufout,MPIL,ib,ntbt ,1,MPII,MPIC,ierr)
call MPI_UNPACK(bufout,MPIL,ib,idebug,1,MPII,MPIC,ierr)
call MPI_UNPACK(bufout,MPIL,ib,iorest,1,MPII,MPIC,ierr)
call MPI_UNPACK(bufout,MPIL,ib,ispvar,NSNAPS,MPII,MPIC,ierr)
call MPI_UNPACK(bufout,MPIL,ib,isplev,NSNAPS,MPII,MPIC,ierr)
call MPI_UNPACK(bufout,MPIL,ib,fnrest,80,
& MPI_CHARACTER,MPIC,ierr)
if(idebug.gt.3)then
write(ioslave,"(a)")' Slave - message MSG_CONTROL received'
endif
c
c=======================================================================
c 4. Receive message type MSG_TOPOG
c=======================================================================
c
elseif(msgtag.eq.MSG_TOPOG) then
c
c-----------------------------------------------------------------------
c receive and unpack kmt and grid information from the master
c-----------------------------------------------------------------------
c
call MPI_RECV(bufout,MPIL,MPIR,itid,msgtag,MPIC,istat,ierr)
call MPI_GET_COUNT(istat,MPIR,lbuff,ierr)
if(lbuff.gt.LENBUF)then
write(ioslave,*) ' error in m_recv when receiving ',
& ' MSG_TOPOG'
write(ioslave,*) ' buffer overflow'
endif
lbuff1 = nint(bufout(1))
it = nint(bufout(2))
jt = nint(bufout(3))
icycl = nint(bufout(4))
iswm1 = nint(bufout(5))
jswm1 = nint(bufout(6))
stlon = bufout(7)
stlat = bufout(8)
lbuff = 8
do 20 j=1,jt
do 20 i=1,it
lbuff = lbuff+1
kmt(i,j) = bufout(lbuff)
20 continue
do 30 j=1,jt
do 30 i=1,it
lbuff = lbuff+1
kmu(i,j) = bufout(lbuff)
30 continue
do 40 j=1,jt
do 40 i=1,it
lbuff = lbuff+1
kpn(i,j) = bufout(lbuff)
40 continue
if(idebug.gt.3)then
write(ioslave,"(a)")' Slave - message MSG_TOPOG received'
endif
c
c=======================================================================
c 5. Receive message type MSG_RQ_TSI
c timestep 'tsi' information request from master
c=======================================================================
c
elseif(msgtag.eq.MSG_RQ_TSI)then
call MPI_RECV(itttsi2,1,MPII,itid,msgtag,MPIC,istat,ierr)
ltsip = .true.
if(idebug.gt.3)then
write(ioslave,"(a)")' Slave - message MSG_RQ_TSI received'
endif
c
c=======================================================================
c 6. Receive message type MSG_RQ_ARC
c timestep 'tsi' information request from master
c=======================================================================
c
elseif(msgtag.eq.MSG_RQ_ARC)then
larchq = .true.
call MPI_RECV(bufout,MPIL,MPI_PACKED,itid,msgtag,
& MPIC,istat,ierr)
call MPI_GET_COUNT(istat,MPI_PACKED,lb,ierr)
ib = 0
call MPI_UNPACK(bufout,MPIL,ib,ittarch,1,MPII,MPIC,ierr)
call MPI_UNPACK(bufout,MPIL,ib,idvar ,1,MPII,MPIC,ierr)
call MPI_UNPACK(bufout,MPIL,ib,jarchl ,1,MPII,MPIC,ierr)
call MPI_UNPACK(bufout,MPIL,ib,jarchu ,1,MPII,MPIC,ierr)
if(idebug.gt.3)then
write(ioslave,900)idvar,jarchl,jarchu,ittarch
write(outstr,900)idvar,jarchl,jarchu,ittarch
call s_send(MSG_OUTSTR)
900 format(' Slave - message MSG_RQ_ARC received, idvar = ',4I6)
endif
c
c=======================================================================
c 7. Receive message type MSG_ARC_CLR
c archive complete. Clear archive buffers
c=======================================================================
c
elseif(msgtag.eq.MSG_ARC_CLR)then
call MPI_RECV(ittarch,1,MPII,itid,msgtag,MPIC,istat,ierr)
if(ittarch.ne.ittsav) then
write(ioslave,901) ittarch, ittsav
write(outstr,901) ittarch, ittsav
call s_send(MSG_OUTSTR)
901 format(' Slave . Archive clear timestep mis-match',2i10)
endif
c unset archive flag (in case next master request arrives early)
archts = .false.
larchp = .false.
larchq = .false.
if(idebug.gt.3)then
write(ioslave,"(a)")
& ' Slave - message MSG_ARC_CLR received'
endif
c
c=======================================================================
c 8. Receive message type MSG_TIMEVAR restart time variables
c=======================================================================
c
elseif(msgtag.eq.MSG_TIMEVAR) then
call MPI_RECV(bufout,MPIL,MPIR,itid,msgtag,MPIC,istat,ierr)
call MPI_GET_COUNT(istat,MPIR,lbuff,ierr)
if(lbuff.gt.LENBUF)then