Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
59 changes: 35 additions & 24 deletions docs/build/reference/openmp-enable-openmp-2-0-support.md
Original file line number Diff line number Diff line change
@@ -1,47 +1,57 @@
---
title: "/openmp (Enable OpenMP 2.0 Support)"
ms.date: "11/04/2016"
title: "/openmp (Enable OpenMP Support)"
ms.date: "04/15/2019"
f1_keywords: ["/openmp", "VC.Project.VCCLCompilerTool.OpenMP"]
helpviewer_keywords: ["/openmp compiler option [C++]", "-openmp compiler option [C++]"]
ms.assetid: 9082b175-18d3-4378-86a7-c0eb95664e13
---
# /openmp (Enable OpenMP 2.0 Support)
# /openmp (Enable OpenMP Support)

Causes the compiler to process `#pragma`[omp](../../preprocessor/omp.md).
Causes the compiler to process [`#pragma omp`](../../preprocessor/omp.md) directives in support of OpenMP.

## Syntax

```
/openmp
```
::: moniker range=">= vs-2019"

> **/openmp**\[**:**__experimental__]

::: moniker-end

::: moniker range="<= vs-2017"

> **/openmp**

::: moniker-end

## Remarks

`#pragma omp` is used to specify [Directives](../../parallel/openmp/reference/openmp-directives.md) and [Clauses](../../parallel/openmp/reference/openmp-clauses.md). If **/openmp** is not specified in a compilation, the compiler ignores OpenMP clauses and directives. [OpenMP Function](../../parallel/openmp/reference/openmp-functions.md) calls are processed by the compiler even if **/openmp** is not specified.
`#pragma omp` is used to specify [Directives](../../parallel/openmp/reference/openmp-directives.md) and [Clauses](../../parallel/openmp/reference/openmp-clauses.md). If **/openmp** isn't specified in a compilation, the compiler ignores OpenMP clauses and directives. [OpenMP Function](../../parallel/openmp/reference/openmp-functions.md) calls are processed by the compiler even if **/openmp** isn't specified.

Applications compiled with **/openmp** and **/clr** can only be run in a single application domain process; multiple application domains are not supported. That is, when the module constructor (.cctor) is run, it will detect the process is compiled with **/openmp** and if the application is being loaded into a non-default runtime. For more information, see [appdomain](../../cpp/appdomain.md), [/clr (Common Language Runtime Compilation)](clr-common-language-runtime-compilation.md), and [Initialization of Mixed Assemblies](../../dotnet/initialization-of-mixed-assemblies.md).
::: moniker range=">= vs-2019"

If you attempt to load an application compiled with **/openmp** and **/clr** into a non-default application domain, a <xref:System.TypeInitializationException> exception will be thrown outside the debugger and a OpenMPWithMultipleAppdomainsException exception will be thrown in the debugger.
The C++ compiler currently supports the OpenMP 2.0 standard. However, Visual Studio 2019 also now offers SIMD functionality. To use SIMD, compile by using the **/openmp:experimental** option. This option enables both the usual OpenMP features, and additional OpenMP SIMD features not available when using the **/openmp** switch.

::: moniker-end

Applications compiled by using both **/openmp** and **/clr** can only be run in a single application domain process. Multiple application domains aren't supported. That is, when the module constructor (`.cctor`) is run, it detects if the process is compiled using **/openmp**, and if the app is loaded into a non-default runtime. For more information, see [appdomain](../../cpp/appdomain.md), [/clr (Common Language Runtime Compilation)](clr-common-language-runtime-compilation.md), and [Initialization of Mixed Assemblies](../../dotnet/initialization-of-mixed-assemblies.md).

If you attempt to load an app compiled using both **/openmp** and **/clr** into a non-default application domain, a <xref:System.TypeInitializationException> exception is thrown outside the debugger, and a `OpenMPWithMultipleAppdomainsException` exception is thrown in the debugger.

These exceptions can also be raised in the following situations:

- If your application compiled with **/clr**, but not with **/openmp**, is loaded into a non-default application domain but where the process includes an application that was compiled with **/openmp**.
- If your application is compiled using **/clr** but not **/openmp**, and is loaded into a non-default application domain, where the process includes an app compiled using **/openmp**.

