I am trying to parallelize a very long-running function in a DLL. The DLL in question is begin built with the command line:
/JMC /permissive- /MP /ifcOutput “x64Debug” /GS /W3 /Zc:wchar_t /ZI /Gm- /Od /sdl /Fd”x64Debugvc143.pdb” /Zc:inline /D “_WINDOWS” /D “_USRDLL” /D “BOOST_INTERPROCESS_SHARED_DIR_FUNC” /D “_SILENCE_FPOS_SEEKPOS_DEPRECATION_WARNING” /D “USE_NEW_CACHE” /D “_UNICODE” /D “UNICODE” /D “_WINDLL” /D “_DEBUG” /errorReport:prompt /WX /Zc:forScope /RTC1 /Gd /MTd /std:c++17 /FC /Fa”x64Debug” /EHsc /nologo /Fo”x64Debug” /Fp”x64DebugMyLib.pch” /diagnostics:column
I believe the /MP flag should be allowing the pragma to work.
Due to a classification issue, I can only provide the relevant excerpt.
#include <omp.h>
...
int totalThreads = omp_get_num_procs();
int nThreads = totalThreads;
if (totalThreads > 6)
{
nThreads -= 4;
}
else if (totalThreads > 2)
{
nThreads -= 2;
}
stringstream ss;
ss << "Total Threads: " << totalThreads << " using: " << nThreads;
TRACE(ss.str().c_str());
omp_set_num_threads(nThreads);
#pragma omp parallel for
for (int i = 0; i < 11; i++)
{
int avail = omp_get_num_threads();
stringstream ss;
ss <<"parallel run: " << i << " of " << avail;
TRACE(ss.str().c_str());
The TRACE macro executes a real-time UDP logger which reports “Total Threads: 20 using 16” which is what I expected from the TRACE outside of the loop. The second TRACE reports: “parallel run: 0 of 1”. If the for loop were actually being run in parallel, I would expect to see “parallel run: 0 of 16”.
The 0 of 1 is what I would expect outside of the loop, as omp_get_num_procs returns 1 for serial areas of code.
What am I missing? there are no warnings.