如何在makefile中使用OpenMP?

问题描述 投票:-1回答:1

我正在使用Makefile来设置mo代码所需的环境。我正在学习并行化,并感谢您的帮助。

# The list of packages used by the macro:
USED_PKGS = xAODRootAccess xAODTruth xAODJet xAODMissingET
test: test.o
    `root-config --ld` -o $@ `root-config --libs` \
        -L$(ROOTCOREDIR)/lib `rc get_ldflags $(USED_PKGS)` $^
clean:
    rm -f test.o
    rm -f test
.SUFFIXES: .C .o
.C.o:
    `root-config --cxx` -c -o $@ `root-config --cflags` \
        -I$(ROOTCOREDIR)/include `rc get_cxxflags $(USED_PKGS)` $<

我已经安装了OpenMPI并将其添加到PATH和LD_LIBRARY_PATH。

我的代码非常简单,只想根据Makefile进行检查:

int main()
{
    int i;
#pragma omp parallel for
    for ( i = 0; i < 1e8; i++ )
    {
        int y = 2*i;
    }
}
c++ gcc makefile g++ openmp
1个回答
0
投票

好的,所以我在玩完之后想出来了。如果其他人正在寻找相同的东西,Makefile应该是这样的:

# The list of packages used by the macro:
USED_PKGS = xAODRootAccess xAODTruth xAODJet xAODMissingET
test: test.o
    `root-config --ld` -o $@ `root-config --libs` \
        -L$(ROOTCOREDIR)/lib `rc get_ldflags $(USED_PKGS)` $^ -fopenmp
clean:
    rm -f test.o
    rm -f test
.SUFFIXES: .C .o
.C.o:
    `root-config --cxx` -c -o $@ `root-config --cflags` \
        -I$(ROOTCOREDIR)/include `rc get_cxxflags $(USED_PKGS)` $< -fopenmp

-fopenmp应添加到两行中。

© www.soinside.com 2019 - 2024. All rights reserved.