- If you pass your **/clr** application to a utility, such as regasm.exe ([Regasm.exe (Assembly Registration Tool)](/dotnet/framework/tools/regasm-exe-assembly-registration-tool)), which loads its target assemblies into a non-default application domain.
- If you pass your **/clr** app to a utility, such as [regasm.exe](/dotnet/framework/tools/regasm-exe-assembly-registration-tool), which loads its target assemblies into a non-default application domain.

The common language runtime's code access security doesn’t work in OpenMP regions. If you apply a CLR code access security attribute outside a parallel region, it won't be in effect in the parallel region.

Microsoft advises that you do not write **/openmp** applications that allows partially trusted callers, using <xref:System.Security.AllowPartiallyTrustedCallersAttribute>, or any CLR code access security attributes.
Microsoft doesn't recommend that you write **/openmp** apps that allow partially trusted callers. Don't use <xref:System.Security.AllowPartiallyTrustedCallersAttribute>, or any CLR code access security attributes.

### To set this compiler option in the Visual Studio development environment

1. Open the project's **Property Pages** dialog box. For details, see [Set C++ compiler and build properties in Visual Studio](../working-with-project-properties.md).

1. Expand the **Configuration Properties** node.

1. Expand the **C/C++** node.

1. Select the **Language** property page.
1. Expand the **Configuration Properties** > **C/C++** > **Language** property page.

1. Modify the **OpenMP Support** property.

Expand All @@ -51,13 +61,13 @@ Microsoft advises that you do not write **/openmp** applications that allows par

## Example

The following sample shows some of the effects of threadpool startup versus using the threadpool after it started up. Assuming an x64, single core, dual processor the threadpool takes about 16ms to startup. After that though there is very little cost for the threadpool.
The following sample shows some of the effects of thread pool startup versus using the thread pool after it has started. Assuming an x64, single core, dual processor, the thread pool takes about 16 ms to start up. After that, there's little extra cost for the thread pool.

When you compile with **/openmp**, the second call to test2 never runs any longer than if you compile with **/openmp-**, as there is no threadpool startup. At a million iterations the **/openmp** version is faster than the **/openmp-** version for the second call to test2, and at 25 iterations both **/openmp-** and **/openmp** versions register less than the clock granularity.
When you compile using **/openmp**, the second call to test2 never runs any longer than if you compile using **/openmp-**, as there's no thread pool startup. At a million iterations, the **/openmp** version is faster than the **/openmp-** version for the second call to test2. At 25 iterations, both **/openmp-** and **/openmp** versions register less than the clock granularity.

So if you have only one loop in your application and it runs in less than 15ms (adjusted for the approximate overhead on your machine), **/openmp** may not be appropriate, but if it's anything more than that, you may want to consider using **/openmp**.
If you have only one loop in your application and it runs in less than 15 ms (adjusted for the approximate overhead on your machine), **/openmp** may not be appropriate. If it's higher, you may want to consider using **/openmp**.

