-Mconcur with -shared

If a shared library is created with -Mconcur at compile and link time, will the resulting shared object code run in multiple threads. For example a Matlab MEX function which is a shared library with exported function mexFunction. If I compile the code with -Mconcur will it use multiple threads, or will this only work when creating a program also linked as -Mconcur.

Hi Christopher,

This should work when compiling a shared library using -Mconcur will execute in parallel even if an application is not compiled or linked with -Mconcur (or even with the PGI compilers). You do have to remember to set the environment variable NCPUS. Though, I have not tried it myself and am not 100% positive. I’ll try and get an example together to see if I can convince myself this does work as stated.

  • Mat

Yes, I too have verified this works.

Related to this is using -mp/-Mconcur in matlab. Matlab crashes when “unloading” the library. This only happens when NCPUS > 1. I’ve tried digging through the assembly output from objdump -d, but compiler generated PIC code was not covered in any of my assembly classes! I think this is a matlab problem as programs exhibit no behavior of this sort. I’ve reported this to the mathworks, but there response is that matlab is single-threaded and trying to use multi-threaded code produces undefined behavior. I can send the assembly code if desired. I’m sure the portland group doesn’t really feel like looking into it either, but any thoughts on the matter would be appreciated. I’ve seen tremendous improvement with the parallel code in stand-alone programs, but we use a lot of matlab here and so I’ve been testing whether we can use openMP on our libraries. I’ve used the pthread library for parallelizing large loops, but openMP is much cleaner :)! Really impressed with PGI thus fard and will be recommending it despite the matlab problem.


Hi Chris,

We don’t have Matlab here so we wouldn’t be able to recreate problem and just looking at the disassembly from objdump probably wouldn’t help in this case. However, one thing you can try is to use the core file, if it exists, to determine what caused the crash and where it occurred.

Using pgdbg run: "pgdbg -core "

Once loaded, type “where” in the command window to get a stack trace.

Also, thank you for the compliment!

  • Mat