I want to parallelize the following code, and find which thread doing which task
subroutine costfunction(r,n,k,distancereg,indices,new_centro,cluster,cost,tid)
203 integer, dimension (:), allocatable, intent(out) :: distancereg, indices
204 integer, dimension (:), allocatable, intent(out) :: cluster
205 real, dimension (:,:), allocatable, intent(in) :: r
206 real, dimension (:,:), intent(in), allocatable :: new_centro
207 real, dimension(:), intent(out), allocatable :: cost
208 integer :: i,k
209 integer, intent (in):: tid
210 allocate(cluster(k))
211 allocate(cost(k))
212 allocate(distancereg(k))
213
214 call min_distance(r,n,k,centroid,distance,indices,distancereg)
215 cluster = 0
216
217 !$OMP PARALLEL DO private (i,k) shared (cluster,cost,indices)
218 tid = omp_get_thread_num()
219 do i=1,k
220 cost(i)=0
221 cluster(i)=count(indices==i)
222 cost(i)=(1.0/cluster(i))*distancereg(i)
223 print*, tid
224 end do
225 !$OMP END PARALLEL DO
226 print*," total sum of cluster members ",sum(cluster)," vs N ",n
227
228 end subroutine
But when it turns error on line 218 (tid) saying that unexpected assignment statement. I dont know where is the mistake,
The !$omp parallel do
should include only a do loop, no other statements.
If you want other statements, you can use an ordinary !$omp parallel
region with an !$omp do
inside. It is not required to combine the parallel
and do
into a single directive even if there is just the loop and nothing more.