```
```cpp
// cpp_compiler_options_openmp.cpp
#include <omp.h>
#include <stdio.h>
Expand Down Expand Up @@ -103,5 +113,6 @@ int main(int argc, char* argv[]) {

## See also

[MSVC Compiler Options](compiler-options.md)<br/>
[MSVC Compiler Command-Line Syntax](compiler-command-line-syntax.md)
[MSVC Compiler Options](compiler-options.md) \
[MSVC Compiler Command-Line Syntax](compiler-command-line-syntax.md) \
[OpenMP in MSVC](../../parallel/openmp/openmp-in-visual-cpp.md)
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
---
title: "Linker Tools Warning LNK4049"
ms.date: "04/09/2019"
ms.date: "04/15/2019"
f1_keywords: ["LNK4049"]
helpviewer_keywords: ["LNK4049"]
ms.assetid: 5fd5fb24-c860-4149-a557-0ac26a65d97c
Expand All @@ -9,7 +9,9 @@ ms.assetid: 5fd5fb24-c860-4149-a557-0ac26a65d97c

> symbol '*symbol*' defined in '*filename.obj*' is imported

The symbol was both exported from and imported to the program.
[__declspec(dllimport)](../../cpp/dllexport-dllimport.md) was specified for *symbol* even though the symbol is defined in object file *filename.obj* in the same image. Remove the `__declspec(dllimport)` modifier to resolve this warning.

## Remarks

This warning is generated by the linker when you define a symbol in one object file and reference it by using the `__declspec(dllimport)` declaration modifier in another.

Expand All @@ -25,7 +27,7 @@ To resolve LNK4049, try one of the following procedures:

- Remove the `__declspec(dllimport)` modifier from the forward declaration of the symbol that triggered LNK4049. You can search for symbols within a binary image by using the **DUMPBIN** utility. The **DUMPBIN /SYMBOLS** switch displays the COFF symbol table of the image. For more information on the **DUMPBIN** utility, see [DUMPBIN Reference](../../build/reference/dumpbin-reference.md).

- Temporarily disable incremental linking and whole-program optimization. When recompiled, the application generates Warning LNK4217, which includes the name of the function which references the imported symbol. Remove the `__declspec(dllimport)` declaration modifier from the imported symbol and re-enable incremental linking or whole-program optimization as required.
- Temporarily disable incremental linking and whole-program optimization. When recompiled, the application generates Warning LNK4217, which includes the name of the function that references the imported symbol. Remove the `__declspec(dllimport)` declaration modifier from the imported symbol and re-enable incremental linking or whole-program optimization as required.

Although the final generated code behaves correctly, the code generated to call the imported function is less efficient than calling the function directly. This warning doesn't appear when you compile by using the [/clr](../../build/reference/clr-common-language-runtime-compilation.md) option.

Expand Down
12 changes: 10 additions & 2 deletions docs/error-messages/tool-errors/linker-tools-warning-lnk4217.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
---
title: "Linker Tools Warning LNK4217"
ms.date: "04/09/2019"
ms.date: "04/15/2019"
f1_keywords: ["LNK4217"]
helpviewer_keywords: ["LNK4217"]
ms.assetid: 280dc03e-5933-4e8d-bb8c-891fbe788738
Expand All @@ -11,6 +11,8 @@ ms.assetid: 280dc03e-5933-4e8d-bb8c-891fbe788738

[__declspec(dllimport)](../../cpp/dllexport-dllimport.md) was specified for a symbol even though the symbol is defined in an object file in the same image. Remove the `__declspec(dllimport)` modifier to resolve this warning.

## Remarks

*symbol* is the symbol name that's defined within the image. *function* is the function that's importing the symbol.

This warning doesn't appear when you compile by using the [/clr](../../build/reference/clr-common-language-runtime-compilation.md) option.
Expand All @@ -33,4 +35,10 @@ And then,
__declspec(dllexport) void func(unsigned short*) {}
```

Attempting to link these two modules will result in LNK4217. Compile the second sample with the import library of the first sample to resolve.
Attempting to link these two modules will result in LNK4217. Compile the second sample with the import library of the first sample to resolve.

## See also

[Linker Tools Warning LNK4049](linker-tools-warning-lnk4049.md) \
[Linker Tools Warning LNK4286](linker-tools-warning-lnk4286.md) \
[dllexport, dllimport](../../cpp/dllexport-dllimport.md)
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
---
title: "Linker Tools Warning LNK4286"
ms.date: "04/09/2019"
ms.date: "04/15/2019"
f1_keywords: ["LNK4286"]
helpviewer_keywords: ["LNK4286"]
---
Expand All @@ -23,5 +23,5 @@ For more information on import and export data declarations, see [dllexport, dll
## See also

[Linker Tools Warning LNK4049](linker-tools-warning-lnk4049.md) \
[Linker Tools Warning LNK4286](linker-tools-warning-lnk4286.md) \
[Linker Tools Warning LNK4217](linker-tools-warning-lnk4217.md) \
[dllexport, dllimport](../../cpp/dllexport-dllimport.md)