- Marcar como novo
- Marcador
- Subscrever
- Silenciar
- Subscrever fonte RSS
- Destacar
- Imprimir
- Denunciar conteúdo inapropriado
Hi,
I have recenly implemented openMP in our software. I want the same source code that can
be complied parallelly or sequentially. The question is that howto do thatif I want to specify the number of threads as input?
My code is like the following:
....
call omp_set_num_threads(thread_num)
!$OMP parallel do private(num_thread)
DO I = 1, NP
num_thread=1
!$ num_thread = omp_get_thread_num()+1
.....
ENDDO
The number of threads thread_num is read from input. Inside the paralle region, the thread number num_thread from each thread
is used.For a non-openMP platform,thread_num is set to be1 from input.
!$ is treated as comment by a non-OpenMP compiler. So the do loop is run serially. But 'call omp_set_num_threads()' library can not be compiled in a non-openMP compiler.
Do you have any suggestions about setting the number of threads in openMP while the code can be compiled in non-opnMP platform? Thanks.
I have recenly implemented openMP in our software. I want the same source code that can
be complied parallelly or sequentially. The question is that howto do thatif I want to specify the number of threads as input?
My code is like the following:
....
call omp_set_num_threads(thread_num)
!$OMP parallel do private(num_thread)
DO I = 1, NP
num_thread=1
!$ num_thread = omp_get_thread_num()+1
.....
ENDDO
The number of threads thread_num is read from input. Inside the paralle region, the thread number num_thread from each thread
is used.For a non-openMP platform,thread_num is set to be1 from input.
!$ is treated as comment by a non-OpenMP compiler. So the do loop is run serially. But 'call omp_set_num_threads()' library can not be compiled in a non-openMP compiler.
Do you have any suggestions about setting the number of threads in openMP while the code can be compiled in non-opnMP platform? Thanks.
- Marcas:
- Intel® Fortran Compiler
Link copiado
4 Respostas
- Marcar como novo
- Marcador
- Subscrever
- Silenciar
- Subscrever fonte RSS
- Destacar
- Imprimir
- Denunciar conteúdo inapropriado
Could you just "omp comment" out the call in the same way?
!$ use omp_lib
...
!$ call omp_set_num_threads(thread_num)
You could use "normal" compiler directives too:
!DEC$ IF DEFINED(_OPENMP)
call omp_set_num_threads(thread_num)
!DEC$ ELSE
write (*,"(A)") "I can only deal with one thing at a time"
!DEC$ ENDIF
Or you could use the C-like preprocessor (/fpp command line option):
#ifdef _OPENMP
call omp_set_num_threads(thread_num)
#else
write (*,"(A)") "I'm feeling very serial today"
#endif
!$ use omp_lib
...
!$ call omp_set_num_threads(thread_num)
You could use "normal" compiler directives too:
!DEC$ IF DEFINED(_OPENMP)
call omp_set_num_threads(thread_num)
!DEC$ ELSE
write (*,"(A)") "I can only deal with one thing at a time"
!DEC$ ENDIF
Or you could use the C-like preprocessor (/fpp command line option):
#ifdef _OPENMP
call omp_set_num_threads(thread_num)
#else
write (*,"(A)") "I'm feeling very serial today"
#endif
- Marcar como novo
- Marcador
- Subscrever
- Silenciar
- Subscrever fonte RSS
- Destacar
- Imprimir
- Denunciar conteúdo inapropriado
You can also link with the OpenMP "stubs" library, which links in NO-OP functions.
Or you can write your own no-op stub functions.
Comment what may happen in your code when a requrest is made for more than one thread while linked with stubs. Or possibly write out a diagnostic message
write (*,*) "Attempting to specify ", nThreads, "threads when OpenMP not available, using 1 thread instead"
nThreads = 1
Jim
Or you can write your own no-op stub functions.
Comment what may happen in your code when a requrest is made for more than one thread while linked with stubs. Or possibly write out a diagnostic message
write (*,*) "Attempting to specify ", nThreads, "threads when OpenMP not available, using 1 thread instead"
nThreads = 1
Jim
- Marcar como novo
- Marcador
- Subscrever
- Silenciar
- Subscrever fonte RSS
- Destacar
- Imprimir
- Denunciar conteúdo inapropriado
I use the following seemingly obvious method:
#ifdef _OPENMP
#else
num_thread=1
#endif
given that it is standard practice to guard all omp_ calls by #ifdef _OPENMP so as to permit compilation without OpenMP compiler.
#ifdef _OPENMP
#else
num_thread=1
#endif
given that it is standard practice to guard all omp_ calls by #ifdef _OPENMP so as to permit compilation without OpenMP compiler.
- Marcar como novo
- Marcador
- Subscrever
- Silenciar
- Subscrever fonte RSS
- Destacar
- Imprimir
- Denunciar conteúdo inapropriado
#if... requires a preprocessor
I prefer to use #if myself since I use IVF which has a preprocessor (also has OpenMP).
OP requested technique for system with compiler without OpenMP support. It is unknown as to if this compiler (or system) has a preprocessor for use with Fortran.
Jim
I prefer to use #if myself since I use IVF which has a preprocessor (also has OpenMP).
OP requested technique for system with compiler without OpenMP support. It is unknown as to if this compiler (or system) has a preprocessor for use with Fortran.
Jim
Responder
Opções do tópico
- Subscrever fonte RSS
- Marcar tópico como novo
- Marcar tópico como lido
- Flutuar este Tópico para o utilizador atual
- Marcador
- Subscrever
- Página amigável para impressora