Reputation: 31
I'm having trouble getting OpenMP support in Visual Studio 2015.
I've configured the project options to use /openmp (project->properties->C/C++->language->OpenMP support:yes), the code is as follows (very simple code, to test OpenMP):
#include <iostream>
#include <omp.h>
int main(int argc, char* argv[])
{
int n = 0;
#pragma omp parallel
{
std::cout << std::endl << "Hello World!";
}
return 0;
}
Only one thread runs and "Hello World!" is printed only once.
Upvotes: 2
Views: 12900
Reputation: 2290
I was able to compile the program with VS2015 Community Version 14.0 Update 1
on Windows 8.1 64bit
with OpenMP support.
Below, follow a list of steps that may help:
Project-> Properties -> C/C++ -> Language
Change Open MP Support
to Yes(/openmp)
Click Apply
Command Line
and confirm that /openmp
appears somewhere at the compiler's options.If it appears, click Ok
and build the project.
Before run the program, put a breakpoint at the line:
int n = 0;
Run the the program by clicking on Local Windows Debugger
When the program stops at the breakpoint, go to Debug -> Windows -> Disassembly
Somewhere, near the breakpoint, look for an assembly line like:
call __vcomp_fork (?????????h)
If you find this line, chances are that openmp is ok and running.
Some other checks that can help:
Get a tool from Windows Sysinternals like Process Explorer (GUI) or ListDLLs (command line).
ListDLLs:
With the program stopped at the breakpoint, open task manager and look for the PID
of the process.
Open a command prompt and run the command:
listdlls [PID] | findstr -i vcomp
Should appear something like VCOMP140D.DLL
or VCOMP140.DLL
or VCOMP????.DLL
.
If it not appears, probably the compiler couldn't find the openmp dll so you'll have to see if this library is available at some point on your system.
Two last tips that may save your time:
If you change any configuration (e.g. Debug -> Release
or x86 -> x64
),
check again if Command Line
has the /openmp
option set ok.
If you try to force the compiler to C language (instead of C++), maybe the pragma:
#pragma omp parallel for
will not work (Update: Apparently this problem does not happen anymore on VS2017).
It shows me the message:
INTERNAL COMPILER ERROR in 'C:\Program Files (x86)\Microsoft Visual Studio 14.0\VC\bin\CL.exe'
Come back the compiler to C++ language and the parallel for
will works ok.
Upvotes: 7
Reputation: 31
Partial answer: I was not able to get the compiler to accept /openmp through the config/GUI, but compiling in console with cl.exe /openmp works.
Upvotes: 0