-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathMacMPI_X.f
7476 lines (7476 loc) · 257 KB
/
MacMPI_X.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
c-----------------------------------------------------------------------
c Partial MPI library based on Open Transport in the Macintosh OS,
c using TCP/IP protocol.
c No local buffering of messages is implemented, so that all messages
c must be received in the order sent, and receives with wildcard
c sources are not supported. the following subroutines are implemented:
c MPI_INIT, MPI_FINALIZE, MPI_SEND, MPI_RECV, MPI_ISEND, MPI_IRECV
c MPI_TEST, MPI_WAIT, MPI_SENDRECV, MPI_SSEND, MPI_ISSEND, MPI_WAITALL
c MPI_WAITANY, MPI_GET_COUNT, MPI_INITIALIZED, MPI_COMM_SIZE
c MPI_COMM_RANK, MPI_COMM_DUP, MPI_COMM_SPLIT, MPI_COMM_FREE
c MPI_CART_CREATE, MPI_CART_COORDS, MPI_CART_GET, MPI_CART_SHIFT
c MPI_CART_RANK, MPI_CART_SUB, MPI_DIMS_CREATE
c MPI_BCAST, MPI_BARRIER, MPI_REDUCE, MPI_SCAN
c MPI_ALLREDUCE, MPI_GATHER, MPI_ALLGATHER, MPI_SCATTER, MPI_ALLTOALL
c MPI_GATHERV, MPI_ALLGATHERV, MPI_SCATTERV, MPI_ALLTOALLV
c MPI_REDUCE_SCATTER, MPI_ABORT, MPI_WTIME, MPI_WTICK, MPI_TYPE_EXTENT
c MPI_REQUEST_FREE, MPI_GET_PROCESSOR_NAME, MPI_ERRHANDLER_SET
c Open Transport is described in Inside Macintosh: Networking with Open
c Transport, verson 1.3 [Apple Computer, Cupertino, CA, 1997], and at:
c http://developer.apple.com/techpubs/mac/NetworkingOT/NetworkingWOT-2.
c html
c The Message Passing Interface (MPI) is described in the reference,
c M. Snir, S. Otto, S. Huss-Lederman, D. Walker, and J. Dongarra,
c MPI: The Complete Reference [MIT Press, Cambridge, MA,1996].
c Fortran unit 2 is used throughout for error messages, and
c Fortran units 3 and 4 are used in MPI_INIT.
c written by viktor k. decyk, ucla
c copyright 1999, regents of the university of california.
c all rights reserved.
c no warranty for proper operation of this software is given or implied.
c software or information may be copied, distributed, and used at own
c risk; it may not be distributed without this notice included verbatim
c with each file.
c update: april 1, 2004
block data
implicit none
c declare internal mpi common block
integer nproc, idproc, cfig0, stime, mapcomm, notifierUPP
integer MAXS, MAXC, MAXD, MAXQ, epref, ioc, nevents
parameter(MAXS=32,MAXC=10,MAXD=6,MAXQ=MAXC*(MAXS+MAXD+3))
dimension epref(MAXS+1), ioc(4,MAXS+1), nevents(MAXS+1), stime(2)
dimension mapcomm(MAXS+MAXD+3,MAXC)
c nproc = number of real or virtual processors obtained
c cfig0 = OTConfiguration structure template
c MAXS = maximum number of nodes connected
c MAXC = maximum number of communicators
c MAXD = maximum number of topology dimensions
c LDM = (0,1) = (NO,YES) register AppleTalk port for Launch Den Mother
c epref = array of endpoint references for each participating node
c ioc = array of context pointers for notifier function
c ioc(1,i) = endpoint reference for notifier for endpoint i
c ioc(2,i) = processor id for listener for endpoint i
c ioc(3,i) = handle for current receive from endpoint i
c ioc(4,i) = handle for current send to endpoint i
c nevents = log of unknown notifier events
c mapcomm = communicator map
c mapcomm(1:nproc,i) = actual proc id for given rank in communicator i
c mapcomm(nproc+1:MAXS,i) = MPI_UNDEFINED
c mapcomm(MAXS+1,i) = number of processes in comm i
c mapcomm(MAXS+2,i) = rank for this node in comm i
c mapcomm(MAXS+3,i) = ndims = number of dimensions in topology in comm i
c mapcomm(MAXS+4:MAXS+3+ndims,i) = size of dimension in comm i,
c negative if non-periodic
c mapcomm(MAXS+4+ndims:MAXS+3+MAXD,i) = 0
common /mpiparms/ nproc, idproc, cfig0, epref, ioc, nevents, stime
1, mapcomm, notifierUPP
c declare common block for non-blocking messages
integer MAXM, MAXMS, MAXP
integer curreq, header, rwrec, monitor, trash, mqueue
parameter(MAXM=2*MAXS,MAXMS=5*MAXM,MAXP=2*(MAXS+1))
dimension curreq(5,MAXM), header(10,MAXM), rwrec(14,MAXM)
dimension trash(256), mqueue(2,MAXS+1)
c MAXM = maximum number of outstanding messages on a node
c monitor = (0,1,2) = (suppress,display,display & log) monitor messages
c curreq = request record for transmission parameters, see rwstat
c header = message envelope
c header(1,i) = communicator, header(2,i) = tag, header(3,i) = datatype
c header(4,i) = length of data (in bytes) for message handle i
c rwrec = read/write record for asynchronous messages, see rwstat
c mqueue = message request queue
c mqueue(1,i) = end of message queue for receives from endpoint i
c mqueue(2,i) = end of message queue for sends to endpoint i
common /mpisendrec/ monitor, curreq, header, rwrec, trash, mqueue
c common block for message window
c cpptr = pointer to window structure
c nsp = amount of space between boxes
c nbx = size of box
c nds = number of message sizes monitored
c mbs = maximum maximum bandwidth in MB/sec expected
integer cpptr
integer*2 crect(4), nsp, nbx, nds, mbs
common /winmess/ cpptr, crect, nsp, nbx, nds, mbs
c declare adsp common block
integer nameid
c nameid = adsp portname ID
common /adsp/ nameid
c declare error handler common block
integer errh
dimension errh(MAXC)
c errh = error handler
common /mpierrh/ errh
save /mpiparms/, /mpisendrec/, /winmess/, /adsp/, /mpierrh/
data nproc, cfig0, notifierUPP /-1,0,0/
data epref /MAXS*0,0/
data nevents /MAXS*0,0/
data mapcomm /MAXQ*0/
data curreq /MAXMS*0/
data monitor /1/
data mqueue /MAXP*0/
data cpptr, nsp, nbx, nds, mbs /0,8,16,24,10/
data nameid /0/
data errh /MAXC*1/
end
c-----------------------------------------------------------------------
subroutine MPI_INIT(ierror)
c initialize the MPI execution environment
c ierror = error indicator
c input: none, output: ierror
implicit none
integer ierror
c declare internal mpi common block
integer nproc, idproc, cfig0
integer MAXS, MAXC, MAXD, LDM, epref, ioc, nevents, stime, mapcomm
integer notifierUPP
parameter(MAXS=32,MAXC=10,MAXD=6,LDM=0)
dimension epref(MAXS+1), ioc(4,MAXS+1), nevents(MAXS+1), stime(2)
dimension mapcomm(MAXS+MAXD+3,MAXC)
c nproc = number of real or virtual processors obtained
c idproc = processor id
c cfig0 = OTConfiguration structure template
c epref = array of endpoint references for each participating node
c ioc = array of context pointers for notifier function
c stime = first time stamp if MPI_Init successful
c mapcomm = communicator map
common /mpiparms/ nproc, idproc, cfig0, epref, ioc, nevents, stime
1, mapcomm, notifierUPP
c declare common block for non-blocking messages
integer monitor
c monitor = (0,1,2) = (suppress,display,display & log) monitor messages
common /mpisendrec/ monitor
c function declarations
integer InitOpenTransportInContext, OTCreateConfiguration
integer OTCloneConfiguration, OTOpenEndpointInContext
integer OTInetGetInterfaceInfo, OTCloseProvider
integer OTInetHostToString, OTInetStringToHost, NewOTNotifyUPP
integer OTConnect, OTElapsedMilliseconds, OTGetEndpointState
integer otpinit, ioresult, lencstr, lenstr
logical checkesc
external InitOpenTransportInContext, OTCreateConfiguration
external OTCloneConfiguration, OTOpenEndpointInContext
external OTInetGetInterfaceInfo, OTCloseProvider
external OTInetHostToString, OTInetStringToHost, NewOTNotifyUPP
external OTConnect, OTElapsedMilliseconds, OTGetEndpointState
external otpinit, ioresult, lencstr, lenstr, checkesc, notifier
c OT constants
integer kInitOTForApplicationMask
integer kOTNotFoundErr, AF_INET, kOTNoAddressErr
integer kOTAnyInetAddress, kOTOutStateErr, kOTBadAddressErr
integer kDefaultInetInterface
parameter(kInitOTForApplicationMask=1)
parameter(kOTNotFoundErr=-3201,AF_INET=2,kOTNoAddressErr=-3154)
parameter(kOTAnyInetAddress=0,kOTOutStateErr=-3155)
parameter(kOTBadAddressErr=-3150,kDefaultInetInterface=-1)
c MPI constants
integer MPI_UNDEFINED, MPI_STATUS_SIZE, MPI_INTEGER
parameter(MPI_UNDEFINED=-1,MPI_STATUS_SIZE=5,MPI_INTEGER=18)
c local data
integer*2 intw(2), info(276), addrb(8), addrl(8), addrn(8)
integer longw, address, nerr, nofile, nv, i, oss, response, oldadd
integer cfig, portnum, pshift, epref0
integer pnumid(3), reqad(4), repad(4), scall(10), enum(8)
integer ptime(2), delta(2), epinfo(8)
integer stat(MPI_STATUS_SIZE)
character*36 ename
character*16 myself, location, fname
c longw and intw are used to convert types between integer*2 and integer
equivalence(longw,intw)
data cfig, portnum, pshift, epref0 /0,0,0,0/
c set MPI_COMM_WORLD and MPI_COMM_SELF mapping
do 5 i = 1, MAXS
mapcomm(i,1) = i - 1
mapcomm(i,2) = MPI_UNDEFINED
5 continue
if (monitor.eq.2) write (2,*) 'MPI_INIT started'
c
c Open Open Transport
c
c Get information about the operating environment
call Gestalt(VAL4('sysv'),response)
c Check if MacOS 8.6 or higher is installed
if (response.lt.2144) then
write (2,*) 'MacMPI_X requires MacOS 8.6 or higher'
nv = response/256
response = response - 256*nv
nerr = response/16
response = response - 16*nerr
write (ename,'(i1,".",2i1)') nv, nerr, response
write (2,*) 'MacOS detected: ', ename
ierror = -7
return
endif
c Initialize Open Transport for use by application
oss = InitOpenTransportInContext(val4(kInitOTForApplicationMask),v
1al4(0))
if (oss.ne.0) then
write (2,*) 'Cannot Open Transport, oss = ', oss
ierror = oss
return
endif
c Obtain the current time stamp
call OTGetTimeStamp(stime)
c Create a structure defining a provider's configuration
cfig0 = OTCreateConfiguration('tcp'//char(0))
if (cfig0.eq.0) then
write (2,*) 'Insufficient Memory for tcp Endpoint'
ierror = -4
call CloseOpenTransportInContext(val4(0))
return
elseif (cfig0.eq.(-1)) then
write (2,*) 'Invalid Configuration for tcp Endpoint'
ierror = -4
call CloseOpenTransportInContext(val4(0))
return
endif
c Copy an OTConfiguration structure
cfig = OTCloneConfiguration(val4(cfig0))
c Create a dummy endpoint provider just to make sure TCP/IP is active
epref0 = OTOpenEndpointInContext(val4(cfig),val4(0),epinfo,oss,val
14(0))
c Obtain information about the Internet environment
oss = OTInetGetInterfaceInfo(info,val4(kDefaultInetInterface))
if (oss.ne.0) then
write (2,*) 'INS GetInterfaceInfo Error, oss = ', oss
if (oss.eq.kOTNotFoundErr) then
write (2,*) 'Requested information does not exist'
write (2,*) 'TCP/IP may not be active'
endif
ierror = oss
oss = OTCloseProvider(val4(epref0))
call CloseOpenTransportInContext(val4(0))
return
endif
c Close the dummy endpoint provider
oss = OTCloseProvider(val4(epref0))
intw(1) = info(1)
intw(2) = info(2)
address = longw
oldadd = address
c
c Everyone opens a port
c
c Open file containing portnum (and possibly participating nodes)
c first line in nodelist file on all nodes contains common portnum
c if the file is missing or empty, a default number of 5013 is used
open(unit=3,file='nodelist_ip',form='formatted',status='old',iosta
1t=nofile)
if (nofile.ne.0) then
open(unit=3,file='nodelist',form='formatted',status='old',iosta
1t=nofile)
endif
if (nofile.eq.0) then
read (3,'(i10)',iostat=nerr) portnum
if ((nerr.ne.0).or.(portnum.lt.5000).or.(portnum.gt.49152)) the
1n
portnum = 5013
endif
else
portnum = 5013
endif
c Construct InetAddress of listener
addrn(1) = AF_INET
addrn(2) = portnum
addrn(3) = info(1)
addrn(4) = info(2)
c Convert an address into a character string
intw(1) = addrn(3)
intw(2) = addrn(4)
call OTInetHostToString(val4(longw),myself)
nv = lencstr(myself)
myself(nv+1:16) = ' '
ename = myself
c Establish port connection end
c Set TNetbuf for specifying address
reqad(2) = 16
reqad(3) = loc(addrn)
reqad(4) = 1
c Set TNetbuf for address which is returned
repad(1) = 16
repad(3) = loc(addrb)
c Set TNetbuf for specifying address for local computer
scall(2) = 16
scall(3) = loc(addrn)
nproc = 0
c Create Univeral Proc Ptr for notifier function
notifierUPP = NewOTNotifyUPP(notifier)
c Initialize synchronous listener endpoint provider
oss = otpinit(MAXS+1,reqad,repad)
if (oss.ne.0) then
if (oss.eq.kOTNoAddressErr) then
write (2,*) 'portnum likely already exists = ', portnum
endif
ierror = oss
call MPI_FINALIZE(nerr)
return
endif
c Save copy of portnum
pnumid(1) = addrn(2)
c Register adsp endpoint for puppy
if (LDM.ne.0) then
call regport(portnum,ierror)
if (ierror.ne.0) then
write (2,*) 'Unable to register adsp port for puppy'
c call MPI_FINALIZE(nerr)
endif
endif
c Pass processor id to listener notifier
ioc(2,MAXS+1) = nproc + 1
c debug
if (monitor.eq.2) then
write (2,*) 'local host=', myself(1:nv), ',port=', addrb(2)
endif
c
c Determine if node is master (idproc=0) or slave (idproc>0).
c on the master node, the second and subsequent lines of nodelist file
c contain IP addresses of the nodes participating, in dotted-decimal
c format (for example, "12.13.14.15").
c if this list of nodes is missing, then the node is a slave.
c every node also makes a connection to itself.
c
location = ' '
if (nofile.eq.0) read (3,'(a16)',iostat=nerr) location
c must be slave
if ((nofile.ne.0).or.(nerr.ne.0).or.(location.eq.' ')) then
idproc = 1
c may be master
else
if (((location.eq.'self').or.(location.eq.myself)).and.(pnumid(
11).eq.portnum)) then
idproc = 0
close(unit=2)
fname = 'MPIERRS00'
open(unit=2,file=fname,form='formatted',status='unknown')
else
c must be slave
idproc = 1
endif
endif
c Update port number
portnum = pnumid(1)
c
c * * * begin main iteration loop * * *
c
c Prepare to accept connection
c
c Establish connection end
c Connections to oneself requires a new socket
10 addrb(2) = kOTAnyInetAddress
c Set TNetbuf for specifying address
reqad(2) = 16
reqad(3) = loc(addrb)
reqad(4) = 0
c Set TNetbuf for address which is returned
repad(1) = 16
repad(3) = loc(addrl)
c Initialize synchronous endpoint provider
oss = otpinit(nproc+1,reqad,repad)
if (oss.ne.0) then
ierror = oss
call MPI_FINALIZE(nerr)
return
endif
c For connections to oneself, jump to OTConnect
if (idproc.eq.nproc) then
ioc(2,MAXS+1) = MAXS+1
go to 70
endif
c Obtain the current time stamp
call OTGetTimeStamp(ptime)
c Wait for connection
20 if (ioresult(ioc(1,MAXS+1)).gt.0) then
if (checkesc(1)) then
ierror = -9
call writerrs('MPI_INIT: ',ierror)
return
c Wait up to one minute for next connection
else
if (OTElapsedMilliseconds(ptime).lt.60000) then
go to 20
else
write (2,*) 'OTListen Wait Time Exceeded'
ierror = -5
call MPI_FINALIZE(nerr)
return
endif
endif
else
oss = ioresult(ioc(1,MAXS+1))
if (oss.ne.0) then
write (2,*) 'OTListen failed, oss = ', oss
ierror = oss
call MPI_FINALIZE(nerr)
return
endif
endif
c Receive portnum for verification and processor id from remote node
nproc = nproc + 1
mapcomm(MAXS+1,1) = nproc
c Reset iocompletion flag to notifier
ioc(2,MAXS+1) = nproc + 1
call MPI_RECV(enum,3,MPI_INTEGER,nproc-1,3,0,stat,ierror)
c Extract processor id and base portnum and shift on first connection
if (nproc.eq.1) then
idproc = enum(2)
pshift = portnum - enum(3)
portnum = enum(3)
mapcomm(MAXS+2,1) = idproc
close(unit=2)
if (idproc.lt.10) then
write (fname,'(8hMPIERRS0,i1)') idproc
else
write (fname,'(7hMPIERRS,i2)') idproc
endif
open(unit=2,file=fname,form='formatted',status='unknown')
endif
c Check if remote portnum agrees with local portnum
nerr = pnumid(1) - enum(1)
c Send reject flag to remote node
call MPI_SEND(nerr,1,MPI_INTEGER,nproc-1,4,0,ierror)
c Reject if portnums disagree
if (nerr.ne.0) then
write (2,*) 'Session rejected, idproc = ', idproc
write (2,*) 'Portnums do not agree'
ierror = 5
write (2,*) 'remote portnum = ', enum(1)
call MPI_FINALIZE(nerr)
return
endif
c Check for processor number overflow
if (nproc.gt.MAXS) then
write (2,*) 'processor number overflow, nproc = ', nproc
ierror = 6
call MPI_FINALIZE(nerr)
return
endif
c debug
if (monitor.eq.2) then
write (2,*) 'connection accepted with idproc = ', nproc-1
endif
c Accept more connections
if (idproc.ge.nproc) go to 10
c
c Master prepares to start connection
c
c Find internet address of requested node
40 nv = lenstr(location)
c Convert a character string into an address
oss = OTInetStringToHost(location(1:nv)//char(0),address)
if (oss.ne.0) then
write (2,*) 'OTInetStringToHost failed, oss = ', oss
if (oss.eq.kOTBadAddressErr) then
write (2,*) 'Invalid IP address = ', location(1:nv)
write (2,*) 'Invalid nodelist file possibly being used'
endif
ierror = oss
call MPI_FINALIZE(nerr)
return
endif
c second cpu on a node uses incremented port number
if (address.eq.oldadd) then
pshift = pshift + 1
else
pshift = 0
oldadd = address
endif
pnumid(1) = portnum + pshift
addrn(1) = AF_INET
addrn(2) = pnumid(1)
longw = address
addrn(3) = intw(1)
addrn(4) = intw(2)
c Convert an address into a character string
call OTInetHostToString(val4(longw),ename)
nv = lencstr(ename)
c Establish connection end
c Create a new socket for this endpoint
addrb(2) = kOTAnyInetAddress
c Set TNetbuf for specifying address
reqad(2) = 16
reqad(3) = loc(addrb)
reqad(4) = 0
c Set TNetbuf for address which is returned
repad(1) = 16
repad(3) = loc(addrl)
c Initialize synchronous endpoint provider
oss = otpinit(nproc+1,reqad,repad)
if (oss.ne.0) then
ierror = oss
call MPI_FINALIZE(nerr)
return
endif
c Set TNetbuf for specifying address for remote computer
scall(2) = 16
scall(3) = loc(addrn)
c Set TNetbuf for specifying options
70 scall(5) = 0
scall(6) = 0
c Set TNetbuf for specifying data
scall(8) = 0
scall(9) = 0
c debug
if (monitor.eq.2) then
write (2,*) 'requesting connection with=',ename(1:nv),pnumid(1)
endif
c Pause to let OS get some time
if (checkesc(1)) then
ierror = -9
call writerrs('MPI_INIT: ',ierror)
return
endif
c Obtain the current time stamp
call OTGetTimeStamp(ptime)
call OTGetTimeStamp(delta)
c Request a connection to a remote peer
oss = OTConnect(val4(epref(nproc+1)),scall,val4(0))
c Wait for connection
80 if (ioresult(ioc(1,nproc+1)).gt.0) then
if (checkesc(1)) then
ierror = -9
call writerrs('MPI_INIT: ',ierror)
return
c Wait up to one minute for next connection
else
if (OTElapsedMilliseconds(ptime).lt.60000) then
response = OTGetEndpointState(val4(epref(nproc+1)))
c Try again every second if no response
if ((response.lt.5).and.(OTElapsedMilliseconds(delta).gt.
11000)) then
oss = OTConnect(val4(epref(nproc+1)),scall,val4(0))
c Obtain the current time stamp
call OTGetTimeStamp(delta)
endif
go to 80
else
write (2,*) 'OTConnect Wait Time Exceeded'
write (2,*) 'Trying to start location = ', ename(1:nv),
1pnumid(1)
ierror = -6
call MPI_FINALIZE(nerr)
return
endif
endif
else
oss = ioresult(ioc(1,nproc+1))
if (oss.ne.0) then
write (2,*) 'OTConnect Error, oss = ', oss
write (2,*) 'Trying to start location = ', ename(1:nv), pnum
1id(1)
if (oss.eq.kOTOutStateErr) then
write (2,*) 'Endpoint not in an appropriate state'
write (2,*) 'Remote node may be unknown or inaccessible'
endif
ierror = oss
call MPI_FINALIZE(nerr)
return
endif
endif
c debug
if (monitor.eq.2) then
write (2,*) 'tentative connection started with=', ename(1:nv),
1pnumid(1)
endif
c Send portnum for verification and processor id to remote node
nerr = nproc
nproc = nproc + 1
mapcomm(MAXS+1,1) = nproc
if (nerr.gt.idproc) then
c Set processor id
pnumid(2) = nerr
pnumid(3) = portnum
call MPI_SEND(pnumid,3,MPI_INTEGER,nproc-1,3,0,ierror)
c Read and check reject flag
call MPI_RECV(nerr,1,MPI_INTEGER,nproc-1,4,0,stat,ierror)
if (nerr.ne.0) then
write (2,*) 'Connection rejected, reject info = ', nerr
write (2,*) 'Portnums do not agree, idproc = ', nproc-1
ierror = 12
call MPI_FINALIZE(nerr)
return
endif
endif
c Check for processor number overflow
if (nproc.gt.MAXS) then
write (2,*) 'processor number overflow, nproc = ', nproc
ierror = 6
call MPI_FINALIZE(nerr)
return
endif
c debug
if (monitor.eq.2) then
write (2,*) 'connection confirmed with idproc = ', nproc-1
endif
c Pass current location to next node
if (nproc.gt.(idproc+2)) then
call MPI_SEND(location,4,MPI_INTEGER,idproc+1,1,0,nerr)
endif
c Read location of next node from file
if (idproc.eq.0) then
if ((nproc.ge.2).or.(location.eq.'self').or.(location.eq.myself
1)) then
if (nofile.ne.0) go to 90
read (3,'(a16)',iostat=nerr) location
c End of file
if ((nerr.ne.0).or.(location.eq.' ')) go to 90
endif
c Receive location of next node from another processor
else
call MPI_RECV(location,4,MPI_INTEGER,idproc-1,1,0,stat,nerr)
c End of file marker received
if (stat(4).eq.0) go to 90
endif
c Start another connection
go to 40
c
c * * * end main iteration loop * * *
c
c All expected nodes activated
90 nv = nproc - 1
c debug
if (monitor.eq.2) then
write (2,*) 'all nodes activated: idproc, nproc=', idproc,nproc
endif
c Send null record to next processor
if (idproc.lt.nv) then
call MPI_SEND(location,0,MPI_INTEGER,idproc+1,1,0,nerr)
endif
if (nofile.eq.0) close(unit=3)
c Check number of processors
if (idproc.eq.nv) then
do 100 i = 1, nv
call MPI_SEND(nproc,1,MPI_INTEGER,nv-i,2,0,nerr)
100 continue
else
call MPI_RECV(response,1,MPI_INTEGER,nv,2,0,stat,nerr)
c Local processor does not agree with last processor on total number
if (response.ne.nproc) then
write (2,*) 'processor number error, local/remote nproc = '
1, nproc, response
ierror = 7
call MPI_FINALIZE(nerr)
return
endif
endif
c Clear unused MPI_COMM_WORLD mapping
do 95 i = nproc+1, MAXS
mapcomm(i,1) = MPI_UNDEFINED
95 continue
mapcomm(MAXS+3,1) = 0
c Set MPI_COMM_SELF
mapcomm(1,2) = idproc
mapcomm(MAXS+1,2) = 1
mapcomm(MAXS+2,2) = 0
mapcomm(MAXS+3,2) = 0
c Create window for showing MPI message status
if (monitor.gt.0) then
call messwin(nproc)
call checkesc(1)
if (monitor.eq.2) then
write (2,*) 'MPI_INIT complete'
write (2,*)
endif
endif
c Set error code to success
ierror = 0
return
end
c-----------------------------------------------------------------------
subroutine regport(portnum,ierror)
c Finds name of current computer by first finding network address of
c current computer, then finding a registered entity with type name
c 'PPCToolBox' which resides at that address. The object name
c corresponding to that entity is the current computer name. This only
c works if the user has set Program Linking on in the File Sharing
c control panel. If computer name is found, then a portname is created
c whose entity name consists of object = computer name, type = portnum
c If it already exists, it is first deleted, then reregistered.
implicit none
integer portnum, ierror
c declare adsp common block
integer nameid
c nameid = adsp portname ID
common /adsp/ nameid
c function declarations
integer OTOpenAppleTalkServicesInContext, OTATalkGetInfo
integer OTCloseProvider
integer OTCreateConfiguration, OTOpenMapperInContext, OTIoctl
integer OTDestroyConfiguration, OTSetBlocking, OTLookupName
integer OTGetNBPEntityLengthAsAddress
integer OTDeleteName, OTRegisterName
integer lenstr, instr
external OTOpenAppleTalkServicesInContext, OTATalkGetInfo
external OTCloseProvider
external OTCreateConfiguration, OTOpenMapperInContext, OTIoctl
external OTDestroyConfiguration, OTSetBlocking, OTLookupName
external OTGetNBPEntityLengthAsAddress
external OTDeleteName, OTRegisterName
external lenstr, instr
c OT constants
integer kDefaultAppleTalkServicesPath
integer kATalkFullSelfSend, kOTNoDataErr, kOTNoAddressErr
parameter(kDefaultAppleTalkServicesPath=-3)
parameter(kATalkFullSelfSend=21551,kOTNoDataErr=-3162)
parameter(kOTNoAddressErr=-3154)
c local data
integer*2 intw(2), atinfo(11), addrb(4), addrn(54)
integer longw, aref, oss, address, nodeid, cfig, mref, nv, i, club
integer ucptr
integer info(3), req(9), rep(4), aname(25), treq(7), trep(4)
character selfsend, rbuff(1888)
character*36 ename
c longw and intw are used to convert types between integer*2 and integer
equivalence(longw,intw)
data ucptr, cfig, mref, oss /0,0,0,0/
ierror = 0
selfsend = char(1)
aref = 0
c Open a synchronous AppleTalk service provider
c aref = OTOpenAppleTalkServicesInContext(val4(kDefaultAppleTalkServ
c 1icesPath),val4(0),oss,val4(0))
if (aref.eq.0) then
write (2,*) 'Invalid ATS, oss = ', oss
ierror = oss
return
endif
c Set TNetbuf to receive AppleTalk Info
info(1) = 22
info(2) = 0
info(3) = loc(atinfo)
c Obtain information about the AppleTalk environment
oss = OTATalkGetInfo(val4(aref),info)
if (oss.ne.0) then
write (2,*) 'ATS GetInfo Error, oss = ', oss
ierror = oss
call OTCloseProvider(val4(aref))
return
endif
address = atinfo(2)
intw(1) = 0
intw(2) = atinfo(3)
nodeid = longw/256
c Close a provider of any type
oss = OTCloseProvider(val4(aref))
if (oss.ne.0) write (2,*) 'Close ATS Provider Error, oss = ', oss
c Create a structure defining a provider's configuration
cfig = OTCreateConfiguration('nbp'//char(0))
if (cfig.eq.0) then
write (2,*) 'Insufficient Memory for nbp Mapper'
ierror = -4
return
elseif (cfig.eq.(-1)) then
write (2,*) 'Invalid Configuration for nbp Mapper'
ierror = -4
return
endif
c Create a synchronous mapper provider
mref = OTOpenMapperInContext(val4(cfig),val4(0),oss,val4(0))
if (mref.eq.0) then
write (2,*) 'Invalid NBP Mapper, oss = ', oss
ierror = oss
call OTDestroyConfiguration(val4(cfig))
return
endif
c Enable ADSP SelfSend
c Send a module-specific command to Open Transport protocol module
oss = OTIoctl(val4(mref),val4(kATalkFullSelfSend),val1(ichar(selfs
1end)))
if (oss.lt.0) then
write (2,*) 'OTIoctl SelfSend Error, oss = ', oss
c Save old value
else
selfsend = char(oss)
endif
c Set a provider to wait or block until function can complete
oss = OTSetBlocking(val4(mref))
if (oss.ne.0) then
write (2,*) 'NBP Mapper Set Blocking Error, oss = ', oss
ierror = oss
call OTCloseProvider(val4(mref))
return
endif
c Look for names with type 'PPCToolBox'
ename = '=:PPCToolBox@*'//char(0)
c Set TNetbuf for name to be looked up
req(2) = 14
req(3) = loc(ename)
c Set TNetbuf to use defaults for address search
req(5) = 0
req(6) = 0
c Set number of names you expect to be returned
req(7) = 16
c Set timeout to default
req(8) = 0
req(9) = 0
c Set TNetbuf for names which are found
rep(1) = 1888
rep(3) = loc(rbuff)
c Find all addresses that correspond to a particular name or pattern
oss = OTLookupName(val4(mref),req,rep)
if (oss.ne.0) then
write (2,*) 'OTLookup Error, rspcount, oss = ', rep(4), oss
if (oss.eq.kOTNoDataErr) then
write (2,*) 'Cannot find PPCToolBox on any computer'
endif
ierror = oss
else
nv = 1
i = 1
5 club = loc(rbuff(nv))
c Get network address of found entity
addrb(2) = word(club+6)
intw(1) = 0
intw(2) = word(club+8)
c Check if network and nodeid agrees
if ((addrb(2).ne.address).or.((longw/256).ne.nodeid)) then
i = i + 1
if (i.gt.rep(4)) then
write (2,*) 'Cannot find PPCToolBox on current computer'
ierror = 8
c Look up more addresses
else
nv = nv + ((word(club)-1)/4 + (word(club+2)-1)/4 + 3)*4
go to 5
endif
c Found correct address
else
ierror = 0
endif
endif
if (ierror.ne.0) then
write (2,*) 'Program Linking may not be enabled'
call OTCloseProvider(val4(mref))
return
endif
c Extract object name
nv = word(club)
ucptr = club + 4 + nv
nv = word(club+2)
call OTSetNBPEntityFromAddress(aname,val4(ucptr),val4(nv))
c Check if port name is already being used
write (ename,'(i5)') portnum
nv = lenstr(ename) + 1
ename(nv:nv) = char(0)
nv = instr(ename)
c Set the type part of an NBP entity structure
call OTSetNBPType(aname,ename(nv:))
c Set the zone part of an NBP entity structure
call OTSetNBPZone(aname,'*'//char(0))
c Store an NBP entity structure as an NBP address string
call OTSetAddressFromNBPEntity(addrn(2),aname)
addrn(1) = 258
c Obtain the size of an NBP entity structure formatted as string
nv = OTGetNBPEntityLengthAsAddress(aname)
i = nv/2
if (nv.gt.(2*i)) addrn(i+2) = 256*(addrn(i+2)/256)
c Set TNetbuf for name to be deleted
info(2) = nv
info(3) = loc(addrn(2))
c Remove a previously registered entity name
oss = OTDeleteName(val4(mref),info)
if (oss.eq.0) then
write (2,'(1x,a22,16a2)') 'closed old adsp port: '
1, (addrn(i+1),i=1,(nv-1)/2+1)
endif
c Set TNetbufs for name to be registered
treq(2) = nv
treq(3) = loc(addrn(2))
treq(5) = 0
treq(6) = 0
treq(7) = 0
trep(1) = 8
trep(3) = loc(addrb)
trep(4) = 0
c Register a name on the network
oss = OTRegisterName(val4(mref),treq,trep)
nameid = trep(4)
if (oss.ne.0) then
write (2,*) 'OTRegisterName Error, oss = ', oss
endif
c Close a provider of any type
oss = OTCloseProvider(val4(mref))
if (oss.ne.0) write (2,*) 'Close NBP Provider Error, oss=', oss
return
end
c-----------------------------------------------------------------------
subroutine delport()
c this subroutine deletes adsp portname
implicit none
c declare adsp common block
integer nameid
c nameid = adsp portname ID
common /adsp/ nameid
c function declarations
integer OTCreateConfiguration, OTOpenMapperInContext
integer OTSetBlocking, OTDeleteNameByID, OTCloseProvider
external OTCreateConfiguration, OTOpenMapperInContext
external OTSetBlocking, OTDeleteNameByID, OTCloseProvider
c local data
integer cfig, oss, mref
data cfig, mref /0,0/
c Create a structure defining a provider's configuration
cfig = OTCreateConfiguration('nbp'//char(0))
if (cfig.eq.0) then
write (2,*) 'delport: Insufficient Memory for nbp Mapper'
return
elseif (cfig.eq.(-1)) then
write (2,*) 'delport: Invalid Configuration for nbp Mapper'
return
endif
c Create a synchronous mapper provider
mref = OTOpenMapperInContext(val4(cfig),val4(0),oss,val4(0))
if (mref.eq.0) then
write (2,*) 'delport: Invalid NBP Mapper, oss = ', oss
call OTDestroyConfiguration(val4(cfig))
return
endif
c Set a provider to wait or block until function can complete
oss = OTSetBlocking(val4(mref))
if (oss.ne.0) then
write (2,*) 'delport: NBP Mapper Set Blocking Error, oss=', oss
call OTCloseProvider(val4(mref))
return
endif
c Remove a previously registered name as specified by its name ID
oss = OTDeleteNameByID(val4(mref),val4(nameid))
if (oss.ne.0) then
write (2,*) 'OTDeleteNameByID Error, oss = ', oss
endif
oss = OTCloseProvider(val4(mref))
if (oss.ne.0) then
write (2,*) 'delport: Close NBP Provider Error, oss=', oss
endif
return
end
c-----------------------------------------------------------------------
subroutine notifier(context,event,result,cookie)
c notifier function for asynchronous and completion events
implicit none
integer context, event, result, cookie
value context, event, result, cookie
c declare internal mpi common block
integer nproc, idproc, cfig0
integer MAXS, MAXC, MAXD, epref, ioc, nevents, stime, mapcomm
parameter(MAXS=32,MAXC=10,MAXD=6)
dimension epref(MAXS+1), ioc(4,MAXS+1), nevents(MAXS+1), stime(2)
dimension mapcomm(MAXS+MAXD+3,MAXC)
c epref = array of endpoint references for each participating node
c nevents = log of unknown notifier events
common /mpiparms/ nproc, idproc, cfig0, epref, ioc, nevents, stime
1, mapcomm
c declare common block for non-blocking messages
integer MAXM, curreq, header, rwrec, monitor, trash, mqueue
parameter(MAXM=2*MAXS)
dimension curreq(5,MAXM), header(10,MAXM), rwrec(14,MAXM)
dimension trash(256), mqueue(2,MAXS+1)
c rwrec = read/write record for asynchronous messages
c trash = trash bin for unwanted data
c mqueue = message request queue
common /mpisendrec/ monitor, curreq, header, rwrec, trash, mqueue
c function declarations
integer OTListen, OTAccept, OTRcvConnect, OTRcvDisconnect
integer OTRcvOrderlyDisconnect, OTGetEndpointState, OTIoctl
integer OTSndOrderlyDisconnect, OTRcv, OTLook, OTSnd
external OTListen, OTAccept, OTRcvConnect, OTRcvDisconnect
external OTRcvOrderlyDisconnect, OTGetEndpointState, OTIoctl
external OTSndOrderlyDisconnect, OTRcv, OTLook, OTSnd
c OT constants
integer T_LISTEN, T_CONNECT, T_DISCONNECT, T_DISCONNECTCOMPLETE
integer T_ACCEPTCOMPLETE, T_PASSCON, T_ORDREL, kStreamIoctlEvent
integer T_DATA, T_GODATA, T_INREL, I_FLUSH, FLUSHRW, kOTNoDataErr
integer kOTLookErr, kOTFlowErr, kENOMEMErr
parameter(T_LISTEN=1,T_CONNECT=2,T_DISCONNECT=16)
parameter(T_DISCONNECTCOMPLETE=536870917)
parameter(T_ACCEPTCOMPLETE=536870915,T_PASSCON=4096,T_ORDREL=128)
parameter(kStreamIoctlEvent=553648133,T_DATA=4,T_GODATA=256)
parameter(T_INREL=7,I_FLUSH=16645,FLUSHRW=3,kOTNoDataErr=-3162)
parameter(kOTLookErr=-3158,kOTFlowErr=-3161,kENOMEMErr=-3211)
c local data
integer n, m, oss, tryagn, addrb(4), call(10)
tryagn = 0
c Get reference to endpoint
n = long(context)
c Check event
10 select case (event)
case (T_LISTEN)
c Set TNetbuf for address which is returned
call(1) = 16
call(3) = loc(addrb)
c Set TNetbuf for options which are returned
call(4) = 0
call(6) = 0
c Set TNetbuf for data which is returned