Newer
Older
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
!***********************************************************************
!
!
SUBROUTINE read_b_asc
!
!
!***********************************************************************
!
!
! Subroutine to read in the data associated with the bodies from
! the ASCII input file.
!=======================================================================
USE fly_h
implicit none
INCLUDE 'mpif.h'
! Declaration of local variables.
! -------------------------------
INTEGER(KIND=MPI_ADDRESS_KIND) :: startIndex
INTEGER :: p,tag,istatus(MPI_STATUS_SIZE)
CHARACTER(LEN=4) :: ifl
CHARACTER(LEN=256) :: name_file
!
!
! mass_read is the value of the mass of each body of the simulation
!
!=======================================================================
! propagate the mass_read value to all bodies
DO p=1,nb_res_loc(me+1)
mass(p)=mass_read
ENDDO
! Read in body data.
! ------------------
IF(nbodies.GT.nbodsmax) &
CALL error('read_b_asc error1: inconsistent input')
IF (me.EQ.0) THEN ! PE0 execute the read operation
pos_rmt=0.0
! Open input body data file.
! --------------------------
name_file=ibodfile
IF(tstep.GT.1000) WRITE(ifl,'(I4.4)') tstep
IF(tstep.GE.100 .AND. tstep .LT. 1000) WRITE(ifl,'(I3.3)') tstep
IF(tstep.GE.10 .AND. tstep .LT. 100) WRITE(ifl,'(I2.2)') tstep
IF(tstep.LT. 10) WRITE(ifl,'(I1.1)') tstep
name_file=TRIM(name_file)//ifl
OPEN(UNIT=ubodsin,FILE=name_file,STATUS='OLD')
DO p=1,nb_res_loc(me+1)
READ(ubodsin,*) pos(1,p),pos(2,p),pos(3,p)
ENDDO
DO PE_indx=1,NPES-1 ! read and transmit
DO p=1,nb_res_loc(PE_indx+1)
READ(ubodsin,*) pos_rmt(1,p),pos_rmt(2,p),pos_rmt(3,p)
ENDDO
NLONG=nb_res_loc(PE_indx+1)*3
tag = 1
CALL MPI_SEND(pos_rmt(1,1),NLONG, MPI_REAL8, PE_indx, tag, MPI_COMM_WORLD, ierror)
ENDDO
DO p=1,nb_res_loc(me+1)
READ(ubodsin,*) vel(1,p),vel(2,p),vel(3,p)
ENDDO
DO PE_indx=1,NPES-1 ! read and transmit
DO p=1,nb_res_loc(PE_indx+1)
READ(ubodsin,*) pos_rmt(1,p),pos_rmt(2,p),pos_rmt(3,p)
ENDDO
NLONG=nb_res_loc(PE_indx+1)*3
tag = 2
CALL MPI_SEND(pos_rmt(1,1),NLONG, MPI_REAL8, PE_indx, tag, MPI_COMM_WORLD, ierror)
ENDDO
100 FORMAT(3(1X,F20.10))
CLOSE(ubodsin)
ELSE ! IF (me.eq.NPES-1)
NLONG=nb_res_loc(me+1)*3
tag=1
CALL MPI_RECV(pos(1,1), NLONG, MPI_REAL8, PE0, tag, MPI_COMM_WORLD, istatus, ierror)
tag=2
CALL MPI_RECV(vel(1,1), NLONG, MPI_REAL8, PE0, tag, MPI_COMM_WORLD, istatus, ierror)
ENDIF ! IF (me.eq.NPES-1)
CALL MPI_BARRIER(MPI_COMM_WORLD,ierror)
IF(me.eq.0) THEN
write(uterm,*)' pos first = ', pos(1:3,1)
write(uterm,*) 'vel first = ', vel(1:3,1)
call flush(uterm)
ENDIF
CALL MPI_BARRIER(MPI_COMM_WORLD,ierror)
IF(me.eq.npes-1) THEN
write(uterm,*) 'pos last = ', pos(1:3,nb_res_loc(me+1))
write(uterm,*) 'vel last = ', vel(1:3,nb_res_loc(me+1))
call flush(uterm)
ENDIF
RETURN
END