Applying the target Attribute to Multiple Declarations

This topic only applies to Intel® Many Integrated Core Architecture (Intel® MIC Architecture).

When you have several data and function declarations, rather than specifying each declaration with its own target attribute. you can enclose a group of data and function declarations between the push and pop variants of the offload_attribute pragma.

When offloaded code makes use of declarations from C standard headers, Intel® Threading Building Blocks (Intel® TBB), Intel® Cilk™ Plus, or user-written #include declarations, you must enclose those declarations within the offload_attribute pragma, with a specified target-name corresponding to the offload model under which the declarations are used.

Note

The code represented by the external routine in the header files must exist on the coprocessor either as a system library or as a user library that can run on Intel® MIC Architecture.

Enclose the calls to the include files when offloading using a pragma as follows:

#pragma offload_attribute(push, target(mic))
...
#pragma offload_attribute(pop) 

Enclose the calls to the include files when offloading using shared virtual memory as follows:

#pragma offload_attribute(push, _Cilk_shared)
...
#pragma offload_attribute(pop)

You can only use functions and data under a single offload model within your program, so any include file you call can only be marked for use under a single offload model. Consequently, you cannot use the keyword _Cilk_offload with any include file enclosed between #pragma offload_attribute(push, target(mic)) and #pragma offload_attribute(pop).

Conversely, you cannot use the the #pragma offload statement with any include file enclosed between #pragma offload_attribute(push, _Cilk_shared) and #pragma offload_attribute(pop)

Note

There is one important exception for the virtual shared memory model: Do not enclose C standard headers within #pragma offload_attribute(push, _Cilk_shared) and #pragma offload_attribute(pop). Such decoration is unnecessary and may lead to undefined symbols at run-time.

Example

The functions function_1 and function_2 each need the target attribute, as do all the declarations within some include files. It is convenient to put the offload_attribute pragma around all those declarations.

#pragma offload_attribute(push,target(mic))
#include <stdio.h>
#include <math.h>

void function_1();
void function_2();
#pragma offload_attribute(pop)


int main()
{
        #pragma offload target(mic)
        {
                function_1();
                printf("...");
        }
        ...
        #pragma offload target(mic)
        function_2();
        ...
}

Optimization Notice

Intel's compilers may or may not optimize to the same degree for non-Intel microprocessors for optimizations that are not unique to Intel microprocessors. These optimizations include SSE2, SSE3, and SSSE3 instruction sets and other optimizations. Intel does not guarantee the availability, functionality, or effectiveness of any optimization on microprocessors not manufactured by Intel. Microprocessor-dependent optimizations in this product are intended for use with Intel microprocessors. Certain optimizations not specific to Intel microarchitecture are reserved for Intel microprocessors. Please refer to the applicable product User and Reference Guides for more information regarding the specific instruction sets covered by this notice.

Notice revision #20110804

For more complete information about compiler optimizations, see our Optimization Notice.