Declarations of functions and variables in the mic

Source: Internet
Author: User

C++/C use

__declspec (target (MIC)) function or variable declaration

Or

__ATTRIBUTE__ ((Target (MIC))) function or variable declaration

Examples are as follows:

intvoid func ();

Note here that there are two underscores before and after attribute, the sample code is as follows:

#include <stdlib.h>#include<stdio.h>#include<string.h>#defineLEN 5__attribute__ ((Target (MIC)))voidFuncheck (inth) {#ifdef __mic__ printf ("Index on MIC:%d \ n", h); #elseprintf ("Index on CPU:%d \ n", h); #endif    }intMainintargcint**argv) {    inti; #pragmaOffload Target (MIC) for(i=0; i<len;i++) {Funcheck (i); }    return 0;}

Before and after the mic is also two underline, this code __mic__ is a macro definition provided by the mic, this macro definition is used to check whether the program runs on the device side, that is, the mic side, it is important to note that this definition can not be checked in the offload code snippet!

Compiling icc-o Demo demo.c

Execution ./demo

The results are as follows:

Index on mic:0
Index on Mic:1
Index on Mic:2
Index on Mic:3
Index on Mic:4

Declarations of functions and variables in the mic

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.