- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
I have a question regarding using MODULE in openMP.
Our program can be simplied by the following example. The parallel region iswithin subroutine SUB1. Variables A & B are from VAR1_ARRAYS modules. To remove the data dependence,we madeA & B as private. However, we found that A & B values are the same from different thread even though they should be different. Clearly A & B values are shared among the threads.
Within subroutine SUB1, variables A & B were not used even though they were marked asPRIVATE at he beginning of the parallel region. I am wondering if private will not work for this kinds of MODULES? Dowe have to pass A & B parameters in CALL SUB2(A,B) and CALL SUB3(A,B) instead ofusing MODULE?Or we have a bug somewhere?
MAIN program
call SUB1
.......
STOP
END
SUBROUTINE SUB1
USE VAR1_ARRAYS, ONLY: A, B
......
!$OMP parallel do private(A,B)
DO I = 1, II
CALL SUB2
CALL SUB3
ENDDO
RETURN
END
SUBROUTINE SUB2
USE VAR1_ARRAYS, ONLY: A, B
...
A=...
B=...
RETURN
END
SUBROUTINE SUB3
USE VAR1_ARRAYS, ONLY: A, B
...
C=A*B
...
RETURN
END
SUBROUTINEMODULES
MODULE VAR1_ARRAYS
REAL A, B
END MODULE
RETURN
END
Link Copied
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
I would expect that
REAL :: A, B
COMMON /FOO/ A, B
...
!$OMP PARALLEL DO PRIVATE(A,B)
Should provide for seperate storage for A and B
*** within the scope of the parallel region
*** and subsequently as dummy args when calling subroutine from parallel region
*** but not as common when calling subroutine within parallel region
The same behavior should apply to module data
What the user wants from the code sketch would be best served using THREADPRIVATE data (as you suggested).
*** cauton about thread private data ***
Learn how to use thread private data, it is your friend provided you use it correctly
1) Each thread has a seperateinstance of thread private data.
2) As contradictory as it may seem, use SHARED(xxx) for thread private data.
In this context SHARED means the parallel region is to use the variables
as-was expressed in the serial section (or parallel nested region prior to entering
next nested parallel region containing SHARED clause). Due to the fact that
the serial code has seperate instances of the thread private data
the as-was placement of the data was private per thread.
Marking as PRIVATE would make another instance of this data.
(potentially on the stack and uninitialized)
3) If you exit a parallel region and enter another parallel region
there is no assurance that the omp_get_thread_num() team members
of one team are the same threads of the same team member numbers
running in the other parallel region(s). Additionally, the two (multiple)
regions may have a different number of threads.
i.e. make sure allocations and initializations, if required,have beendone.
This may require insertion of
IF(.NOT. ALLOCATED(...
IF(.NOT. YourOnceOnlyCodeFlagInThreadPrivate) CALL YourOnceOnlyInit()
into your code
Once you familiarize your self with thread private data, it is relatively easy to use.
Jim Dempsey
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
assigned inside the parallel region.
Just want to confirm one thing, I don't need to declare threadprivate inside parallel regionafter USE VAR1_ARRAYS from every subroutine, right?
*************
MODULE VAR1_ARRAYS
REAL A,B
!$OMP threadprivate(a,b)
END MODULE
****************
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
subroutine foo
use var1_arrays
write(*,*) 'A located at', LOC(A)
!$OMP PARALLEL DEFAULT(PRIVATE)
!$OMP CRITICAL
write(*,*) 'A located at', LOC(A), OMP_GET_THREAD_NUM()
!$OMP END CRITICAL
!$OMP END PARALLEL
end subroutine foo
It is not clear as to if DEFAULT(PRIVATE) applies to threadprivate variables
I would assume that I will assume that it does
!$OMP PARALLEL DEFAULT(PRIVATE) SHARED(A,B)
would explicitly state that A and B were the variables as-were outside the scope of the parallel region.
Jim Dempsey
- Subscribe to RSS Feed
- Mark Topic as New
- Mark Topic as Read
- Float this Topic for Current User
- Bookmark
- Subscribe
- Printer Friendly Page