- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
I am trying to parallelize a DO loop such as,
Nthread = OMP_get_max_threads()
allocate (A(N,Nthread))
A = 0.
!$OMP PARALLEL NUM_THREADS(Nthread) DEFAULT(shared) PRIVATE (i, ithread)
ithread = OMP_get_thread_num()+1 ! ... does this line belong here?
!$OMP DO SCHEDULE (static)
do i = 1,N
A(i,ithread) = ' ... results of long calculations'
end do
!$OMP END DO
!$OMP END PARALLEL
I want to allocate memory on my own and not have OpenMP make copies of the array A. Is the location of my call to ithread correct? I thought that after the call to the parallel, OpenMP spawns Nthread jobs but if I call ithread the way I have it, OpenMP will run the DO loop Nthread times which is not what I wanted.
Could someone please help me to understand how I can specify the thread ID's (i.e., ithread) to load the array A?
Thank you all so much for your help!
Sincerely,
David
Link Copied
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
@david47
I am not sure if I get your question / intention right.
First !$omp parallel is not a call to parallel, it instructs the compiler to create a parallel region and create threads according to the value of OMP_NUM_THREADS.
The array A is shared among threads as you do not declare it as private. There are no additional copies of array A.
!$omp do
Is a work sharing construct, the following iteration space of the do loop is distributed among threads created by the parallel region.
e.g. OMP_NUM_THREADS=2, N=10, iteration 1-5 will be executed by thread 0, 6-10 will be executed by thread 1, (assuming static scheduling).
With your usage of omp_get_thread_num() you will see:
A(1:5,1)=some data
A(5:10,1)=0
A(1:5,2)=0
A(5:10,2)=some data
However, the do loop is for sure not executed nthread times.
Best
Tobias
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
- Subscribe to RSS Feed
- Mark Topic as New
- Mark Topic as Read
- Float this Topic for Current User
- Bookmark
- Subscribe
- Printer Friendly Page