WAVEWATCH III  beta 0.0.1
yowrankModule.F90
Go to the documentation of this file.
1 !PDLIB Software License
2 !
3 !Software, as understood herein, shall be broadly interpreted as being inclusive of algorithms,
4 !source code, object code, data bases and related documentation, all of which shall be furnished
5 !free of charge to the Licensee. Corrections, upgrades or enhancements may be furnished and, if
6 !furnished, shall also be furnished to the Licensee without charge. NOAA, however, is not
7 !required to develop or furnish such corrections, upgrades or enhancements.
8 !Roland & Partner software, whether that initially furnished or corrections or upgrades,
9 !are furnished "as is". Roland & Partner furnishes its software without any warranty
10 !whatsoever and is not responsible for any direct, indirect or consequential damages
11 !that may be incurred by the Licensee. Warranties of merchantability, fitness for any
12 !particular purpose, title, and non-infringement, are specifically negated.
13 !The Licensee is not required to develop any software related to the licensed software.
14 !However, in the event that the Licensee does so, the Licensee is required to offer same
15 !to Roland & Partner for inclusion under the instant licensing terms with Roland & Partner
16 !licensed software along with documentation regarding its principles, use and its advantages.
17 !This includes changes to the wave model proper including numerical and physical approaches
18 !to wave modeling, and boundary layer parameterizations embedded in the wave model
19 !A Licensee may reproduce sufficient software to satisfy its needs.
20 !All copies shall bear the name of the software with any version number
21 !as well as replicas of any applied copyright notice, trademark notice,
22 !other notices and credit lines. Additionally, if the copies have been modified,
23 !e.g. with deletions or additions, this shall be so stated and identified.
24 !All of Licensee's employees who have a need to use the software may have access
25 !to the software but only after reading the instant license and stating, in writing,
26 !that they have read and understood the license and have agreed to its terms.
27 !Licensee is responsible for employing reasonable efforts to assure
28 !that only those of its employees that should have access to the software, in fact, have access.
29 !The Licensee may use the software for any purpose relating to sea state prediction.
30 !No disclosure of any portion of the software, whether by means of a media or verbally,
31 !may be made to any third party by the Licensee or the Licensee's employees
32 !The Licensee is responsible for compliance with any applicable export or
33 !import control laws of the United States, the European Union and Germany.
34 !
35 !© 2009 Roland&Partner, Georgenstr.32, 64297 Germany. All rights reserved.
36 !PDLIB is a trademark of Roland & Partner. No unauthorized use without permission.
37 !
42 
45  use yowerr
46  implicit none
47  private
49 
50  type, public :: t_rank
52  integer :: np = 0
53 
55  integer :: npa = 0
56 
59  integer, allocatable :: iplg(:)
60 
62  integer:: istart = 0
63  end type t_rank
64 
68  type(t_rank),public, allocatable :: rank(:)
69  integer, public, allocatable :: ipgl_to_proc(:), ipgl_tot(:)
70  integer, public, allocatable :: ipgl_npa(:)
71 
72 contains
73 
75  subroutine initrankmodule()
77  implicit none
78  integer :: stat
79 
80  if(allocated(rank)) deallocate(rank)
81  allocate(rank(ntasks), stat=stat)
82  if(stat/=0) CALL abort('rank allocation failure')
83 
84  call exchangeiplg()
85  call calcistart()
86  end subroutine initrankmodule
87 
90  subroutine exchangeiplg()
92  use yowdatapool, only: ntasks, myrank, comm, itype
93  use mpi
94  implicit none
95  integer :: i, ierr, stat
96  integer :: sendRqst(nTasks), recvRqst(nTasks)
97  integer :: recvStat(MPI_STATUS_SIZE, nTasks), sendStat(MPI_STATUS_SIZE, nTasks)
98  integer IPglob, J, istat
99 
100  ! step1 exchange np
101  ! step2 exchange npa
102  ! step3 allocate rank%iplg
103  ! step4 exchange iplg
104 
105  ! step1 exchange np
106  ! post receives
107  do i=1, ntasks
108  if(i /= myrank+1) then
109  call mpi_irecv(rank(i)%np, 1, itype, i-1, &
110  42, comm, recvrqst(i), ierr)
111  if(ierr/=mpi_success) then
112  CALL parallel_abort("MPI_IRecv", ierr)
113  endif
114  else
115  recvrqst(i) = mpi_request_null
116  endif
117  end do
118 
119  ! post sends
120  do i=1, ntasks
121  if(i /= myrank+1) then
122  call mpi_isend(np, 1, itype, i-1, &
123  42, comm, sendrqst(i), ierr)
124  if(ierr/=mpi_success) then
125  CALL parallel_abort("MPI_ISend", ierr)
126  endif
127  else
128  sendrqst(i) = mpi_request_null
129  endif
130  end do
131 
132  rank(myrank+1)%np = np
133 
134  ! Wait for completion
135  call mpi_waitall(ntasks, recvrqst, recvstat,ierr)
136  if(ierr/=mpi_success) CALL parallel_abort("waitall", ierr)
137  call mpi_waitall(ntasks, sendrqst, sendstat,ierr)
138  if(ierr/=mpi_success) CALL parallel_abort("waitall", ierr)
139 
140  ! step2 exchange npa
141  ! post receives
142  do i=1, ntasks
143  if(i /= myrank+1) then
144  call mpi_irecv(rank(i)%npa, 1, itype, i-1, &
145  42, comm, recvrqst(i), ierr)
146  if(ierr/=mpi_success) then
147  CALL parallel_abort("MPI_IRecv", ierr)
148  endif
149  else
150  recvrqst(i) = mpi_request_null
151  endif
152  end do
153 
154  ! post sends
155  do i=1, ntasks
156  if(i /= myrank+1) then
157  call mpi_isend(npa, 1, itype, i-1, &
158  42, comm, sendrqst(i), ierr)
159  if(ierr/=mpi_success) then
160  CALL parallel_abort("MPI_ISend", ierr)
161  endif
162  else
163  sendrqst(i) = mpi_request_null
164  endif
165  end do
166 
167  rank(myrank+1)%npa = npa
168 
169  ! Wait for completion
170  call mpi_waitall(ntasks, recvrqst, recvstat,ierr)
171  if(ierr/=mpi_success) CALL parallel_abort("waitall", ierr)
172  call mpi_waitall(ntasks, sendrqst, sendstat,ierr)
173  if(ierr/=mpi_success) CALL parallel_abort("waitall", ierr)
174 
175  ! step3 allocal rank%iplg
176  do i=1, ntasks
177  if(allocated(rank(i)%iplg)) deallocate(rank(i)%iplg)
178  allocate(rank(i)%iplg(rank(i)%npa), stat=stat)
179  if(stat/=0) CALL abort('rank%iplg allocation failure')
180  rank(i)%iplg = 0
181  end do
182 
183  ! step4 exchange iplg
184  ! post receives
185  do i=1, ntasks
186  if(i /= myrank+1) then
187  call mpi_irecv(rank(i)%iplg, rank(i)%npa, itype, i-1, &
188  42, comm, recvrqst(i), ierr)
189  if(ierr/=mpi_success) then
190  CALL parallel_abort("MPI_IRecv", ierr)
191  endif
192  else
193  recvrqst(i) = mpi_request_null
194  endif
195  end do
196 
197  ! post sends
198  do i=1, ntasks
199  if(i /= myrank+1) then
200  call mpi_isend(iplg, npa, itype, i-1, &
201  42, comm, sendrqst(i), ierr)
202  if(ierr/=mpi_success) then
203  CALL parallel_abort("MPI_ISend", ierr)
204  endif
205  else
206  sendrqst(i) = mpi_request_null
207  endif
208  end do
209 
210  rank(myrank+1)%iplg = iplg
211 
212  ! Wait for completion
213  call mpi_waitall(ntasks, recvrqst, recvstat,ierr)
214  if(ierr/=mpi_success) CALL parallel_abort("waitall", ierr)
215  call mpi_waitall(ntasks, sendrqst, sendstat,ierr)
216  if(ierr/=mpi_success) CALL parallel_abort("waitall", ierr)
217 
218  allocate(ipgl_to_proc(np_global), ipgl_tot(np_global), stat=istat)
219  if(istat /= 0) CALL parallel_abort("allocatation error", 1)
220  do i=1,ntasks
221  DO j=1,rank(i)%np
222  ipglob=rank(i)%iplg(j)
223  ipgl_to_proc(ipglob)=i
224  ipgl_tot(ipglob)=j
225  END DO
226  END DO
227  allocate(ipgl_npa(np_global), stat=istat)
228  if(istat /= 0) CALL parallel_abort("allocatation error b", 1)
229  ipgl_npa=0
230  DO j=1,rank(myrank+1)%npa
231  ipglob=rank(myrank+1)%iplg(j)
232  ipgl_npa(ipglob)=j
233  END DO
234  end subroutine exchangeiplg
235 
237  subroutine calcistart()
239  implicit none
240  integer :: ir
241 
242  rank(1)%IStart = 1
243  do ir=2, ntasks
244  rank(ir)%IStart = rank(ir-1)%IStart + rank(ir-1)%np
245  end do
246  end subroutine calcistart
247 
248  subroutine finalizerankmodule()
249  implicit none
250  integer :: i
251 
252  if(allocated(rank)) then
253  do i=1, size(rank)
254  if(allocated(rank(i)%iplg)) deallocate(rank(i)%iplg)
255  end do
256  deallocate(rank)
257  endif
258  end subroutine finalizerankmodule
259 end module yowrankmodule
yowerr::parallel_abort
subroutine parallel_abort(string, error)
Definition: yowerr.F90:43
yowrankmodule::ipgl_tot
integer, dimension(:), allocatable, public ipgl_tot
Definition: yowrankModule.F90:69
yowrankmodule::initrankmodule
subroutine, public initrankmodule()
allocate and exchange
Definition: yowrankModule.F90:76
yowrankmodule::rank
type(t_rank), dimension(:), allocatable, public rank
Provides access to some information of all threads e.g.
Definition: yowrankModule.F90:68
yowrankmodule::exchangeiplg
subroutine exchangeiplg()
send iplg from this thread to every neighbor thread
Definition: yowrankModule.F90:91
yowrankmodule::ipgl_to_proc
integer, dimension(:), allocatable, public ipgl_to_proc
Definition: yowrankModule.F90:69
yownodepool::iplg
integer, dimension(:), allocatable, public iplg
Node local to global mapping.
Definition: yownodepool.F90:116
yowerr
Has some subroutine to make a nice error message.
Definition: yowerr.F90:39
yownodepool::npa
integer, public npa
number of ghost + resident nodes this partition holds
Definition: yownodepool.F90:99
yownodepool::np_global
integer, public np_global
number of nodes, global
Definition: yownodepool.F90:89
yowrankmodule::ipgl_npa
integer, dimension(:), allocatable, public ipgl_npa
Definition: yowrankModule.F90:70
yowdatapool::myrank
integer, save myrank
The thread id.
Definition: yowdatapool.F90:62
yowrankmodule::calcistart
subroutine calcistart()
Definition: yowrankModule.F90:238
yownodepool
Has data that belong to nodes.
Definition: yownodepool.F90:39
yowrankmodule
Provides access to some information of all threads e.g.
Definition: yowrankModule.F90:44
yownodepool::np
integer, public np
number of nodes, local
Definition: yownodepool.F90:93
yowdatapool
Has fancy data.
Definition: yowdatapool.F90:39
yowdatapool::comm
integer, save, public comm
MPI Communicator.
Definition: yowdatapool.F90:66
yowrankmodule::t_rank
Definition: yowrankModule.F90:50
yowerr::abort
subroutine abort(string, line, file, errno)
print various error strings and exit.
Definition: yowerr.F90:93
yowrankmodule::finalizerankmodule
subroutine, public finalizerankmodule()
Definition: yowrankModule.F90:249
yowdatapool::itype
integer, save itype
MPI Integer Type.
Definition: yowdatapool.F90:70
yowdatapool::ntasks
integer, save ntasks
Number of threads.
Definition: yowdatapool.F90:58