39 mpi_comm, mpi_file, NN_src_ind_loc)
51 integer*4 :: nn_loc, mpi_id, mpi_np, count, mpi_comm, mpi_ierr
52 integer*4,
dimension(:),
allocatable :: NN_src_ind_ip
53 integer*4,
dimension(count) :: NN_src_ind_loc
54 integer*4,
dimension(mpi_np) :: count_proc_nhe
56 character*70 :: file_tomo, mpi_file, file_nhe_nnind, file_nhe_proc
57 character*70 :: file_nhe_new, file_nhe_nnind_new
58 integer*4 :: npts_tomo, stat, error, n_neighbours
59 real(kdkind) :: query_vec(3)
60 real(kdkind),
dimension(:),
allocatable :: xs_ip, ys_ip, zs_ip
61 real(kdkind),
dimension(:,:),
allocatable :: nodes_in_xyz
63 type(
kdtree2),
pointer :: kd2_obj
64 type(kdtree2_result) :: result_temp(1)
66 real*8 :: t0, t1, time_elapsed
67 real*8,
dimension(5) :: dummy
68 integer*4 :: i, j, ipt, inode, ip, ncount, unit_mpi
71 call mpi_barrier(mpi_comm, mpi_ierr)
72 call mpi_allgather(count, 1, speed_integer, count_proc_nhe, 1, speed_integer, mpi_comm, mpi_ierr)
83 file_tomo =
'tomo_xyz_mech.in'
85 open(124,file=file_tomo)
89 allocate(nodes_in_xyz(3,npts_tomo),stat=error)
91 write(*,*)
'error: couldnt allocate memory for array,',&
97 read(124,*)(nodes_in_xyz(i,ipt), i=1,3), (dummy(j), j=1,5)
106 kd2_obj =>
kdtree2_create(nodes_in_xyz,sort=.false.,rearrange=.true.)
116 file_nhe_proc =
'nhexyz000000.mpi'
117 file_nhe_nnind =
'nhenni000000.mpi'
120 write(file_nhe_proc(12:12),
'(i1)') ip
121 write(file_nhe_nnind(12:12),
'(i1)') ip
122 else if (ip .lt. 100)
then
123 write(file_nhe_proc(11:12),
'(i2)') ip
124 write(file_nhe_nnind(11:12),
'(i2)') ip
125 else if (ip .lt. 1000)
then
126 write(file_nhe_proc(10:12),
'(i3)') ip
127 write(file_nhe_nnind(10:12),
'(i3)') ip
128 else if (ip .lt. 10000)
then
129 write(file_nhe_proc(9:12),
'(i4)') ip
130 write(file_nhe_nnind(9:12),
'(i4)') ip
131 else if (ip .lt. 100000)
then
132 write(file_nhe_proc(8:12),
'(i5)') ip
133 write(file_nhe_nnind(8:12),
'(i5)') ip
134 else if (ip .lt. 1000000)
then
135 write(file_nhe_proc(7:12),
'(i6)') ip
136 write(file_nhe_nnind(7:12),
'(i6)') ip
139 if(len_trim(mpi_file) .ne. 70)
then
140 file_nhe_new = mpi_file(1:len_trim(mpi_file)) //
'/' // file_nhe_proc
141 file_nhe_nnind_new = mpi_file(1:len_trim(mpi_file)) //
'/' // file_nhe_nnind
143 file_nhe_new = file_nhe_proc
144 file_nhe_nnind_new = file_nhe_nnind
147 open(unit_mpi,file=file_nhe_new)
148 read(unit_mpi,*) ncount
149 if(ncount.ne.count_proc_nhe(ip+1))
then
150 write(*,*)
'ncount in NHE_proc files are not consistent'
154 if (ncount.gt.0)
then
155 allocate(xs_ip(ncount), ys_ip(ncount), zs_ip(ncount))
156 allocate(nn_src_ind_ip(ncount))
158 read(unit_mpi,*) xs_ip(inode), ys_ip(inode), zs_ip(inode)
166 if (ncount.gt.0)
then
168 query_vec(1) = xs_ip(inode)
169 query_vec(2) = ys_ip(inode)
170 query_vec(3) = zs_ip(inode)
172 nn_src_ind_ip(inode) = result_temp(1)%idx
176 open(unit_mpi,file=file_nhe_nnind_new)
177 if (ncount.gt.0)
then
179 write(unit_mpi,*) nn_src_ind_ip(i)
181 deallocate(xs_ip, ys_ip, zs_ip, nn_src_ind_ip)
188 deallocate(nodes_in_xyz)
194 call mpi_barrier(mpi_comm, mpi_ierr)
201 file_nhe_nnind =
'nhenni000000.mpi'
202 unit_mpi = 1500 + mpi_id
203 if (mpi_id.lt. 10)
then
204 write(file_nhe_nnind(12:12),
'(i1)') mpi_id
205 else if (mpi_id .lt. 100)
then
206 write(file_nhe_nnind(11:12),
'(i2)') mpi_id
207 else if (mpi_id .lt. 1000)
then
208 write(file_nhe_nnind(10:12),
'(i3)') mpi_id
209 else if (mpi_id .lt. 10000)
then
210 write(file_nhe_nnind(9:12),
'(i4)') mpi_id
211 else if (mpi_id .lt. 100000)
then
212 write(file_nhe_nnind(8:12),
'(i5)') mpi_id
213 else if (mpi_id .lt. 1000000)
then
214 write(file_nhe_nnind(7:12),
'(i6)') mpi_id
217 if(len_trim(mpi_file) .ne. 70)
then
218 file_nhe_nnind_new = mpi_file(1:len_trim(mpi_file)) //
'/' // file_nhe_nnind
220 file_nhe_nnind_new = file_nhe_nnind
223 open(unit_mpi,file=file_nhe_nnind_new)
226 read(unit_mpi,*) nn_src_ind_loc(inode)
231 call mpi_barrier(mpi_comm, mpi_ierr)