error in compiling using both gsl and openmp

General OpenMP discussion

error in compiling using both gsl and openmp

Postby robjons21 » Sun May 13, 2012 5:38 pm

Hello All,
I am trying to write a program that uses both GSL and OpenMP.

I have no problem using GSL and OpenMP separately, but I'm having issues using both. For instance, I can compile the GSL program By typing
Code: Select all
$gcc -c Bessel.c
$gcc Bessel.o -lgsl -lgslcblas -lm
$./a.out


and it works.

I was also able to compile the program that uses OpenMP In this case I typed
Code: Select all
$gcc -fopenmp test_omp.c
$./a.out


And I got what I wanted (all 4 threads I have were used).

However, when I simply write a program that combines the two codes
Code: Select all
#include <stdio.h>
#include <gsl/gsl_sf_bessel.h>
#include <omp.h>

int
main (void)
{
   double x = 5.0;
   double y = gsl_sf_bessel_J0 (x);
   printf ("J0(%g) = %.18e\n", x, y);`


int dimension = 4;
int i = 0;
int j = 0;
#pragma omp parallel private(i, j)
for (i =0; i < dimension; i++)
    for (j = 0; j < dimension; j++)
        printf("i=%d, jjj=%d, thread = %d\n", i, j, omp_get_thread_num());

return 0;

}`

Then I try to compile to typing
Code: Select all
$gcc -c Bessel_omp_test.c
$gcc Bessel_omp_test.o -fopenmp -lgsl -lgslcblas -lm
$./a.out

The GSL part works (The Bessel function is computed), but only one thread is used for the OpenMP part. I'm not sure what's wrong here...
If any body can help me here!!!
Thanks
robjons21
 
Posts: 1
Joined: Sun May 13, 2012 12:28 pm

Re: error in compiling using both gsl and openmp

Postby MarkB » Mon May 14, 2012 12:29 pm

I think you need to compile and link with the -fopenmp flag:

Code: Select all
$gcc -c -fopenmp Bessel_omp_test.c
$gcc Bessel_omp_test.o -fopenmp -lgsl -lgslcblas -lm
$./a.out
MarkB
 
Posts: 456
Joined: Thu Jan 08, 2009 10:12 am
Location: EPCC, University of Edinburgh


Return to Using OpenMP

Who is online

Users browsing this forum: No registered users and 15 guests