I am been such a nube, here how it works:
module variables
use omp_lib
integer :: row, col
integer :: omp_threads_id, omp_num_of_nodes
real*8, allocatable, dimension ( : ) :: GLOBAL ( :, :, : )
real*8, allocatable, dimension ( : ) :: LOCAL( :, : )
!$omp threadprivate(GLOBAL, LOCAL)
end module variables
module sublocal
use variables
implicit none
contains
subroutine sub
integer :: i, j
do i = 1, 2
allocate(LOCAL(2, 2))
LOCAL = 0
do j = 1, 2
LOCAL(i, j) = i+j*4
GLOBAL(1, i, j) = LOCAL(i, j)
print*, 'SUB: ',GLOBAL(1, i, j)
end do
deallocate(LOCAL)
end do
end subroutine sub
end module sublocal
program openmp
use variables
use sublocal
use omp_lib
implicit none
print*, '----------------------------------------------'
omp_num_of_nodes = omp_get_num_procs()
call omp_set_num_threads( omp_num_of_nodes )
print*, 'Number of threads available: ', omp_num_of_nodes
!$omp parallel
omp_threads_id = omp_get_thread_num()
print*, 'Thread number: ', omp_threads_id, 'responded.'
!$omp end parallel
print*, '----------------------------------------------'
!$omp parallel default(shared)
!$omp do private(row, col)
do row=1, 2
allocate(GLOBAL(2, 2, 2))
GLOBAL = 0
do col=1, 2
omp_threads_id = omp_get_thread_num()
call sub
print*, 'MAIN: 'GLOBAL(1, row, col)
end do
deallocate(GLOBAL)
end do
!$omp end do
!$omp end parallel
call system("PAUSE")
end program openmp
Rules:
A variable can only appear in a THREADPRIVATE directive in the scope in which it is declared, and a THREADPRIVATE variable or common block may only appear once in a given scope. The variable must not be an element of a common block, or be declared in an EQUIVALENCE statement.
NOTE: I wanted to know how often Intel support checks this forum thread? Since my question was here more than 24 hours, and if I post my question wrong can you highlight which part in order to post next time more correct question to get faster respond.
Thanks for everything.