2

I have a strange issue. I have a Matlab mexfunction in which I have used OpenMP directives/functions. Before the beginning of a parallel section (parallel for...), I use commands to set and print the number of threads created:


nP = omp_get_num_procs();
omp_set_num_threads(nP);
mexPrintf("\n Num of threads= %d\n",nP);
.
.
.
#pragma omp parallel for shared(...)

The issue is, at the output, it prints 'Num of threads= 12', but the parallel section which follows does not run on all 12 cores of my machine (but on only 1 core). My program was written long back and I had no such issue earlier (it ran on all 12 cores). Recently, the system got corrupted and OS (Win 7 Pro) was reinstalled with updated version of Matlab 2011b (earlier 2010b). I also installed Visual Studio 2010 Pro.

Is there anything I am missing or overlooking?

Andrey Rubshtein
  • 20,795
  • 11
  • 69
  • 104
  • Did you configure Windows to use only one core? http://www.sevenforums.com/tutorials/66504-processors-limit-number-used-windows-7-a.html. Windows Server 2008 has also limits depending on the editon you did buy how many cores are used (http://www.directionsonmicrosoft.com/sample/DOMIS/update/2008/02feb/0208ws2plp_ch.htm). – Alois Kraus Jan 16 '12 at 21:23
  • @AloisKraus: The question says Windows 7 Pro, which supports two physical processor sockets (and many cores/socket). – Ben Voigt Jan 16 '12 at 22:08

1 Answers1

0

Are you calling mex functions inside the omp parallel for block?

I've had the best luck extracting pointers first sequentially, then processing in parallel, and then loading results into matlab variables sequentially at the end. That way the parallel code is pure C++, no mex functions called (that could wait for a shared lock).

Of course, make sure you're actually compiling with OpenMP enabled... otherwise the directives get ignored and you end up with sequential code.

Ben Voigt
  • 277,958
  • 43
  • 419
  • 720