PGI User Forum
 SearchSearch   MemberlistMemberlist     RegisterRegister   ProfileProfile    Log inLog in 

CUDA-x86.

Problem with : OMP_NUM_THREADS
Goto page 1, 2  Next
 
Post new topic   Reply to topic    PGI User Forum Forum Index -> Programming and Compiling
View previous topic :: View next topic  
Author Message
forest_gump



Joined: 05 Oct 2006
Posts: 23

PostPosted: Thu Oct 05, 2006 4:05 am    Post subject: Problem with : OMP_NUM_THREADS Reply with quote

Hello ,

I have a program that use Open Mp Pragma with C, and put this test part in it



int nthreads, tid,maxth;



/* Fork a team of threads giving them their own copies of variables */

#pragma omp parallel private(tid)

{

/* Obtain thread number */
omp_set_num_threads(4);
tid = omp_get_thread_num();
maxth=omp_get_max_threads();
printf("Hello World from thread = %d\n", tid);



/* Only master thread does this */



// #pragma omp master

if(tid==0)

{

nthreads = omp_get_num_threads();

printf("Number of threads = %d\n", nthreads);
printf("Heloo max = %d\n", maxth);
}

}


[size=12]and he display to me


Hello World from thread = 0
Number of threads = 1
Heloo max = 3
[/size]

that false because i have server with four procesor !!!!!
and i try to export : OMP_NUM_THREADS, and get the same thing, the problem is that Number of threads is always one = 1, no parrallel execution

Any help would be deeply appreciated...
Thank's


Last edited by forest_gump on Thu Oct 05, 2006 5:11 am; edited 1 time in total
Back to top
View user's profile
Michael Suess



Joined: 14 Aug 2006
Posts: 5

PostPosted: Thu Oct 05, 2006 5:11 am    Post subject: Reply with quote

The results you get are correct. Remember that setting the number of threads with omp_set_num_threads () only effects the next parallel region, so nothing changes for the current parallel region (and therefore that statement in your code has no effect).

On the other hand, when you do set the environment variable OMP_NUM_THREADS, you should see a difference and if I do that and compile your program with the Portland Compiler, I do see a difference. Or did you maybe forget to compile with -mp? If you leave out that switch, I get the same results as you. So make sure to use it.

Hope that helps,
best regards,
Michael

--
Michael Suess
My blog on parallel programming
Back to top
View user's profile
forest_gump



Joined: 05 Oct 2006
Posts: 23

PostPosted: Thu Oct 05, 2006 6:02 am    Post subject: Reply with quote

Michael Suess wrote:
The results you get are correct. Remember that setting the number of threads with omp_set_num_threads () only effects the next parallel region, so nothing changes for the current parallel region (and therefore that statement in your code has no effect).

On the other hand, when you do set the environment variable OMP_NUM_THREADS, you should see a difference and if I do that and compile your program with the Portland Compiler, I do see a difference. Or did you maybe forget to compile with -mp? If you leave out that switch, I get the same results as you. So make sure to use it.

Hope that helps,
best regards,
Michael

--
Michael Suess
My blog on parallel programming




/******************************/
thank's but it's doesn't resolve the probleme
remember if that i dont use -mp it not display the s_max and the messages, else i use export and i get the same result..
is there any configuration of servet on other
that's the r
pgcc -B -02 -mp -c -o .....
......


pgcc -02 -mp *.o -o exec -lm
Back to top
View user's profile
mkcolg



Joined: 30 Jun 2004
Posts: 5952
Location: The Portland Group Inc.

PostPosted: Thu Oct 05, 2006 8:38 am    Post subject: Reply with quote

Hi forest_gump,

Besides calling omp_set_num_threads before the parallel section, you also need to use brackets to define the start and end of the section.

Fo example:
Code:
% cat omptest.c
#include <omp.h>

int main() {

  int nthreads, tid, maxth;

  /* Fork a team of threads giving them their own copies of variables */

  omp_set_num_threads(4);
#pragma omp parallel private(tid)
 {   
  /* Obtain thread number */
  //omp_set_num_threads(4);
  tid = omp_get_thread_num();
  maxth=omp_get_max_threads();
  printf("Hello World from thread = %d\n", tid);

  /* Only master thread does this */

  // #pragma omp master

  if(tid==0)
    {
      nthreads = omp_get_num_threads();
      printf("Number of threads = %d\n", nthreads);
      printf("Heloo max = %d\n", maxth);
     }
 }
  exit(0);
}

% pgcc -V6.2-3 -mp omptest.c -o omp.out
% omp.out
Hello World from thread = 0
Number of threads = 4
Heloo max = 4
Hello World from thread = 1
Hello World from thread = 3
Hello World from thread = 2


Hope this helps,
Mat
Back to top
View user's profile
forest_gump



Joined: 05 Oct 2006
Posts: 23

PostPosted: Thu Oct 05, 2006 9:27 am    Post subject: Reply with quote

mkcolg wrote:
Hi forest_gump,

Besides calling omp_set_num_threads before the parallel section, you also need to use brackets to define the start and end of the section.

Fo example:
Code:
% cat omptest.c
#include <omp.h>

int main() {

  int nthreads, tid, maxth;

  /* Fork a team of threads giving them their own copies of variables */

  omp_set_num_threads(4);
#pragma omp parallel private(tid)
 {   
  /* Obtain thread number */
  //omp_set_num_threads(4);
  tid = omp_get_thread_num();
  maxth=omp_get_max_threads();
  printf("Hello World from thread = %d\n", tid);

  /* Only master thread does this */

  // #pragma omp master

  if(tid==0)
    {
      nthreads = omp_get_num_threads();
      printf("Number of threads = %d\n", nthreads);
      printf("Heloo max = %d\n", maxth);
     }
 }
  exit(0);
}

% pgcc -V6.2-3 -mp omptest.c -o omp.out
% omp.out
Hello World from thread = 0
Number of threads = 4
Heloo max = 4
Hello World from thread = 1
Hello World from thread = 3
Hello World from thread = 2


Hope this helps,
Mat




thank's but i try this exemple just now and it work, but my main program do the same "that mean 1 threads whith 3thread maximun "
O yeah this programme use #ifdef PRRALLELE, to differ Parrallel from sequetien declaration,
i think that a compilation may heave an effct that 's why i give make file format


pgcc -B -mp -O2 -c -o n.o n.c
pgcc -B -mp -O2 -c -o an.o an.c
pgcc -B -mp -O2 -c -o ad.o ad.c
pgcc -B -mp -O2 -c -o tn.o tn.c
pgcc -B -mp -O2 -c -o o.o o.c
......ant other in the same way


pgcc -B -mp *.o (all the o extension) -o exec -lm

oh yeah thank and thank you
Back to top
View user's profile
Display posts from previous:   
Post new topic   Reply to topic    PGI User Forum Forum Index -> Programming and Compiling All times are GMT - 7 Hours
Goto page 1, 2  Next
Page 1 of 2

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © phpBB Group