C++ 英特尔c&x2B+;编译器:如何在宏定义/定义中编译和链接openmp pragma?
我有一个在宏定义中使用pragma的简单代码。使用QtMinGW just fine,代码编译和运行良好C++ 英特尔c&x2B+;编译器:如何在宏定义/定义中编译和链接openmp pragma?,c++,openmp,intel,icc,C++,Openmp,Intel,Icc,我有一个在宏定义中使用pragma的简单代码。使用QtMinGW just fine,代码编译和运行良好 #include <omp.h> #include <stdio.h> #define NUMEL 1024 #define OMP_PARALLEL _Pragma("omp parallel") #define OMP_FOR _Pragma("omp for") #define main_func(par)
#include <omp.h>
#include <stdio.h>
#define NUMEL 1024
#define OMP_PARALLEL _Pragma("omp parallel")
#define OMP_FOR _Pragma("omp for")
#define main_func(par) \
int main(){ \
int a[NUMEL]; \
OMP_PARALLEL \
{ \
int i; \
OMP_FOR \
for (i=0; i<NUMEL; i++){ \
printf("THRD : %d \n", omp_get_thread_num()); \
a[i] = tan(i*2); \
} \
} \
return 0; \
}
main_func(par)
通过反复尝试,我注意到如果添加;在下面这样的行的末尾,错误变为链接错误:
#define OMP_PARALLEL _Pragma("omp parallel");
#define OMP_FOR _Pragma("omp for");
链接错误
任何评论都将不胜感激。在国际商会论坛上的一些问答之后,结果是
#define OMP_PARALLEL __pragma(omp parallel)
#define OMP_FOR __pragma(omp for)
我希望它能帮助别人。。。我留下了测试代码和makefile,所以您也可以自己尝试。我花了三天时间才把这件事弄清楚
如果你觉得我的Q/A有帮助,请随意投票
#include <omp.h>
#include <stdio.h>
#define NUMEL 1024
#define OMP_PARALLEL __pragma(omp parallel)
#define OMP_FOR __pragma(omp for)
#define main_func(par) \
int main(){ \
int a[NUMEL]; \
OMP_PARALLEL \
{ \
int i; \
OMP_FOR \
for (i=0; i<NUMEL; i++){ \
printf("THRD : %d \n", omp_get_thread_num()); \
a[i] = tan(i*2); \
} \
} \
return 0; \
}
main_func(par)
int main2(){
int a[NUMEL];
#pragma omp parallel
{
int i;
#pragma omp for
for (i=0; i<NUMEL; i++){
printf("THRD : %d \n", omp_get_thread_num());
a[i] = tan(i*2);
}
}
return 0;
}
#包括
#包括
#定义NUMEL 1024
#定义OMP_PARALLEL(OMP并行)pragma(OMP并行)
#定义OMP_FOR u pragma(OMP FOR)
#定义主功能(par)\
int main(){\
int a[NUMEL]\
OMP_并行\
{ \
int i\
奥姆普\
对于(i=0;iYou可能希望-march=native
,如果您要在构建的同一台机器上运行,则启用它所拥有的ISA扩展。而不仅仅是基线SSE2。我认为ICL在默认情况下启用优化(与其他编译器不同),因此省略-O3
。
#define OMP_PARALLEL __pragma(omp parallel)
#define OMP_FOR __pragma(omp for)
#include <omp.h>
#include <stdio.h>
#define NUMEL 1024
#define OMP_PARALLEL __pragma(omp parallel)
#define OMP_FOR __pragma(omp for)
#define main_func(par) \
int main(){ \
int a[NUMEL]; \
OMP_PARALLEL \
{ \
int i; \
OMP_FOR \
for (i=0; i<NUMEL; i++){ \
printf("THRD : %d \n", omp_get_thread_num()); \
a[i] = tan(i*2); \
} \
} \
return 0; \
}
main_func(par)
int main2(){
int a[NUMEL];
#pragma omp parallel
{
int i;
#pragma omp for
for (i=0; i<NUMEL; i++){
printf("THRD : %d \n", omp_get_thread_num());
a[i] = tan(i*2);
}
}
return 0;
}
PROJECT_ROOT = $(dir $(abspath $(lastword $(MAKEFILE_LIST))))
CXX=icl
CC=icl
LD =xilink
LIBDIR=Debug/lib/
OBJDIR=Debug/obj/
CFLAGS=/Qopenmp
LDFLAGS= /nodefaultlib:vcomp libiomp5md.lib
OBJS = $(OBJDIR)test_omp.obj
all: test_omp
test_omp: $(OBJS)
$(LD) $(LDFLAGS) $(OBJS) -Fe:test_omp.exe
$(OBJDIR)%.obj: $(PROJECT_ROOT)%.cpp
$(CXX) -c $(CFLAGS) $(CXXFLAGS) $(CPPFLAGS) -Fo:$@ $<
$(OBJDIR)%.obj: $(PROJECT_ROOT)%.c
$(CC) $(CFLAGS) $(CPPFLAGS) -Fo:$@ -c $<
clean:
rm -fr test_icl $(OBJS) test_omp.exe