- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Hello,
I encounter an error when compiling my software when activating openMP. This is a small program showing what I want to do :
program test_threadsafety use omp_lib implicit none integer :: i, nb nb = 20 !$omp parallel default(shared) !$omp do schedule(runtime) do i = 1, nb call make_save_variable(i) end do !$omp end do !$omp end parallel contains subroutine make_save_variable(i) implicit none integer, intent(in) :: i !$omp threadprivate(thread_id) integer, save :: thread_id = -1 if( thread_id == -1 ) then print *,'getting thread id ' thread_id = omp_get_thread_num() end if print *, 'in thread ', thread_id, ' iterator : ', i end subroutine end program
I have to say that it works fine with gfortran.... I run a 17.0.4 version of ifort.
Is this a bug or am I doing something wrong ?
Thanks for the help...
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Also the NAG compiler has no problem with the code. It looks like that ifort does not like the declaration of thread_id to come after the OMP statement. If I move the declaration up ahead of the OMP directive, the code also compiles with ifort. However, I don't know whether the standard has to say anything about this, but from the logical of the program flow, the declaration should come first.
Link Copied
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Also the NAG compiler has no problem with the code. It looks like that ifort does not like the declaration of thread_id to come after the OMP statement. If I move the declaration up ahead of the OMP directive, the code also compiles with ifort. However, I don't know whether the standard has to say anything about this, but from the logical of the program flow, the declaration should come first.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Thanks for the quick reply and the resolution.
That was a really stupid error from me ! Now that you pointed that out it makes so much sense... I will have to fix some bad programming habit.

- Subscribe to RSS Feed
- Mark Topic as New
- Mark Topic as Read
- Float this Topic for Current User
- Bookmark
- Subscribe
- Printer Friendly Page