Nek5000
SEM for Incompressible NS
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros Modules Pages
byte_mpi.F90
Go to the documentation of this file.
1 subroutine byte_sync_mpi(mpi_fh)
2  implicit none
3  integer, intent(in) :: mpi_fh
4 #ifdef MPIIO
5  include 'mpif.h'
6  call mpi_file_sync(mpi_fh,ierr)
7 #endif
8 
9  return
10 end subroutine byte_sync_mpi
11 
12 !--------------------------------------------------------------------------
13 subroutine byte_open_mpi(fname,mpi_fh,ierr)
14  implicit none
15 
16  character(132) :: fname
17  integer :: mpi_fh, ierr
18 
19 #ifdef MPIIO
20  include 'mpif.h'
21 
22  if(nid == pid0 .OR. nid == pid0r) then
23  ! write(*,*) nid, 'call MPI_file_open',fname
24  call mpi_file_open(nekcomm_io,fname, &
25  mpi_mode_rdwr+mpi_mode_create, &
26  mpi_info_null,mpi_fh,ierr)
27  if(ierr /= 0) then
28  write(6,*) 'ABORT: Error in byte_open_mpi ', ierr
29  return
30  endif
31  endif
32 #else
33  write(6,*) 'byte_open_mpi: No MPI-IO support!'
34  ierr=1
35  return
36 #endif
37 
38  ierr=0
39  return
40 end subroutine byte_open_mpi
41 
42 !--------------------------------------------------------------------------
43 subroutine byte_read_mpi(buf,icount,iorank,mpi_fh,ierr)
44  use kinds, only : r4
45  implicit none
46 
47  real(r4) :: buf(1) ! buffer
48  integer :: icount, iorank, mpi_fh, ierr
49 
50 #ifdef MPIIO
51  include 'mpif.h'
52 
53  if(nid == pid0 .OR. nid == pid0r) then
54  iout = 4*icount ! icount is in 4-byte words
55  if(iorank >= 0 .AND. nid /= iorank) iout = 0
56  ! write(*,*) 'byte_read_mpi', nid, iout/4
57 #ifdef MPIIO_NOCOL
58  call mpi_file_read(mpi_fh,buf,iout,mpi_byte, &
59  mpi_status_ignore,ierr)
60 #else
61  call mpi_file_read_all(mpi_fh,buf,iout,mpi_byte, &
62  mpi_status_ignore,ierr)
63 #endif
64  if(ierr /= 0) then
65  write(6,*) 'ABORT: Error in byte_read_mpi ', ierr
66  return
67  endif
68  endif
69 #else
70  write(6,*) 'byte_read_mpi: No MPI-IO support!'
71  ierr=1
72  return
73 #endif
74 
75  ierr=0
76 
77  return
78 end subroutine byte_read_mpi
79 
80 !--------------------------------------------------------------------------
81 subroutine byte_write_mpi(buf,icount,iorank,mpi_fh,ierr)
82  use kinds, only : r4
83  implicit none
84 
85  real(r4) :: buf(1) ! buffer
86  integer :: icount, iorank, mpi_fh, ierr
87 
88 #ifdef MPIIO
89  include 'mpif.h'
90 
91  if(nid == pid0 .OR. nid == pid0r) then
92  iout = 4*icount ! icount is in 4-byte words
93  if(iorank >= 0 .AND. nid /= iorank) iout = 0
94  ! write(*,*) 'byte_write', nid, iout/4
95 #ifdef MPIIO_NOCOL
96  call mpi_file_write(mpi_fh,buf,iout,mpi_byte, &
97  mpi_status_ignore,ierr)
98 #else
99  call mpi_file_write_all(mpi_fh,buf,iout,mpi_byte, &
100  mpi_status_ignore,ierr)
101 #endif
102  if(ierr /= 0) then
103  write(6,*) 'ABORT: Error in byte_write_mpi ', ierr
104  return
105  endif
106  endif
107 #else
108  write(6,*) 'byte_write_mpi: No MPI-IO support!'
109  ierr=1
110  return
111 #endif
112  ierr=0
113  return
114 end subroutine byte_write_mpi
115 
116 !--------------------------------------------------------------------------
117 subroutine byte_close_mpi(mpi_fh,ierr)
118  use size_m, only : nid
119  implicit none
120 
121  integer :: mpi_fh, ierr
122 
123 #ifdef MPIIO
124  include 'mpif.h'
125  if(nid == pid0 .OR. nid == pid0r) then
126  call mpi_file_close(mpi_fh,ierr)
127  endif
128  if(ierr /= 0) then
129  write(6,*) 'ABORT: Error in byte_close_mpi ', ierr
130  return
131  endif
132 #else
133  if(nid == 0) write(6,*) 'byte_close_mpi: No MPI-IO support!'
134  ierr=1
135  return
136 #endif
137 
138  return
139 end subroutine byte_close_mpi
140 
141 !--------------------------------------------------------------------------
142 subroutine byte_set_view(ioff_in,mpi_fh)
143  use kinds, only : i8
144  implicit none
145 
146  integer(i8) :: ioff_in
147  integer :: mpi_fh
148 
149 #ifdef MPIIO
150  include 'mpif.h'
151 
152  if(nid == pid0 .OR. nid == pid0r) then
153  if(ioff_in < 0) then
154  write(6,*) 'byte_set_view: offset<0!'
155  call exitt
156  endif
157  ! write(*,*) 'dataoffset', nid, ioff_in
158  call mpi_file_set_view(mpi_fh,ioff_in,mpi_byte,mpi_byte, &
159  'native',mpi_info_null,ierr)
160  if(ierr /= 0) then
161  write(6,*) 'ABORT: Error in byte_set_view ', ierr
162  call exitt
163  endif
164  endif
165 #endif
166 
167  return
168 end subroutine byte_set_view
169 
170 !--------------------------------------------------------------------------
171 subroutine nek_comm_io(nn)
172  implicit none
173 
174  integer :: nn
175 
176 #ifdef MPIIO
177  include 'mpif.h'
178 ! c!ommon /nekmpi/ mid,mp,nekcomm,nekgroup,nekreal
179 ! c!ommon /scrns/ irank_io(0:lp-1)
180 
181 #ifdef MPIIO_NOCOL
182  if(nid == 0) then
183  j = 0
184  if(nid == pid0 .OR. nid == pid0r) then
185  irank_io(j) = nid
186  j = j + 1
187  endif
188  do ir = 1,np-1
189  call csend(ir,idum,4,ir,0) ! handshake
190  call crecv(ir,ibuf,4)
191  if(ibuf > 0) then
192  irank_io(j) = ibuf
193  j = j + 1
194  endif
195  enddo
196  else
197  mtype = nid
198  ibuf = -1
199  if(nid == pid0) then
200  ibuf = nid
201  endif
202  call crecv(mtype,idum,4) ! hand-shake
203  call csend(mtype,ibuf,4,0,0) ! u4 :=: u8
204  endif
205 
206  call bcast(irank_io,isize*nn)
207 
208 ! write(6,*) 'nid', nid, (irank_io(i),i=0,nn-1)
209 
210  call mpi_comm_group(nekcomm,nekgroup,ierr)
211  if(ierr > 0) call exitt
212  call mpi_group_incl(nekgroup,nn,irank_io,nekgroup_io,ierr)
213  if(ierr > 0) call exitt
214  call mpi_comm_create(nekcomm,nekgroup_io,nekcomm_io,ierr)
215  if(ierr > 0) call exitt
216  call mpi_group_free(nekgroup_io,ierr)
217  if(ierr > 0) call exitt
218  call mpi_group_free(nekgroup,ierr)
219  if(ierr > 0) call exitt
220 #else
221  nekcomm_io = nekcomm
222  return
223 #endif
224 
225 #endif
226 
227  return
228 end subroutine nek_comm_io
subroutine mpi_group_free
Definition: mpi_dummy.F90:1071
subroutine mpi_comm_create(icomm, igroup, icommd, ierr)
Definition: mpi_dummy.F90:1056
subroutine bcast(buf, len)
Definition: comm_mpi.F90:289
subroutine byte_set_view(ioff_in, mpi_fh)
Definition: byte_mpi.F90:142
subroutine crecv(mtype, buf, lenm)
Definition: comm_mpi.F90:223
void exitt()
Definition: comm_mpi.F90:411
subroutine mpi_comm_group(icomm, igroup, ierr)
Definition: mpi_dummy.F90:1063
subroutine byte_read_mpi(buf, icount, iorank, mpi_fh, ierr)
Definition: byte_mpi.F90:43
subroutine byte_close_mpi(mpi_fh, ierr)
Definition: byte_mpi.F90:117
subroutine nek_comm_io(nn)
Definition: byte_mpi.F90:171
subroutine byte_sync_mpi(mpi_fh)
Definition: byte_mpi.F90:1
static uint np
Definition: findpts_test.c:63
subroutine csend(mtype, buf, len, jnid, jpid)
Definition: comm_mpi.F90:209
subroutine byte_open_mpi(fname, mpi_fh, ierr)
Definition: byte_mpi.F90:13
subroutine byte_write_mpi(buf, icount, iorank, mpi_fh, ierr)
Definition: byte_mpi.F90:81