C recursion multithreaded but multiplies only at first call

General OpenMP discussion

C recursion multithreaded but multiplies only at first call

Postby amiba » Sat Jan 11, 2014 5:49 pm

Somethin I might get soon, but maybe someone could explain this to me, what is quicker. I'am very new to OpenMP. I did a short programm that uses recursion. My Processor is able to use 8 threads. But if I watch the Cores it is only using the multiplication of threads in the first call of the subroutine.

Here is the basic code:
Code: Select all
int wins_c_Kalaha(char whole, __gameboard__ board)
  int i,min_win;
some code;
#pragma omp parallel for private(i) schedule(dynamic)
  for(i=8;i<14;i++) if(board.s[i]) min_win=((j=wins_c_Kalaha(i,board)) < min_win ? j : min_win;
some code;

The result is working but if there are 6 possibilieties in the first turn, it uses 6 Thread at all if there are 2 only two and it gets not more multiplicated in one of the subrutines. Is there a way to tell it to start as long as there is a thread free new threads in this subcall. What did I wrong that this is happend and for what is that private(i) needed, that I took only out of a discription somewhere.

May someone more expirenced whith this OpenMP tell me this small informations. Thanks for help, because I like to understand all I programm more to sort out faults in other programs where there must not be a fault.
Posts: 1
Joined: Sat Jan 11, 2014 4:39 pm

Re: C recursion multithreaded but multiplies only at first c

Postby MarkB » Tue Jan 14, 2014 3:24 am

Hi there,

I expect your OpenMP implementation has nested parallelism disabled by default: to enable it you can set the environment variable OMP_NESTED=true or call omp_set_nested(1)

Declaring i private is not required: as the parallel loop iterator it is private by default.

Using nested parallel for recursive parallelism is rather inflexible and heavyweight: you might want to look at using (nested) tasks instead.

Hope that helps,
Posts: 486
Joined: Thu Jan 08, 2009 10:12 am
Location: EPCC, University of Edinburgh

Return to Using OpenMP

Who is online

Users browsing this forum: Exabot [Bot], Google [Bot], Yahoo [Bot] and 6 guests