How to initialize the parallelization

General OpenMP discussion

How to initialize the parallelization

Postby OMP_Son » Mon May 27, 2013 11:05 pm

DEar All,

I wish to use the OpenMP in gfortran. Gnu fortran is integrated in CodeBlocks IDE editor, I set the required linker directive(-fopenmp) in order to be able to use the features of parallelism but simple code snippet below returns the unintelligible results for number of process running. It seems that there is not any initialization difficulties since there is no complain from compiler during compilation time, otherwise compiler would raise unknown functions/procedures for all the calling.

What am I doing wrong here?

Code: Select all
program main
integer::threads,id
    !$OMP PARALLEL
    threads = omp_get_num_procs();
    id = omp_get_thread_num()
    write(*,*)'In parallel region (T)? ',  omp_get_max_threads()
    write(*,*)'Threads allocated : ', OMP_get_num_procs()
    !$OMP PARALLEL END
end
OMP_Son
 
Posts: 1
Joined: Sun Nov 04, 2012 8:00 am

Re: How to initialize the parallelization

Postby MarkB » Tue May 28, 2013 2:57 am

Hi there,

You do need to compile with -fopenmp as well as link with it, otherwise the OpenMP directives will be silently ignored, and the OpenMP library functions implicitly given the wrong type. Since !$OMP PARALLEL END is not the right syntax (should be !$OMP END PARALLEL) you ought to be seeing a compiler error!
You also need to add USE OMP_LIB at the start of the program to get the correct types for the library functions.

If you wish to find out the number of threads executing the current parallel region, you should call omp_get_num_threads().

omp_get_max_threads() returns the number of threads that would be used to execute a parallel region if a parallel construct were encountered at that point in the code. Calling this from inside a parallel region will return 1 if nested parallelism is not enabled. You could call this before the parallel region, in which case it will give you what you are looking for.

omp_get_num_procs() returns the number of processors in the hardware the code is executing on.



Hope that helps,
Mark.
MarkB
 
Posts: 422
Joined: Thu Jan 08, 2009 10:12 am

Re: How to initialize the parallelization

Postby ftinetti » Tue May 28, 2013 3:39 am

Hi

Gnu fortran is integrated in CodeBlocks IDE editor, I set the required linker directive(-fopenmp) in order to be able to use the features of parallelism

Last time I did something in CodeBlocks (many months ago...) I had to set -fopenmp as a compiler as well as linker project options as follows:

Project --> Build options... (project name selected in the left panel)
Compiler settings --> Other options: -fopenmp
Linker settings --> Other linker options: -fopenmp

But maybe it has been changed... I'm curious: what do you mean by "Gnu fortran is integrated in CodeBlocks IDE editor"?

HTH,

Fernando.
ftinetti
 
Posts: 567
Joined: Wed Feb 10, 2010 2:44 pm


Return to Using OpenMP

Who is online

Users browsing this forum: No registered users and 8 guests